2024-03-29 15:22:31 +01:00
|
|
|
|
import { Component, Input, OnInit, SimpleChanges } from '@angular/core';
|
|
|
|
|
import { UntypedFormGroup } from '@angular/forms';
|
|
|
|
|
import { DescriptionTemplate } from '@app/core/model/description-template/description-template';
|
|
|
|
|
import { DescriptionTemplatePersist } from '@app/core/model/description-template/description-template-persist';
|
|
|
|
|
import { Description } from '@app/core/model/description/description';
|
|
|
|
|
import { DescriptionEditorModel } from '@app/ui/description/editor/description-editor.model';
|
2023-12-20 08:20:38 +01:00
|
|
|
|
import { VisibilityRulesService } from '@app/ui/description/editor/description-form/visibility-rules/visibility-rules.service';
|
2023-11-24 17:42:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-final-preview-component',
|
|
|
|
|
templateUrl: './final-preview.component.html',
|
|
|
|
|
styleUrls: ['./final-preview.component.scss'],
|
2023-12-29 16:04:16 +01:00
|
|
|
|
providers: [VisibilityRulesService]
|
2023-11-24 17:42:23 +01:00
|
|
|
|
})
|
|
|
|
|
|
2023-12-29 16:04:16 +01:00
|
|
|
|
export class FinalPreviewComponent implements OnInit {
|
|
|
|
|
|
2023-11-24 17:42:23 +01:00
|
|
|
|
|
2024-03-29 15:22:31 +01:00
|
|
|
|
@Input() descriptionTemplatePersist: DescriptionTemplatePersist;
|
|
|
|
|
descriptionTemplate: DescriptionTemplate;
|
2024-03-20 11:35:55 +01:00
|
|
|
|
|
2024-03-29 15:22:31 +01:00
|
|
|
|
previewPropertiesFormGroup
|
2023-11-24 17:42:23 +01:00
|
|
|
|
@Input() formGroup = null;
|
2024-03-20 11:35:55 +01:00
|
|
|
|
|
2023-12-29 16:04:16 +01:00
|
|
|
|
constructor(private visibilityRulesService: VisibilityRulesService) {
|
|
|
|
|
|
2023-11-24 17:42:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-29 15:22:31 +01:00
|
|
|
|
private generatePreviewForm() {
|
|
|
|
|
|
|
|
|
|
this.descriptionTemplate = this.buildDescriptionTemplate(this.descriptionTemplatePersist);
|
|
|
|
|
|
|
|
|
|
const mockDescription: Description = {
|
|
|
|
|
descriptionTemplate: this.descriptionTemplate
|
|
|
|
|
}
|
|
|
|
|
const descriptionEditorModel = new DescriptionEditorModel().fromModel(mockDescription, mockDescription.descriptionTemplate);
|
|
|
|
|
this.previewPropertiesFormGroup = descriptionEditorModel.properties.buildForm() as UntypedFormGroup;
|
|
|
|
|
|
|
|
|
|
this.visibilityRulesService.setContext(this.descriptionTemplate.definition, this.previewPropertiesFormGroup);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private buildDescriptionTemplate(persist: DescriptionTemplatePersist) : DescriptionTemplate{
|
|
|
|
|
if (persist == null) return null;
|
|
|
|
|
return {
|
|
|
|
|
id: persist.id,
|
|
|
|
|
label: persist.label,
|
|
|
|
|
description: persist.description,
|
|
|
|
|
groupId: undefined,
|
|
|
|
|
version: undefined,
|
|
|
|
|
language: persist.language,
|
|
|
|
|
type: undefined,
|
|
|
|
|
status: persist.status,
|
|
|
|
|
definition: persist.definition,
|
|
|
|
|
users: persist.users
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-29 16:04:16 +01:00
|
|
|
|
|
2023-11-24 17:42:23 +01:00
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
2024-03-29 15:22:31 +01:00
|
|
|
|
this.generatePreviewForm();
|
2023-11-24 17:42:23 +01:00
|
|
|
|
}
|
2023-12-29 16:04:16 +01:00
|
|
|
|
|
2024-03-29 15:22:31 +01:00
|
|
|
|
// ngOnChanges(changes: SimpleChanges) {
|
|
|
|
|
// if(changes['descriptionTemplatePersist']) this.generatePreviewForm();
|
|
|
|
|
// }
|
|
|
|
|
|
2023-11-24 17:42:23 +01:00
|
|
|
|
}
|