prefill description pop up clean up
This commit is contained in:
parent
804ba2d537
commit
6fe74c2218
|
@ -0,0 +1,41 @@
|
|||
import { UntypedFormBuilder, UntypedFormGroup, Validators } from "@angular/forms";
|
||||
import { DescriptionPrefillingRequest, DescriptionPrefillingRequestData } from "@app/core/model/description-profiling-request/description-profiling-request";
|
||||
import { BackendErrorValidator } from "@common/forms/validation/custom-validator";
|
||||
import { ValidationErrorModel } from "@common/forms/validation/error-model/validation-error-model";
|
||||
import { Validation, ValidationContext } from "@common/forms/validation/validation-context";
|
||||
import { Guid } from "@common/types/guid";
|
||||
|
||||
export class DescriptionPrefillingRequestEditorModel implements DescriptionPrefillingRequest {
|
||||
prefillingSourceId: Guid;
|
||||
descriptionTemplateId: Guid;
|
||||
data: DescriptionPrefillingRequestData;
|
||||
project: string[];
|
||||
|
||||
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
|
||||
|
||||
constructor(
|
||||
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
|
||||
) { }
|
||||
|
||||
buildForm(context: ValidationContext = null, disabled: boolean = false): UntypedFormGroup {
|
||||
if (context == null) { context = this.createValidationContext(); }
|
||||
|
||||
return this.formBuilder.group({
|
||||
prefillingSourceId: [{ value: this.prefillingSourceId, disabled: disabled }, context.getValidation('prefillingSourceId').validators],
|
||||
descriptionTemplateId: [{ value: this.descriptionTemplateId, disabled: disabled }, context.getValidation('descriptionTemplateId').validators],
|
||||
data: [{ value: this.data, disabled: disabled }, context.getValidation('data').validators],
|
||||
});
|
||||
}
|
||||
|
||||
createValidationContext(): ValidationContext {
|
||||
|
||||
const baseContext: ValidationContext = new ValidationContext();
|
||||
const baseValidationArray: Validation[] = new Array<Validation>();
|
||||
baseValidationArray.push({ key: 'prefillingSourceId', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, `prefillingSourceId`)] });
|
||||
baseValidationArray.push({ key: 'descriptionTemplateId', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, `descriptionTemplateId`)] });
|
||||
baseValidationArray.push({ key: 'data', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, `data`)] });
|
||||
|
||||
baseContext.validation = baseValidationArray;
|
||||
return baseContext;
|
||||
}
|
||||
}
|
|
@ -5,22 +5,20 @@ import { DescriptionPrefillingRequest, PrefillingSearchRequest } from "@app/core
|
|||
import { DescriptionTemplate } from "@app/core/model/description-template/description-template";
|
||||
import { Dmp } from "@app/core/model/dmp/dmp";
|
||||
import { Prefilling } from "@app/core/model/prefilling-source/prefilling-source";
|
||||
import { DmpBlueprintService } from "@app/core/services/dmp/dmp-blueprint.service";
|
||||
import { PrefillingSourceService } from "@app/core/services/prefilling-source/prefilling-source.service";
|
||||
import { ProgressIndicationService } from "@app/core/services/progress-indication/progress-indication-service";
|
||||
import { SingleAutoCompleteConfiguration } from "@app/library/auto-complete/single/single-auto-complete-configuration";
|
||||
import { DescriptionTemplateEditorResolver } from "@app/ui/admin/description-template/editor/description-template-editor.resolver";
|
||||
import { BaseComponent } from "@common/base/base.component";
|
||||
import { FormService } from "@common/forms/form-service";
|
||||
import { Guid } from "@common/types/guid";
|
||||
import { TranslateService } from "@ngx-translate/core";
|
||||
import { UUID } from "crypto";
|
||||
import { Observable } from "rxjs";
|
||||
import { map, takeUntil } from "rxjs/operators";
|
||||
import { DescriptionEditorResolver } from "../description-editor.resolver";
|
||||
import { nameof } from "ts-simple-nameof";
|
||||
import { Description } from "@app/core/model/description/description";
|
||||
import { IsActive } from "@app/core/common/enum/is-active.enum";
|
||||
import { DescriptionPrefillingRequestEditorModel } from "./prefill-description-editor.model";
|
||||
|
||||
@Component({
|
||||
selector: 'prefill-description-component',
|
||||
|
@ -39,11 +37,7 @@ export class PrefillDescriptionDialogComponent extends BaseComponent implements
|
|||
availableDescriptionTemplates: DescriptionTemplate[] = [];
|
||||
|
||||
constructor(public dialogRef: MatDialogRef<PrefillDescriptionDialogComponent>,
|
||||
// private dmpBlueprintService: DmpBlueprintService,
|
||||
// private dialog: MatDialog,
|
||||
// private language: TranslateService,
|
||||
private progressIndicationService: ProgressIndicationService,
|
||||
private fb: UntypedFormBuilder,
|
||||
public prefillingSourceService: PrefillingSourceService,
|
||||
private formService: FormService,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any) {
|
||||
|
@ -58,15 +52,9 @@ export class PrefillDescriptionDialogComponent extends BaseComponent implements
|
|||
this.progressIndicationService.getProgressIndicationObservable().pipe(takeUntil(this._destroyed)).subscribe(x => {
|
||||
setTimeout(() => { this.progressIndication = x; });
|
||||
});
|
||||
this.prefillForm = this.fb.group({
|
||||
type: this.fb.control(false),
|
||||
descriptionTemplateId: this.fb.control(null, Validators.required),
|
||||
prefillingSourceId: this.fb.control(null, Validators.required),
|
||||
data: this.fb.control(null, Validators.required),
|
||||
})
|
||||
// if (this.data.availableProfiles && this.data.availableProfiles.length === 1) {
|
||||
// this.addProfileIfUsedLessThanMax(this.data.availableProfiles[0]);
|
||||
// }
|
||||
const editorModel = new DescriptionPrefillingRequestEditorModel();
|
||||
this.prefillForm = editorModel.buildForm(null, false);
|
||||
|
||||
this.prefillAutoCompleteConfiguration = {
|
||||
filterFn: this.searchDescriptions.bind(this),
|
||||
loadDataOnStart: false,
|
||||
|
@ -81,105 +69,6 @@ export class PrefillDescriptionDialogComponent extends BaseComponent implements
|
|||
this.prefillForm.get('data').setValue(null);
|
||||
}
|
||||
|
||||
// addProfileIfUsedLessThanMax(profile: DescriptionProfileModel) {
|
||||
// const dmpSectionIndex = this.data.datasetFormGroup.get('dmpSectionIndex').value;
|
||||
// const blueprintId = this.data.datasetFormGroup.get('dmp').value.profile.id;
|
||||
// this.dmpBlueprintService.getSingle(blueprintId, this.getBlueprintDefinitionFields())
|
||||
// .pipe(takeUntil(this._destroyed))
|
||||
// .subscribe(result => {
|
||||
// const section = result.definition.sections[dmpSectionIndex];
|
||||
// if (section.hasTemplates) {
|
||||
// const foundTemplate = section.descriptionTemplates.find(template => template.descriptionTemplateId === Guid.parse(profile.id));
|
||||
// if (foundTemplate !== undefined) {
|
||||
// let count = 0;
|
||||
// if (this.data.datasetFormGroup.get('dmp').value.datasets != null) {
|
||||
// for (let dataset of this.data.datasetFormGroup.get('dmp').value.datasets) {
|
||||
// if (dataset.dmpSectionIndex === dmpSectionIndex && dataset.profile.id === foundTemplate.descriptionTemplateId) {
|
||||
// count++;
|
||||
// }
|
||||
// }
|
||||
// if (count < foundTemplate.maxMultiplicity) {
|
||||
// this.prefillForm.get('profile').patchValue(profile);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// this.prefillForm.get('profile').patchValue(profile);
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// this.prefillForm.get('profile').patchValue(profile);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
// checkMinMax(event, profile: DescriptionProfileModel) {
|
||||
// event.stopPropagation();
|
||||
// const dmpSectionIndex = this.data.datasetFormGroup.get('dmpSectionIndex').value;
|
||||
// const blueprintId = this.data.datasetFormGroup.get('dmp').value.profile.id;
|
||||
// this.dmpBlueprintService.getSingle(blueprintId, this.getBlueprintDefinitionFields())
|
||||
// .pipe(takeUntil(this._destroyed))
|
||||
// .subscribe(result => {
|
||||
// const section = result.definition.sections[dmpSectionIndex];
|
||||
// if (section.hasTemplates) {
|
||||
// const foundTemplate = section.descriptionTemplates.find(template => template.descriptionTemplateId === Guid.parse(profile.id));
|
||||
// if (foundTemplate !== undefined) {
|
||||
// let count = 0;
|
||||
// if (this.data.datasetFormGroup.get('dmp').value.datasets != null) {
|
||||
// for (let dataset of this.data.datasetFormGroup.get('dmp').value.datasets) {
|
||||
// if (dataset.dmpSectionIndex === dmpSectionIndex && dataset.profile.id === foundTemplate.descriptionTemplateId) {
|
||||
// count++;
|
||||
// }
|
||||
// }
|
||||
// if (count === foundTemplate.maxMultiplicity) {
|
||||
// this.dialog.open(PopupNotificationDialogComponent, {
|
||||
// data: {
|
||||
// title: this.language.instant('DATASET-EDITOR.MAX-DESCRIPTION-DIALOG.TITLE'),
|
||||
// message: this.language.instant('DATASET-EDITOR.MAX-DESCRIPTION-DIALOG.MESSAGE')
|
||||
// }, maxWidth: '30em'
|
||||
// });
|
||||
// }
|
||||
// else {
|
||||
// this.prefillForm.get('profile').setValue(profile);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// this.prefillForm.get('profile').setValue(profile);
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// this.prefillForm.get('profile').setValue(profile);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
// private getBlueprintDefinitionFields() {
|
||||
// return [
|
||||
// [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.id)].join('.'),
|
||||
// [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.label)].join('.'),
|
||||
// [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.description)].join('.'),
|
||||
// [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.ordinal)].join('.'),
|
||||
// [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.hasTemplates)].join('.'),
|
||||
|
||||
// [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.id)].join('.'),
|
||||
// [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.category)].join('.'),
|
||||
// [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.dataType)].join('.'),
|
||||
// [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.systemFieldType)].join('.'),
|
||||
// [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.label)].join('.'),
|
||||
// [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.placeholder)].join('.'),
|
||||
// [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.description)].join('.'),
|
||||
// [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.required)].join('.'),
|
||||
// [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.ordinal)].join('.'),
|
||||
|
||||
// [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.id)].join('.'),
|
||||
// [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.descriptionTemplateId)].join('.'),
|
||||
// [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.label)].join('.'),
|
||||
// [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.minMultiplicity)].join('.'),
|
||||
// [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.maxMultiplicity)].join('.'),
|
||||
// ]
|
||||
// }
|
||||
|
||||
public compareWith(object1: any, object2: any) {
|
||||
return object1 && object2 && object1.id === object2.id;
|
||||
}
|
||||
|
@ -194,22 +83,6 @@ export class PrefillDescriptionDialogComponent extends BaseComponent implements
|
|||
}
|
||||
|
||||
next() {
|
||||
// if (this.isPrefilled) {
|
||||
// if (this.prefillForm.get('prefill').value.data == null) {
|
||||
// this.prefillingService.getPrefillingDescription(this.prefillForm.get('prefill').value.pid, this.prefillForm.get('profile').value.id, this.prefillForm.get('prefill').value.key).subscribe(wizard => {
|
||||
// wizard.profile = this.prefillForm.get('profile').value;
|
||||
// this.closeDialog(wizard);
|
||||
// });
|
||||
// }
|
||||
// else {
|
||||
// this.prefillingService.getPrefillingDescriptionUsingData(this.prefillForm.get('prefill').value.data, this.prefillForm.get('profile').value.id, this.prefillForm.get('prefill').value.key).subscribe(wizard => {
|
||||
// wizard.profile = this.prefillForm.get('profile').value;
|
||||
// this.closeDialog(wizard);
|
||||
// });
|
||||
// }
|
||||
// } else {
|
||||
// this.closeDialog();
|
||||
// }
|
||||
const formData = this.formService.getValue(this.prefillForm.value) as DescriptionPrefillingRequest;
|
||||
|
||||
this.prefillingSourceService.generate(formData, DescriptionEditorResolver.descriptionTemplateLookupFields(nameof<Description>(x => x.descriptionTemplate)))
|
||||
|
|
Loading…
Reference in New Issue