diff --git a/apps/red-ui/src/app/upload-download/file-download.service.ts b/apps/red-ui/src/app/upload-download/file-download.service.ts index cfe71b196..d21882ae1 100644 --- a/apps/red-ui/src/app/upload-download/file-download.service.ts +++ b/apps/red-ui/src/app/upload-download/file-download.service.ts @@ -8,17 +8,20 @@ import { download } from '../utils/file-download-utils'; import { ProjectWrapper } from '../state/model/project.wrapper'; import { FileStatusWrapper } from '../screens/file/model/file-status.wrapper'; import { mergeMap, tap } from 'rxjs/operators'; +import { DownloadStatusWrapper } from './model/download-status.wrapper'; +import { AppStateService } from '../state/app-state.service'; @Injectable({ providedIn: 'root' }) export class FileDownloadService { - public downloads: DownloadStatus[] = []; - public pendingDownloads: DownloadStatus[] = []; + public downloads: DownloadStatusWrapper[] = []; + public pendingDownloads: DownloadStatusWrapper[] = []; private inProgressDownloads = new Set(); constructor( private readonly _applicationRef: ApplicationRef, + private readonly _appStateService: AppStateService, private readonly _downloadControllerService: DownloadControllerService, private readonly _translateService: TranslateService, private readonly _appConfigService: AppConfigService, @@ -48,10 +51,9 @@ export class FileDownloadService { private _getDownloadStatus() { return this._downloadControllerService.getDownloadStatus().pipe( tap((statusResponse) => { - this.downloads = statusResponse.downloadStatus; + this.downloads = statusResponse.downloadStatus.map((d) => new DownloadStatusWrapper(d)); this.downloads.forEach((d) => { if (!d.lastDownload && d.status === 'READY') { - this.inProgressDownloads.add(d.storageId); this.performDownload(d); } }); @@ -61,7 +63,9 @@ export class FileDownloadService { ); } - public performDownload(status: DownloadStatus) { + public performDownload(status: DownloadStatusWrapper) { + this.inProgressDownloads.add(status.storageId); + status.inProgress = true; this._downloadControllerService .downloadFile( { @@ -70,12 +74,17 @@ export class FileDownloadService { false, 'response' ) - .subscribe((response) => { - download(response, status.filename); - console.log('done'); - setTimeout(() => { + .subscribe( + (response) => { + download(response, status.filename); + setTimeout(() => { + this.inProgressDownloads.delete(status.storageId); + }, 1000); + }, + () => { this.inProgressDownloads.delete(status.storageId); - }, 1000); - }); + status.inProgress = false; + } + ); } } diff --git a/apps/red-ui/src/app/upload-download/model/download-status.wrapper.ts b/apps/red-ui/src/app/upload-download/model/download-status.wrapper.ts new file mode 100644 index 000000000..fe63d857f --- /dev/null +++ b/apps/red-ui/src/app/upload-download/model/download-status.wrapper.ts @@ -0,0 +1,40 @@ +import { DownloadDetails, DownloadStatus } from '@redaction/red-ui-http'; + +export class DownloadStatusWrapper { + inProgress: boolean; + displayName: string; + + constructor(private _downloadStatus: DownloadStatus) {} + + get creationDate() { + return this._downloadStatus.creationDate; + } + + get downloadDetails(): DownloadDetails { + return this._downloadStatus.downloadDetails; + } + + get filename() { + return this._downloadStatus.filename; + } + + get lastDownload() { + return this._downloadStatus.lastDownload; + } + + get mimeType() { + return this._downloadStatus.mimeType; + } + + get projectId() { + return this._downloadStatus.projectId; + } + + get status() { + return this._downloadStatus.status; + } + + get storageId() { + return this._downloadStatus.storageId; + } +} diff --git a/apps/red-ui/src/app/upload-download/model/project-download.model.ts b/apps/red-ui/src/app/upload-download/model/project-download.model.ts deleted file mode 100644 index d38651b24..000000000 --- a/apps/red-ui/src/app/upload-download/model/project-download.model.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { ProjectWrapper } from '../../state/model/project.wrapper'; - -export interface ProjectDownloadModel { - fileIds: string[]; - project: ProjectWrapper; - completed: boolean; - error: any; - type: 'REDACTED' | 'PREVIEW'; -}