Fixes bug on DMP Template (profile) not showing saved values. (Issue #134)

This commit is contained in:
gkolokythas 2019-07-25 14:06:22 +03:00
parent ee367b3032
commit 273b05da00
5 changed files with 60 additions and 26 deletions

View File

@ -1,5 +1,4 @@
export interface DmpProfileExternalAutoCompleteField {
placeholder: string;
url: string;
optionsRoot: string;
multiAutoComplete: boolean;

View File

@ -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)
);
}
});

View File

@ -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<FormGroup>();
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;
}
}

View File

@ -82,7 +82,7 @@
</div>
<app-dynamic-dmp-field-resolver *ngIf="selectedDmpProfileDefinition" [formGroup]="formGroup"
[dmpProfileDefinition]="selectedDmpProfileDefinition"
[dmpProfileId]="selectedDmpProfileId">
[dmpProfileId]="formGroup.get('profile').value.id">
</app-dynamic-dmp-field-resolver>
</div>

View File

@ -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;
})