diff --git a/dmp-frontend/src/app/core/model/dmp-profile/dmp-profile-external-autocomplete.ts b/dmp-frontend/src/app/core/model/dmp-profile/dmp-profile-external-autocomplete.ts index cd7ff2964..955ba48bf 100644 --- a/dmp-frontend/src/app/core/model/dmp-profile/dmp-profile-external-autocomplete.ts +++ b/dmp-frontend/src/app/core/model/dmp-profile/dmp-profile-external-autocomplete.ts @@ -1,5 +1,4 @@ export interface DmpProfileExternalAutoCompleteField { - placeholder: string; url: string; optionsRoot: string; multiAutoComplete: boolean; diff --git a/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts b/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts index e655acbb1..0214f658b 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts +++ b/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts @@ -250,13 +250,13 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC this.dmpService.createDmp(this.formGroup.getRawValue()) .pipe(takeUntil(this._destroyed)) .subscribe( - complete => { - if (showAddDatasetDialog) { - this.addDatasetOpenDialog(complete); - } - else { this.onCallbackSuccess() } - }, - error => this.onCallbackError(error) + complete => { + if (showAddDatasetDialog) { + this.addDatasetOpenDialog(complete); + } + else { this.onCallbackSuccess() } + }, + error => this.onCallbackError(error) ); } @@ -304,8 +304,8 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC this.dmpService.delete(this.dmp.id) .pipe(takeUntil(this._destroyed)) .subscribe( - complete => { this.onCallbackSuccess() }, - error => this.onDeleteCallbackError(error) + complete => { this.onCallbackSuccess() }, + error => this.onDeleteCallbackError(error) ); } }); diff --git a/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.model.ts b/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.model.ts index bf2f401ed..d7a359007 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.model.ts +++ b/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.model.ts @@ -15,6 +15,10 @@ import { ValidJsonValidator } from "../../../library/auto-complete/auto-complete import { UserInfoListingModel } from "../../../core/model/user/user-info-listing"; import { DatasetModel } from "../../../core/model/dataset/dataset"; import { ProjectTabModel } from "./project-tab/project-tab-model"; +import { DmpProfileExternalAutoCompleteFieldDataEditorModel } from "../../admin/dmp-profile/editor/external-autocomplete/dmp-profile-external-autocomplete-field-editor.model"; +import { DmpProfileType } from "../../../core/common/enum/dmp-profile-type"; +import { DmpProfileFieldDataType } from "../../../core/common/enum/dmp-profile-field-type"; +import { DmpProfileField } from "../../../core/model/dmp-profile/dmp-profile-field"; export class DmpEditorModel { public id: string; @@ -86,6 +90,15 @@ export class DmpEditorModel { if (this.dynamicFields) { this.dynamicFields.forEach(item => dynamicFields.push(item.buildForm())); } formGroup.addControl('dynamicFields', new FormBuilder().array(dynamicFields)); + if (this.definition) { + const fields = new Array(); + this.definition.fields.forEach(item => fields.push(new DmpDefinitionFieldEditorModel().fromModel(item).buildForm())); + const definition = new FormBuilder().group({ + fields: new FormBuilder().array(fields) + }); + formGroup.addControl('definition', definition); + } + return formGroup; } @@ -162,3 +175,39 @@ export class DmpDynamicFieldDependencyEditorModel { } } +export class DmpDefinitionFieldEditorModel implements DmpProfileField { + public id: string; + public type: DmpProfileType; + public dataType: DmpProfileFieldDataType; + public required = false; + public label: string; + public value: any; + public externalAutocomplete?: DmpProfileExternalAutoCompleteFieldDataEditorModel; + + fromModel(item: DmpProfileField): DmpDefinitionFieldEditorModel { + this.type = item.type; + this.dataType = item.dataType; + this.required = item.required; + this.label = item.label; + this.id = item.id; + this.value = item.value; + if (item.externalAutocomplete) + this.externalAutocomplete = new DmpProfileExternalAutoCompleteFieldDataEditorModel().fromModel(item.externalAutocomplete); + return this; + } + + buildForm(): FormGroup { + const formGroup = new FormBuilder().group({ + type: [this.type], + id: [this.id], + dataType: [this.dataType], + required: [this.required], + label: [this.label], + value: [this.value] + }); + if (this.externalAutocomplete) { + formGroup.addControl('externalAutocomplete', this.externalAutocomplete.buildForm()); + } + return formGroup; + } +} diff --git a/dmp-frontend/src/app/ui/dmp/editor/general-tab/general-tab.component.html b/dmp-frontend/src/app/ui/dmp/editor/general-tab/general-tab.component.html index c3adfec5f..a6c3f1c34 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/general-tab/general-tab.component.html +++ b/dmp-frontend/src/app/ui/dmp/editor/general-tab/general-tab.component.html @@ -82,7 +82,7 @@ + [dmpProfileId]="formGroup.get('profile').value.id"> diff --git a/dmp-frontend/src/app/ui/dmp/editor/general-tab/general-tab.component.ts b/dmp-frontend/src/app/ui/dmp/editor/general-tab/general-tab.component.ts index 3016c9db7..2ed2b4218 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/general-tab/general-tab.component.ts +++ b/dmp-frontend/src/app/ui/dmp/editor/general-tab/general-tab.component.ts @@ -43,7 +43,6 @@ export class GeneralTabComponent extends BaseComponent implements OnInit { dmpProfileAutoCompleteConfiguration: SingleAutoCompleteConfiguration; selectedDmpProfileDefinition: DmpProfileDefinition; - selectedDmpProfileId: string; constructor( private dmpProfileService: DmpProfileService, @@ -57,17 +56,7 @@ export class GeneralTabComponent extends BaseComponent implements OnInit { ngOnInit() { - if (this.formGroup.get('profile')) - this.dmpProfileService.getSingle(this.formGroup.get('profile').value.id) - .pipe(takeUntil(this._destroyed)) - .subscribe(result => { - this.selectedDmpProfileDefinition = result.definition; - this.selectedDmpProfileId = result.id; - if (this.formGroup.get('properties')) { - - } - }); - + if (this.formGroup.get('definition')) { this.selectedDmpProfileDefinition = this.formGroup.get('definition').value; } this.registerFormEventsForDmpProfile(); this.dmpProfileAutoCompleteConfiguration = { @@ -102,7 +91,6 @@ export class GeneralTabComponent extends BaseComponent implements OnInit { registerFormEventsForDmpProfile(definitionProperties?: DmpProfileDefinition): void { this.formGroup.get('profile').valueChanges .pipe( - startWith(null), takeUntil(this._destroyed)) .subscribe(Option => { if (Option instanceof Object) { @@ -111,11 +99,9 @@ export class GeneralTabComponent extends BaseComponent implements OnInit { .pipe(takeUntil(this._destroyed)) .subscribe(result => { this.selectedDmpProfileDefinition = result.definition; - this.selectedDmpProfileId = result.id; }); } else { this.selectedDmpProfileDefinition = null; - this.selectedDmpProfileId = null; } this.selectedDmpProfileDefinition = definitionProperties; })