2019-12-06 15:14:12 +09:00
|
|
|
import { Component, OnInit, Inject, OnDestroy, ViewChild } from '@angular/core';
|
2019-10-24 15:37:33 +09:00
|
|
|
import {
|
|
|
|
UCAP_NATIVE_SERVICE,
|
|
|
|
NativeService,
|
2019-12-12 17:15:09 +09:00
|
|
|
WindowState,
|
|
|
|
UpdateInfo
|
2019-10-24 15:37:33 +09:00
|
|
|
} from '@ucap-webmessenger/native';
|
2019-12-17 11:44:59 +09:00
|
|
|
import { Observable, Subscription, of } from 'rxjs';
|
2019-11-25 10:47:44 +09:00
|
|
|
import { Store, select } from '@ngrx/store';
|
2019-11-25 09:41:15 +09:00
|
|
|
|
2019-11-25 10:47:44 +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';
|
2019-10-24 15:37:33 +09:00
|
|
|
|
2019-11-25 10:47:44 +09:00
|
|
|
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
|
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 } from '@ucap-webmessenger/daesang';
|
2019-11-25 10:47:44 +09:00
|
|
|
|
2019-10-24 15:37:33 +09:00
|
|
|
@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
|
|
|
|
2019-11-25 10:47:44 +09:00
|
|
|
loginRes: LoginResponse;
|
|
|
|
loginResSubscription: Subscription;
|
2019-12-17 11:44:59 +09:00
|
|
|
appUserInfo: AppUserInfo;
|
2019-10-24 15:37:33 +09:00
|
|
|
|
2019-12-12 17:15:09 +09:00
|
|
|
updateInfo$: Observable<UpdateInfo>;
|
|
|
|
|
2019-12-06 15:14:12 +09:00
|
|
|
showWeblink = false;
|
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
|
|
|
|
2019-10-24 15:37:33 +09:00
|
|
|
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,
|
2019-12-17 11:44:59 +09:00
|
|
|
private localStorageService: LocalStorageService,
|
|
|
|
private sessionStorageService: SessionStorageService,
|
|
|
|
private daesangApiService: DaesangApiService
|
|
|
|
) {
|
|
|
|
this.appUserInfo = this.localStorageService.encGet<AppUserInfo>(
|
|
|
|
KEY_APP_USER_INFO,
|
|
|
|
environment.customConfig.appKey
|
|
|
|
);
|
|
|
|
}
|
2019-10-24 15:37:33 +09:00
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.windowStateChanged$ = this.nativeService.windowStateChanged();
|
2019-11-25 10:47:44 +09:00
|
|
|
|
|
|
|
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
|
|
|
|
);
|
|
|
|
|
|
|
|
// WebLink init..
|
|
|
|
this.initWebLink();
|
2019-11-25 10:47:44 +09:00
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe();
|
2019-12-12 17:15:09 +09:00
|
|
|
|
|
|
|
this.updateInfo$ = this.store.pipe(
|
|
|
|
select(AppStore.SettingSelector.UpdateSelector.updateInfo)
|
|
|
|
);
|
2019-10-24 15:37:33 +09:00
|
|
|
}
|
|
|
|
|
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) {
|
2019-12-17 11:44:59 +09:00
|
|
|
// urlInfo.webLinkAllowedList.push(
|
|
|
|
// ...[
|
|
|
|
// 'WebLinkMail',
|
|
|
|
// 'WebLinkMailCnt',
|
|
|
|
// 'WebLinkPayment',
|
|
|
|
// 'WebLinkPaymentCnt'
|
|
|
|
// ]
|
|
|
|
// );
|
|
|
|
|
2019-12-15 14:01:45 +09:00
|
|
|
this.weblink = urlInfo.webLink.filter(
|
|
|
|
weblink =>
|
|
|
|
urlInfo.webLinkAllowedList.filter(type => type === weblink.key)
|
|
|
|
.length > 0
|
|
|
|
);
|
|
|
|
|
|
|
|
if (
|
|
|
|
urlInfo.webLinkAllowedList.indexOf('WebLinkMail') > -1 &&
|
|
|
|
urlInfo.webLinkAllowedList.indexOf('WebLinkMailCnt') > -1
|
|
|
|
) {
|
|
|
|
// 메일 카운트 체크.
|
|
|
|
const link = urlInfo.webLink.filter(
|
|
|
|
weblink => weblink.key === 'WebLinkMailCnt'
|
|
|
|
);
|
|
|
|
if (link.length > 0) {
|
|
|
|
const WebLinkMailCnt = link[0];
|
2019-12-17 11:44:59 +09:00
|
|
|
const loginPw = this.appUserInfo.loginPw;
|
|
|
|
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(console.log(error)))
|
|
|
|
)
|
|
|
|
.subscribe();
|
2019-12-15 14:01:45 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
urlInfo.webLinkAllowedList.indexOf('WebLinkPayment') > -1 &&
|
|
|
|
urlInfo.webLinkAllowedList.indexOf('WebLinkPaymentCnt') > -1
|
|
|
|
) {
|
|
|
|
// 결제 카운트 체크.
|
|
|
|
const link = urlInfo.webLink.filter(
|
|
|
|
weblink => weblink.key === 'WebLinkPaymentCnt'
|
|
|
|
);
|
|
|
|
if (link.length > 0) {
|
|
|
|
const WebLinkPaymentCnt = link[0];
|
2019-12-17 11:44:59 +09:00
|
|
|
const WebLinkMailCnt = link[0];
|
|
|
|
const loginPw = this.appUserInfo.loginPw;
|
|
|
|
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
|
|
|
|
.retrievePaymentCount(url)
|
|
|
|
.pipe(
|
|
|
|
take(1),
|
|
|
|
map(res => {
|
|
|
|
this.webLinkBadgePayment = res.count;
|
|
|
|
}),
|
|
|
|
catchError(error => of(console.log(error)))
|
|
|
|
)
|
|
|
|
.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();
|
|
|
|
}
|
|
|
|
}
|
2019-10-24 15:37:33 +09:00
|
|
|
|
|
|
|
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 {
|
2019-11-25 10:47:44 +09:00
|
|
|
this.store.dispatch(AuthenticationStore.logoutConfirmation());
|
2019-11-25 09:41:15 +09:00
|
|
|
}
|
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
|
|
|
|
|
|
|
onToggleWebLinkSelector(): void {
|
|
|
|
this.showWeblink = !this.showWeblink;
|
|
|
|
}
|
2019-12-13 16:51:44 +09:00
|
|
|
onClickWebLink(link: WebLink): void {
|
2019-12-17 11:44:59 +09:00
|
|
|
const loginPw = this.appUserInfo.loginPw;
|
|
|
|
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-17 11:44:59 +09:00
|
|
|
getShowWebLinkbadge(link: WebLink): boolean {
|
|
|
|
const showType = [
|
|
|
|
'WebLinkMail',
|
|
|
|
'WebLinkMailCnt',
|
|
|
|
'WebLinkPayment',
|
|
|
|
'WebLinkPaymentCnt'
|
|
|
|
];
|
|
|
|
|
|
|
|
if (showType.indexOf(link.key) > -1) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
getWebLinkBadgeCount(link: WebLink): number {
|
|
|
|
if (link.key === 'WebLinkMail') {
|
|
|
|
return this.webLinkBadgeMail;
|
|
|
|
} else if (link.key === 'WebLinkPayment') {
|
|
|
|
return this.webLinkBadgePayment;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2019-12-12 17:15:09 +09:00
|
|
|
|
|
|
|
onClickUpdate() {
|
|
|
|
this.store.dispatch(UpdateStore.applyInstantUpdate());
|
|
|
|
}
|
2019-10-24 15:37:33 +09:00
|
|
|
}
|