From 11262a4427fce0a7d735dfbc774bb81d3d8b969a Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 17 Jun 2021 11:44:53 -0400 Subject: [PATCH] LPXXX Support dynamic Angular config changes Starting with facets. Signed-off-by: Bill Erickson --- Open-ILS/src/eg2/src/app/core/config.ts | 27 ++++++++++++++++++++++ .../app/staff/catalog/result/facets.component.ts | 5 +++- Open-ILS/src/eg2/src/index.html | 1 + Open-ILS/web/js/angular-config.js | 16 +++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 Open-ILS/src/eg2/src/app/core/config.ts create mode 100644 Open-ILS/web/js/angular-config.js diff --git a/Open-ILS/src/eg2/src/app/core/config.ts b/Open-ILS/src/eg2/src/app/core/config.ts new file mode 100644 index 0000000000..83555b1327 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/core/config.ts @@ -0,0 +1,27 @@ +/* Reads content from /js/angular-config.js to make it available as + * dynamic content to pre-compiled angular components. + * Note this is not an Angular Service, since it may need to be + * accessed before a service-loading class can instantiate its services. + */ +declare var ANGULAR_CONFIG; // defined in /js/angular-config.js + +export class AngularConfig { + + // Return the value found at the specified path in ANGULAR_CONFIG. + // E.g. AngularConfig.value('catalog', 'facets'); + static value(...path: string[]): any { + if (typeof ANGULAR_CONFIG === undefined) { + return null; + } + + let val = ANGULAR_CONFIG; + + Object.keys(arguments).sort().forEach(pos => { + const key = arguments[pos]; + if (val[key] === undefined) { return null; } + val = val[key] + }); + + return val; + } +} diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/result/facets.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/result/facets.component.ts index aacb27c3bc..5e0ae8059a 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/result/facets.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/result/facets.component.ts @@ -3,8 +3,11 @@ import {CatalogService} from '@eg/share/catalog/catalog.service'; import {CatalogUrlService} from '@eg/share/catalog/catalog-url.service'; import {CatalogSearchContext, FacetFilter} from '@eg/share/catalog/search-context'; import {StaffCatalogService} from '../catalog.service'; +import {AngularConfig} from '@eg/core/config'; -export const FACET_CONFIG = { +let facetConfig = AngularConfig.value('catalog', 'facets'); + +export const FACET_CONFIG = facetConfig || { display: [ {facetClass : 'author', facetOrder : ['personal', 'corporate']}, {facetClass : 'subject', facetOrder : ['topic']}, diff --git a/Open-ILS/src/eg2/src/index.html b/Open-ILS/src/eg2/src/index.html index 9ecb4c51fb..aedc25be1e 100644 --- a/Open-ILS/src/eg2/src/index.html +++ b/Open-ILS/src/eg2/src/index.html @@ -13,5 +13,6 @@ + diff --git a/Open-ILS/web/js/angular-config.js b/Open-ILS/web/js/angular-config.js new file mode 100644 index 0000000000..e087503073 --- /dev/null +++ b/Open-ILS/web/js/angular-config.js @@ -0,0 +1,16 @@ + +const ANGULAR_CONFIG = { + catalog: { + facets: { + display: [ + {facetClass : 'author', facetOrder : ['personal', 'corporate']}, + {facetClass : 'subject', facetOrder : ['topic']}, + {facetClass : 'identifier', facetOrder : ['genre']}, + {facetClass : 'series', facetOrder : ['seriestitle']}, + {facetClass : 'subject', facetOrder : ['name', 'geographic']} + ], + displayCount : 5 + } + } +} + -- 2.11.0