208 lines
6.5 KiB
TypeScript
Raw Normal View History

2020-01-29 09:58:40 +09:00
import { Component, OnInit, Inject, OnDestroy } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA, PageEvent } from '@angular/material';
import { KEY_LOGIN_RES_INFO, KEY_VER_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-01-29 09:58:40 +09:00
import * as StatusStore from '@app/store/messenger/status';
import {
UserInfoSS,
QueryProtocolService,
DeptSearchType,
SSVC_TYPE_QUERY_DEPT_USER_DATA,
DeptUserData,
SSVC_TYPE_QUERY_DEPT_USER_RES,
DeptUserResponse
} from '@ucap-webmessenger/protocol-query';
import { LoginResponse } from '@ucap-webmessenger/protocol-authentication';
2020-01-30 17:16:20 +09:00
import { map, catchError, take } from 'rxjs/operators';
import { Subscription, of, Observable } 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 { TranslateService } from '@ngx-translate/core';
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';
import { DialogService } from '@ucap-webmessenger/ui';
import {
ProfileDialogComponent,
ProfileDialogData,
ProfileDialogResult
} from '../profile/profile.dialog.component';
2020-01-29 09:58:40 +09:00
export interface IntegratedSearchDialogData {
keyword: string;
}
export interface IntegratedSearchDialogResult {}
@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;
sessionVerinfo: VersionInfo2Response;
2020-01-29 09:58:40 +09:00
environmentsInfo: EnvironmentsInfo;
presence$: Observable<StatusBulkInfo[]>;
2020-01-29 09:58:40 +09:00
searchSubscription: Subscription;
searchUserInfos: UserInfoSS[] = [];
searchingProcessing = false;
currentSearchWord: string;
totalCount = 0;
pageCurrent = 1;
pageListCount = 20;
constructor(
public dialogRef: MatDialogRef<
IntegratedSearchDialogData,
IntegratedSearchDialogResult
>,
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService,
@Inject(MAT_DIALOG_DATA) public data: IntegratedSearchDialogData,
private queryProtocolService: QueryProtocolService,
private sessionStorageService: SessionStorageService,
2020-01-30 17:16:20 +09:00
private daesangProtocolService: DaesangProtocolService,
private dialogService: DialogService,
2020-01-29 09:58:40 +09:00
private store: Store<any>,
private logger: NGXLogger
) {
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
);
2020-01-29 09:58:40 +09:00
}
ngOnInit() {
this.onSearch(this.data.keyword);
this.presence$ = this.store.pipe(
select(AppStore.MessengerSelector.StatusSelector.selectAllStatusBulkInfo)
);
2020-01-29 09:58:40 +09:00
}
onSearch(searchWord: string) {
this.currentSearchWord = this.data.keyword;
if (searchWord.trim().length > 0) {
this.searchingProcessing = true;
const searchUserInfos: UserInfoSS[] = [];
this.searchSubscription = this.queryProtocolService
.deptUser({
divCd: 'INT_SRCH',
companyCode: this.loginRes.companyCode,
searchRange: DeptSearchType.All,
search: searchWord.trim(),
senderCompanyCode: this.loginRes.companyCode,
senderEmployeeType: this.loginRes.userInfo.employeeType,
pageCurrent: this.pageCurrent,
pageListCount: this.pageListCount
})
.pipe(
map(res => {
switch (res.SSVC_TYPE) {
case SSVC_TYPE_QUERY_DEPT_USER_DATA:
const userInfos = (res as DeptUserData).userInfos;
searchUserInfos.push(...userInfos);
break;
case SSVC_TYPE_QUERY_DEPT_USER_RES:
{
const response = res as DeptUserResponse;
// 검색 결과 처리.
this.searchUserInfos = searchUserInfos;
this.totalCount = response.pageTotalCount;
this.pageCurrent = response.pageCurrent;
this.pageListCount = response.pageListCount;
this.searchingProcessing = false;
// 검색 결과에 따른 프레즌스 조회.
if (searchUserInfos.length > 0) {
2020-01-29 09:58:40 +09:00
this.store.dispatch(
StatusStore.bulkInfo({
divCd: 'INT_SRCH',
userSeqs: this.searchUserInfos.map(user => user.seq)
})
);
}
console.log(this.searchUserInfos);
}
break;
}
}),
catchError(error => {
this.searchingProcessing = false;
return of(this.logger.error(error));
})
)
.subscribe();
} else {
// clear list.
this.searchingProcessing = false;
this.searchUserInfos = [];
}
}
ngOnDestroy(): void {
if (!!this.searchSubscription) {
this.searchSubscription.unsubscribe();
}
}
2020-01-29 13:14:26 +09:00
onCancel(): void {
this.dialogRef.close({});
}
2020-01-29 09:58:40 +09:00
onChangePage(event: PageEvent) {
this.pageCurrent = event.pageIndex + 1;
this.pageListCount = event.pageSize;
this.onSearch(this.currentSearchWord);
}
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(res => {
if (!!res && !!res.userInfo) {
this.dialogService.open<
ProfileDialogComponent,
ProfileDialogData,
ProfileDialogResult
>(ProfileDialogComponent, {
data: {
userInfo: res.userInfo
}
});
}
})
)
.subscribe();
}
2020-01-29 09:58:40 +09:00
}