270 lines
7.6 KiB
TypeScript
Raw Normal View History

2019-12-06 15:14:12 +09:00
import { Component, OnInit, Inject, OnDestroy, ViewChild } 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
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';
import { NGXLogger } from 'ngx-logger';
@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;
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
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,
private logger: NGXLogger
2019-12-17 13:00:33 +09:00
) {}
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.showWeblink = false;
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) {
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 =>
2019-12-18 08:49:34 +09:00
urlInfo.webLinkAllowedList
.filter(
type => type !== 'WebLinkMailCnt' && type !== 'WebLinkPaymentCnt'
)
.filter(type => type === weblink.key).length > 0
2019-12-15 14:01:45 +09:00
);
2019-12-18 08:49:34 +09:00
if (urlInfo.webLinkAllowedList.indexOf('WebLinkMail') > -1) {
2019-12-15 14:01:45 +09:00
// 메일 카운트 체크.
const link = urlInfo.webLink.filter(
weblink => weblink.key === 'WebLinkMailCnt'
);
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
}
}
2019-12-18 08:49:34 +09:00
if (urlInfo.webLinkAllowedList.indexOf('WebLinkPayment') > -1) {
2019-12-15 14:01:45 +09:00
// 결제 카운트 체크.
const link = urlInfo.webLink.filter(
weblink => weblink.key === 'WebLinkPaymentCnt'
);
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 11:44:59 +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
.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
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 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-17 11:44:59 +09:00
getShowWebLinkbadge(link: WebLink): boolean {
const showType = ['WebLinkMail', 'WebLinkPayment'];
2019-12-17 11:44:59 +09:00
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());
}
}