Skip to content

Commit

Permalink
DSS-770: FE: Add downloadable error file to business licence upload h…
Browse files Browse the repository at this point in the history
…istory
  • Loading branch information
OleksandrBohuslavskyi committed Sep 6, 2024
1 parent fdd9d24 commit 119cbda
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 6 deletions.
9 changes: 8 additions & 1 deletion frontend/src/app/common/services/business-licence.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpClient } from '@angular/common/http';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable, of } from 'rxjs';
import { environment } from '../../../environments/environment';
Expand All @@ -7,6 +7,8 @@ import { environment } from '../../../environments/environment';
providedIn: 'root'
})
export class BusinessLicenceService {
textHeaders = new HttpHeaders().set('Content-Type', 'text/plain; charset=utf-8');

constructor(private httpClient: HttpClient) { }

getUploadHistory(
Expand All @@ -29,6 +31,11 @@ export class BusinessLicenceService {
return this.httpClient.get<any>(url);
}

downloadErrors(id: number): Observable<any> {
return this.httpClient.get<any>(`${environment.API_HOST}/rentallistingreports/uploads/${id}/errorfile`,
{ headers: this.textHeaders, responseType: 'text' as 'json' });
}

uploadFile(file: any, orgId: number): Observable<any> {
const formData = new FormData();
formData.append('organizationId', orgId.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ export class BulkComplianceNoticeComponent implements OnInit {
}

onListingSelected(e: any): void {
console.log(e);
if (e.checked) {
this.selectedListings = this.listings.filter(l => l.listingStatusType !== 'I');
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ export class BulkTakedownRequestComponent implements OnInit {
}

onListingSelected(e: any): void {
console.log(e);
if (e.checked) {
this.selectedListings = this.listings.filter(l => l.listingStatusType !== 'I');
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ export class ExportListingsComponent implements OnInit {
this.loaderService.loadingStart();
this.listingService.getJurisdictions().subscribe({
next: (jurisdictions) => {
console.log(jurisdictions);

if (jurisdictions) {
this.jurisdictions = jurisdictions;
this.dateLastUpdated = this.jurisdictions[0].updDtm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
<i class="pi pi-angle-up"
*ngIf="this.sort && this.sort.prop === 'total' && this.sort.dir === 'asc'"></i>
</th>
<th class="sortable-header" [class.sorted]="this.sort && this.sort.prop === 'errors'"
(click)="onSort('errors')">
Errors
<i class="pi pi-angle-down"
*ngIf="this.sort && this.sort.prop === 'errors' && this.sort.dir === 'desc'"></i>
<i class="pi pi-angle-up"
*ngIf="this.sort && this.sort.prop === 'errors' && this.sort.dir === 'asc'"></i>
</th>
<th class="sortable-header" [class.sorted]="this.sort && this.sort.prop === 'updDtm'"
(click)="onSort('updDtm')">
Upload Date
Expand Down Expand Up @@ -74,6 +82,17 @@
<ng-template #pending><span class="state-pending">{{uploadHistory.status}}</span></ng-template>
</td>
<td>{{ uploadHistory.total }}</td>
<td>

<button *ngIf="uploadHistory.errors>0; else zero"
[id]="'downloadErrors_'+uploadHistory.uploadDeliveryId" pButton
class="p-button-link zero-padding"
(click)="onDownloadErrors(uploadHistory.uploadDeliveryId,uploadHistory.organizationNm,uploadHistory.reportPeriodYM)">{{uploadHistory.errors
|| '-'}}&nbsp;
<i class="pi pi-download" *ngIf="uploadHistory.errors>0"></i></button>
<ng-template #zero>{{0}}</ng-template>

</td>
<td>{{ uploadHistory.updDtm |date:'YYYY-MM-dd' }}</td>
<td>{{ uploadHistory.givenNm }} {{uploadHistory.familyNm}}</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,26 @@ export class UploadBusinessLicenseComponent implements OnInit {
}

onPageChange(e: any): void {
console.log(e.page + 1);
this.getHistoryRecords(e.page + 1);
}

onDownloadErrors(rowId: number, platform: string, date: string): void {
this.loaderService.loadingStart(' It may take several minutes to prepare your download file. Please do not close this tab until your download is complete.');
this.BLService.downloadErrors(rowId).subscribe({
next: (content) => {
const element = document.createElement('a');
element.setAttribute('href', `data:text/plain;charset=utf-8,${encodeURIComponent(content)}`);
element.setAttribute('download', `errors_${platform}_${date}.csv`);

element.click();
},
complete: () => {
this.loaderService.loadingEnd();
this.cd.detectChanges();
},
});
}

private getHistoryRecords(selectedPageNumber: number = 1): void {
this.loaderService.loadingStart();
this.BLService.getUploadHistory(
Expand Down

0 comments on commit 119cbda

Please sign in to comment.