From: Galen Charlton Date: Sat, 25 Jan 2020 15:28:08 +0000 (-0500) Subject: implement the run-immediately checkbox X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=ad065543e43b47ae6af0ad3b18ac8d41e202cedb;p=working%2FEvergreen.git implement the run-immediately checkbox Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search-form.component.html b/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search-form.component.html index 4f4221eada..0858c8cdcd 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search-form.component.html +++ b/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search-form.component.html @@ -114,7 +114,13 @@
-
+
+
+ + +
diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search-form.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search-form.component.ts index 1a2c685f25..92a07f6e95 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search-form.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search-form.component.ts @@ -17,6 +17,7 @@ export class AcqSearchFormComponent implements OnInit, AfterViewInit { @Input() initialSearchTerms: AcqSearchTerm[] = []; @Input() defaultSearchSetting = ''; + @Input() runImmediatelySetting = ''; @Input() searchTypeLabel = ''; @Output() searchSubmitted = new EventEmitter(); @@ -30,6 +31,7 @@ export class AcqSearchFormComponent implements OnInit, AfterViewInit { validSearchTypes = ['lineitems', 'purchaseorders', 'invoices', 'selectionlists']; defaultSearchType = 'lineitems'; searchConjunction = 'all'; + runImmediately = false; searchTerms: AcqSearchTerm[] = []; @@ -44,58 +46,66 @@ export class AcqSearchFormComponent implements OnInit, AfterViewInit { ngOnInit() { const self = this; - this.hints.forEach( - function(hint) { - const o = {}; - o['__label'] = self.idl.classes[hint].label; - o['__fields'] = []; - self.idl.classes[hint].fields.forEach( - function(field) { - if (!field.virtual) { - o['__fields'].push(field.name); - o[field.name] = { - label: field.label, - datatype: field.datatype - }; - self.searchTermDatatypes[hint + ':' + field.name] = field.datatype; - if (field.datatype === 'link') { - self.searchFieldLinkedClasses[hint + ':' + field.name] = field.class; + this.store.getItem(this.runImmediatelySetting).then(val => { + this.runImmediately = val + + this.hints.forEach( + function(hint) { + const o = {}; + o['__label'] = self.idl.classes[hint].label; + o['__fields'] = []; + self.idl.classes[hint].fields.forEach( + function(field) { + if (!field.virtual) { + o['__fields'].push(field.name); + o[field.name] = { + label: field.label, + datatype: field.datatype + }; + self.searchTermDatatypes[hint + ':' + field.name] = field.datatype; + if (field.datatype === 'link') { + self.searchFieldLinkedClasses[hint + ':' + field.name] = field.class; + } } } + ); + self.availableSearchFields[hint] = o; + } + ); + + this.hints.push('acqlia'); + this.availableSearchFields['acqlia'] = {'__label': this.idl.classes.acqlia.label, '__fields': []}; + this.pcrud.retrieveAll('acqliad', {'order_by': {'acqliad': 'id'}}) + .subscribe(liad => { + this.availableSearchFields['acqlia']['__fields'].push('' + liad.id()); + this.availableSearchFields['acqlia'][liad.id()] = { + label: liad.description(), + datatype: 'text' + }; + this.searchTermDatatypes['acqlia:' + liad.id()] = 'text'; + }); + + if (this.initialSearchTerms.length > 0) { + this.searchTerms = JSON.parse(JSON.stringify(this.initialSearchTerms)); // deep copy + this.submitSearch(); // if we've been passed an initial search, e.g., via a URL, assume + // we want the results immediately regardless of the workstation + // setting + } else { + this.store.getItem(this.defaultSearchSetting).then( + defaultSearch => { + if (defaultSearch) { + this.searchTerms = JSON.parse(JSON.stringify(defaultSearch.terms)); + this.searchConjunction = defaultSearch.conjunction; + } else { + this.addSearchTerm(); + } + if (this.runImmediately) { + this.submitSearch(); + } } ); - self.availableSearchFields[hint] = o; } - ); - - this.hints.push('acqlia'); - this.availableSearchFields['acqlia'] = {'__label': this.idl.classes.acqlia.label, '__fields': []}; - this.pcrud.retrieveAll('acqliad', {'order_by': {'acqliad': 'id'}}) - .subscribe(liad => { - this.availableSearchFields['acqlia']['__fields'].push('' + liad.id()); - this.availableSearchFields['acqlia'][liad.id()] = { - label: liad.description(), - datatype: 'text' - }; - this.searchTermDatatypes['acqlia:' + liad.id()] = 'text'; }); - - if (this.initialSearchTerms.length > 0) { - this.searchTerms = JSON.parse(JSON.stringify(this.initialSearchTerms)); // deep copy - this.submitSearch(); - } else { - this.store.getItem(this.defaultSearchSetting).then( - defaultSearch => { - if (defaultSearch) { - this.searchTerms = JSON.parse(JSON.stringify(defaultSearch.terms)); - this.searchConjunction = defaultSearch.conjunction; - this.submitSearch(); - } else { - this.addSearchTerm(); - } - } - ); - } } ngAfterViewInit() {} @@ -141,9 +151,13 @@ export class AcqSearchFormComponent implements OnInit, AfterViewInit { } submitSearch() { - this.searchSubmitted.emit({ - terms: this.searchTerms, - conjunction: this.searchConjunction + // tossing setTimeout here to ensure that the + // grid data source is fully initialized + setTimeout(() => { + this.searchSubmitted.emit({ + terms: this.searchTerms, + conjunction: this.searchConjunction + }); }); } @@ -153,4 +167,7 @@ export class AcqSearchFormComponent implements OnInit, AfterViewInit { conjunction: this.searchConjunction }); } + saveRunImmediately() { + return this.store.setItem(this.runImmediatelySetting, this.runImmediately); + } } 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 c3847e20eb..8e9364ef5f 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 @@ -1,4 +1,5 @@ import {Injectable} from '@angular/core'; +import {empty} from 'rxjs'; import {NetService} from '@eg/core/net.service'; import {AuthService} from '@eg/core/auth.service'; import {GridDataSource} from '@eg/share/grid/grid'; @@ -91,6 +92,7 @@ export class AcqSearchService { _terms: AcqSearchTerm[] = []; _conjunction = 'all'; attrDefs: {[code: string]: IdlObject}; + firstRun = true; constructor( private net: NetService, @@ -98,6 +100,7 @@ export class AcqSearchService { private pcrud: PcrudService ) { this.attrDefs = {}; + this.firstRun = true; } fetchAttrDefs(): Promise { @@ -119,6 +122,7 @@ export class AcqSearchService { setSearch(search: AcqSearch) { this._terms = search.terms; this._conjunction = search.conjunction; + this.firstRun = false; } generateAcqSearch(searchType, filters): any { @@ -214,6 +218,15 @@ export class AcqSearchService { this.fetchAttrDefs().then(() => { gridSource.getRows = (pager: Pager) => { + // don't do a search the very first time we + // get invoked, which is during initialization; we'll + // let components higher up the change decide whether + // to submit a search + if (this.firstRun) { + this.firstRun = false; + return empty(); + } + const currentSearch = this.generateAcqSearch(searchType, gridSource.filters); const opts = { ...searchOptions[searchType] }; diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/invoice-results.component.html b/Open-ILS/src/eg2/src/app/staff/acq/search/invoice-results.component.html index ee5dc0eeea..e5823a4a14 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/search/invoice-results.component.html +++ b/Open-ILS/src/eg2/src/app/staff/acq/search/invoice-results.component.html @@ -1,5 +1,6 @@ + i18n-searchTypeLabel searchTypeLabel="Invoice" runImmediatelySetting="eg.acq.search.invoices.run_immediately" + defaultSearchSetting="eg.acq.search.default.invoices"> + i18n-searchTypeLabel searchTypeLabel="Line Item" runImmediatelySetting="eg.acq.search.lineitems.run_immediately" + defaultSearchSetting="eg.acq.search.default.lineitems"> + i18n-searchTypeLabel searchTypeLabel="Selection List" runImmediatelySetting="eg.acq.search.selectionlists.run_immediately" + defaultSearchSetting="eg.acq.search.default.selectionlists"> diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/purchase-order-results.component.html b/Open-ILS/src/eg2/src/app/staff/acq/search/purchase-order-results.component.html index b3c2528e91..14c6d96785 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/search/purchase-order-results.component.html +++ b/Open-ILS/src/eg2/src/app/staff/acq/search/purchase-order-results.component.html @@ -1,5 +1,6 @@ + i18n-searchTypeLabel searchTypeLabel="Purchase Order" runImmediatelySetting="eg.acq.search.purchaseorders.run_immediately" + defaultSearchSetting="eg.acq.search.default.purchaseorders">