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

69 lines
1.6 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
}
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
}
}