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';
9 selector: 'eg-sr-sort-order',
10 styleUrls: ['./sr-sort-order.component.css'],
11 templateUrl: './sr-sort-order.component.html'
14 export class SRSortOrderComponent implements OnInit {
16 @Input() fields: IdlObject[] = [];
17 @Output() fieldsChange = new EventEmitter<IdlObject[]>();
18 @Input() orderByNames: string[] = [];
19 @Output() orderByNamesChange = new EventEmitter<string[]>();
21 @ViewChild('displayList', { static: false }) displayList: NgbAccordion;
22 @ViewChild('orderList', { static: false }) orderList: NgbAccordion;
25 private idl: IdlService,
26 private srSvc: SimpleReporterService
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);
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);
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);
57 moveOrderUp(idx: number) {
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);
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);
75 fieldsInOrderByOrder() {
77 this.orderByNames.forEach(el => {
78 sorted.push(this.fields[this.fields.findIndex(fl => fl.name === el)]);