mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.6 KiB
56 lines
1.6 KiB
/*
|
|
* Squidex Headless CMS
|
|
*
|
|
* @license
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
|
|
*/
|
|
|
|
// tslint:disable: readonly-array
|
|
|
|
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
|
|
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, Output } from '@angular/core';
|
|
|
|
@Component({
|
|
selector: 'sqx-custom-view-editor',
|
|
styleUrls: ['./custom-view-editor.component.scss'],
|
|
templateUrl: './custom-view-editor.component.html',
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
|
})
|
|
export class CustomViewEditorComponent implements OnChanges {
|
|
@Output()
|
|
public fieldNamesChange = new EventEmitter<ReadonlyArray<string>>();
|
|
|
|
@Input()
|
|
public fieldNames: ReadonlyArray<string>;
|
|
|
|
@Input()
|
|
public allFields: ReadonlyArray<string>;
|
|
|
|
public fieldsNotAdded: ReadonlyArray<string>;
|
|
|
|
public ngOnChanges() {
|
|
this.fieldsNotAdded = this.allFields.filter(n => this.fieldNames.indexOf(n) < 0);
|
|
}
|
|
|
|
public drop(event: CdkDragDrop<string[]>) {
|
|
moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
|
|
|
|
this.updateFieldNames(event.container.data);
|
|
}
|
|
|
|
public resetDefault() {
|
|
this.updateFieldNames([]);
|
|
}
|
|
|
|
public addField(field: string) {
|
|
this.updateFieldNames([...this.fieldNames, field]);
|
|
}
|
|
|
|
public removeField(field: string) {
|
|
this.updateFieldNames(this.fieldNames.filter(x => x !== field));
|
|
}
|
|
|
|
private updateFieldNames(fieldNames: ReadonlyArray<string>) {
|
|
this.fieldNamesChange.emit(fieldNames);
|
|
}
|
|
}
|