128 lines
4.1 KiB
TypeScript
Raw Normal View History

2019-11-25 10:57:02 +09:00
import { Component, OnInit, Inject, Renderer2 } from '@angular/core';
2019-11-21 10:29:19 +09:00
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
2019-12-13 14:38:42 +09:00
import { KEY_LOGIN_RES_INFO, KEY_VER_INFO } from '@app/types';
2019-12-16 04:49:27 +09:00
import {
SessionStorageService,
LocalStorageService
} from '@ucap-webmessenger/web-storage';
2019-11-21 10:29:19 +09:00
import { Store } from '@ngrx/store';
import {
DialogService,
2019-12-20 16:30:22 +09:00
TranslateService as UCapTranslateService,
DateService as UCapDateService
} from '@ucap-webmessenger/ui';
2019-11-21 10:29:19 +09:00
import { VersionInfo2Response } from '@ucap-webmessenger/api-public';
import { LoginResponse } from '@ucap-webmessenger/protocol-authentication';
import { map } from 'rxjs/operators';
2019-11-25 10:57:02 +09:00
import { DOCUMENT } from '@angular/common';
2019-12-16 04:49:27 +09:00
import { AppUserInfo, KEY_APP_USER_INFO } from '@app/types/app-user-info.type';
import { environment } from '../../../../../environments/environment';
import {
GeneralSetting,
Settings,
NotificationSetting
} from '@ucap-webmessenger/ui-settings';
2019-12-17 17:27:08 +09:00
import { NativeService, UCAP_NATIVE_SERVICE } from '@ucap-webmessenger/native';
2019-12-18 13:44:26 +09:00
import { TranslateService } from '@ngx-translate/core';
2019-11-21 10:29:19 +09:00
export interface MessengerSettingsDialogData {}
export interface MessengerSettingsDialogResult {}
@Component({
selector: 'app-messenger-settings-dialog',
templateUrl: './messenger-settings.dialog.component.html',
styleUrls: ['./messenger-settings.dialog.component.scss']
})
export class MessengerSettingsDialogComponent implements OnInit {
loginRes: LoginResponse;
sessionVerinfo: VersionInfo2Response;
2019-12-16 04:49:27 +09:00
appUserInfo: AppUserInfo;
2019-11-21 10:29:19 +09:00
constructor(
public dialogRef: MatDialogRef<
MessengerSettingsDialogData,
MessengerSettingsDialogResult
>,
@Inject(MAT_DIALOG_DATA) public data: MessengerSettingsDialogData,
private dialogService: DialogService,
private sessionStorageService: SessionStorageService,
2019-12-16 04:49:27 +09:00
private localStorageService: LocalStorageService,
private ucapTranslateService: UCapTranslateService,
2019-12-20 16:30:22 +09:00
private ucapDateService: UCapDateService,
2019-12-17 17:27:08 +09:00
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService,
2019-12-18 13:44:26 +09:00
private translateService: TranslateService,
2019-11-25 10:57:02 +09:00
private store: Store<any>,
@Inject(DOCUMENT) private document: Document,
private renderer2: Renderer2
2019-11-21 10:29:19 +09:00
) {
2019-12-16 04:49:27 +09:00
this.appUserInfo = this.localStorageService.encGet<AppUserInfo>(
KEY_APP_USER_INFO,
environment.customConfig.appKey
);
2019-11-21 10:29:19 +09:00
this.sessionVerinfo = this.sessionStorageService.get<VersionInfo2Response>(
KEY_VER_INFO
);
this.loginRes = this.sessionStorageService.get<LoginResponse>(
KEY_LOGIN_RES_INFO
);
}
ngOnInit() {}
2019-12-16 04:49:27 +09:00
onChangedGeneralSetting(setting: GeneralSetting) {
if (this.appUserInfo.settings.general.appTheme !== setting.appTheme) {
this.renderer2.setAttribute(
this.document.body,
'class',
setting.appTheme
);
}
if (this.appUserInfo.settings.general.locale !== setting.locale) {
2019-12-18 13:44:26 +09:00
this.translateService.use(setting.locale);
}
if (
this.appUserInfo.settings.general.hrInfoLocale !== setting.hrInfoLocale
) {
this.ucapTranslateService.use(setting.hrInfoLocale);
}
2019-12-20 16:30:22 +09:00
if (this.appUserInfo.settings.general.timezone !== setting.timezone) {
this.ucapDateService.use(setting.timezone);
}
2019-12-17 17:27:08 +09:00
if (this.appUserInfo.settings.general.autoLaunch !== setting.autoLaunch) {
this.nativeService.changeAutoLaunch(setting.autoLaunch);
}
2019-12-18 17:11:58 +09:00
if (
this.appUserInfo.settings.general.startupHideWindow !==
setting.startupHideWindow
) {
this.nativeService.changeStartupHideWindow(setting.startupHideWindow);
}
2019-12-17 17:27:08 +09:00
2019-12-16 04:49:27 +09:00
this.applySettings({ ...this.appUserInfo.settings, general: setting });
}
onChangedNotificationSetting(setting: NotificationSetting) {
this.applySettings({ ...this.appUserInfo.settings, notification: setting });
2019-11-25 10:57:02 +09:00
}
2019-11-21 10:29:19 +09:00
onClickChoice(choice: boolean): void {
this.dialogRef.close({});
}
2019-12-16 04:49:27 +09:00
private applySettings(settings: Settings) {
this.appUserInfo.settings = settings;
this.localStorageService.encSet<AppUserInfo>(
KEY_APP_USER_INFO,
this.appUserInfo,
environment.customConfig.appKey
);
}
2019-11-21 10:29:19 +09:00
}