diff --git a/projects/ucap-webmessenger-app/src/app/layouts/common/dialogs/file-viewer.dialog.component.html b/projects/ucap-webmessenger-app/src/app/layouts/common/dialogs/file-viewer.dialog.component.html index c9536eb9..759de027 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/common/dialogs/file-viewer.dialog.component.html +++ b/projects/ucap-webmessenger-app/src/app/layouts/common/dialogs/file-viewer.dialog.component.html @@ -4,5 +4,6 @@ [imageOnly]="imageOnly" [imageOnlyData]="imageOnlyData" (download)="onDownload($event)" + (saveAs)="onSaveAs($event)" (closed)="onClosedViewer()" > diff --git a/projects/ucap-webmessenger-app/src/app/layouts/common/dialogs/file-viewer.dialog.component.ts b/projects/ucap-webmessenger-app/src/app/layouts/common/dialogs/file-viewer.dialog.component.ts index 26666cbf..431352bb 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/common/dialogs/file-viewer.dialog.component.ts +++ b/projects/ucap-webmessenger-app/src/app/layouts/common/dialogs/file-viewer.dialog.component.ts @@ -7,7 +7,9 @@ import { DeviceType } from '@ucap-webmessenger/core'; import { FileDownloadItem } from '@ucap-webmessenger/api'; import { CommonApiService } from '@ucap-webmessenger/api-common'; import { AppFileService } from '@app/services/file.service'; -import { ImageOnlyDataInfo } from '@ucap-webmessenger/ui'; +import { ImageOnlyDataInfo, SnackBarService } from '@ucap-webmessenger/ui'; +import { UCAP_NATIVE_SERVICE, NativeService } from '@ucap-webmessenger/native'; +import { TranslateService } from '@ngx-translate/core'; export interface FileViewerDialogData { fileInfo: FileEventJson; @@ -46,6 +48,9 @@ export class FileViewerDialogComponent implements OnInit, OnDestroy { @Inject(MAT_DIALOG_DATA) public data: FileViewerDialogData, private commonApiService: CommonApiService, private appFileService: AppFileService, + private translateService: TranslateService, + private snackBarService: SnackBarService, + @Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService, private logger: NGXLogger ) { this.fileInfo = data.fileInfo; @@ -91,6 +96,47 @@ export class FileViewerDialogComponent implements OnInit, OnDestroy { fileDownloadUrl: this.downloadUrl }); } + onSaveAs(fileDownloadItem: FileDownloadItem): void { + this.nativeService + .selectSaveFilePath(this.fileInfo.fileName) + .then(result => { + if (!result) { + return; + } + + if (result.canceled) { + // this.snackBarService.open( + // this.translateService.instant('common.file.results.canceled'), + // this.translateService.instant('common.file.errors.label'), + // { + // duration: 1000 + // } + // ); + } else { + this.saveFile(fileDownloadItem, result.filePath); + } + }) + .catch(reason => { + this.snackBarService.open( + this.translateService.instant('common.file.errors.failToSpecifyPath'), + this.translateService.instant('common.file.errors.label') + ); + }); + } + + saveFile(fileDownloadItem: FileDownloadItem, savePath?: string) { + this.appFileService.fileTalkDownlod({ + req: { + userSeq: this.userSeq, + deviceType: this.deviceType, + token: this.token, + attachmentsSeq: this.fileInfo.attachmentSeq, + fileDownloadItem + }, + fileName: this.fileInfo.fileName, + savePath + }); + } onClosedViewer(): void { this.dialogRef.close(); diff --git a/projects/ucap-webmessenger-ui/src/lib/components/file-viewer.component.html b/projects/ucap-webmessenger-ui/src/lib/components/file-viewer.component.html index 48e45703..a9f80822 100644 --- a/projects/ucap-webmessenger-ui/src/lib/components/file-viewer.component.html +++ b/projects/ucap-webmessenger-ui/src/lib/components/file-viewer.component.html @@ -16,6 +16,7 @@ [imageOnly]="imageOnly" [imageOnlyData]="imageOnlyData" (download)="onDownload($event)" + (saveAs)="onSaveAs($event)" (closed)="onClosedViewer()" > diff --git a/projects/ucap-webmessenger-ui/src/lib/components/file-viewer.component.ts b/projects/ucap-webmessenger-ui/src/lib/components/file-viewer.component.ts index 2bcab9b6..f58d1dac 100644 --- a/projects/ucap-webmessenger-ui/src/lib/components/file-viewer.component.ts +++ b/projects/ucap-webmessenger-ui/src/lib/components/file-viewer.component.ts @@ -26,6 +26,8 @@ export class FileViewerComponent implements OnInit { @Output() download = new EventEmitter(); + @Output() + saveAs = new EventEmitter(); @Output() closed = new EventEmitter(); @@ -58,6 +60,9 @@ export class FileViewerComponent implements OnInit { onDownload(fileDownloadItem: FileDownloadItem): void { this.download.emit(fileDownloadItem); } + onSaveAs(fileDownloadItem: FileDownloadItem): void { + this.saveAs.emit(fileDownloadItem); + } onClosedViewer(): void { this.closed.emit(); diff --git a/projects/ucap-webmessenger-ui/src/lib/components/file-viewer/binary-viewer.component.html b/projects/ucap-webmessenger-ui/src/lib/components/file-viewer/binary-viewer.component.html index 1f7d40a4..cda93e72 100644 --- a/projects/ucap-webmessenger-ui/src/lib/components/file-viewer/binary-viewer.component.html +++ b/projects/ucap-webmessenger-ui/src/lib/components/file-viewer/binary-viewer.component.html @@ -44,6 +44,31 @@ /> + + diff --git a/projects/ucap-webmessenger-ui/src/lib/components/file-viewer/binary-viewer.component.scss b/projects/ucap-webmessenger-ui/src/lib/components/file-viewer/binary-viewer.component.scss index 3385ef7e..a5762dba 100644 --- a/projects/ucap-webmessenger-ui/src/lib/components/file-viewer/binary-viewer.component.scss +++ b/projects/ucap-webmessenger-ui/src/lib/components/file-viewer/binary-viewer.component.scss @@ -60,5 +60,10 @@ margin: 30px; color: #ffffff; } + .btn-group { + button { + margin: 0 5px; + } + } } } diff --git a/projects/ucap-webmessenger-ui/src/lib/components/file-viewer/binary-viewer.component.ts b/projects/ucap-webmessenger-ui/src/lib/components/file-viewer/binary-viewer.component.ts index ab2b655a..9d449a99 100644 --- a/projects/ucap-webmessenger-ui/src/lib/components/file-viewer/binary-viewer.component.ts +++ b/projects/ucap-webmessenger-ui/src/lib/components/file-viewer/binary-viewer.component.ts @@ -18,6 +18,8 @@ export class BinaryViewerComponent implements OnInit { @Output() download = new EventEmitter(); + @Output() + saveAs = new EventEmitter(); @Output() closed = new EventEmitter(); @@ -33,6 +35,11 @@ export class BinaryViewerComponent implements OnInit { this.download.emit(this.fileDownloadItem); } + onClickSaveAs(): void { + this.fileDownloadItem = new FileDownloadItem(); + this.saveAs.emit(this.fileDownloadItem); + } + onClickClose(): void { this.closed.emit(); } diff --git a/projects/ucap-webmessenger-ui/src/lib/components/file-viewer/image-viewer.component.html b/projects/ucap-webmessenger-ui/src/lib/components/file-viewer/image-viewer.component.html index e9124ace..edc4f2ae 100644 --- a/projects/ucap-webmessenger-ui/src/lib/components/file-viewer/image-viewer.component.html +++ b/projects/ucap-webmessenger-ui/src/lib/components/file-viewer/image-viewer.component.html @@ -136,6 +136,32 @@ /> + + +