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: {
_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<void> {
+ 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) {
// 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 = {};
}
}
- 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);
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;
}
}