317 lines
8.8 KiB
TypeScript
Raw Normal View History

import { Component, OnInit, Inject, OnDestroy } from '@angular/core';
import {
UCAP_NATIVE_SERVICE,
NativeService,
2019-12-12 17:15:09 +09:00
WindowState,
UpdateInfo
} from '@ucap-webmessenger/native';
2019-12-17 11:44:59 +09:00
import { Observable, Subscription, of } from 'rxjs';
import { Store, select } from '@ngrx/store';
2019-11-25 09:41:15 +09:00
import * as AppStore from '@app/store';
2019-12-03 14:32:50 +09:00
import * as ChatStore from '@app/store/messenger/chat';
2019-11-25 09:41:15 +09:00
import * as AuthenticationStore from '@app/store/account/authentication';
import * as SettingsStore from '@app/store/messenger/settings';
2019-12-12 17:15:09 +09:00
import * as UpdateStore from '@app/store/setting/update';
import { LoginResponse } from '@ucap-webmessenger/protocol-authentication';
2019-12-17 11:44:59 +09:00
import { tap, take, map, catchError } from 'rxjs/operators';
2019-12-13 16:51:44 +09:00
import {
RightDrawer,
KEY_URL_INFO,
LoginInfo,
2019-12-17 11:44:59 +09:00
KEY_LOGIN_INFO,
KEY_LOGIN_RES_INFO,
KEY_VER_INFO
2019-12-13 16:51:44 +09:00
} from '@app/types';
import {
WebLink,
DaesangUrlInfoResponse
} from '@ucap-webmessenger/api-external';
2019-12-17 11:44:59 +09:00
import {
SessionStorageService,
LocalStorageService
} from '@ucap-webmessenger/web-storage';
import { AppUserInfo, KEY_APP_USER_INFO } from '@app/types/app-user-info.type';
import { environment } from '../../../../environments/environment';
import {
DaesangApiService,
DaesangProtocolService,
WebLinkType
} from '@ucap-webmessenger/daesang';
import { NGXLogger } from 'ngx-logger';
import { VersionInfo2Response } from '@ucap-webmessenger/api-public';
import {
ProfileDialogComponent,
ProfileDialogResult,
ProfileDialogData
} from '@app/layouts/messenger/dialogs/profile/profile.dialog.component';
import { DialogService } from '@ucap-webmessenger/ui';
@Component({
selector: 'app-layout-native-top-bar',
templateUrl: './top-bar.component.html',
styleUrls: ['./top-bar.component.scss']
})
export class TopBarComponent implements OnInit, OnDestroy {
windowStateChanged$: Observable<WindowState>;
WindowState = WindowState;
2019-12-12 17:15:09 +09:00
loginRes: LoginResponse;
loginResSubscription: Subscription;
sessionVerinfo: VersionInfo2Response;
2019-12-12 17:15:09 +09:00
updateInfo$: Observable<UpdateInfo>;
2019-12-13 16:51:44 +09:00
loginInfo: LoginInfo;
weblink: WebLink[] = [];
2019-12-17 11:44:59 +09:00
webLinkBadgeMail = 0;
webLinkBadgePayment = 0;
2019-12-06 15:14:12 +09:00
WebLinkType = WebLinkType;
constructor(
2019-11-25 09:41:15 +09:00
private store: Store<any>,
2019-12-13 16:51:44 +09:00
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService,
private dialogService: DialogService,
2019-12-17 11:44:59 +09:00
private localStorageService: LocalStorageService,
private sessionStorageService: SessionStorageService,
private daesangApiService: DaesangApiService,
private daesangProtocolService: DaesangProtocolService,
private logger: NGXLogger
) {}
ngOnInit() {
this.windowStateChanged$ = this.nativeService.windowStateChanged();
this.loginResSubscription = this.store
.pipe(
select(AppStore.AccountSelector.AuthenticationSelector.loginRes),
tap(loginRes => {
this.loginRes = loginRes;
2019-12-15 14:01:45 +09:00
this.loginInfo = this.sessionStorageService.get<LoginInfo>(
KEY_LOGIN_INFO
);
this.sessionVerinfo = this.sessionStorageService.get<
VersionInfo2Response
>(KEY_VER_INFO);
2019-12-15 14:01:45 +09:00
// WebLink init..
this.initWebLink();
})
)
.subscribe();
2019-12-12 17:15:09 +09:00
this.updateInfo$ = this.store.pipe(
select(AppStore.SettingSelector.UpdateSelector.updateInfo)
);
}
2019-12-15 14:01:45 +09:00
initWebLink(): void {
2019-12-17 11:44:59 +09:00
const loginRes = this.sessionStorageService.get<LoginResponse>(
KEY_LOGIN_RES_INFO
);
2019-12-15 14:01:45 +09:00
const urlInfo: DaesangUrlInfoResponse = this.sessionStorageService.get<
DaesangUrlInfoResponse
>(KEY_URL_INFO);
if (!!urlInfo && !!urlInfo.webLink) {
this.weblink = urlInfo.webLink;
if (urlInfo.webLinkAllowedList.indexOf(WebLinkType.Mail) > -1) {
2019-12-15 14:01:45 +09:00
// 메일 카운트 체크.
const link = urlInfo.webLink.filter(
weblink => weblink.key === WebLinkType.MailCnt
2019-12-15 14:01:45 +09:00
);
if (link.length > 0) {
2019-12-17 13:00:33 +09:00
const appUserInfo = this.localStorageService.encGet<AppUserInfo>(
KEY_APP_USER_INFO,
environment.customConfig.appKey
);
2019-12-15 14:01:45 +09:00
const WebLinkMailCnt = link[0];
2019-12-17 13:00:33 +09:00
const loginPw = appUserInfo.loginPw;
2019-12-17 11:44:59 +09:00
const loginPw2 = this.loginInfo.loginPw;
const loginId = this.loginInfo.loginId;
const token = loginRes.tokenString;
const url = WebLinkMailCnt.url
.replace(/(\(%USER_TOKEN%\))/g, token)
.replace(/(\(%USER_ID%\))/g, loginId)
.replace(/(\(%USER_PASS%\))/g, loginPw);
this.daesangApiService
.retrieveMailCount(url)
.pipe(
take(1),
map(res => (this.webLinkBadgeMail = res.count)),
catchError(error => of(this.logger.log(error)))
2019-12-17 11:44:59 +09:00
)
.subscribe();
2019-12-15 14:01:45 +09:00
}
}
if (urlInfo.webLinkAllowedList.indexOf(WebLinkType.Payment) > -1) {
2019-12-15 14:01:45 +09:00
// 결제 카운트 체크.
const link = urlInfo.webLink.filter(
weblink => weblink.key === WebLinkType.PaymentCnt
2019-12-15 14:01:45 +09:00
);
if (link.length > 0) {
2019-12-17 13:00:33 +09:00
const appUserInfo = this.localStorageService.encGet<AppUserInfo>(
KEY_APP_USER_INFO,
environment.customConfig.appKey
);
2019-12-15 14:01:45 +09:00
const WebLinkPaymentCnt = link[0];
2019-12-17 13:00:33 +09:00
const loginPw = appUserInfo.loginPw;
2019-12-17 11:44:59 +09:00
const loginPw2 = this.loginInfo.loginPw;
const loginId = this.loginInfo.loginId;
const token = loginRes.tokenString;
const url = WebLinkPaymentCnt.url
2019-12-17 11:44:59 +09:00
.replace(/(\(%USER_TOKEN%\))/g, token)
.replace(/(\(%USER_ID%\))/g, loginId)
.replace(/(\(%USER_PASS%\))/g, loginPw);
this.daesangApiService
.retrievePaymentCount(url)
.pipe(
take(1),
map(res => {
this.webLinkBadgePayment = res.count;
}),
catchError(error => of(this.logger.log(error)))
2019-12-17 11:44:59 +09:00
)
.subscribe();
2019-12-15 14:01:45 +09:00
}
}
}
}
2019-12-17 11:44:59 +09:00
ngOnDestroy(): void {
if (!!this.loginResSubscription) {
this.loginResSubscription.unsubscribe();
}
}
onClickClose() {
this.nativeService.windowClose();
}
onClickMinimize() {
this.nativeService.windowMinimize();
}
onClickMaxmize() {
this.nativeService.windowMaximize();
}
2019-11-25 09:41:15 +09:00
onClickSettings(): void {
this.store.dispatch(SettingsStore.showDialog());
}
onClickLogout(): void {
this.store.dispatch(AuthenticationStore.logoutConfirmation());
2019-11-25 09:41:15 +09:00
}
2019-12-03 14:32:50 +09:00
getMyProfileImageWidget(): string {
if (!!this.loginRes) {
return this.loginRes.userInfo.profileImageFile;
} else {
return '';
}
}
2020-01-03 14:27:11 +09:00
onClickOpenProfile(event: Event) {
// [GROUP]
// this.queryProtocolService
// .dataUser({
// divCd: 'OPENPROF',
// seq: userInfo.seq,
// 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-03 14:33:15 +09:00
event.preventDefault();
2020-01-03 14:27:11 +09:00
this.logger.debug('onClickOpenProfile');
return;
// [Daesang]
this.daesangProtocolService
.dataUserDaesang({
divCd: 'OPENPROF',
seq: this.loginRes.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();
}
2019-12-03 14:32:50 +09:00
onClickNotice(): void {
this.store.dispatch(
ChatStore.selectedRightDrawer({
req: RightDrawer.Notice
})
);
}
2019-12-06 15:14:12 +09:00
/** About WebLink */
2019-12-13 16:51:44 +09:00
onClickWebLink(link: WebLink): void {
2019-12-17 13:00:33 +09:00
const appUserInfo = this.localStorageService.encGet<AppUserInfo>(
KEY_APP_USER_INFO,
environment.customConfig.appKey
);
const loginPw = appUserInfo.loginPw;
2019-12-17 11:44:59 +09:00
const loginPw2 = this.loginInfo.loginPw;
const loginId = this.loginInfo.loginId;
2019-12-13 16:51:44 +09:00
const token = this.loginRes.tokenString;
2019-12-17 11:44:59 +09:00
const url = link.url
.replace(/(\(%USER_TOKEN%\))/g, token)
.replace(/(\(%USER_ID%\))/g, loginId)
.replace(/(\(%USER_PASS%\))/g, loginPw);
2019-12-13 16:51:44 +09:00
this.nativeService.openDefaultBrowser(url);
}
2019-12-12 17:15:09 +09:00
onClickUpdate() {
this.store.dispatch(UpdateStore.applyInstantUpdate());
}
}