2019-01-18 18:03:45 +01:00
|
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
|
import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
|
2019-01-28 16:47:12 +01:00
|
|
|
|
import { FormArray, FormControl, FormGroup } from '@angular/forms';
|
2019-12-11 15:51:03 +01:00
|
|
|
|
import { DatasetProfileFieldViewStyle } from '@app/core/common/enum/dataset-profile-field-view-style';
|
|
|
|
|
import { ValidationType } from '@app/core/common/enum/validation-type';
|
|
|
|
|
import { DatasetProfileService } from '@app/core/services/dataset-profile/dataset-profile.service';
|
|
|
|
|
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
|
|
|
|
|
import { BooleanDecisionFieldDataEditorModel } from '@app/ui/admin/dataset-profile/admin/field-data/boolean-decision-field-data-editor-model';
|
|
|
|
|
import { CheckBoxFieldDataEditorModel } from '@app/ui/admin/dataset-profile/admin/field-data/check-box-field-data-editor-model';
|
|
|
|
|
import { DatePickerDataEditorModel } from '@app/ui/admin/dataset-profile/admin/field-data/date-picker-data-editor-models';
|
|
|
|
|
import { FreeTextFieldDataEditorModel } from '@app/ui/admin/dataset-profile/admin/field-data/free-text-field-data-editor-model';
|
|
|
|
|
import { RadioBoxFieldDataEditorModel } from '@app/ui/admin/dataset-profile/admin/field-data/radio-box-field-data-editor-model';
|
|
|
|
|
import { ResearchersAutoCompleteFieldDataEditorModel } from '@app/ui/admin/dataset-profile/admin/field-data/researchers-auto-complete-field-data-editor-model';
|
|
|
|
|
import { TextAreaFieldDataEditorModel } from '@app/ui/admin/dataset-profile/admin/field-data/text-area-field-data-editor-model';
|
|
|
|
|
import { WordListFieldDataEditorModel } from '@app/ui/admin/dataset-profile/admin/field-data/word-list-field-data-editor-model';
|
|
|
|
|
import { RuleEditorModel } from '@app/ui/admin/dataset-profile/admin/rule-editor-model';
|
|
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
2019-01-28 14:05:19 +01:00
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
2020-06-04 17:37:30 +02:00
|
|
|
|
import { ExternalDatasetEditorModel } from '@app/ui/dataset/dataset-wizard/dataset-wizard-editor.model';
|
|
|
|
|
import { DataRepositoriesDataEditorModel } from '../../../admin/field-data/data-repositories-data-editor-models';
|
|
|
|
|
import { RegistriesDataEditorModel } from '../../../admin/field-data/registries-data-editor-models';
|
|
|
|
|
import { ServicesDataEditorModel } from '../../../admin/field-data/services-data-editor-models';
|
|
|
|
|
import { TagsDataEditorModel } from '../../../admin/field-data/tags-data-editor-models';
|
|
|
|
|
import { ResearchersDataEditorModel } from '../../../admin/field-data/researchers-data-editor-models';
|
|
|
|
|
import { OrganizationsDataEditorModel } from '../../../admin/field-data/organizations-data-editor-models';
|
|
|
|
|
import { DatasetIdentifierDataEditorModel } from '../../../admin/field-data/dataset-identifier-data-editor-models';
|
|
|
|
|
import { ExternalDatasetsDataEditorModel } from '../../../admin/field-data/external-datasets-data-editor-models';
|
2020-06-25 12:00:29 +02:00
|
|
|
|
import { CurrencyDataEditorModel } from '../../../admin/field-data/currency-data-editor-models';
|
2020-11-05 17:32:19 +01:00
|
|
|
|
import { ValidationDataEditorModel } from '../../../admin/field-data/validation-data-editor-models';
|
2021-02-12 12:23:39 +01:00
|
|
|
|
import { DatasetDescriptionFieldEditorModel } from '@app/ui/misc/dataset-description-form/dataset-description-form.model';
|
|
|
|
|
import { Subscription } from 'rxjs';
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-dataset-profile-editor-field-component',
|
|
|
|
|
templateUrl: './dataset-profile-editor-field.component.html',
|
|
|
|
|
styleUrls: ['./dataset-profile-editor-field.component.scss']
|
|
|
|
|
})
|
2021-02-12 12:23:39 +01:00
|
|
|
|
export class DatasetProfileEditorFieldComponent extends BaseComponent implements OnInit,OnChanges {
|
2019-02-11 13:04:45 +01:00
|
|
|
|
@Input() viewOnly: boolean;
|
2019-01-18 18:03:45 +01:00
|
|
|
|
@Input() form: FormGroup;
|
|
|
|
|
@Input() showOrdinal = true;
|
|
|
|
|
@Input() indexPath: string;
|
2019-01-28 14:05:19 +01:00
|
|
|
|
validationTypeEnum = ValidationType;
|
2019-01-18 18:03:45 +01:00
|
|
|
|
viewStyleEnum = DatasetProfileFieldViewStyle;
|
|
|
|
|
isFieldMultiplicityEnabled = false;
|
|
|
|
|
|
2021-02-12 12:23:39 +01:00
|
|
|
|
@Input() expandView: boolean = true;
|
2019-02-08 10:04:12 +01:00
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
|
constructor(
|
2019-10-15 17:29:34 +02:00
|
|
|
|
public enumUtils: EnumUtils,
|
|
|
|
|
public datasetProfileService: DatasetProfileService
|
2019-01-28 14:05:19 +01:00
|
|
|
|
) { super(); }
|
2021-02-12 12:23:39 +01:00
|
|
|
|
ngOnChanges(changes: SimpleChanges): void {
|
|
|
|
|
this.generatePreviewForm();
|
|
|
|
|
}
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
2021-02-12 12:23:39 +01:00
|
|
|
|
this.showPreview = true;
|
2019-01-18 18:03:45 +01:00
|
|
|
|
if (this.form.get('multiplicity')) {
|
2019-02-01 09:29:00 +01:00
|
|
|
|
if (this.form.get('multiplicity').value.min > 1 && this.form.get('multiplicity').value.max > 1) {
|
2019-01-18 18:03:45 +01:00
|
|
|
|
this.isFieldMultiplicityEnabled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// this.addNewRule();
|
2019-01-28 14:05:19 +01:00
|
|
|
|
|
|
|
|
|
this.form.get('viewStyle').get('renderStyle').valueChanges
|
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
|
.subscribe(x => {
|
2021-02-12 12:23:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const previewStatus = this.showPreview;
|
|
|
|
|
//!! Important to be before the if statement
|
|
|
|
|
this.showPreview = false;
|
|
|
|
|
|
2019-01-28 14:05:19 +01:00
|
|
|
|
if (this.form.get('data')) {
|
|
|
|
|
this.form.removeControl('data');
|
|
|
|
|
|
|
|
|
|
switch (x) {
|
|
|
|
|
case DatasetProfileFieldViewStyle.BooleanDecision:
|
|
|
|
|
this.form.addControl('data', new BooleanDecisionFieldDataEditorModel().buildForm());
|
|
|
|
|
break;
|
|
|
|
|
case DatasetProfileFieldViewStyle.CheckBox:
|
|
|
|
|
this.form.addControl('data', new CheckBoxFieldDataEditorModel().buildForm());
|
|
|
|
|
break;
|
|
|
|
|
case DatasetProfileFieldViewStyle.ComboBox:
|
2019-01-28 16:47:12 +01:00
|
|
|
|
this.form.addControl('data', new WordListFieldDataEditorModel().buildForm());
|
2019-01-28 14:05:19 +01:00
|
|
|
|
break;
|
2019-07-16 15:41:12 +02:00
|
|
|
|
case DatasetProfileFieldViewStyle.InternalDmpEntities:
|
|
|
|
|
this.form.addControl('data', new ResearchersAutoCompleteFieldDataEditorModel().buildForm());
|
|
|
|
|
break;
|
2019-01-28 14:05:19 +01:00
|
|
|
|
case DatasetProfileFieldViewStyle.FreeText:
|
|
|
|
|
this.form.addControl('data', new FreeTextFieldDataEditorModel().buildForm());
|
|
|
|
|
break;
|
|
|
|
|
case DatasetProfileFieldViewStyle.RadioBox:
|
|
|
|
|
this.form.addControl('data', new RadioBoxFieldDataEditorModel().buildForm());
|
|
|
|
|
break;
|
|
|
|
|
case DatasetProfileFieldViewStyle.TextArea:
|
|
|
|
|
this.form.addControl('data', new TextAreaFieldDataEditorModel().buildForm());
|
|
|
|
|
break;
|
2019-02-15 11:26:14 +01:00
|
|
|
|
case DatasetProfileFieldViewStyle.DatePicker:
|
|
|
|
|
this.form.addControl('data', new DatePickerDataEditorModel().buildForm());
|
|
|
|
|
break;
|
2020-06-04 17:37:30 +02:00
|
|
|
|
case DatasetProfileFieldViewStyle.ExternalDatasets:
|
|
|
|
|
this.form.addControl('data', new ExternalDatasetsDataEditorModel().buildForm());
|
|
|
|
|
break;
|
|
|
|
|
case DatasetProfileFieldViewStyle.DataRepositories:
|
|
|
|
|
this.form.addControl('data', new DataRepositoriesDataEditorModel().buildForm());
|
|
|
|
|
break;
|
|
|
|
|
case DatasetProfileFieldViewStyle.Registries:
|
|
|
|
|
this.form.addControl('data', new RegistriesDataEditorModel().buildForm());
|
|
|
|
|
break;
|
|
|
|
|
case DatasetProfileFieldViewStyle.Services:
|
|
|
|
|
this.form.addControl('data', new ServicesDataEditorModel().buildForm());
|
|
|
|
|
break;
|
|
|
|
|
case DatasetProfileFieldViewStyle.Tags:
|
|
|
|
|
this.form.addControl('data', new TagsDataEditorModel().buildForm());
|
|
|
|
|
break;
|
|
|
|
|
case DatasetProfileFieldViewStyle.Researchers:
|
|
|
|
|
this.form.addControl('data', new ResearchersDataEditorModel().buildForm());
|
|
|
|
|
break;
|
|
|
|
|
case DatasetProfileFieldViewStyle.Organizations:
|
|
|
|
|
this.form.addControl('data', new OrganizationsDataEditorModel().buildForm());
|
|
|
|
|
break;
|
|
|
|
|
case DatasetProfileFieldViewStyle.DatasetIdentifier:
|
|
|
|
|
this.form.addControl('data', new DatasetIdentifierDataEditorModel().buildForm());
|
|
|
|
|
break;
|
2020-06-25 12:00:29 +02:00
|
|
|
|
case DatasetProfileFieldViewStyle.Currency:
|
|
|
|
|
this.form.addControl('data', new CurrencyDataEditorModel().buildForm());
|
|
|
|
|
break;
|
2020-11-05 17:32:19 +01:00
|
|
|
|
case DatasetProfileFieldViewStyle.Validation:
|
|
|
|
|
this.form.addControl('data', new ValidationDataEditorModel().buildForm());
|
|
|
|
|
break;
|
2019-01-28 14:05:19 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-12 12:23:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//reset the preview status
|
|
|
|
|
// this.showPreview = previewStatus;
|
|
|
|
|
this.showPreview = true;
|
2019-01-28 14:05:19 +01:00
|
|
|
|
});
|
2019-01-18 18:03:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 10:04:12 +01:00
|
|
|
|
defaulValueRequired(viewStile: DatasetProfileFieldViewStyle): boolean {
|
|
|
|
|
switch (viewStile) {
|
|
|
|
|
case DatasetProfileFieldViewStyle.CheckBox:
|
|
|
|
|
return true;
|
|
|
|
|
case DatasetProfileFieldViewStyle.RadioBox:
|
|
|
|
|
case DatasetProfileFieldViewStyle.TextArea:
|
|
|
|
|
case DatasetProfileFieldViewStyle.FreeText:
|
|
|
|
|
case DatasetProfileFieldViewStyle.ComboBox:
|
2019-07-16 15:41:12 +02:00
|
|
|
|
case DatasetProfileFieldViewStyle.InternalDmpEntities:
|
2019-02-08 10:04:12 +01:00
|
|
|
|
case DatasetProfileFieldViewStyle.BooleanDecision:
|
2019-02-15 11:26:14 +01:00
|
|
|
|
case DatasetProfileFieldViewStyle.DatePicker:
|
2020-06-04 17:37:30 +02:00
|
|
|
|
case DatasetProfileFieldViewStyle.ExternalDatasets:
|
|
|
|
|
case DatasetProfileFieldViewStyle.DataRepositories:
|
|
|
|
|
case DatasetProfileFieldViewStyle.Registries:
|
|
|
|
|
case DatasetProfileFieldViewStyle.Services:
|
|
|
|
|
case DatasetProfileFieldViewStyle.Tags:
|
|
|
|
|
case DatasetProfileFieldViewStyle.Registries:
|
|
|
|
|
case DatasetProfileFieldViewStyle.Organizations:
|
|
|
|
|
case DatasetProfileFieldViewStyle.DatasetIdentifier:
|
2020-06-25 12:00:29 +02:00
|
|
|
|
case DatasetProfileFieldViewStyle.Currency:
|
2020-11-05 17:32:19 +01:00
|
|
|
|
case DatasetProfileFieldViewStyle.Validation:
|
2019-02-08 10:04:12 +01:00
|
|
|
|
return false;
|
|
|
|
|
default:
|
2019-02-11 13:04:45 +01:00
|
|
|
|
return false;
|
2019-02-08 10:04:12 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
|
onIsFieldMultiplicityEnabledChange(isFieldMultiplicityEnabled: boolean) {
|
|
|
|
|
if (!isFieldMultiplicityEnabled) {
|
|
|
|
|
(<FormControl>this.form.get('multiplicity').get('min')).setValue(0);
|
|
|
|
|
(<FormControl>this.form.get('multiplicity').get('max')).setValue(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addNewRule() {
|
|
|
|
|
const rule: RuleEditorModel = new RuleEditorModel();
|
|
|
|
|
(<FormArray>this.form.get('visible').get('rules')).push(rule.buildForm());
|
|
|
|
|
}
|
2021-02-12 12:23:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private _formChangesSubscription:Subscription;
|
|
|
|
|
private _showPreview: boolean = false;;
|
|
|
|
|
|
|
|
|
|
get showPreview(): boolean{
|
|
|
|
|
|
|
|
|
|
return this._showPreview;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set showPreview(value:boolean){
|
|
|
|
|
if(value == false){//hide preview
|
|
|
|
|
//close subsciption
|
|
|
|
|
if(this._formChangesSubscription){
|
|
|
|
|
this._formChangesSubscription.unsubscribe();
|
|
|
|
|
this._formChangesSubscription = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(value == true){
|
|
|
|
|
this._formChangesSubscription = this.form.valueChanges.subscribe(()=>{
|
|
|
|
|
this.generatePreviewForm();
|
|
|
|
|
});
|
|
|
|
|
//initialize
|
|
|
|
|
if(this.form.get('viewStyle').get('renderStyle').value){
|
|
|
|
|
this.generatePreviewForm();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this._showPreview = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
previewForm: FormGroup;
|
|
|
|
|
|
|
|
|
|
generatePreviewForm(){
|
|
|
|
|
this.previewForm = null;
|
|
|
|
|
// this._showPreview = false;
|
|
|
|
|
const fieldEditorModel = new DatasetDescriptionFieldEditorModel();
|
|
|
|
|
|
|
|
|
|
fieldEditorModel.viewStyle= {
|
|
|
|
|
renderStyle: this.form.get('viewStyle').get('renderStyle').value,
|
|
|
|
|
cssClass: null
|
|
|
|
|
};
|
|
|
|
|
|
2021-02-12 15:27:35 +01:00
|
|
|
|
|
|
|
|
|
fieldEditorModel.data = (this.form.get('data') as FormGroup).getRawValue();
|
2021-02-12 12:23:39 +01:00
|
|
|
|
fieldEditorModel.value = this.form.get('defaultValue').get('value').value;
|
|
|
|
|
fieldEditorModel.validationRequired = (this.form.get('validations').value as Array<ValidationType>).includes(ValidationType.Required);
|
|
|
|
|
|
|
|
|
|
if(this.form.get('viewStyle').get('renderStyle').value == DatasetProfileFieldViewStyle.CheckBox){
|
|
|
|
|
fieldEditorModel.value = this.form.get('defaultValue').get('value').value === 'true';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.previewForm = fieldEditorModel.buildForm();
|
|
|
|
|
|
|
|
|
|
// this._showPreview = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// generatePreview(){
|
|
|
|
|
// const fieldEditorModel = new DatasetDescriptionFieldEditorModel();
|
|
|
|
|
|
|
|
|
|
// fieldEditorModel.viewStyle= {
|
|
|
|
|
// renderStyle: this.form.get('viewStyle').get('renderStyle').value,
|
|
|
|
|
// cssClass: null
|
|
|
|
|
// };
|
|
|
|
|
// fieldEditorModel.defaultValue = this.form.get('defaultValue').value;
|
|
|
|
|
// switch (this.form.get('viewStyle').get('renderStyle').value) {
|
|
|
|
|
// case DatasetProfileFieldViewStyle.TextArea:
|
|
|
|
|
// fieldEditorModel.data = {
|
|
|
|
|
// label: this.form.get('data').get('label').value
|
|
|
|
|
// };
|
|
|
|
|
// break;
|
|
|
|
|
|
|
|
|
|
// default:
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // this.previewForm = fieldEditorModel.buildForm();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
2019-01-18 18:03:45 +01:00
|
|
|
|
}
|