Skip to content

Commit

Permalink
persist settings across sessions (in local storage).
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ committed May 21, 2022
1 parent 0aeb13c commit 934f16f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
21 changes: 18 additions & 3 deletions webapp/frontend/src/@treo/services/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,31 @@ import { BehaviorSubject, Observable } from 'rxjs';
import * as _ from 'lodash';
import { TREO_APP_CONFIG } from '@treo/services/config/config.constants';

const SCRUTINY_CONFIG_LOCAL_STORAGE_KEY = 'scrutiny';

@Injectable({
providedIn: 'root'
})
export class TreoConfigService
{
// Private
private _config: BehaviorSubject<any>;

/**
* 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
this._config = new BehaviorSubject(config);
this._config = new BehaviorSubject(currentScrutinyConfig);
}

// -----------------------------------------------------------------------------------------------------
Expand All @@ -27,15 +37,20 @@ export class TreoConfigService
/**
* Setter and getter for config
*/
//Setter
set config(value: any)
{
// Merge the new config over to the current config
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
this._config.next(config);
}

//Getter
get config$(): Observable<any>
{
return this._config.asObservable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy
continue
}

let deviceName = `/dev/${deviceSummary.device.device_name}`
if(deviceSummary.device.host_id){
deviceName = `${deviceSummary.device.host_id} - ${deviceName}`
}
let deviceName = this.deviceTitle(deviceSummary.device)

var deviceSeriesMetadata = {
name: deviceName,
Expand Down

0 comments on commit 934f16f

Please sign in to comment.