2018-06-25 22:44:06 +02:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
OnInit,
|
|
|
|
} from '@angular/core';
|
|
|
|
|
2018-06-26 15:04:12 +02:00
|
|
|
import { ToasterService } from 'angular2-toaster';
|
2018-06-25 22:44:06 +02:00
|
|
|
import { Angulartics2 } from 'angulartics2';
|
|
|
|
|
|
|
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
|
|
|
import { StateService } from 'jslib/abstractions/state.service';
|
|
|
|
import { StorageService } from 'jslib/abstractions/storage.service';
|
|
|
|
|
|
|
|
import { ConstantsService } from 'jslib/services/constants.service';
|
|
|
|
|
2018-07-24 04:45:43 +02:00
|
|
|
import { Utils } from 'jslib/misc/utils';
|
|
|
|
|
2018-06-25 22:44:06 +02:00
|
|
|
@Component({
|
|
|
|
selector: 'app-options',
|
|
|
|
templateUrl: 'options.component.html',
|
|
|
|
})
|
|
|
|
export class OptionsComponent implements OnInit {
|
|
|
|
disableIcons: boolean;
|
|
|
|
locale: string;
|
|
|
|
localeOptions: any[];
|
|
|
|
|
2018-06-26 15:04:12 +02:00
|
|
|
private startingLocale: string;
|
|
|
|
|
2018-06-25 22:44:06 +02:00
|
|
|
constructor(private storageService: StorageService, private stateService: StateService,
|
2018-06-26 15:04:12 +02:00
|
|
|
private analytics: Angulartics2, private i18nService: I18nService,
|
|
|
|
private toasterService: ToasterService) {
|
2018-07-24 04:45:43 +02:00
|
|
|
const localeOptions: any[] = [];
|
2018-06-25 22:44:06 +02:00
|
|
|
i18nService.supportedTranslationLocales.forEach((locale) => {
|
2018-07-24 04:45:43 +02:00
|
|
|
localeOptions.push({ name: locale, value: locale });
|
2018-06-25 22:44:06 +02:00
|
|
|
});
|
2018-07-24 04:45:43 +02:00
|
|
|
localeOptions.sort(Utils.getSortFunction(i18nService, 'name'));
|
|
|
|
localeOptions.splice(0, 0, { name: i18nService.t('default'), value: null });
|
|
|
|
this.localeOptions = localeOptions;
|
2018-06-25 22:44:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async ngOnInit() {
|
|
|
|
this.disableIcons = await this.storageService.get<boolean>(ConstantsService.disableFaviconKey);
|
2018-06-26 15:04:12 +02:00
|
|
|
this.locale = this.startingLocale = await this.storageService.get<string>(ConstantsService.localeKey);
|
2018-06-25 22:44:06 +02:00
|
|
|
}
|
|
|
|
|
2018-06-26 15:04:12 +02:00
|
|
|
async submit() {
|
2018-06-25 22:44:06 +02:00
|
|
|
await this.storageService.save(ConstantsService.disableFaviconKey, this.disableIcons);
|
|
|
|
await this.stateService.save(ConstantsService.disableFaviconKey, this.disableIcons);
|
|
|
|
await this.storageService.save(ConstantsService.localeKey, this.locale);
|
2018-06-26 15:04:12 +02:00
|
|
|
this.analytics.eventTrack.next({ action: 'Saved Options' });
|
|
|
|
if (this.locale !== this.startingLocale) {
|
|
|
|
window.location.reload();
|
|
|
|
} else {
|
|
|
|
this.toasterService.popAsync('success', null, this.i18nService.t('optionsUpdated'));
|
|
|
|
}
|
2018-06-25 22:44:06 +02:00
|
|
|
}
|
|
|
|
}
|