persist settings across sessions (in local storage).

pull/262/head
Jason Kulatunga 3 years ago
parent 0aeb13c181
commit 934f16f0a5

@ -3,6 +3,8 @@ import { BehaviorSubject, Observable } from 'rxjs';
import * as _ from 'lodash'; import * as _ from 'lodash';
import { TREO_APP_CONFIG } from '@treo/services/config/config.constants'; import { TREO_APP_CONFIG } from '@treo/services/config/config.constants';
const SCRUTINY_CONFIG_LOCAL_STORAGE_KEY = 'scrutiny';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
@ -10,14 +12,22 @@ export class TreoConfigService
{ {
// Private // Private
private _config: BehaviorSubject<any>; private _config: BehaviorSubject<any>;
/** /**
* Constructor * Constructor
*/ */
constructor(@Inject(TREO_APP_CONFIG) config: any) constructor(@Inject(TREO_APP_CONFIG) defaultConfig: any)
{ {
let currentScrutinyConfig = defaultConfig
let localConfigStr = localStorage.getItem(SCRUTINY_CONFIG_LOCAL_STORAGE_KEY)
if(localConfigStr){
//check localstorage for a value
let localConfig = JSON.parse(localConfigStr)
currentScrutinyConfig = localConfig
}
// Set the private defaults // Set the private defaults
this._config = new BehaviorSubject(config); this._config = new BehaviorSubject(currentScrutinyConfig);
} }
// ----------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------
@ -27,15 +37,20 @@ export class TreoConfigService
/** /**
* Setter and getter for config * Setter and getter for config
*/ */
//Setter
set config(value: any) set config(value: any)
{ {
// Merge the new config over to the current config // Merge the new config over to the current config
const config = _.merge({}, this._config.getValue(), value); const config = _.merge({}, this._config.getValue(), value);
//Store the config in localstorage
localStorage.setItem(SCRUTINY_CONFIG_LOCAL_STORAGE_KEY, JSON.stringify(config));
// Execute the observable // Execute the observable
this._config.next(config); this._config.next(config);
} }
//Getter
get config$(): Observable<any> get config$(): Observable<any>
{ {
return this._config.asObservable(); return this._config.asObservable();

@ -129,10 +129,7 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy
continue continue
} }
let deviceName = `/dev/${deviceSummary.device.device_name}` let deviceName = this.deviceTitle(deviceSummary.device)
if(deviceSummary.device.host_id){
deviceName = `${deviceSummary.device.host_id} - ${deviceName}`
}
var deviceSeriesMetadata = { var deviceSeriesMetadata = {
name: deviceName, name: deviceName,

Loading…
Cancel
Save