]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider-search-form.component.ts
LP1959048: manual ng lint fixes
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / acq / provider / acq-provider-search-form.component.ts
1 import {Component, OnInit, Output, EventEmitter} from '@angular/core';
2 import {AuthService} from '@eg/core/auth.service';
3 import {AcqProviderSearchTerm, AcqProviderSearch} from './acq-provider-search.service';
4 import {StoreService} from '@eg/core/store.service';
5 import {OrgFamily} from '@eg/share/org-family-select/org-family-select.component';
6
7 @Component({
8   selector: 'eg-acq-provider-search-form',
9   styleUrls: ['acq-provider-search-form.component.css'],
10   templateUrl: './acq-provider-search-form.component.html'
11 })
12
13 export class AcqProviderSearchFormComponent implements OnInit {
14
15     @Output() searchSubmitted = new EventEmitter<AcqProviderSearch>();
16
17     collapsed = false;
18
19     providerName = '';
20     providerCode = '';
21     providerOwners: OrgFamily;
22     contactName = '';
23     providerEmail = '';
24     providerPhone = '';
25     providerCurrencyType = '';
26     providerSAN = '';
27     providerEDIDefault = null;
28     providerURL = '';
29     providerIsActive = 'active';
30
31     constructor(
32         private localStore: StoreService,
33         private auth: AuthService,
34     ) {}
35
36     ngOnInit() {
37         const self = this;
38         this.providerOwners = {primaryOrgId: this.auth.user().ws_ou(), includeDescendants: true};
39         this.collapsed = this.localStore.getLocalItem('eg.acq.provider.search.collapse_form') || false;
40     }
41
42     clearSearch() {
43         this.providerName = '';
44         this.providerCode = '';
45         this.providerOwners = {primaryOrgId: this.auth.user().ws_ou(), includeDescendants: true};
46         this.contactName = '';
47         this.providerEmail = '';
48         this.providerPhone = '';
49         this.providerCurrencyType = '';
50         this.providerSAN = '';
51         this.providerEDIDefault = null;
52         this.providerURL = '';
53         this.providerIsActive = 'active';
54     }
55
56     submitSearch() {
57
58         const searchTerms: AcqProviderSearchTerm[] = [];
59         if (this.providerName) {
60             searchTerms.push({ classes: ['acqpro'], fields: ['name'], op: 'ilike', value: this.providerName });
61         }
62         if (this.providerCode) {
63             searchTerms.push({ classes: ['acqpro'], fields: ['code'], op: 'ilike', value: this.providerCode });
64         }
65         if (this.providerOwners) {
66             searchTerms.push({ classes: ['acqpro'], fields: ['owner'], op: 'in', value: this.providerOwners.orgIds });
67         }
68         if (this.contactName) {
69             searchTerms.push({ classes: ['acqpc'], fields: ['name'], op: 'ilike', value: this.contactName });
70         }
71         if (this.providerEmail) {
72             searchTerms.push({ classes: ['acqpro', 'acqpc'], fields: ['email', 'email'], op: 'ilike', value: this.providerEmail });
73         }
74         if (this.providerPhone) {
75             // this requires the flesh hash to contain: { ... join: { acqpc: { type: 'left' } } ... }
76             searchTerms.push({
77                 classes: ['acqpc', 'acqpro', 'acqpro'],
78                 fields: ['phone', 'phone', 'fax_phone'],
79                 op: 'ilike',
80                 value: this.providerPhone,
81             });
82         }
83         if (this.providerCurrencyType) {
84             searchTerms.push({ classes: ['acqpro'], fields: ['currency_type'], op: '=', value: this.providerCurrencyType });
85         }
86         if (this.providerSAN) {
87             searchTerms.push({ classes: ['acqpro'], fields: ['san'], op: 'ilike', value: this.providerSAN });
88         }
89         if (this.providerEDIDefault) {
90             searchTerms.push({ classes: ['acqpro'], fields: ['edi_default'], op: '=', value: this.providerEDIDefault });
91         }
92         if (this.providerURL) {
93             searchTerms.push({ classes: ['acqpro'], fields: ['url'], op: 'ilike', value: this.providerURL });
94         }
95         switch (this.providerIsActive) {
96             case 'active': {
97                 searchTerms.push({ classes: ['acqpro'], fields: ['active'], op: '=', value: 't' });
98                 break;
99             }
100             case 'inactive': {
101                 searchTerms.push({ classes: ['acqpro'], fields: ['active'], op: '=', value: 'f' });
102                 break;
103             }
104         }
105
106         // tossing setTimeout here to ensure that the
107         // grid data source is fully initialized
108         setTimeout(() => {
109             this.searchSubmitted.emit({
110                 terms: searchTerms,
111             });
112         });
113     }
114
115     toggleCollapse() {
116         this.collapsed = ! this.collapsed;
117         this.localStore.setLocalItem('eg.acq.provider.search.collapse_form', this.collapsed);
118     }
119
120 }