131 lines
3.3 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';
import { Observable, Subscription } 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';
import { tap } from 'rxjs/operators';
2019-12-13 16:51:44 +09:00
import {
RightDrawer,
KEY_URL_INFO,
LoginInfo,
KEY_LOGIN_INFO
} from '@app/types';
import {
WebLink,
DaesangUrlInfoResponse
} from '@ucap-webmessenger/api-external';
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
@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-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,
private sessionStorageService: SessionStorageService
) {
this.loginInfo = this.sessionStorageService.get<LoginInfo>(KEY_LOGIN_INFO);
const urlInfo: DaesangUrlInfoResponse = this.sessionStorageService.get<
DaesangUrlInfoResponse
>(KEY_URL_INFO);
if (!!urlInfo.webLink) {
this.weblink = urlInfo.webLink.filter(
weblink =>
urlInfo.webLinkAllowedList.filter(type => type === weblink.key)
.length > 0
);
}
}
ngOnInit() {
this.windowStateChanged$ = this.nativeService.windowStateChanged();
this.loginResSubscription = this.store
.pipe(
select(AppStore.AccountSelector.AuthenticationSelector.loginRes),
tap(loginRes => {
this.loginRes = loginRes;
})
)
.subscribe();
2019-12-12 17:15:09 +09:00
this.updateInfo$ = this.store.pipe(
select(AppStore.SettingSelector.UpdateSelector.updateInfo)
);
}
ngOnDestroy(): void {}
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 {
const loginPw = this.loginInfo.loginPw;
const token = this.loginRes.tokenString;
const url = link.url.replace('(%USER_TOKEN%)', token);
this.nativeService.openDefaultBrowser(url);
}
2019-12-12 17:15:09 +09:00
onClickUpdate() {
this.store.dispatch(UpdateStore.applyInstantUpdate());
}
}