329 lines
9.7 KiB
TypeScript
Raw Normal View History

2020-03-06 16:42:14 +09:00
import {
Component,
OnInit,
Inject,
OnDestroy,
ChangeDetectorRef
} from '@angular/core';
2020-02-18 10:54:35 +09:00
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
2020-03-06 16:42:14 +09:00
import { KEY_VER_INFO, MainMenu, KEY_AUTH_INFO } from '@app/types';
2020-01-29 09:58:40 +09:00
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
import { Store, select } from '@ngrx/store';
import * as AppStore from '@app/store';
2020-03-06 16:42:14 +09:00
import * as QueryStore from '@app/store/messenger/query';
import * as ChatStore from '@app/store/messenger/chat';
import * as SettingsStore from '@app/store/messenger/settings';
import * as SyncStore from '@app/store/messenger/sync';
import { UserInfoSS, AuthResponse } from '@ucap-webmessenger/protocol-query';
2020-01-29 09:58:40 +09:00
import { LoginResponse } from '@ucap-webmessenger/protocol-authentication';
2020-03-06 16:42:14 +09:00
import { map, take, tap } from 'rxjs/operators';
import { Subscription, Observable, BehaviorSubject } from 'rxjs';
2020-01-29 09:58:40 +09:00
import { EnvironmentsInfo, KEY_ENVIRONMENTS_INFO } from '@app/types';
import { NGXLogger } from 'ngx-logger';
import { NativeService, UCAP_NATIVE_SERVICE } from '@ucap-webmessenger/native';
import { environment } from '../../../../../environments/environment';
import { StatusBulkInfo } from '@ucap-webmessenger/protocol-status';
import { VersionInfo2Response } from '@ucap-webmessenger/api-public';
2020-01-30 17:16:20 +09:00
import { DaesangProtocolService } from '@ucap-webmessenger/daesang';
2020-03-06 16:42:14 +09:00
import { DialogService } from '@ucap-webmessenger/ui';
2020-01-30 17:16:20 +09:00
import {
ProfileDialogComponent,
ProfileDialogData,
ProfileDialogResult
} from '../profile/profile.dialog.component';
2020-03-06 16:42:14 +09:00
import {
SelectGroupDialogComponent,
SelectGroupDialogData,
SelectGroupDialogResult
} from '../group/select-group.dialog.component';
import { TranslateService } from '@ngx-translate/core';
import { GroupDetailData } from '@ucap-webmessenger/protocol-sync';
import { ConferenceService } from '@ucap-webmessenger/api-prompt';
2020-01-29 09:58:40 +09:00
export interface IntegratedSearchDialogData {
keyword: string;
}
export interface IntegratedSearchDialogResult {
clear: boolean;
}
2020-01-29 09:58:40 +09:00
@Component({
selector: 'app-integrated-search.dialog',
templateUrl: './integrated-search.dialog.component.html',
styleUrls: ['./integrated-search.dialog.component.scss']
})
export class IntegratedSearchDialogComponent implements OnInit, OnDestroy {
loginRes: LoginResponse;
loginResSubscription: Subscription;
sessionVerinfo: VersionInfo2Response;
2020-01-29 09:58:40 +09:00
environmentsInfo: EnvironmentsInfo;
2020-03-06 16:42:14 +09:00
authInfo: AuthResponse;
2020-01-29 09:58:40 +09:00
2020-03-06 16:42:14 +09:00
searchDepartmentUserInfoListSubscription: Subscription;
searchingProcessing$: Observable<boolean>;
2020-01-29 09:58:40 +09:00
2020-03-06 16:42:14 +09:00
departmentUserInfoList: UserInfoSS[] = [];
originDepartmentUserInfoList: UserInfoSS[] = [];
selectedUserList: UserInfoSS[] = []; // selected user in departmentUserList detail
2020-01-29 09:58:40 +09:00
2020-03-06 16:42:14 +09:00
profileImageRoot: string;
presenceSubscription: Subscription;
presenceSubject = new BehaviorSubject<StatusBulkInfo[]>(undefined);
currentSearchWord: string;
2020-02-07 17:37:20 +09:00
2020-01-29 09:58:40 +09:00
constructor(
public dialogRef: MatDialogRef<
IntegratedSearchDialogData,
IntegratedSearchDialogResult
>,
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService,
@Inject(MAT_DIALOG_DATA) public data: IntegratedSearchDialogData,
private sessionStorageService: SessionStorageService,
2020-01-30 17:16:20 +09:00
private daesangProtocolService: DaesangProtocolService,
private dialogService: DialogService,
2020-03-06 16:42:14 +09:00
private translateService: TranslateService,
private conferenceService: ConferenceService,
2020-01-29 09:58:40 +09:00
private store: Store<any>,
2020-03-06 16:42:14 +09:00
private changeDetectorRef: ChangeDetectorRef,
2020-01-29 09:58:40 +09:00
private logger: NGXLogger
) {
this.environmentsInfo = this.sessionStorageService.get<EnvironmentsInfo>(
KEY_ENVIRONMENTS_INFO
);
2020-03-06 16:42:14 +09:00
this.authInfo = this.sessionStorageService.get<AuthResponse>(KEY_AUTH_INFO);
this.sessionVerinfo = this.sessionStorageService.get<VersionInfo2Response>(
KEY_VER_INFO
);
2020-01-29 09:58:40 +09:00
}
ngOnInit() {
2020-03-06 16:42:14 +09:00
this.profileImageRoot = this.sessionVerinfo.profileRoot;
this.loginResSubscription = this.store
.pipe(
select(AppStore.AccountSelector.AuthenticationSelector.loginRes),
tap(loginRes => {
this.loginRes = loginRes;
})
)
.subscribe();
2020-03-06 16:42:14 +09:00
this.searchDepartmentUserInfoListSubscription = this.store
.pipe(
select(
AppStore.MessengerSelector.QuerySelector
.integrateSearchDepartmentUserInfoList
)
)
.subscribe(list => {
this.departmentUserInfoList = list;
this.originDepartmentUserInfoList = list;
});
2020-03-06 16:42:14 +09:00
this.searchingProcessing$ = this.store.pipe(
select(
AppStore.MessengerSelector.QuerySelector
.integrateSearchDepartmentProcessing
)
);
2020-03-06 16:42:14 +09:00
this.presenceSubscription = this.store
.pipe(
select(
AppStore.MessengerSelector.StatusSelector.selectAllStatusBulkInfo
)
)
.subscribe(presence => {
this.presenceSubject.next(presence);
});
this.onSearch(this.data.keyword);
2020-01-29 09:58:40 +09:00
}
ngOnDestroy(): void {
if (!!this.loginResSubscription) {
this.loginResSubscription.unsubscribe();
}
2020-03-06 16:42:14 +09:00
if (!!this.searchDepartmentUserInfoListSubscription) {
this.searchDepartmentUserInfoListSubscription.unsubscribe();
}
if (!!this.presenceSubscription) {
this.presenceSubscription.unsubscribe();
}
}
2020-01-29 09:58:40 +09:00
onSearch(searchWord: string) {
2020-02-07 17:37:20 +09:00
if (this.currentSearchWord !== searchWord) {
this.currentSearchWord = searchWord;
}
2020-01-29 09:58:40 +09:00
if (searchWord.trim().length > 0) {
2020-03-06 16:42:14 +09:00
this.store.dispatch(
QueryStore.integrateSearchDeptUser({
2020-01-29 09:58:40 +09:00
companyCode: this.loginRes.companyCode,
2020-03-06 16:42:14 +09:00
search: searchWord.trim()
2020-01-29 09:58:40 +09:00
})
2020-03-06 16:42:14 +09:00
);
2020-01-29 09:58:40 +09:00
} else {
// clear list.
2020-03-06 16:42:14 +09:00
this.store.dispatch(QueryStore.integrateClearSearchDeptUser({}));
2020-01-29 09:58:40 +09:00
}
}
2020-03-06 16:42:14 +09:00
/** Selected User Handling */
onToggleAllUser(params: { isChecked: boolean; userInfos: UserInfoSS[] }) {
params.userInfos.forEach(userInfo => {
if (params.isChecked) {
if (
this.selectedUserList.filter(user => user.seq === userInfo.seq)
.length === 0
) {
this.selectedUserList = [...this.selectedUserList, userInfo];
}
} else {
this.selectedUserList = this.selectedUserList.filter(
user => user.seq !== userInfo.seq
);
}
});
}
onToggleUser(userInfo: UserInfoSS) {
if (userInfo.seq === this.loginRes.userSeq) {
return;
}
if (
this.selectedUserList.filter(user => user.seq === userInfo.seq).length ===
0
) {
this.selectedUserList = [...this.selectedUserList, userInfo];
} else {
this.selectedUserList = this.selectedUserList.filter(
item => item.seq !== userInfo.seq
);
}
this.changeDetectorRef.detectChanges();
}
/** Handling chipset for selectedUserList */
onClickDeleteUser(userInfo: UserInfoSS) {
this.selectedUserList = this.selectedUserList.filter(
item => item.seq !== userInfo.seq
);
this.changeDetectorRef.detectChanges();
2020-01-29 13:14:26 +09:00
}
2020-03-06 16:42:14 +09:00
/** Handling Button */
async onClickAddGroup() {
this.logger.debug('onClickAddGroup', this.selectedUserList);
const result = await this.dialogService.open<
SelectGroupDialogComponent,
SelectGroupDialogData,
SelectGroupDialogResult
>(SelectGroupDialogComponent, {
width: '600px',
data: {
title: this.translateService.instant('group.selectTargetGroup')
}
});
if (!!result && !!result.choice && result.choice) {
if (!!result.group) {
const oldGroup: GroupDetailData = result.group;
const trgtUserSeq: number[] = [];
result.group.userSeqs.map(seq => trgtUserSeq.push(seq));
this.selectedUserList
.filter(v => result.group.userSeqs.indexOf(v.seq) < 0)
.forEach(user => {
trgtUserSeq.push(user.seq);
});
2020-01-29 09:58:40 +09:00
2020-03-06 16:42:14 +09:00
this.store.dispatch(
SyncStore.updateGroupMember({
oldGroup,
trgtUserSeq
})
);
}
}
2020-01-29 09:58:40 +09:00
}
2020-03-06 16:42:14 +09:00
onClickChatOpen() {
if (!!this.selectedUserList && this.selectedUserList.length > 0) {
// Open Room.
const seq: number[] = [];
this.selectedUserList.map(user => seq.push(user.seq));
this.store.dispatch(ChatStore.openRoom({ userSeqList: seq }));
2020-01-30 17:16:20 +09:00
2020-03-06 16:42:14 +09:00
// GNB Change to Chat
this.store.dispatch(
SettingsStore.selectedGnbMenuIndex({
menuIndex: MainMenu.Chat
})
);
}
}
onClickConference() {
const targetUserSeqs = this.selectedUserList.map(userInfo => userInfo.seq);
if (!!targetUserSeqs && targetUserSeqs.length > 0) {
this.conferenceService.conferenceCreate({
userSeq: this.loginRes.userSeq,
deviceType: this.environmentsInfo.deviceType,
tokenKey: this.loginRes.tokenString,
targetUserSeqs
});
}
}
2020-01-30 17:16:20 +09:00
onClickOpenProfile(userSeq: number) {
if (!userSeq || userSeq < 0) {
return;
}
this.daesangProtocolService
.dataUserDaesang({
divCd: 'OPENPROF',
seq: userSeq,
senderCompanyCode: this.loginRes.userInfo.companyCode,
senderEmployeeType: this.loginRes.userInfo.employeeType
})
.pipe(
take(1),
map(async res => {
2020-01-30 17:16:20 +09:00
if (!!res && !!res.userInfo) {
const result = await this.dialogService.open<
2020-01-30 17:16:20 +09:00
ProfileDialogComponent,
ProfileDialogData,
ProfileDialogResult
>(ProfileDialogComponent, {
data: {
userInfo: res.userInfo
}
});
if (!!result) {
if (!!result.closeEvent && result.closeEvent === 'CHAT') {
this.onCancel();
}
}
2020-01-30 17:16:20 +09:00
}
})
)
.subscribe();
}
onClickHide(): void {
this.dialogRef.addPanelClass('hideDialog');
}
2020-03-06 16:42:14 +09:00
onCancel(): void {
this.dialogRef.close({ clear: true });
2020-03-06 16:42:14 +09:00
}
2020-01-29 09:58:40 +09:00
}