Fix prefs
This commit is contained in:
parent
9daa71609f
commit
8f27ba6735
1 changed files with 13 additions and 8 deletions
|
@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
|
||||||
import { HttpClient } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import {
|
import {
|
||||||
map,
|
map,
|
||||||
|
merge,
|
||||||
Observable,
|
Observable,
|
||||||
ReplaySubject,
|
ReplaySubject,
|
||||||
shareReplay,
|
shareReplay,
|
||||||
|
@ -72,11 +73,9 @@ export class PrefsService {
|
||||||
get(k: string): Observable<any> {
|
get(k: string): Observable<any> {
|
||||||
if (!this._getPref.get(k)) {
|
if (!this._getPref.get(k)) {
|
||||||
return this.prefs$.pipe(
|
return this.prefs$.pipe(
|
||||||
map((res) => {
|
switchMap((res) => {
|
||||||
let rv = <Preferences>res.sysPrefs;
|
let rv = <Preferences>res.sysPrefs;
|
||||||
return <Preferences>mergeDeep(rv, res.userPrefs);
|
let pref = <Preferences>mergeDeep(rv, res.userPrefs);
|
||||||
}),
|
|
||||||
switchMap((pref) => {
|
|
||||||
let ns = new ReplaySubject<any>(1);
|
let ns = new ReplaySubject<any>(1);
|
||||||
ns.next(pref ? pref[k] : null);
|
ns.next(pref ? pref[k] : null);
|
||||||
return ns;
|
return ns;
|
||||||
|
@ -88,17 +87,23 @@ export class PrefsService {
|
||||||
}
|
}
|
||||||
|
|
||||||
set(pref: string, value: any) {
|
set(pref: string, value: any) {
|
||||||
|
if (this.last == null) {
|
||||||
|
this.last = <UserSysPreferences>{};
|
||||||
|
}
|
||||||
|
if (this.last.userPrefs == null) {
|
||||||
|
this.last.userPrefs = <Preferences>{};
|
||||||
|
}
|
||||||
this.last.userPrefs[pref] = value;
|
this.last.userPrefs[pref] = value;
|
||||||
let ex = this._getPref.get(pref);
|
let ex = this._getPref.get(pref);
|
||||||
if (ex == null) {
|
if (ex == null) {
|
||||||
ex = new ReplaySubject<any>(1);
|
ex = new ReplaySubject<any>(1);
|
||||||
this._getPref.set(pref, ex);
|
this._getPref.set(pref, ex);
|
||||||
|
ex.next(value);
|
||||||
}
|
}
|
||||||
console.log("set", pref, value);
|
console.log('gonna up');
|
||||||
this.http
|
this.http
|
||||||
.put<Preferences>('/api/prefs/stillbox', this.last.userPrefs)
|
.put<Preferences>('/api/prefs/stillbox', this.last.userPrefs)
|
||||||
.subscribe((ev) => {});
|
.subscribe((ev) => {});
|
||||||
console.log("set", pref, value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +113,7 @@ export class PrefsService {
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
export function isObject(item: any): boolean {
|
export function isObject(item: any): boolean {
|
||||||
return (item && typeof item === 'object' && !Array.isArray(item));
|
return item && typeof item === 'object' && !Array.isArray(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue