import {Component, Input, OnInit} from '@angular/core'; import {ModalController} from '@ionic/angular'; import {uuid_v4} from '../../../../utility'; @Component({ selector: 'editor-database-columns', templateUrl: './columns.component.html', styleUrls: ['./columns.component.scss'], }) export class ColumnsComponent implements OnInit { @Input() columnSets: Array<{headerName: string, field: string, Type: string, additionalData: any}> = []; constructor( protected modals: ModalController ) { } ngOnInit() {} onAddColumnClick() { this.columnSets.push({headerName: '', field: uuid_v4(), Type: '', additionalData: {}}); } onAddOption(i) { const set = this.columnSets[i]; if ( !Array.isArray(set.additionalData.options) ) { set.additionalData.options = []; } set.additionalData.options.push({value: ''}); } onDeleteOptionClick(i, n) { const set = this.columnSets[i]; set.additionalData.options = set.additionalData.options.filter((x, index) => index !== n); } dismissModal(doSave = true) { if ( doSave ) { this.columnSets = this.columnSets.map(x => { if ( !x.field ) { x.field = uuid_v4(); } return x; }); this.modals.dismiss(this.columnSets); } else { this.modals.dismiss(); } } onDeleteClick(i) { this.columnSets = this.columnSets.filter((x, index) => { return index !== i; }); } onUpArrow(i) { if ( this.columnSets[i - 1] ) { const temp = this.columnSets[i]; this.columnSets[i] = this.columnSets[i - 1]; this.columnSets[i - 1] = temp; } } onDownArrow(i) { if ( this.columnSets[i + 1] ) { const temp = this.columnSets[i]; this.columnSets[i] = this.columnSets[i + 1]; this.columnSets[i + 1] = temp; } } }