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