2020-02-09 05:09:46 +00:00
|
|
|
import {Component, Input, OnInit} from '@angular/core';
|
2020-11-10 14:03:42 +00:00
|
|
|
import {AlertController, ModalController} from '@ionic/angular';
|
2020-11-10 13:45:56 +00:00
|
|
|
import {uuid_v4} from '../../../../utility';
|
2020-02-09 05:09:46 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'editor-database-columns',
|
|
|
|
templateUrl: './columns.component.html',
|
|
|
|
styleUrls: ['./columns.component.scss'],
|
|
|
|
})
|
|
|
|
export class ColumnsComponent implements OnInit {
|
2020-02-18 17:19:05 +00:00
|
|
|
@Input() columnSets: Array<{headerName: string, field: string, Type: string, additionalData: any}> = [];
|
2020-02-09 05:09:46 +00:00
|
|
|
|
|
|
|
constructor(
|
2020-11-10 14:03:42 +00:00
|
|
|
protected modals: ModalController,
|
|
|
|
protected alerts: AlertController,
|
2020-02-09 05:09:46 +00:00
|
|
|
) { }
|
|
|
|
|
|
|
|
ngOnInit() {}
|
|
|
|
|
|
|
|
onAddColumnClick() {
|
2020-11-10 13:45:56 +00:00
|
|
|
this.columnSets.push({headerName: '', field: uuid_v4(), Type: '', additionalData: {}});
|
2020-02-18 17:19:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2020-02-09 05:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dismissModal(doSave = true) {
|
|
|
|
if ( doSave ) {
|
|
|
|
this.columnSets = this.columnSets.map(x => {
|
2020-11-10 13:45:56 +00:00
|
|
|
if ( !x.field ) {
|
|
|
|
x.field = uuid_v4();
|
|
|
|
}
|
2020-02-09 05:09:46 +00:00
|
|
|
return x;
|
2020-10-22 03:40:20 +00:00
|
|
|
});
|
|
|
|
|
2020-02-09 05:09:46 +00:00
|
|
|
this.modals.dismiss(this.columnSets);
|
|
|
|
} else {
|
|
|
|
this.modals.dismiss();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onDeleteClick(i) {
|
2020-11-10 14:03:42 +00:00
|
|
|
this.alerts.create({
|
|
|
|
header: 'Delete column?',
|
|
|
|
message: 'Are you sure you want to delete this column? Its data will be lost.',
|
|
|
|
buttons: [
|
|
|
|
{ text: 'Keep It', role: 'cancel' },
|
|
|
|
{
|
|
|
|
text: 'Delete It',
|
|
|
|
handler: () => {
|
|
|
|
this.columnSets = this.columnSets.filter((x, index) => {
|
|
|
|
return index !== i;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}
|
|
|
|
],
|
|
|
|
}).then(alert => alert.present());
|
2020-02-09 05:09:46 +00:00
|
|
|
}
|
|
|
|
|
2020-02-19 07:12:59 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-26 04:00:53 +00:00
|
|
|
iteratePin(i) {
|
|
|
|
if ( !this.columnSets[i].additionalData.pinned ) {
|
|
|
|
this.columnSets[i].additionalData.pinned = 'left';
|
|
|
|
} else if ( this.columnSets[i].additionalData.pinned === 'left' ) {
|
|
|
|
this.columnSets[i].additionalData.pinned = 'right';
|
|
|
|
} else {
|
|
|
|
delete this.columnSets[i].additionalData.pinned;
|
|
|
|
}
|
|
|
|
}
|
2020-02-09 05:09:46 +00:00
|
|
|
}
|