2023-12-20 08:20:38 +01:00
|
|
|
import { Component, Input } from '@angular/core';
|
|
|
|
import { UntypedFormGroup } from '@angular/forms';
|
|
|
|
import { DescriptionTemplate } from '@app/core/model/description-template/description-template';
|
2023-12-28 16:18:49 +01:00
|
|
|
import { Description } from '@app/core/model/description/description';
|
|
|
|
import { DmpBlueprintDefinitionSection } from '@app/core/model/dmp-blueprint/dmp-blueprint';
|
|
|
|
import { Dmp } from '@app/core/model/dmp/dmp';
|
|
|
|
import { DescriptionTemplateService } from '@app/core/services/description-template/description-template.service';
|
|
|
|
import { DescriptionService } from '@app/core/services/description/description.service';
|
|
|
|
import { DmpBlueprintService } from '@app/core/services/dmp/dmp-blueprint.service';
|
2023-12-20 08:20:38 +01:00
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
2023-12-28 16:18:49 +01:00
|
|
|
import { takeUntil } from 'rxjs/operators';
|
2023-12-20 08:20:38 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-description-base-fields-editor-component',
|
|
|
|
templateUrl: 'description-base-fields-editor.component.html',
|
|
|
|
styleUrls: ['./description-base-fields-editor.component.scss']
|
|
|
|
})
|
|
|
|
export class DescriptionBaseFieldsEditorComponent extends BaseComponent {
|
|
|
|
|
|
|
|
@Input() formGroup: UntypedFormGroup;
|
2023-12-28 16:18:49 +01:00
|
|
|
@Input() availableDescriptionTemplates: DescriptionTemplate[] = [];
|
|
|
|
@Input() description: Description;
|
2023-12-20 08:20:38 +01:00
|
|
|
viewOnly = false; //TODO: not used.
|
|
|
|
|
|
|
|
constructor(
|
2023-12-28 16:18:49 +01:00
|
|
|
private dmpBlueprintService: DmpBlueprintService,
|
|
|
|
private descriptionTemplateService: DescriptionTemplateService,
|
2023-12-20 08:20:38 +01:00
|
|
|
) { super(); }
|
|
|
|
|
2023-12-28 16:18:49 +01:00
|
|
|
ngOnInit() {
|
|
|
|
const section: DmpBlueprintDefinitionSection = this.dmpBlueprintService.getSection(this.description.dmp.blueprint, this.description.dmpDescriptionTemplate.sectionId);
|
|
|
|
const descriptionTemplateIds = section ? section.descriptionTemplates.map(x => x.descriptionTemplateId) : [];
|
|
|
|
if (descriptionTemplateIds && descriptionTemplateIds.length > 0) {
|
|
|
|
this.descriptionTemplateService.query(this.descriptionTemplateService.buildAutocompleteLookup(null, null, descriptionTemplateIds))
|
|
|
|
.pipe(takeUntil(this._destroyed)).subscribe(queryResult => {
|
|
|
|
this.availableDescriptionTemplates = queryResult.items;
|
|
|
|
});
|
|
|
|
}
|
2023-12-20 08:20:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public compareWith(object1: any, object2: any) {
|
|
|
|
return object1 && object2 && object1.id === object2.id;
|
|
|
|
}
|
|
|
|
}
|