From 25232baafea5b6984db74d15790a53868bae807f Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Fri, 24 Jan 2020 06:18:51 -0500 Subject: [PATCH] implement LI grid filtering for acqlia title and author Signed-off-by: Galen Charlton --- .../src/app/staff/acq/search/acq-search.service.ts | 73 ++++++++++++++++------ .../acq/search/lineitem-results.component.html | 4 +- 2 files changed, 55 insertions(+), 22 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.service.ts b/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.service.ts index 55f30d726c..c3847e20eb 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.service.ts @@ -2,7 +2,9 @@ import {Injectable} from '@angular/core'; import {NetService} from '@eg/core/net.service'; import {AuthService} from '@eg/core/auth.service'; import {GridDataSource} from '@eg/share/grid/grid'; +import {PcrudService} from '@eg/core/pcrud.service'; import {Pager} from '@eg/share/util/pager'; +import {IdlObject} from '@eg/core/idl.service'; const defaultSearch = { lineitem: { @@ -88,11 +90,30 @@ export class AcqSearchService { _terms: AcqSearchTerm[] = []; _conjunction = 'all'; + attrDefs: {[code: string]: IdlObject}; constructor( private net: NetService, - private auth: AuthService + private auth: AuthService, + private pcrud: PcrudService ) { + this.attrDefs = {}; + } + + fetchAttrDefs(): Promise { + if (Object.keys(this.attrDefs).length) { + return Promise.resolve(); + } + return new Promise((resolve, reject) => { + this.pcrud.retrieveAll('acqliad', {}, + {atomic: true} + ).subscribe(list => { + list.forEach(acqliad => { + this.attrDefs[acqliad.code()] = acqliad; + }); + resolve(); + }); + }); } setSearch(search: AcqSearch) { @@ -141,6 +162,7 @@ export class AcqSearchService { // note that date filters coming from the grid do not need // to worry about __castdate because the grid filter supplies // both the start and end times + const observables = []; Object.keys(filters).forEach(filterField => { filters[filterField].forEach(condition => { const searchTerm: Object = {}; @@ -166,11 +188,20 @@ export class AcqSearchService { } } - searchTerm[filterField] = filterVal; if (filterOp in operatorMap) { searchTerm[operatorMap[filterOp]] = true; } - andTerms[coreRecType].push(searchTerm); + if ((['title', 'author'].indexOf(filterField) > -1) && + (filterField in this.attrDefs)) { + if (!('acqlia' in andTerms)) { + andTerms['acqlia'] = []; + } + searchTerm[this.attrDefs[filterField].id()] = filterVal; + andTerms['acqlia'].push(searchTerm); + } else { + searchTerm[filterField] = filterVal; + andTerms[coreRecType].push(searchTerm); + } }); }); console.debug(andTerms); @@ -180,23 +211,25 @@ export class AcqSearchService { getAcqSearchDataSource(searchType: string): GridDataSource { const gridSource = new GridDataSource(); - gridSource.getRows = (pager: Pager) => { - - const currentSearch = this.generateAcqSearch(searchType, gridSource.filters); - - const opts = { ...searchOptions[searchType] }; - opts['offset'] = pager.offset; - opts['limit'] = pager.limit; - return this.net.request( - 'open-ils.acq', - 'open-ils.acq.' + searchType + '.unified_search', - this.auth.token(), - currentSearch.andTerms, - currentSearch.orTerms, - null, - opts - ); - }; + this.fetchAttrDefs().then(() => { + gridSource.getRows = (pager: Pager) => { + + const currentSearch = this.generateAcqSearch(searchType, gridSource.filters); + + const opts = { ...searchOptions[searchType] }; + opts['offset'] = pager.offset; + opts['limit'] = pager.limit; + return this.net.request( + 'open-ils.acq', + 'open-ils.acq.' + searchType + '.unified_search', + this.auth.token(), + currentSearch.andTerms, + currentSearch.orTerms, + null, + opts + ); + }; + }); return gridSource; } } diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.html b/Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.html index 794fa4029f..18eee2c7bd 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.html +++ b/Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.html @@ -59,8 +59,8 @@ - - + + -- 2.11.0