argos/dmp-frontend/src/app/ui/admin/dataset-profile/editor/components/section/dataset-profile-editor-sect...

122 lines
3.7 KiB
TypeScript
Raw Normal View History

import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
2019-01-18 18:03:45 +01:00
import { FormArray, FormGroup } from '@angular/forms';
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';
Description boxes in admin forms replaced with rich text editor <angular-editor>. 1. dataset-profile-editor-composite-field.component.ts & dataset-profile-editor-section.component.ts & dataset-profile-editor.component.ts: Initialize AngularEditorConfig. 2. dataset-profile-editor-composite-field.component.html & dataset-profile-editor-section.component.html & dataset-profile-editor.component.html: Use <angular-editor> in description. 3. multiple-auto-complete.component.html & dataset-profile-listing.component.html & form-section.component.html: Show description as html. 4. dataset-profile.module.ts: Imported HttpClientModule, AngularEditorModule (needed for <angular-editor>). 5. available-profiles.component.html: Show description as html, under the Dataset Template title, not as tooltip (matTooltip does not receive html). 6. available-profiles.component.ts: Added styleUrls: ['available-profiles.component.scss']. 7. available-profiles.component.scss: [NEW] Added css for class "list-option" to cut description if too long. 8. form-composite-title.component.html: Show description and extendedDescription as html | Add view more/less functionality to show/hide extendedDescription. 9. form-composite-title.component.ts: Added "public showExtendedDescription: boolean = false;" field. 10. form-composite-title.component.scss: Added css for "more" class, to make "view more/less" seem like link. 11. assets/i18n/: In language files added DATASET-EDITOR.QUESTION.EXTENDED-DESCRIPTION.VIEW-MORE (-LESS). 12. assets/styles.css: Added css for <angular-editor>, to be similar to the other text areas and forms.
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 {
Description boxes in admin forms replaced with rich text editor <angular-editor>. 1. dataset-profile-editor-composite-field.component.ts & dataset-profile-editor-section.component.ts & dataset-profile-editor.component.ts: Initialize AngularEditorConfig. 2. dataset-profile-editor-composite-field.component.html & dataset-profile-editor-section.component.html & dataset-profile-editor.component.html: Use <angular-editor> in description. 3. multiple-auto-complete.component.html & dataset-profile-listing.component.html & form-section.component.html: Show description as html. 4. dataset-profile.module.ts: Imported HttpClientModule, AngularEditorModule (needed for <angular-editor>). 5. available-profiles.component.html: Show description as html, under the Dataset Template title, not as tooltip (matTooltip does not receive html). 6. available-profiles.component.ts: Added styleUrls: ['available-profiles.component.scss']. 7. available-profiles.component.scss: [NEW] Added css for class "list-option" to cut description if too long. 8. form-composite-title.component.html: Show description and extendedDescription as html | Add view more/less functionality to show/hide extendedDescription. 9. form-composite-title.component.ts: Added "public showExtendedDescription: boolean = false;" field. 10. form-composite-title.component.scss: Added css for "more" class, to make "view more/less" seem like link. 11. assets/i18n/: In language files added DATASET-EDITOR.QUESTION.EXTENDED-DESCRIPTION.VIEW-MORE (-LESS). 12. assets/styles.css: Added css for <angular-editor>, to be similar to the other text areas and forms.
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;
@Input() viewOnly: boolean;
@Output() fieldsetAdded = new EventEmitter<String>(); //returns the id of the fieldset added
2019-01-18 18:03:45 +01:00
constructor() { super(); }
ngOnInit() {
//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();
fieldSet.ordinal = (this.form.get('fieldSets') as FormArray).length;
2019-01-18 18:03:45 +01:00
const field: FieldEditorModel = new FieldEditorModel();
field.id = Guid.create().toString();
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) {
fieldSet.id = Guid.create().toString();
2021-02-04 11:22:52 +01:00
//this.dataModel.fieldSets.push(fieldSet);
//}
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);
}
}