128 lines
4.1 KiB
TypeScript
128 lines
4.1 KiB
TypeScript
import { Component, OnInit, Inject, Renderer2 } from '@angular/core';
|
|
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
|
|
import { KEY_LOGIN_RES_INFO, KEY_VER_INFO } from '@app/types';
|
|
import {
|
|
SessionStorageService,
|
|
LocalStorageService
|
|
} from '@ucap-webmessenger/web-storage';
|
|
|
|
import { Store } from '@ngrx/store';
|
|
|
|
import {
|
|
DialogService,
|
|
TranslateService as UCapTranslateService,
|
|
DateService as UCapDateService
|
|
} from '@ucap-webmessenger/ui';
|
|
import { VersionInfo2Response } from '@ucap-webmessenger/api-public';
|
|
import { LoginResponse } from '@ucap-webmessenger/protocol-authentication';
|
|
import { map } from 'rxjs/operators';
|
|
import { DOCUMENT } from '@angular/common';
|
|
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';
|
|
import { NativeService, UCAP_NATIVE_SERVICE } from '@ucap-webmessenger/native';
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
|
|
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;
|
|
appUserInfo: AppUserInfo;
|
|
|
|
constructor(
|
|
public dialogRef: MatDialogRef<
|
|
MessengerSettingsDialogData,
|
|
MessengerSettingsDialogResult
|
|
>,
|
|
@Inject(MAT_DIALOG_DATA) public data: MessengerSettingsDialogData,
|
|
private dialogService: DialogService,
|
|
private sessionStorageService: SessionStorageService,
|
|
private localStorageService: LocalStorageService,
|
|
private ucapTranslateService: UCapTranslateService,
|
|
private ucapDateService: UCapDateService,
|
|
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService,
|
|
private translateService: TranslateService,
|
|
private store: Store<any>,
|
|
@Inject(DOCUMENT) private document: Document,
|
|
private renderer2: Renderer2
|
|
) {
|
|
this.appUserInfo = this.localStorageService.encGet<AppUserInfo>(
|
|
KEY_APP_USER_INFO,
|
|
environment.customConfig.appKey
|
|
);
|
|
|
|
this.sessionVerinfo = this.sessionStorageService.get<VersionInfo2Response>(
|
|
KEY_VER_INFO
|
|
);
|
|
this.loginRes = this.sessionStorageService.get<LoginResponse>(
|
|
KEY_LOGIN_RES_INFO
|
|
);
|
|
}
|
|
|
|
ngOnInit() {}
|
|
|
|
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) {
|
|
this.translateService.use(setting.locale);
|
|
}
|
|
if (
|
|
this.appUserInfo.settings.general.hrInfoLocale !== setting.hrInfoLocale
|
|
) {
|
|
this.ucapTranslateService.use(setting.hrInfoLocale);
|
|
}
|
|
|
|
if (this.appUserInfo.settings.general.timezone !== setting.timezone) {
|
|
this.ucapDateService.use(setting.timezone);
|
|
}
|
|
|
|
if (this.appUserInfo.settings.general.autoLaunch !== setting.autoLaunch) {
|
|
this.nativeService.changeAutoLaunch(setting.autoLaunch);
|
|
}
|
|
if (
|
|
this.appUserInfo.settings.general.startupHideWindow !==
|
|
setting.startupHideWindow
|
|
) {
|
|
this.nativeService.changeStartupHideWindow(setting.startupHideWindow);
|
|
}
|
|
|
|
this.applySettings({ ...this.appUserInfo.settings, general: setting });
|
|
}
|
|
|
|
onChangedNotificationSetting(setting: NotificationSetting) {
|
|
this.applySettings({ ...this.appUserInfo.settings, notification: setting });
|
|
}
|
|
|
|
onClickChoice(choice: boolean): void {
|
|
this.dialogRef.close({});
|
|
}
|
|
|
|
private applySettings(settings: Settings) {
|
|
this.appUserInfo.settings = settings;
|
|
|
|
this.localStorageService.encSet<AppUserInfo>(
|
|
KEY_APP_USER_INFO,
|
|
this.appUserInfo,
|
|
environment.customConfig.appKey
|
|
);
|
|
}
|
|
}
|