From: Bill Erickson Date: Thu, 7 Dec 2017 03:13:19 +0000 (-0500) Subject: LP#626157 Ang2 experiments X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=9a7d23f07e9812cf60d4d85cc51a6ddbc9391ee5;p=working%2FEvergreen.git LP#626157 Ang2 experiments Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/webby-src/src/app/share/catalog/catalog.service.ts b/Open-ILS/webby-src/src/app/share/catalog/catalog.service.ts index f7efc0fdef..e88d12f4dc 100644 --- a/Open-ILS/webby-src/src/app/share/catalog/catalog.service.ts +++ b/Open-ILS/webby-src/src/app/share/catalog/catalog.service.ts @@ -22,7 +22,7 @@ export const CATALOG_CCVM_FILTERS = [ export class EgCatalogService { ccvmMap: {[ccvm:string] : EgIdlObject[]} = {}; - cmfMap: {[cmf:string] : EgIdlObject[]} = {}; + cmfMap: {[cmf:string] : EgIdlObject} = {}; constructor( private net: EgNetService, @@ -32,7 +32,6 @@ export class EgCatalogService { ) {} search(ctx: CatalogSearchContext): Promise { - ctx.result = {}; ctx.searchInProgress = true; var fullQuery = ctx.compileSearch(); @@ -74,6 +73,46 @@ export class EgCatalogService { }) } + fetchFacets(ctx: CatalogSearchContext): Promise { + + if (!ctx.result) return Promise.resolve(); + + return new Promise((resolve, reject) => { + this.net.request('open-ils.search', + 'open-ils.search.facet_cache.retrieve', + ctx.result.facet_key + ).subscribe(facets => { + let facetData = {}; + Object.keys(facets).forEach(cmfId => { + let facetHash = facets[cmfId]; + let cmf = this.cmfMap[cmfId]; + + let cmfData = []; + Object.keys(facetHash).forEach(value => { + let count = facetHash[value]; + cmfData.push({value : value, count : count}); + }); + + if (!facetData[cmf.field_class()]) + facetData[cmf.field_class()] = {}; + + facetData[cmf.field_class()][cmf.name()] = { + cmfLabel : cmf.label(), + valueList : cmfData.sort((a, b) => { + if (a.count > b.count) return -1; + if (a.count < b.count) return 1; + // secondary alpha sort on display value + return a.value < b.value ? -1 : 1; + }) + }; + }); + + ctx.result.facetData = facetData; + resolve(); + }); + }) + } + fetchCcvms(): Promise { if (Object.keys(this.ccvmMap).length) diff --git a/Open-ILS/webby-src/src/app/share/catalog/search-context.ts b/Open-ILS/webby-src/src/app/share/catalog/search-context.ts index a77cb6c685..d71b063122 100644 --- a/Open-ILS/webby-src/src/app/share/catalog/search-context.ts +++ b/Open-ILS/webby-src/src/app/share/catalog/search-context.ts @@ -30,7 +30,7 @@ export class CatalogSearchContext { isStaff: boolean; // Result from most recent search. - result: any; + result: any = {}; searchInProgress: boolean = false; // Utility stuff diff --git a/Open-ILS/webby-src/src/app/staff/catalog/resolver.service.ts b/Open-ILS/webby-src/src/app/staff/catalog/resolver.service.ts index e948cbb184..8929d551ae 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/resolver.service.ts +++ b/Open-ILS/webby-src/src/app/staff/catalog/resolver.service.ts @@ -28,7 +28,8 @@ export class EgCatalogResolver implements Resolve> { console.debug('EgCatalogResolver:resolve()'); return Promise.all([ - this.cat.fetchCcvms() + this.cat.fetchCcvms(), + this.cat.fetchCmfs() ]); } } diff --git a/Open-ILS/webby-src/src/app/staff/catalog/result/facets.component.html b/Open-ILS/webby-src/src/app/staff/catalog/result/facets.component.html index 124d5e74af..a951dc92aa 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/result/facets.component.html +++ b/Open-ILS/webby-src/src/app/staff/catalog/result/facets.component.html @@ -1 +1,42 @@ -TEST FACETS + +
+
+
+
+
+
+
+ {{searchContext.result.facetData[facetConf.facetClass][name].cmfLabel}} +
+ +
+
+
+
+
+
diff --git a/Open-ILS/webby-src/src/app/staff/catalog/result/facets.component.ts b/Open-ILS/webby-src/src/app/staff/catalog/result/facets.component.ts index 03d8a2f490..6bfce97439 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/result/facets.component.ts +++ b/Open-ILS/webby-src/src/app/staff/catalog/result/facets.component.ts @@ -3,6 +3,17 @@ import {EgCatalogService} from '@eg/share/catalog/catalog.service'; import {CatalogSearchContext} from '@eg/share/catalog/search-context'; import {StaffCatalogService} from '../staff-catalog.service'; +export const FACET_CONFIG = { + 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 +}; + @Component({ selector: 'eg-catalog-result-facets', styleUrls: ['facets.component.css'], @@ -11,16 +22,28 @@ import {StaffCatalogService} from '../staff-catalog.service'; export class ResultFacetsComponent implements OnInit { searchContext: CatalogSearchContext; + facetConfig: any; constructor( private cat: EgCatalogService, private staffCat: StaffCatalogService - ) {} + ) { + this.facetConfig = FACET_CONFIG; + } ngOnInit() { this.searchContext = this.staffCat.searchContext; } + facetIsApplied(cls: string, name: string, value: string) { + return this.searchContext.facetFilters.filter(f => { + return ( + f.facetClass == cls && + f.facetName == name && + f.facetValue == value + ); + })[0]; + } } diff --git a/Open-ILS/webby-src/src/app/staff/catalog/result/record.component.html b/Open-ILS/webby-src/src/app/staff/catalog/result/record.component.html index e04da00c3e..7c817ce677 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/result/record.component.html +++ b/Open-ILS/webby-src/src/app/staff/catalog/result/record.component.html @@ -99,14 +99,14 @@
diff --git a/Open-ILS/webby-src/src/app/staff/catalog/result/results.component.html b/Open-ILS/webby-src/src/app/staff/catalog/result/results.component.html index cf88c4c5db..796016c3ab 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/result/results.component.html +++ b/Open-ILS/webby-src/src/app/staff/catalog/result/results.component.html @@ -13,7 +13,7 @@
- +
diff --git a/Open-ILS/webby-src/src/app/staff/catalog/result/results.component.ts b/Open-ILS/webby-src/src/app/staff/catalog/result/results.component.ts index 1e0b0986b4..290d358705 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/result/results.component.ts +++ b/Open-ILS/webby-src/src/app/staff/catalog/result/results.component.ts @@ -57,6 +57,7 @@ export class ResultsComponent implements OnInit { if (!this.searchContext.query[0]) return; this.cat.search(this.searchContext).then(ok => { + this.cat.fetchFacets(this.searchContext); this.fleshSearchResults(); }); } diff --git a/Open-ILS/webby-src/src/app/staff/catalog/search-form.component.html b/Open-ILS/webby-src/src/app/staff/catalog/search-form.component.html index 1d6949b2ba..831bb3d833 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/search-form.component.html +++ b/Open-ILS/webby-src/src/app/staff/catalog/search-form.component.html @@ -73,12 +73,12 @@ TODO focus search input (click)="searchContext.reset()"> Clear Form - -