pdnsmanager/frontend/src/app/services/state.service.ts

81 lines
2.2 KiB
TypeScript
Raw Normal View History

2018-04-09 11:16:06 +02:00
import { SessionApitype } from './../apitypes/Session.apitype';
2018-04-08 13:02:00 +02:00
import { Injectable } from '@angular/core';
@Injectable()
export class StateService {
2018-04-09 11:16:06 +02:00
private _isLoggedIn = false;
2018-04-08 13:02:00 +02:00
get isLoggedIn(): boolean {
return this._isLoggedIn;
}
set isLoggedIn(_isLoggedIn: boolean) {
this._isLoggedIn = _isLoggedIn;
2018-04-09 11:16:06 +02:00
this.saveLocalStorage();
2018-04-08 13:02:00 +02:00
}
2018-04-09 11:16:06 +02:00
private _isAdmin = false;
2018-04-08 13:02:00 +02:00
get isAdmin(): boolean {
return this._isAdmin;
}
set isAdmin(_isAdmin: boolean) {
this._isAdmin = _isAdmin;
2018-04-09 11:16:06 +02:00
this.saveLocalStorage();
2018-04-08 13:02:00 +02:00
}
2018-04-09 11:16:06 +02:00
private _apiToken: string = null;
2018-04-08 13:02:00 +02:00
get apiToken(): string {
return this._apiToken;
}
set apiToken(_apiToken: string) {
this._apiToken = _apiToken;
2018-04-09 11:16:06 +02:00
this.saveLocalStorage();
2018-04-08 13:02:00 +02:00
}
2018-04-09 11:16:06 +02:00
private _isNative = false;
2018-04-08 13:02:00 +02:00
get isNative(): boolean {
return this._isNative;
}
set isNative(_isNative: boolean) {
this._isNative = _isNative;
2018-04-09 11:16:06 +02:00
this.saveLocalStorage();
}
private _pageSize = 25;
get pageSize(): number {
return this._pageSize;
}
set pageSize(_pageSize: number) {
this._pageSize = _pageSize;
this.saveLocalStorage();
}
private _pageSizes = [5, 10, 25, 50, 100];
get pageSizes(): Array<number> {
return this._pageSizes;
2018-04-08 13:02:00 +02:00
}
2018-04-12 09:27:56 +02:00
private _recordTypes = [
'A', 'A6', 'AAAA', 'AFSDB', 'ALIAS', 'CAA', 'CDNSKEY', 'CDS', 'CERT', 'CNAME', 'DHCID',
'DLV', 'DNAME', 'DNSKEY', 'DS', 'EUI48', 'EUI64', 'HINFO',
'IPSECKEY', 'KEY', 'KX', 'LOC', 'MAILA', 'MAILB', 'MINFO', 'MR',
'MX', 'NAPTR', 'NS', 'NSEC', 'NSEC3', 'NSEC3PARAM', 'OPENPGPKEY',
'OPT', 'PTR', 'RKEY', 'RP', 'RRSIG', 'SIG', 'SPF',
'SRV', 'TKEY', 'SSHFP', 'TLSA', 'TSIG', 'TXT', 'WKS', 'MBOXFW', 'URL'
];
get recordTypes(): Array<string> {
return this._recordTypes;
}
2018-04-08 13:02:00 +02:00
constructor() {
2018-04-09 11:16:06 +02:00
this.loadLocalStorage();
2018-04-08 13:02:00 +02:00
}
2018-04-09 11:16:06 +02:00
private saveLocalStorage() {
localStorage.setItem('pdnsmanagerstate', JSON.stringify(this));
2018-04-08 13:02:00 +02:00
}
2018-04-09 11:16:06 +02:00
private loadLocalStorage() {
Object.assign(this, JSON.parse(localStorage.getItem('pdnsmanagerstate')));
2018-04-08 13:02:00 +02:00
}
}