2019-12-04 07:37:19 +00:00
|
|
|
import { Component, OnInit, ViewChild, OnDestroy, Inject } from '@angular/core';
|
2019-11-12 05:08:14 +00:00
|
|
|
import { MatPaginator, MatTableDataSource } from '@angular/material';
|
|
|
|
import {
|
|
|
|
FileInfo,
|
|
|
|
FileDownloadInfo,
|
2019-12-04 07:37:19 +00:00
|
|
|
FileType
|
2019-11-12 05:08:14 +00:00
|
|
|
} from '@ucap-webmessenger/protocol-file';
|
|
|
|
import { Subscription, combineLatest } from 'rxjs';
|
|
|
|
import { Store, select } from '@ngrx/store';
|
|
|
|
|
|
|
|
import * as AppStore from '@app/store';
|
|
|
|
import * as ChatStore from '@app/store/messenger/chat';
|
|
|
|
import { tap, map } from 'rxjs/operators';
|
2019-11-12 08:10:11 +00:00
|
|
|
import {
|
|
|
|
Info,
|
|
|
|
EventJson,
|
2019-12-04 07:37:19 +00:00
|
|
|
FileEventJson
|
2019-11-12 08:10:11 +00:00
|
|
|
} from '@ucap-webmessenger/protocol-event';
|
|
|
|
import { FileUtil } from '@ucap-webmessenger/core';
|
|
|
|
import { CommonApiService } from '@ucap-webmessenger/api-common';
|
|
|
|
import { LoginResponse } from '@ucap-webmessenger/protocol-authentication';
|
|
|
|
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
|
|
|
|
import { KEY_LOGIN_RES_INFO } from '@app/types/login-res-info.type';
|
|
|
|
import { EnvironmentsInfo, KEY_ENVIRONMENTS_INFO } from '@app/types';
|
|
|
|
import { VersionInfo2Response } from '@ucap-webmessenger/api-public';
|
|
|
|
import { KEY_VER_INFO } from '@app/types/ver-info.type';
|
2019-12-04 07:37:19 +00:00
|
|
|
import { UCAP_NATIVE_SERVICE, NativeService } from '@ucap-webmessenger/native';
|
|
|
|
import { NGXLogger } from 'ngx-logger';
|
2019-11-12 05:08:14 +00:00
|
|
|
|
|
|
|
export interface FileInfoTotal {
|
|
|
|
info: FileInfo;
|
|
|
|
checkInfo: FileDownloadInfo[];
|
2019-11-12 08:10:11 +00:00
|
|
|
eventInfo?: Info<FileEventJson>;
|
2019-11-12 05:08:14 +00:00
|
|
|
}
|
2019-11-11 05:31:26 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-layout-chat-right-drawer-album-box',
|
|
|
|
templateUrl: './album-box.component.html',
|
2019-12-04 07:37:19 +00:00
|
|
|
styleUrls: ['./album-box.component.scss']
|
2019-11-11 05:31:26 +00:00
|
|
|
})
|
2019-11-12 05:08:14 +00:00
|
|
|
export class AlbumBoxComponent implements OnInit, OnDestroy {
|
2019-11-12 08:10:11 +00:00
|
|
|
filteredList: FileInfoTotal[] = [];
|
2019-11-12 05:08:14 +00:00
|
|
|
fileInfoTotal: FileInfoTotal[];
|
|
|
|
fileInfoList: FileInfo[];
|
|
|
|
fileInfoListSubscription: Subscription;
|
|
|
|
|
2019-11-12 08:10:11 +00:00
|
|
|
selectedFile: FileInfoTotal;
|
|
|
|
selectedFileList: FileInfoTotal[] = [];
|
|
|
|
|
|
|
|
loginRes: LoginResponse;
|
|
|
|
environmentsInfo: EnvironmentsInfo;
|
|
|
|
sessionVerinfo: VersionInfo2Response;
|
|
|
|
|
|
|
|
FileType = FileType;
|
|
|
|
currentTabIndex = 0;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private store: Store<any>,
|
|
|
|
private sessionStorageService: SessionStorageService,
|
2019-12-04 07:37:19 +00:00
|
|
|
private commonApiService: CommonApiService,
|
|
|
|
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService,
|
|
|
|
private loggger: NGXLogger
|
2019-11-12 08:10:11 +00:00
|
|
|
) {
|
|
|
|
this.loginRes = this.sessionStorageService.get<LoginResponse>(
|
|
|
|
KEY_LOGIN_RES_INFO
|
|
|
|
);
|
|
|
|
this.environmentsInfo = this.sessionStorageService.get<EnvironmentsInfo>(
|
|
|
|
KEY_ENVIRONMENTS_INFO
|
|
|
|
);
|
|
|
|
this.sessionVerinfo = this.sessionStorageService.get<VersionInfo2Response>(
|
|
|
|
KEY_VER_INFO
|
|
|
|
);
|
|
|
|
}
|
2019-11-12 05:08:14 +00:00
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.fileInfoListSubscription = combineLatest([
|
|
|
|
this.store.pipe(select(AppStore.MessengerSelector.RoomSelector.roomInfo)),
|
|
|
|
this.store.pipe(
|
|
|
|
select(AppStore.MessengerSelector.EventSelector.selectAllFileInfoList)
|
|
|
|
),
|
|
|
|
this.store.pipe(
|
|
|
|
select(
|
|
|
|
AppStore.MessengerSelector.EventSelector.selectAllFileInfoCheckList
|
|
|
|
)
|
2019-11-12 08:10:11 +00:00
|
|
|
),
|
|
|
|
this.store.pipe(
|
|
|
|
select(AppStore.MessengerSelector.EventSelector.selectAllInfoList)
|
2019-12-04 07:37:19 +00:00
|
|
|
)
|
2019-11-12 05:08:14 +00:00
|
|
|
])
|
|
|
|
.pipe(
|
|
|
|
tap(() => (this.fileInfoTotal = [])),
|
2019-11-12 08:10:11 +00:00
|
|
|
tap(([roomInfo, fileInfoList, fileInfoCheckList, eventList]) => {
|
2019-11-12 05:08:14 +00:00
|
|
|
this.fileInfoList = fileInfoList.filter(fileInfo => {
|
|
|
|
if (
|
|
|
|
fileInfo.roomSeq === roomInfo.roomSeq &&
|
|
|
|
(fileInfo.type === FileType.Image ||
|
|
|
|
fileInfo.type === FileType.Video)
|
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.fileInfoList.map(fileInfo => {
|
2019-11-12 08:10:11 +00:00
|
|
|
const events = eventList.filter(
|
|
|
|
event => event.seq === fileInfo.eventSeq
|
|
|
|
);
|
|
|
|
|
2019-11-12 05:08:14 +00:00
|
|
|
this.fileInfoTotal.push({
|
|
|
|
info: fileInfo,
|
|
|
|
checkInfo: fileInfoCheckList.filter(
|
|
|
|
checkInfo => checkInfo.seq === fileInfo.seq
|
2019-11-12 08:10:11 +00:00
|
|
|
),
|
|
|
|
eventInfo:
|
2019-12-04 07:37:19 +00:00
|
|
|
events.length > 0 ? (events[0] as Info<FileEventJson>) : null
|
2019-11-12 05:08:14 +00:00
|
|
|
});
|
|
|
|
});
|
2019-11-12 08:10:11 +00:00
|
|
|
|
|
|
|
this.onSelectedIndexChange(this.currentTabIndex);
|
2019-11-12 05:08:14 +00:00
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe();
|
|
|
|
}
|
2019-11-11 05:31:26 +00:00
|
|
|
|
2019-11-12 05:08:14 +00:00
|
|
|
ngOnDestroy(): void {
|
|
|
|
if (!!this.fileInfoListSubscription) {
|
|
|
|
this.fileInfoListSubscription.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
2019-11-12 08:10:11 +00:00
|
|
|
|
|
|
|
getExtention(name: string): string {
|
|
|
|
return FileUtil.getExtension(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
getImageUrl(fileInfo: FileInfoTotal): string {
|
|
|
|
return this.commonApiService.urlForFileTalkDownload(
|
|
|
|
{
|
|
|
|
userSeq: this.loginRes.userSeq,
|
|
|
|
deviceType: this.environmentsInfo.deviceType,
|
|
|
|
token: this.loginRes.tokenString,
|
2019-12-04 07:37:19 +00:00
|
|
|
attachmentsSeq: fileInfo.info.seq
|
2019-11-12 08:10:11 +00:00
|
|
|
},
|
|
|
|
this.sessionVerinfo.downloadUrl
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
onSelectedIndexChange(index: number) {
|
|
|
|
this.selectedFile = null;
|
|
|
|
this.currentTabIndex = index;
|
|
|
|
if (this.currentTabIndex === 0) {
|
|
|
|
// Image
|
|
|
|
this.filteredList = this.fileInfoTotal.filter(
|
|
|
|
fileInfo => fileInfo.info.type === FileType.Image
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
// Video
|
|
|
|
this.filteredList = this.fileInfoTotal.filter(
|
|
|
|
fileInfo => fileInfo.info.type === FileType.Video
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onClickImage(event: MouseEvent, fileInfo: FileInfoTotal) {
|
|
|
|
if (!!event) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.selectedFile = fileInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
getCheckItem(fileInfo: FileInfoTotal) {
|
|
|
|
if (this.selectedFileList) {
|
|
|
|
if (
|
|
|
|
this.selectedFileList.filter(
|
|
|
|
info => info.info.seq === fileInfo.info.seq
|
|
|
|
).length > 0
|
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onCheckItem(value: boolean, fileInfo: FileInfoTotal) {
|
|
|
|
if (value) {
|
|
|
|
this.onClickImage(undefined, fileInfo);
|
|
|
|
this.selectedFileList.push(fileInfo);
|
|
|
|
} else {
|
|
|
|
this.selectedFileList = this.selectedFileList.filter(
|
|
|
|
info => info.info.seq !== fileInfo.info.seq
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onClickDownload(fileInfo: FileInfoTotal) {
|
|
|
|
console.log(fileInfo);
|
|
|
|
}
|
2019-12-04 07:37:19 +00:00
|
|
|
|
|
|
|
onClickOpenDownloadFolder(): void {
|
|
|
|
this.nativeService
|
|
|
|
.openDefaultDownloadFolder()
|
|
|
|
.then(result => {
|
|
|
|
if (!!result) {
|
|
|
|
} else {
|
|
|
|
throw new Error('response Error');
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(reason => {
|
|
|
|
this.loggger.error(reason);
|
|
|
|
});
|
|
|
|
}
|
2019-11-11 05:31:26 +00:00
|
|
|
}
|