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';
7 selector: 'eg-sr-sort-order',
8 styleUrls: ['./sr-sort-order.component.css'],
9 templateUrl: './sr-sort-order.component.html'
12 export class SRSortOrderComponent {
14 @Input() fields: IdlObject[] = [];
15 @Output() fieldsChange = new EventEmitter<IdlObject[]>();
16 @Input() orderByNames: string[] = [];
17 @Output() orderByNamesChange = new EventEmitter<string[]>();
19 @ViewChild('displayList', { static: false }) displayList: NgbAccordion;
20 @ViewChild('orderList', { static: false }) orderList: NgbAccordion;
23 private idl: IdlService,
24 private srSvc: SimpleReporterService
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);
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);
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);
52 moveOrderUp(idx: number) {
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);
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);
70 fieldsInOrderByOrder() {
72 this.orderByNames.forEach(el => {
73 sorted.push(this.fields[this.fields.findIndex(fl => fl.name === el)]);