From 99ff8ac6cd89ab81dc05e4ba0c87b46da4d01a2b Mon Sep 17 00:00:00 2001 From: Timo Date: Mon, 1 Feb 2021 15:34:05 +0200 Subject: [PATCH] Async Download --- apps/red-ui/src/app/app.module.ts | 2 - .../file-actions/file-actions.component.html | 12 - .../app/common/service/permissions.service.ts | 4 - .../file-download-btn.component.html | 19 +- .../file-download-btn.component.ts | 63 +-- .../report-download-btn.component.html | 21 - .../report-download-btn.component.scss | 0 .../report-download-btn.component.ts | 55 --- .../file-preview-screen.component.html | 4 +- .../file-preview-screen.component.ts | 35 +- .../project-listing-actions.component.html | 6 +- .../bulk-actions/bulk-actions.component.ts | 4 +- .../project-overview-screen.component.html | 3 - .../project-overview-screen.component.ts | 4 - .../red-ui/src/app/state/app-state.service.ts | 18 - .../download-status-overlay.component.html | 36 +- .../download-status-overlay.component.ts | 27 +- .../upload-download/file-download.service.ts | 140 +++---- apps/red-ui/src/assets/i18n/de.json | 385 ++++++++++++++---- apps/red-ui/src/assets/i18n/en.json | 18 +- .../src/assets/styles/red-page-layout.scss | 15 +- libs/red-cache/src/lib/caches/cache-utils.ts | 2 +- .../src/lib/api/downloadController.service.ts | 7 +- 23 files changed, 444 insertions(+), 436 deletions(-) delete mode 100644 apps/red-ui/src/app/components/buttons/report-download-btn/report-download-btn.component.html delete mode 100644 apps/red-ui/src/app/components/buttons/report-download-btn/report-download-btn.component.scss delete mode 100644 apps/red-ui/src/app/components/buttons/report-download-btn/report-download-btn.component.ts diff --git a/apps/red-ui/src/app/app.module.ts b/apps/red-ui/src/app/app.module.ts index 8e0c34413..5bdc49032 100644 --- a/apps/red-ui/src/app/app.module.ts +++ b/apps/red-ui/src/app/app.module.ts @@ -94,7 +94,6 @@ import { RulesScreenComponent } from './screens/admin/rules-screen/rules-screen. import { WatermarkScreenComponent } from './screens/admin/watermark-screen/watermark-screen.component'; import { PdfViewerScreenComponent } from './screens/pdf-viewer-screen/pdf-viewer-screen.component'; import { HtmlDebugScreenComponent } from './screens/html-debug-screen/html-debug-screen.component'; -import { ReportDownloadBtnComponent } from './components/buttons/report-download-btn/report-download-btn.component'; import { ProjectListingActionsComponent } from './screens/project-listing-screen/project-listing-actions/project-listing-actions.component'; import { HasScrollbarDirective } from './utils/has-scrollbar.directive'; import { RuleSetsListingScreenComponent } from './screens/admin/rule-sets-listing-screen/rule-sets-listing-screen.component'; @@ -352,7 +351,6 @@ const matImports = [ WatermarkScreenComponent, PdfViewerScreenComponent, HtmlDebugScreenComponent, - ReportDownloadBtnComponent, FileDownloadBtnComponent, ProjectListingActionsComponent, RuleSetActionsComponent, diff --git a/apps/red-ui/src/app/common/file-actions/file-actions.component.html b/apps/red-ui/src/app/common/file-actions/file-actions.component.html index d4e5d31df..c79677b24 100644 --- a/apps/red-ui/src/app/common/file-actions/file-actions.component.html +++ b/apps/red-ui/src/app/common/file-actions/file-actions.component.html @@ -39,20 +39,8 @@ > - - - - - - -
-
-
-
-
-
-
-
-
-
diff --git a/apps/red-ui/src/app/components/buttons/file-download-btn/file-download-btn.component.ts b/apps/red-ui/src/app/components/buttons/file-download-btn/file-download-btn.component.ts index 2bffeb302..c51f4c463 100644 --- a/apps/red-ui/src/app/components/buttons/file-download-btn/file-download-btn.component.ts +++ b/apps/red-ui/src/app/components/buttons/file-download-btn/file-download-btn.component.ts @@ -1,12 +1,10 @@ -import { ChangeDetectorRef, Component, EventEmitter, Input, Output } from '@angular/core'; +import { ChangeDetectorRef, Component, Input } from '@angular/core'; import { PermissionsService } from '../../../common/service/permissions.service'; import { ProjectWrapper } from '../../../state/model/project.wrapper'; import { FileStatusWrapper } from '../../../screens/file/model/file-status.wrapper'; import { FileManagementControllerService } from '@redaction/red-ui-http'; import { StatusOverlayService } from '../../../upload-download/status-overlay.service'; import { FileDownloadService } from '../../../upload-download/file-download.service'; -import { PdfViewerDataService } from '../../../screens/file/service/pdf-viewer-data.service'; -import { saveAs } from 'file-saver'; import { UserPreferenceService } from '../../../common/service/user-preference.service'; export type MenuState = 'OPEN' | 'CLOSED'; @@ -23,8 +21,6 @@ export class FileDownloadBtnComponent { @Input() type: 'default' | 'primary' | 'warn' | 'dark-bg' = 'default'; @Input() tooltipClass: string; - @Output() menuStateChanged = new EventEmitter(); - constructor( private readonly _permissionsService: PermissionsService, private readonly _fileDownloadService: FileDownloadService, @@ -34,16 +30,7 @@ export class FileDownloadBtnComponent { private readonly _fileManagementControllerService: FileManagementControllerService ) {} - openMenu($event: MouseEvent) { - $event.stopPropagation(); - this.menuStateChanged.emit('OPEN'); - } - - onMenuClosed() { - this.menuStateChanged.emit('CLOSED'); - } - - get canDownloadRedactedFiles() { + get canDownloadFiles() { if (Array.isArray(this.file)) { return this.file.reduce((acc, file) => acc && this._permissionsService.canDownloadRedactedFile(file), true); } else { @@ -51,48 +38,12 @@ export class FileDownloadBtnComponent { } } - downloadRedactedFilesPreview($event: MouseEvent) { - $event.preventDefault(); - if (Array.isArray(this.file)) { - // Bulk Download - this._fileDownloadService.downloadProjectFiles( - this.file.map((file) => file.fileId), - this.project, - 'PREVIEW' - ); + downloadFiles($event: MouseEvent) { + $event.stopPropagation(); + // Bulk Download + this._fileDownloadService.downloadFiles(Array.isArray(this.file) ? this.file : [this.file], this.project).subscribe((data) => { this._statusOverlayService.openDownloadStatusOverlay(); this._changeDetectorRef.detectChanges(); - } else { - this._fileManagementControllerService - .downloadPreviewFile(this.file.projectId, this.file.fileId, true, this.file.lastProcessed, 'body') - .subscribe((data) => saveAs(data, (this.file).filename)); - } - } - - downloadRedactedFiles($event: MouseEvent) { - $event.preventDefault(); - if (Array.isArray(this.file)) { - // Bulk Download - this._fileDownloadService.downloadProjectFiles( - this.file.map((file) => file.fileId), - this.project, - 'REDACTED' - ); - this._statusOverlayService.openDownloadStatusOverlay(); - this._changeDetectorRef.detectChanges(); - } else { - // this._singleFileDownloadService.loadFile('REDACTED', this.file).subscribe((data) => saveAs(data, (this.file).filename)); - } - } - - get canDownloadFlatRedactedFile() { - return this._userPreferencesService.areDevFeaturesEnabled && !Array.isArray(this.file); - } - - downloadFlatRedactedFiles($event: MouseEvent) { - $event.preventDefault(); - // this._singleFileDownloadService - // .loadFile('FLAT_REDACTED', this.file) - // .subscribe((data) => saveAs(data, (this.file).filename)); + }); } } diff --git a/apps/red-ui/src/app/components/buttons/report-download-btn/report-download-btn.component.html b/apps/red-ui/src/app/components/buttons/report-download-btn/report-download-btn.component.html deleted file mode 100644 index 291c375e2..000000000 --- a/apps/red-ui/src/app/components/buttons/report-download-btn/report-download-btn.component.html +++ /dev/null @@ -1,21 +0,0 @@ - -
- - -
-
-
-
-
-
-
diff --git a/apps/red-ui/src/app/components/buttons/report-download-btn/report-download-btn.component.scss b/apps/red-ui/src/app/components/buttons/report-download-btn/report-download-btn.component.scss deleted file mode 100644 index e69de29bb..000000000 diff --git a/apps/red-ui/src/app/components/buttons/report-download-btn/report-download-btn.component.ts b/apps/red-ui/src/app/components/buttons/report-download-btn/report-download-btn.component.ts deleted file mode 100644 index e8c3f18a8..000000000 --- a/apps/red-ui/src/app/components/buttons/report-download-btn/report-download-btn.component.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'; -import { PermissionsService } from '../../../common/service/permissions.service'; -import { AppStateService } from '../../../state/app-state.service'; -import { ProjectWrapper } from '../../../state/model/project.wrapper'; -import { FileStatusWrapper } from '../../../screens/file/model/file-status.wrapper'; -import { MatMenuTrigger } from '@angular/material/menu'; - -export type MenuState = 'OPEN' | 'CLOSED'; - -@Component({ - selector: 'redaction-report-download-btn', - templateUrl: './report-download-btn.component.html', - styleUrls: ['./report-download-btn.component.scss'] -}) -export class ReportDownloadBtnComponent implements OnInit { - @Input() project: ProjectWrapper; - @Input() file: FileStatusWrapper; - @Input() tooltipPosition: 'above' | 'below' | 'before' | 'after' = 'above'; - @Input() type: 'default' | 'primary' | 'warn' | 'dark-bg' = 'default'; - @Input() tooltipClass: string; - - @Output() menuStateChanged = new EventEmitter(); - @ViewChild('menuTrigger') menuTrigger: MatMenuTrigger; - - constructor(public readonly permissionsService: PermissionsService, private readonly _appStateService: AppStateService) {} - - ngOnInit(): void {} - - openMenu($event: MouseEvent) { - $event.stopPropagation(); - this.menuTrigger.openMenu(); - this.menuStateChanged.emit('OPEN'); - } - - onMenuClosed() { - this.menuStateChanged.emit('CLOSED'); - } - - get isApproved() { - if (this.file) { - return this.file.isApproved; - } else { - return this.project.allFilesApproved; - } - } - - downloadRedactionReport($event: MouseEvent, template: string) { - $event.preventDefault(); - if (this.file) { - this._appStateService.downloadFileRedactionReport(this.file, template); - } else { - this._appStateService.downloadRedactionReport(this.project, template); - } - } -} diff --git a/apps/red-ui/src/app/screens/file/file-preview-screen/file-preview-screen.component.html b/apps/red-ui/src/app/screens/file/file-preview-screen/file-preview-screen.component.html index ccf817548..d60fdc47e 100644 --- a/apps/red-ui/src/app/screens/file/file-preview-screen/file-preview-screen.component.html +++ b/apps/red-ui/src/app/screens/file/file-preview-screen/file-preview-screen.component.html @@ -1,4 +1,4 @@ -
+