2021-02-17 17:39:07 +01:00
|
|
|
|
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
2019-01-18 18:03:45 +01:00
|
|
|
|
import { FormArray, FormGroup } from '@angular/forms';
|
2019-12-11 15:51:03 +01:00
|
|
|
|
import { FieldEditorModel } from '@app/ui/admin/dataset-profile/admin/field-editor-model';
|
|
|
|
|
import { FieldSetEditorModel } from '@app/ui/admin/dataset-profile/admin/field-set-editor-model';
|
|
|
|
|
import { SectionEditorModel } from '@app/ui/admin/dataset-profile/admin/section-editor-model';
|
|
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
|
|
|
|
import { Guid } from '@common/types/guid';
|
2019-01-18 18:03:45 +01:00
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
2021-10-12 17:14:22 +02:00
|
|
|
|
import {AngularEditorConfig} from "@kolkov/angular-editor";
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-dataset-profile-editor-section-component',
|
|
|
|
|
templateUrl: './dataset-profile-editor-section.component.html',
|
|
|
|
|
styleUrls: ['./dataset-profile-editor-section.component.scss']
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export class DatasetProfileEditorSectionComponent extends BaseComponent implements OnInit {
|
2021-10-12 17:14:22 +02:00
|
|
|
|
editorConfig: AngularEditorConfig = {
|
|
|
|
|
editable: true,
|
|
|
|
|
spellcheck: true,
|
|
|
|
|
height: 'auto',
|
|
|
|
|
minHeight: '0',
|
|
|
|
|
maxHeight: 'auto',
|
|
|
|
|
width: '100%',
|
|
|
|
|
minWidth: '0',
|
|
|
|
|
translate: 'yes',
|
|
|
|
|
enableToolbar: true,
|
|
|
|
|
showToolbar: true,
|
|
|
|
|
placeholder: 'Enter text here...',
|
|
|
|
|
defaultParagraphSeparator: '',
|
|
|
|
|
defaultFontName: '',
|
|
|
|
|
defaultFontSize: '',
|
|
|
|
|
sanitize: true,
|
|
|
|
|
toolbarPosition: 'top',
|
|
|
|
|
toolbarHiddenButtons: [
|
|
|
|
|
[
|
|
|
|
|
'heading',
|
|
|
|
|
'fontName'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'fontSize',
|
|
|
|
|
'backgroundColor',
|
|
|
|
|
'customClasses',
|
|
|
|
|
'insertImage',
|
|
|
|
|
'insertVideo',
|
|
|
|
|
'removeFormat',
|
|
|
|
|
'toggleEditorMode'
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
|
@Input() form: FormGroup;
|
2021-02-04 11:22:52 +01:00
|
|
|
|
//@Input() dataModel: SectionEditorModel;
|
2019-01-18 18:03:45 +01:00
|
|
|
|
@Input() indexPath: string;
|
2019-02-11 13:04:45 +01:00
|
|
|
|
@Input() viewOnly: boolean;
|
2021-02-17 17:39:07 +01:00
|
|
|
|
@Output() fieldsetAdded = new EventEmitter<String>(); //returns the id of the fieldset added
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
|
|
constructor() { super(); }
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
2021-02-18 16:13:56 +01:00
|
|
|
|
|
|
|
|
|
//TODO
|
|
|
|
|
// this.form.root.get('pages').valueChanges
|
|
|
|
|
// .pipe(takeUntil(this._destroyed))
|
|
|
|
|
// .subscribe(x =>
|
|
|
|
|
// this.keepPageSelectionValid(x)
|
|
|
|
|
// );
|
2019-01-18 18:03:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addField() {
|
|
|
|
|
const fieldSet: FieldSetEditorModel = new FieldSetEditorModel();
|
2021-02-18 16:13:56 +01:00
|
|
|
|
fieldSet.ordinal = (this.form.get('fieldSets') as FormArray).length;
|
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
|
const field: FieldEditorModel = new FieldEditorModel();
|
2019-12-11 15:51:03 +01:00
|
|
|
|
field.id = Guid.create().toString();
|
2021-02-18 16:13:56 +01:00
|
|
|
|
field.ordinal = 0;//first field in fields
|
2019-01-18 18:03:45 +01:00
|
|
|
|
fieldSet.fields.push(field);
|
2021-02-04 11:22:52 +01:00
|
|
|
|
// if (this.dataModel.fieldSets) {
|
2019-12-11 15:51:03 +01:00
|
|
|
|
fieldSet.id = Guid.create().toString();
|
2021-02-04 11:22:52 +01:00
|
|
|
|
//this.dataModel.fieldSets.push(fieldSet);
|
|
|
|
|
//}
|
2021-02-17 17:39:07 +01:00
|
|
|
|
const fieldsetsArray = this.form.get('fieldSets') as FormArray;
|
|
|
|
|
fieldsetsArray.push(fieldSet.buildForm());
|
|
|
|
|
|
|
|
|
|
const fieldSetForm = fieldsetsArray.at(fieldsetsArray.length-1);
|
|
|
|
|
//emit id inserted
|
|
|
|
|
if(fieldSetForm){
|
|
|
|
|
const id: string = fieldSetForm.get('id').value;
|
|
|
|
|
this.fieldsetAdded.emit(id);
|
|
|
|
|
}
|
2019-01-18 18:03:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addSectioninSection() {
|
|
|
|
|
const section: SectionEditorModel = new SectionEditorModel();
|
2021-02-04 11:22:52 +01:00
|
|
|
|
//this.dataModel.sections.push(section);
|
2019-01-18 18:03:45 +01:00
|
|
|
|
(<FormArray>this.form.get('sections')).push(section.buildForm());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DeleteSectionInSection(index) {
|
2021-02-04 11:22:52 +01:00
|
|
|
|
//this.dataModel.sections.splice(index, 1);
|
2019-01-18 18:03:45 +01:00
|
|
|
|
(<FormArray>this.form.get('sections')).removeAt(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
deleteFieldSet(index) {
|
2021-02-04 11:22:52 +01:00
|
|
|
|
//this.dataModel.fieldSets.splice(index, 1);
|
2019-01-18 18:03:45 +01:00
|
|
|
|
(<FormArray>this.form.get('fieldSets')).removeAt(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
keepPageSelectionValid(pagesJson: Array<any>) {
|
|
|
|
|
const selectedPage = this.form.get('page').value as String;
|
|
|
|
|
// const pages: Array<PageEditorModel> = JsonSerializer.fromJSONArray(pagesJson, Page);
|
|
|
|
|
if (pagesJson.find(elem => elem.id === selectedPage) === undefined) {
|
|
|
|
|
this.form.get('page').reset();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getFieldTile(formGroup: FormGroup, index: number) {
|
|
|
|
|
if (formGroup.get('title') && formGroup.get('title').value && formGroup.get('title').value.length > 0) { return formGroup.get('title').value; }
|
|
|
|
|
return "Field " + (index + 1);
|
|
|
|
|
}
|
|
|
|
|
}
|