LPXXX Support dynamic Angular config changes user/berick/lpxxx-angular-dynamic-config
authorBill Erickson <berickxx@gmail.com>
Thu, 17 Jun 2021 15:44:53 +0000 (11:44 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 17 Jun 2021 15:44:55 +0000 (11:44 -0400)
Starting with facets.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/core/config.ts [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/catalog/result/facets.component.ts
Open-ILS/src/eg2/src/index.html
Open-ILS/web/js/angular-config.js [new file with mode: 0644]

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 (file)
index 0000000..83555b1
--- /dev/null
@@ -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;
+    }
+}
index aacb27c..5e0ae80 100644 (file)
@@ -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']},
index 9ecb4c5..aedc25b 100644 (file)
@@ -13,5 +13,6 @@
   <script src="/js/dojo/opensrf/JSON_v1.js"></script>
   <script src="/js/dojo/opensrf/opensrf.js"></script>
   <script src="/js/dojo/opensrf/opensrf_ws.js"></script>
+  <script src="/js/angular-config.js"></script>
 </body>
 </html>
diff --git a/Open-ILS/web/js/angular-config.js b/Open-ILS/web/js/angular-config.js
new file mode 100644 (file)
index 0000000..e087503
--- /dev/null
@@ -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
+        }
+    }
+}
+