]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/reporter/simple/sr-sort-order.component.ts
LP1959048: manual ng lint fixes
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / reporter / simple / sr-sort-order.component.ts
1 import {Component, Input, Output, EventEmitter, ViewChild} from '@angular/core';
2 import {NgbAccordion} from '@ng-bootstrap/ng-bootstrap';
3 import {IdlService, IdlObject} from '@eg/core/idl.service';
4 import {SimpleReporterService} from './simple-reporter.service';
5
6 @Component({
7     selector: 'eg-sr-sort-order',
8     styleUrls: ['./sr-sort-order.component.css'],
9     templateUrl: './sr-sort-order.component.html'
10 })
11
12 export class SRSortOrderComponent {
13
14     @Input() fields: IdlObject[] = [];
15     @Output() fieldsChange = new EventEmitter<IdlObject[]>();
16     @Input() orderByNames: string[] = [];
17     @Output() orderByNamesChange = new EventEmitter<string[]>();
18
19     @ViewChild('displayList', { static: false }) displayList: NgbAccordion;
20     @ViewChild('orderList', { static: false }) orderList: NgbAccordion;
21
22     constructor(
23         private idl: IdlService,
24         private srSvc: SimpleReporterService
25     ) {
26     }
27
28     updateField(field: IdlObject) {
29         const idx = this.fields.findIndex(el => el.name === field.name);
30         this.fields[idx] = field;
31         this.fieldsChange.emit(this.fields);
32     }
33
34     moveDisplayUp(idx: number) {
35         if ( idx > 0 ) { // should always be the case, but we check anyway
36             const hold: IdlObject = this.fields[idx - 1];
37             this.fields[idx - 1] = this.fields[idx];
38             this.fields[idx] = hold;
39             this.fieldsChange.emit(this.fields);
40         }
41     }
42
43     moveDisplayDown(idx: number) {
44         if ( idx < this.fields.length ) { // see above comment
45             const hold: IdlObject = this.fields[idx + 1];
46             this.fields[idx + 1] = this.fields[idx];
47             this.fields[idx] = hold;
48             this.fieldsChange.emit(this.fields);
49         }
50     }
51
52     moveOrderUp(idx: number) {
53         if ( idx > 0 ) {
54             const hold: string = this.orderByNames[idx - 1];
55             this.orderByNames[idx - 1] = this.orderByNames[idx];
56             this.orderByNames[idx] = hold;
57             this.orderByNamesChange.emit(this.orderByNames);
58         }
59     }
60
61     moveOrderDown(idx: number) {
62         if ( idx < this.orderByNames.length ) {
63             const hold: string = this.orderByNames[idx + 1];
64             this.orderByNames[idx + 1] = this.orderByNames[idx];
65             this.orderByNames[idx] = hold;
66             this.orderByNamesChange.emit(this.orderByNames);
67         }
68     }
69
70     fieldsInOrderByOrder() {
71         const sorted = [];
72         this.orderByNames.forEach(el => {
73             sorted.push(this.fields[this.fields.findIndex(fl => fl.name === el)]);
74         });
75         return sorted;
76     }
77
78 }