From: Bill Erickson Date: Fri, 3 Aug 2018 17:38:46 +0000 (-0400) Subject: LP#1775466 Support server-stored settings X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=5626c7142a850aae75ac0b86130d614537e5acfa;p=working%2FEvergreen.git LP#1775466 Support server-stored settings Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/eg2/src/app/core/store.service.ts b/Open-ILS/src/eg2/src/app/core/store.service.ts index cce5a4686a..43ffa6f148 100644 --- a/Open-ILS/src/eg2/src/app/core/store.service.ts +++ b/Open-ILS/src/eg2/src/app/core/store.service.ts @@ -1,8 +1,18 @@ /** * Store and retrieve data from various sources. */ -import {Injectable} from '@angular/core'; +import {Injectable, Injector} from '@angular/core'; import {CookieService} from 'ngx-cookie'; +import {NetService} from './net.service'; + +// Settings summary objects returned by the API +export interface ServerSettingSummary { + name: string; + value: string; + has_org_setting: boolean; + has_user_setting: boolean; + has_workstation_setting: boolean; +} @Injectable({providedIn: 'root'}) export class StoreService { @@ -13,6 +23,11 @@ export class StoreService { // Note cookies shared with /eg/staff must be stored at "/" loginSessionBasePath = '/'; + // Loaded on demand to avoid circular ref in compiler. + auth: any; + + cache: {[key: string]: ServerSettingSummary}; + // Set of keys whose values should disappear at logout. loginSessionKeys: string[] = [ 'eg.auth.token', @@ -21,7 +36,12 @@ export class StoreService { 'eg.auth.time.oc' ]; - constructor(private cookieService: CookieService) {} + constructor( + private injector: Injector, + private cookieService: CookieService, + private net: NetService) { + this.cache = {}; + } private parseJson(valJson: string): any { if (valJson === undefined || valJson === null || valJson === '') { @@ -85,7 +105,29 @@ export class StoreService { } getServerItem(key: string): Promise { - return Promise.resolve(); + + if (this.cache[key]) { + return Promise.resolve(this.cache[key].value); + } + + if (!this.auth) { + this.auth = this.injector.get('AuthService'); + } + + if (this.auth.token()) { + return Promise.reject('auth token required for server settings'); + } + + return this.net.request( + 'open-ils.actor', + 'open-ils.actor.settings.retrieve', + [key], this.auth.token() + ).toPromise().then( + (summary: ServerSettingSummary) => { + this.cache[summary.name] = summary; + return summary.value; + } + ); } getSessionItem(key: string): any {