diff --git a/apps/red-ui/src/app/modules/dossier/dialogs/edit-dossier-dialog/deleted-documents/edit-dossier-deleted-documents.component.ts b/apps/red-ui/src/app/modules/dossier/dialogs/edit-dossier-dialog/deleted-documents/edit-dossier-deleted-documents.component.ts index d9d3b8d88..f220b38a9 100644 --- a/apps/red-ui/src/app/modules/dossier/dialogs/edit-dossier-dialog/deleted-documents/edit-dossier-deleted-documents.component.ts +++ b/apps/red-ui/src/app/modules/dossier/dialogs/edit-dossier-dialog/deleted-documents/edit-dossier-deleted-documents.component.ts @@ -12,7 +12,7 @@ import { TableColumnConfig, TitleColors, } from '@iqser/common-ui'; -import { FileManagementControllerService, IFile } from '@redaction/red-ui-http'; +import { IFile } from '@redaction/red-ui-http'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import * as moment from 'moment'; import { ConfigService } from '@services/config.service'; @@ -22,6 +22,7 @@ import { distinctUntilChanged, map } from 'rxjs/operators'; import { DossiersDialogService } from '../../../services/dossiers-dialog.service'; import { AppStateService } from '@state/app-state.service'; import { FilesService } from '@services/entity-services/files.service'; +import { FileManagementService } from '../../../shared/services/file-management.service'; interface FileListItem extends IFile, IListable { readonly canRestore: boolean; @@ -55,7 +56,7 @@ export class EditDossierDeletedDocumentsComponent extends ListingComponent { const fileIds = files.map(f => f.fileId); - await this._fileManagementController.restoreFiles(fileIds, this.dossier.id).toPromise(); + await this._fileManagementService.restore(fileIds, this.dossier.id).toPromise(); this._removeFromList(fileIds); await this._appStateService.reloadActiveDossierFiles(); this.updateDossier.emit(); @@ -121,7 +122,7 @@ export class EditDossierDeletedDocumentsComponent extends ListingComponent f.fileId); - await this._fileManagementController.hardDeleteFile(this.dossier.id, fileIds).toPromise(); + await this._fileManagementService.hardDelete(this.dossier.id, fileIds).toPromise(); this._removeFromList(fileIds); this.updateDossier.emit(); } diff --git a/apps/red-ui/src/app/modules/dossier/screens/dossier-overview/components/bulk-actions/dossier-overview-bulk-actions.component.ts b/apps/red-ui/src/app/modules/dossier/screens/dossier-overview/components/bulk-actions/dossier-overview-bulk-actions.component.ts index 101d03029..b2fbcef85 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/dossier-overview/components/bulk-actions/dossier-overview-bulk-actions.component.ts +++ b/apps/red-ui/src/app/modules/dossier/screens/dossier-overview/components/bulk-actions/dossier-overview-bulk-actions.component.ts @@ -1,6 +1,6 @@ import { Component, EventEmitter, Input, Output } from '@angular/core'; import { AppStateService } from '@state/app-state.service'; -import { FileManagementControllerService, ReanalysisControllerService } from '@redaction/red-ui-http'; +import { ReanalysisControllerService } from '@redaction/red-ui-http'; import { PermissionsService } from '@services/permissions.service'; import { File } from '@models/file/file'; import { FileActionService } from '../../../../shared/services/file-action.service'; @@ -10,8 +10,9 @@ import { CircleButtonTypes, ConfirmationDialogInput, ListingService, LoadingServ import { TranslateService } from '@ngx-translate/core'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { Dossier } from '@state/model/dossier'; -import { LongPressEvent } from '../../../../../shared/directives/long-press.directive'; -import { UserPreferenceService } from '../../../../../../services/user-preference.service'; +import { LongPressEvent } from '@shared/directives/long-press.directive'; +import { UserPreferenceService } from '@services/user-preference.service'; +import { FileManagementService } from '../../../../shared/services/file-management.service'; @Component({ selector: 'redaction-dossier-overview-bulk-actions', @@ -29,7 +30,7 @@ export class DossierOverviewBulkActionsComponent { constructor( private readonly _appStateService: AppStateService, private readonly _dialogService: DossiersDialogService, - private readonly _fileManagementControllerService: FileManagementControllerService, + private readonly _fileManagementService: FileManagementService, private readonly _reanalysisControllerService: ReanalysisControllerService, private readonly _permissionsService: PermissionsService, private readonly _fileActionService: FileActionService, @@ -134,8 +135,8 @@ export class DossierOverviewBulkActionsComponent { }), async () => { this._loadingService.start(); - await this._fileManagementControllerService - .deleteFiles( + await this._fileManagementService + .delete( this.selectedFiles.map(item => item.fileId), this.dossier.dossierId, ) diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts index c4b0a10e0..334ab7739 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts @@ -28,7 +28,7 @@ import { PermissionsService } from '@services/permissions.service'; import { timer } from 'rxjs'; import { UserPreferenceService } from '@services/user-preference.service'; import { UserService } from '@services/user.service'; -import { FileManagementControllerService, FileStatus, List } from '@redaction/red-ui-http'; +import { FileStatus, List } from '@redaction/red-ui-http'; import { PdfViewerDataService } from '../../services/pdf-viewer-data.service'; import { download } from '@utils/file-download-utils'; import { ViewMode } from '@models/file/view-mode'; @@ -44,6 +44,7 @@ import { User } from '@models/user'; import { FilesService } from '@services/entity-services/files.service'; import { DossiersService } from '@services/entity-services/dossiers.service'; import { Dossier } from '@state/model/dossier'; +import { FileManagementService } from '../../shared/services/file-management.service'; import Annotation = Core.Annotations.Annotation; const ALL_HOTKEY_ARRAY = ['Escape', 'F', 'f']; @@ -99,7 +100,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni private readonly _fileDownloadService: PdfViewerDataService, private readonly _filesService: FilesService, private readonly _ngZone: NgZone, - private readonly _fileManagementControllerService: FileManagementControllerService, + private readonly _fileManagementService: FileManagementService, private readonly _loadingService: LoadingService, private readonly _filterService: FilterService, private readonly _translateService: TranslateService, @@ -515,8 +516,8 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni } downloadOriginalFile() { - this.addSubscription = this._fileManagementControllerService - .downloadOriginalFile(this.fileData.file.dossierId, this.fileId, true, this.fileData.file.cacheIdentifier, 'response') + this.addSubscription = this._fileManagementService + .downloadOriginalFile(this.fileData.file.dossierId, this.fileId, 'response', true, this.fileData.file.cacheIdentifier) .subscribe(data => { download(data, this.fileData.file.filename); }); diff --git a/apps/red-ui/src/app/modules/dossier/services/pdf-viewer-data.service.ts b/apps/red-ui/src/app/modules/dossier/services/pdf-viewer-data.service.ts index c49be6c66..0d954c037 100644 --- a/apps/red-ui/src/app/modules/dossier/services/pdf-viewer-data.service.ts +++ b/apps/red-ui/src/app/modules/dossier/services/pdf-viewer-data.service.ts @@ -1,17 +1,13 @@ import { Injectable } from '@angular/core'; import { forkJoin, Observable, of } from 'rxjs'; import { catchError, map, tap } from 'rxjs/operators'; -import { - FileManagementControllerService, - ManualRedactionControllerService, - RedactionLogControllerService, - ViewedPagesControllerService, -} from '@redaction/red-ui-http'; +import { ManualRedactionControllerService, RedactionLogControllerService, ViewedPagesControllerService } from '@redaction/red-ui-http'; import { FileDataModel } from '@models/file/file-data.model'; import { AppStateService } from '@state/app-state.service'; import { PermissionsService } from '@services/permissions.service'; import { File } from '@models/file/file'; import { DossiersService } from '@services/entity-services/dossiers.service'; +import { FileManagementService } from '../shared/services/file-management.service'; @Injectable() export class PdfViewerDataService { @@ -20,7 +16,7 @@ export class PdfViewerDataService { private readonly _dossiersService: DossiersService, private readonly _permissionsService: PermissionsService, private readonly _man: ManualRedactionControllerService, - private readonly _fileManagementControllerService: FileManagementControllerService, + private readonly _fileManagementService: FileManagementService, private readonly _redactionLogControllerService: RedactionLogControllerService, private readonly _viewedPagesControllerService: ViewedPagesControllerService, ) {} @@ -56,6 +52,6 @@ export class PdfViewerDataService { } downloadOriginalFile(file: File): Observable { - return this._fileManagementControllerService.downloadOriginalFile(file.dossierId, file.fileId, true, file.cacheIdentifier, 'body'); + return this._fileManagementService.downloadOriginalFile(file.dossierId, file.fileId, 'body', true, file.cacheIdentifier); } } diff --git a/apps/red-ui/src/app/modules/dossier/shared/components/file-actions/file-actions.component.ts b/apps/red-ui/src/app/modules/dossier/shared/components/file-actions/file-actions.component.ts index d0e1c506a..294e55f14 100644 --- a/apps/red-ui/src/app/modules/dossier/shared/components/file-actions/file-actions.component.ts +++ b/apps/red-ui/src/app/modules/dossier/shared/components/file-actions/file-actions.component.ts @@ -13,7 +13,7 @@ import { StatusBarConfig, Toaster, } from '@iqser/common-ui'; -import { FileManagementControllerService, FileStatus } from '@redaction/red-ui-http'; +import { FileStatus } from '@redaction/red-ui-http'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { UserService } from '@services/user.service'; import { filter } from 'rxjs/operators'; @@ -21,6 +21,7 @@ import { UserPreferenceService } from '@services/user-preference.service'; import { LongPressEvent } from '@shared/directives/long-press.directive'; import { FileActionService } from '../../services/file-action.service'; import { DossiersService } from '@services/entity-services/dossiers.service'; +import { FileManagementService } from '../../services/file-management.service'; @Component({ selector: 'redaction-file-actions', @@ -66,7 +67,7 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnInit, OnD private readonly _dialogService: DossiersDialogService, private readonly _fileActionService: FileActionService, private readonly _loadingService: LoadingService, - private readonly _fileManagementControllerService: FileManagementControllerService, + private readonly _fileManagementService: FileManagementService, private readonly _userService: UserService, private readonly _toaster: Toaster, private readonly _userPreferenceService: UserPreferenceService, @@ -135,8 +136,8 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnInit, OnD }), async () => { this._loadingService.start(); - await this._fileManagementControllerService - .deleteFiles([this.file.fileId], this.file.dossierId) + await this._fileManagementService + .delete([this.file.fileId], this.file.dossierId) .toPromise() .catch(error => { this._toaster.error(_('error.http.generic'), { params: error }); diff --git a/apps/red-ui/src/app/modules/dossier/shared/services/file-management.service.ts b/apps/red-ui/src/app/modules/dossier/shared/services/file-management.service.ts new file mode 100644 index 000000000..7197f8d35 --- /dev/null +++ b/apps/red-ui/src/app/modules/dossier/shared/services/file-management.service.ts @@ -0,0 +1,69 @@ +import { GenericService, List, QueryParam, RequiredParam, Validate } from '@iqser/common-ui'; +import { Injectable, Injector } from '@angular/core'; +import { HeadersConfiguration } from '../../../../../../../../libs/common-ui/src/lib/utils/headers-configuration'; +import { HttpHeaders, HttpResponse } from '@angular/common/http'; +import { Observable } from 'rxjs'; + +@Injectable({ + providedIn: 'root', +}) +export class FileManagementService extends GenericService { + constructor(protected readonly _injector: Injector) { + super(_injector, ''); + } + + @Validate() + delete(@RequiredParam() body: List, @RequiredParam() dossierId: string) { + return super._post(body, `delete/${dossierId}`); + } + + @Validate() + hardDelete(@RequiredParam() dossierId: string, @RequiredParam() fileIds: List) { + const queryParams = fileIds.map(id => ({ key: 'fileIds', value: id })); + return super.delete({}, `delete/hard-delete/${dossierId}`, queryParams); + } + + @Validate() + restore(@RequiredParam() body: List, @RequiredParam() dossierId: string) { + return this._post(body, `delete/restore/${dossierId}`); + } + + downloadOriginalFile(dossierId: string, fileId: string, observe?: 'body', inline?: boolean, indicator?: string): Observable; + downloadOriginalFile( + dossierId: string, + fileId: string, + observe?: 'response', + inline?: boolean, + indicator?: string, + ): Observable>; + @Validate() + downloadOriginalFile( + @RequiredParam() dossierId: string, + @RequiredParam() fileId: string, + observe: 'body' | 'response' = 'body', + inline?: boolean, + indicator?: string, + ) { + const queryParams: QueryParam[] = []; + if (inline) { + queryParams.push({ key: 'inline', value: inline }); + } + + if (indicator) { + queryParams.push({ key: 'indicator', value: indicator }); + } + + let headers = new HttpHeaders(); + const httpHeaderAcceptSelected = HeadersConfiguration.selectHeaderAccept(['*/*']); + if (httpHeaderAcceptSelected !== undefined) { + headers = headers.set('Accept', httpHeaderAcceptSelected); + } + + return this._http.request('get', `/download/original/${encodeURIComponent(dossierId)}/${encodeURIComponent(fileId)}`, { + responseType: 'blob', + params: this._queryParams(queryParams), + headers: headers, + observe: observe, + }); + } +} diff --git a/libs/common-ui b/libs/common-ui index 3d3af3988..c16328aa3 160000 --- a/libs/common-ui +++ b/libs/common-ui @@ -1 +1 @@ -Subproject commit 3d3af39881ddc9589042d913180e17ae62928da1 +Subproject commit c16328aa38adcbe68fd20cda2512308ccb8f36f0 diff --git a/libs/red-ui-http/src/lib/api.module.ts b/libs/red-ui-http/src/lib/api.module.ts index d3eadd865..83bfc5de8 100644 --- a/libs/red-ui-http/src/lib/api.module.ts +++ b/libs/red-ui-http/src/lib/api.module.ts @@ -1,7 +1,6 @@ import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core'; import { Configuration } from './configuration'; import { HttpClient } from '@angular/common/http'; -import { FileManagementControllerService } from './api/fileManagementController.service'; import { GeneralSettingsControllerService } from './api/generalSettingsController.service'; import { InfoControllerService } from './api/infoController.service'; import { LicenseReportControllerService } from './api/licenseReportController.service'; @@ -24,7 +23,6 @@ import { StatusReportControllerService } from './api/statusReportController.serv declarations: [], exports: [], providers: [ - FileManagementControllerService, GeneralSettingsControllerService, InfoControllerService, LicenseReportControllerService,