78 lines
2.1 KiB
TypeScript
78 lines
2.1 KiB
TypeScript
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
|
|
import { ucapAnimations } from '../animations';
|
|
|
|
import { FileViewerType } from '../types/file-viewer.type';
|
|
import { FileType, FileInfo, isSound } from '@ucap-webmessenger/protocol-file';
|
|
import { FileDownloadItem } from '@ucap-webmessenger/api';
|
|
import { SelectFileInfo } from '../models/select-file-info';
|
|
|
|
@Component({
|
|
selector: 'ucap-file-viewer',
|
|
templateUrl: './file-viewer.component.html',
|
|
styleUrls: ['./file-viewer.component.scss'],
|
|
animations: ucapAnimations
|
|
})
|
|
export class FileViewerComponent implements OnInit {
|
|
@Input()
|
|
set fileInfo(v: { fileInfos: FileInfo[]; selectFileInfo: SelectFileInfo }) {
|
|
this._fileInfo = v;
|
|
|
|
this.currentFileInfo = v.fileInfos.find(
|
|
f => f.sentMessageJson.attachmentSeq === v.selectFileInfo.attachmentSeq
|
|
);
|
|
}
|
|
// tslint:disable-next-line: variable-name
|
|
_fileInfo: {
|
|
fileInfos: FileInfo[];
|
|
selectFileInfo: SelectFileInfo;
|
|
};
|
|
|
|
@Input()
|
|
fileDownloadUrl: (attachmentSeq: number) => string;
|
|
|
|
@Output()
|
|
download = new EventEmitter<{
|
|
attachmentSeq?: number;
|
|
downloadUrl?: string;
|
|
fileName: string;
|
|
fileDownloadItem: FileDownloadItem;
|
|
}>();
|
|
|
|
@Output()
|
|
closed = new EventEmitter<void>();
|
|
|
|
currentFileInfo: FileInfo;
|
|
FileViewerType = FileViewerType;
|
|
|
|
constructor() {}
|
|
|
|
ngOnInit() {}
|
|
|
|
detectFileViewerType(fileInfo: FileInfo): FileViewerType {
|
|
switch (fileInfo.type) {
|
|
case FileType.Image:
|
|
return FileViewerType.Image;
|
|
case FileType.Sound:
|
|
return FileViewerType.Sound;
|
|
case FileType.Video:
|
|
return FileViewerType.Video;
|
|
default:
|
|
if (isSound(fileInfo)) {
|
|
return FileViewerType.Sound;
|
|
}
|
|
return FileViewerType.Binary;
|
|
}
|
|
}
|
|
onDownload(fileDownloadItem: FileDownloadItem): void {
|
|
this.download.emit({
|
|
attachmentSeq: this.currentFileInfo.sentMessageJson.attachmentSeq,
|
|
fileName: this.currentFileInfo.sentMessageJson.fileName,
|
|
fileDownloadItem
|
|
});
|
|
}
|
|
|
|
onClosedViewer(): void {
|
|
this.closed.emit();
|
|
}
|
|
}
|