From 117d4496573c56bee495f42dc50e782e4d380b71 Mon Sep 17 00:00:00 2001 From: Zavier Banks Date: Fri, 1 Nov 2019 15:55:40 +0000 Subject: [PATCH] LP#1849212 Angular Search Course Reserves Facet Added a facet that filtered the search based on the course reserves. Signed-off-by: Zavier Banks --- .../src/app/share/catalog/catalog-url.service.ts | 14 +++++++- .../eg2/src/app/share/catalog/catalog.service.ts | 40 ++++++++++++++++++---- .../eg2/src/app/staff/catalog/catalog.service.ts | 1 - .../app/staff/catalog/result/results.component.ts | 3 -- .../app/staff/catalog/search-form.component.html | 8 +++++ 5 files changed, 54 insertions(+), 12 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/catalog/catalog-url.service.ts b/Open-ILS/src/eg2/src/app/share/catalog/catalog-url.service.ts index 4c45a4e3c7..945a8ac641 100644 --- a/Open-ILS/src/eg2/src/app/share/catalog/catalog-url.service.ts +++ b/Open-ILS/src/eg2/src/app/share/catalog/catalog-url.service.ts @@ -82,7 +82,7 @@ export class CatalogUrlService { params.matchOp = []; ['format', 'available', 'hasBrowseEntry', 'date1', - 'date2', 'dateOp', 'groupByMetarecord', 'fromMetarecord'] + 'date2', 'dateOp', 'groupByMetarecord', 'fromMetarecord', 'isCourseFiltered'] .forEach(field => { if (ts[field]) { params[field] = ts[field]; @@ -223,6 +223,18 @@ export class CatalogUrlService { } }); + //Booleans + ['isCourseFiltered'].forEach(field =>{ + if(params.has(field)){ + if(params.get(field) == "true" || params.get(field)){ + ts[field] = true; + } + if(params.get(field) == "false" || !params.get(field)){ + ts[field] = false; + } + } + }); + // Arrays ['query', 'fieldClass', 'joinOp', 'matchOp'].forEach(field => { const arr = params.getAll(field); diff --git a/Open-ILS/src/eg2/src/app/share/catalog/catalog.service.ts b/Open-ILS/src/eg2/src/app/share/catalog/catalog.service.ts index 2aaaf1f3ae..d451308036 100644 --- a/Open-ILS/src/eg2/src/app/share/catalog/catalog.service.ts +++ b/Open-ILS/src/eg2/src/app/share/catalog/catalog.service.ts @@ -26,6 +26,7 @@ export class CatalogService { // Allow anyone to watch for completed searches. onSearchComplete: EventEmitter; + course_filtered_query: any; constructor( private idl: IdlService, @@ -37,12 +38,12 @@ export class CatalogService { private basket: BasketService ) { this.onSearchComplete = new EventEmitter(); - + this.retrieveCourseMaterials(); } search(ctx: CatalogSearchContext): Promise { ctx.searchState = CatalogSearchState.SEARCHING; - + if (ctx.showBasket) { return this.basketSearch(ctx); } else if (ctx.marcSearch.isSearchable()) { @@ -109,10 +110,8 @@ export class CatalogService { } termSearch(ctx: CatalogSearchContext): Promise { - let method = 'open-ils.search.biblio.multiclass.query'; let fullQuery; - if (ctx.identSearch.isSearchable()) { fullQuery = ctx.compileIdentSearchQuery(); @@ -128,13 +127,20 @@ export class CatalogService { this.fetchBrowseEntry(ctx); } } - console.debug(`search query: ${fullQuery}`); if (ctx.isStaff) { method += '.staff'; } + if(ctx.termSearch.isCourseFiltered){ + return this.netRequest(ctx, method, fullQuery + this.course_filtered_query +")");//Pass the course filter, combined with the full query + }else{ + return this.netRequest(ctx, method, fullQuery); + } + + } + netRequest(ctx, method, fullQuery): Promise { return new Promise((resolve, reject) => { this.net.request( 'open-ils.search', method, { @@ -142,14 +148,34 @@ export class CatalogService { offset : ctx.pager.offset }, fullQuery, true ).subscribe(result => { - this.applyResultData(ctx, result); + if(ctx.termSearch.isCourseFiltered){ + this.applyResultData(ctx, result) + } + else{ + this.applyResultData(ctx, result) + } ctx.searchState = CatalogSearchState.COMPLETE; this.onSearchComplete.emit(ctx); resolve(); }); }); - } + + /** + * Retrieves course materials info, and adds the ids of the course books to a filter. + */ + retrieveCourseMaterials(){ + this.course_filtered_query = " ("; + var index = 0; + this.pcrud.retrieveAll("acmcm").subscribe(result =>{ + if(index==0){ + this.course_filtered_query += '(id:'+ result.item()+')' + } + this.course_filtered_query += ' || (id:'+ result.item()+')' + index++; + }); + } + // When showing titles linked to a browse entry, fetch // the entry data as well so the UI can display it. diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/catalog.service.ts b/Open-ILS/src/eg2/src/app/staff/catalog/catalog.service.ts index 86501fc10f..e786e609a2 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/catalog.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/catalog.service.ts @@ -74,7 +74,6 @@ export class StaffCatalogService { if (!this.searchContext.isSearchable()) { return; } const params = this.catUrl.toUrlParams(this.searchContext); - // Force a new search every time this method is called, even if // it's the same as the active search. Since router navigation // exits early when the route + params is identical, add a diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/result/results.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/result/results.component.ts index 869eff2e79..daedaf294e 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/result/results.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/result/results.component.ts @@ -94,7 +94,6 @@ export class ResultsComponent implements OnInit, OnDestroy { this.catUrl.applyUrlParams(this.searchContext, params); if (this.searchContext.isSearchable()) { - this.cat.search(this.searchContext) .then(ok => { this.cat.fetchFacets(this.searchContext); @@ -108,7 +107,6 @@ export class ResultsComponent implements OnInit, OnDestroy { // To reduce page display shuffling, avoid showing the list of // records until the first few are ready to render. shouldStartRendering(): boolean { - if (this.searchHasResults()) { const pageCount = this.searchContext.currentResultIds().length; switch (pageCount) { @@ -119,7 +117,6 @@ export class ResultsComponent implements OnInit, OnDestroy { && this.searchContext.result.records[1]; } } - return false; } diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.html b/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.html index d032f3d08f..a2ef565d6c 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.html +++ b/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.html @@ -123,6 +123,14 @@ TODO focus search input Results from All Libraries +
+ + + +
-- 2.11.0