Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring

# Conflicts:
#	dmp-frontend/src/app/ui/description/editor/description-editor.model.ts
This commit is contained in:
amentis 2024-02-08 17:28:07 +02:00
commit 2574cb424e
22 changed files with 178 additions and 185 deletions

View File

@ -55,6 +55,8 @@ BEGIN
);
ALTER TABLE public."DescriptionTemplate" ALTER COLUMN version_status SET NOT NULL;
ALTER TABLE public."DescriptionTemplate" ALTER COLUMN version DROP DEFAULT;
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.010', '2023-11-02 12:00:00.000000+02', now(), 'Aling DescriptionTemplate table.');

View File

@ -17,6 +17,16 @@ export interface DescriptionTemplatePersist extends BaseEntityPersist {
users: UserDescriptionTemplatePersist[];
}
export interface NewVersionDescriptionTemplatePersist extends BaseEntityPersist {
label: string;
description: string;
language: string;
type: Guid;
status: DescriptionTemplateStatus;
definition: DescriptionTemplateDefinitionPersist;
users: UserDescriptionTemplatePersist[];
}
export interface UserDescriptionTemplatePersist {
userId?: Guid;
role?: UserDescriptionTemplateRole;

View File

@ -2,7 +2,7 @@ import { HttpClient, HttpHeaders, HttpResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { IsActive } from '@app/core/common/enum/is-active.enum';
import { DescriptionTemplate } from '@app/core/model/description-template/description-template';
import { DescriptionTemplatePersist } from '@app/core/model/description-template/description-template-persist';
import { DescriptionTemplatePersist, NewVersionDescriptionTemplatePersist } from '@app/core/model/description-template/description-template-persist';
import { DescriptionTemplateLookup } from '@app/core/query/description-template.lookup';
import { MultipleAutoCompleteConfiguration } from '@app/library/auto-complete/multiple/multiple-auto-complete-configuration';
import { SingleAutoCompleteConfiguration } from '@app/library/auto-complete/single/single-auto-complete-configuration';
@ -68,6 +68,15 @@ export class DescriptionTemplateService {
catchError((error: any) => throwError(error)));
}
newVersion(item: NewVersionDescriptionTemplatePersist, reqFields: string[] = []): Observable<DescriptionTemplate> {
const url = `${this.apiBase}/new-version`;
const options = { params: { f: reqFields } };
return this.http
.post<DescriptionTemplate>(url, item).pipe(
catchError((error: any) => throwError(error)));
}
downloadXML(id: Guid): Observable<HttpResponse<Blob>> {
const url = `${this.apiBase}/xml/export/${id}`;
let headerXml: HttpHeaders = this.headers.set('Content-Type', 'application/xml');

View File

@ -14,6 +14,14 @@ const routes: Routes = [
component: DescriptionTemplateListingComponent,
canActivate: [AuthGuard]
},
{
path: 'versions/:groupid',
component: DescriptionTemplateListingComponent,
canActivate: [AuthGuard],
data: {
mode: 'versions-listing'
}
},
{
path: 'new',
canActivate: [AuthGuard],
@ -24,7 +32,7 @@ const routes: Routes = [
permissions: [AppPermission.EditDescriptionTemplate]
},
...BreadcrumbService.generateRouteDataConfiguration({
title: 'BREADCRUMBS.NEW-DMP-BLUEPRINT'
title: 'BREADCRUMBS.NEW-DESCRIPTION-TEMPLATES'
})
}
},
@ -38,13 +46,31 @@ const routes: Routes = [
},
data: {
...BreadcrumbService.generateRouteDataConfiguration({
title: 'BREADCRUMBS.EDIT-DMP-BLUEPRINT'
title: 'BREADCRUMBS.EDIT-DESCRIPTION-TEMPLATES'
}),
authContext: {
permissions: [AppPermission.EditDescriptionTemplate]
}
},
action: 'clone'
}
},
{
path: 'new-version/:newversionid',
canActivate: [AuthGuard],
component: DescriptionTemplateEditorComponent,
canDeactivate: [PendingChangesGuard],
resolve: {
'entity': DescriptionTemplateEditorResolver
},
data: {
...BreadcrumbService.generateRouteDataConfiguration({
title: 'BREADCRUMBS.EDIT-DESCRIPTION-TEMPLATES'
}),
authContext: {
permissions: [AppPermission.EditDescriptionTemplate]
},
action: 'new-version'
}
},
{
path: ':id',
@ -56,7 +82,7 @@ const routes: Routes = [
},
data: {
...BreadcrumbService.generateRouteDataConfiguration({
title: 'BREADCRUMBS.EDIT-DMP-BLUEPRINT'
title: 'BREADCRUMBS.EDIT-DESCRIPTION-TEMPLATES'
}),
authContext: {
permissions: [AppPermission.EditDescriptionTemplate]

View File

@ -65,8 +65,8 @@
<!-- FIELDS -->
<div #inputs transition-group class="col-12" *ngIf="hasFocus" [@fade-in]>
<div *ngFor="let field of fieldsArray.controls; let i=index;" class="row bg-white field-input mt-3" (click)="setTargetField(field)" transition-group-item>
<app-description-template-editor-field-component class="col-12" [form]="field" [showOrdinal]="false" [indexPath]="indexPath + 'f' + i" [viewOnly]="viewOnly" [expandView]="hasFocus" [canBeDeleted]="fieldsArray.length !=1"
[validationErrorModel]="validationErrorModel" [rootPath]="rootPath + 'fields[' + i + '].'" (delete)="deleteField(i)">
<app-description-template-editor-field-component class="col-12" [form]="field" [showOrdinal]="false" [viewOnly]="viewOnly" [expandView]="hasFocus" [canBeDeleted]="fieldsArray.length !=1"
[validationErrorModel]="validationErrorModel" [validationRootPath]="validationRootPath + '.fields[' + i + '].'" (delete)="deleteField(i)">
<div class="arrows mt-2">
<ul class="list-unstyled list-inline d-flex align-items-center">
<li *ngIf="canGoUp(i)" class="text-muted">

View File

@ -1,4 +1,4 @@
import { Component, Input, OnChanges, OnInit, SimpleChanges, ViewChild } from '@angular/core';
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, ViewChild } from '@angular/core';
import { AbstractControl, UntypedFormArray, UntypedFormControl, UntypedFormGroup } from '@angular/forms';
import { MatCheckboxChange } from '@angular/material/checkbox';
import { MatDialog } from '@angular/material/dialog';
@ -39,7 +39,6 @@ import { ValidationErrorModel } from '@common/forms/validation/error-model/valid
export class DescriptionTemplateEditorCompositeFieldComponent extends BaseComponent implements OnInit, OnChanges {
@Input() form: UntypedFormGroup;
@Input() indexPath: string;
@Input() viewOnly: boolean;
@Input() datasetProfileId?: string;
@ -48,7 +47,7 @@ export class DescriptionTemplateEditorCompositeFieldComponent extends BaseCompon
@Input() hasFocus: boolean = false;
@ViewChild("inputs") inputs: TransitionGroupComponent;
@Input() validationErrorModel: ValidationErrorModel;
@Input() rootPath: string;
@Input() validationRootPath: string;
showPreview: boolean = true;
previewDirty: boolean = false;
@ -65,6 +64,7 @@ export class DescriptionTemplateEditorCompositeFieldComponent extends BaseCompon
private myCustomValidators: EditorCustomValidators = new EditorCustomValidators();
isMultiplicityEnabled = false;
constructor(
private dialog: MatDialog,
@ -321,22 +321,22 @@ export class DescriptionTemplateEditorCompositeFieldComponent extends BaseCompon
}
addNewField() {
const field: DescriptionTemplateFieldEditorModel = new DescriptionTemplateFieldEditorModel();
field.id = Guid.create().toString();
// addNewField() {
// const field: DescriptionTemplateFieldEditorModel = new DescriptionTemplateFieldEditorModel();
// field.id = Guid.create().toString();
field.ordinal = (this.form.get('fields') as UntypedFormArray).length;
// field.ordinal = (this.form.get('fields') as UntypedFormArray).length;
const fieldForm = field.buildForm();
// fieldForm.setValidators(this.customFieldValidator());
// const fieldForm = field.buildForm();
// // fieldForm.setValidators(this.customFieldValidator());
// fieldForm.get('viewStyle').get('renderStyle').setValidators(Validators.required);
// // fieldForm.get('viewStyle').get('renderStyle').setValidators(Validators.required);
(<UntypedFormArray>this.form.get('fields')).push(fieldForm);
// (<UntypedFormArray>this.form.get('fields')).push(fieldForm);
this.setTargetField(fieldForm);
fieldForm.updateValueAndValidity();
}
// this.setTargetField(fieldForm);
// fieldForm.updateValueAndValidity();
// }
DeleteField(index) {
@ -573,7 +573,7 @@ export class DescriptionTemplateEditorCompositeFieldComponent extends BaseCompon
}
}
(<UntypedFormArray>this.form.get('fields')).push(new DescriptionTemplateFieldEditorModel(this.validationErrorModel).fromModel(field).buildForm({rootPath: this.rootPath + 'fields[' + this.fieldsArray.length + '].'}));
(<UntypedFormArray>this.form.get('fields')).push(new DescriptionTemplateFieldEditorModel(this.validationErrorModel).fromModel(field).buildForm({rootPath: this.validationRootPath + '.fields[' + this.fieldsArray.length + ']'}));
this.inputs.init();
// fieldForm.get('viewStyle').get('renderStyle').updateValueAndValidity();
// fieldForm.get('data').updateValueAndValidity();

View File

@ -1,3 +1,4 @@
{{validationRootPath}}
<ng-container *ngIf="expandView">
<!-- ACTIONS PER FIELD -->
@ -201,18 +202,18 @@
<ng-container *ngIf="form.get('visibilityRules')?.value.length">
<h4 class="col-12" style="font-weight: bold">{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.FIELDS.RULES-TITLE' | translate}}
</h4>
<app-description-template-editor-visibility-rule-component class="col-12" [form]="form.get('visibilityRules')" [validationErrorModel]="validationErrorModel" [rootPath]="rootPath" [fieldTypeForCheck]="form.get('data').get('fieldType').value" [formArrayOptionsForCheck]="this.form.get('data')?.get('options')" [viewOnly]="viewOnly"></app-description-template-editor-visibility-rule-component>
<app-description-template-editor-visibility-rule-component class="col-12" [form]="form.get('visibilityRules')" [validationErrorModel]="validationErrorModel" [rootPath]="validationRootPath" [fieldTypeForCheck]="form.get('data').get('fieldType').value" [formArrayOptionsForCheck]="this.form.get('data')?.get('options')" [viewOnly]="viewOnly"></app-description-template-editor-visibility-rule-component>
<!-- <div class="col-12" *ngIf="!viewOnly">
<button mat-button class="full-width" (click)="addNewRule()" [disabled]="!form.get('data').get('fieldType').value">{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.ACTIONS.ADD-RULE' | translate}}</button>
</div> -->
</ng-container>
</div>
<div class="row" [ngSwitch]="form.get('data')?.get('fieldType')?.value " *ngIf="expandView">
<div class="row" [ngSwitch]="form.get('data')?.get('fieldType')?.value" >
<app-description-template-editor-external-select-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.EXTERNAL_SELECT" class="col-12" [form]="form" [validationErrorModel]= "validationErrorModel" [rootPath]="rootPath"></app-description-template-editor-external-select-field-component>
<app-description-template-editor-select-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.SELECT" class="col-12" [form]="form" [validationErrorModel]= "validationErrorModel" [rootPath]="rootPath"></app-description-template-editor-select-field-component>
<app-description-template-editor-radio-box-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.RADIO_BOX" class="col-12" [form]="form" [validationErrorModel]= "validationErrorModel" [rootPath]="rootPath"></app-description-template-editor-radio-box-field-component>
<app-description-template-editor-upload-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.UPLOAD" class="col-12" [form]="form" [validationErrorModel]= "validationErrorModel" [rootPath]="rootPath"></app-description-template-editor-upload-field-component>
<app-description-template-editor-external-select-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.EXTERNAL_SELECT" class="col-12" [form]="form" [validationErrorModel]= "validationErrorModel" [rootPath]="validationRootPath"></app-description-template-editor-external-select-field-component>
<app-description-template-editor-select-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.SELECT" class="col-12" [form]="form" [validationErrorModel]= "validationErrorModel" [rootPath]="validationRootPath"></app-description-template-editor-select-field-component>
<app-description-template-editor-radio-box-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.RADIO_BOX" class="col-12" [form]="form" [validationErrorModel]= "validationErrorModel" [rootPath]="validationRootPath"></app-description-template-editor-radio-box-field-component>
<app-description-template-editor-upload-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.UPLOAD" class="col-12" [form]="form" [validationErrorModel]= "validationErrorModel" [rootPath]="validationRootPath"></app-description-template-editor-upload-field-component>
<app-description-template-editor-label-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.BOOLEAN_DECISION" class="col-12" [form]="form"></app-description-template-editor-label-field-component>
<app-description-template-editor-label-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.CHECK_BOX" class="col-12" [form]="form"></app-description-template-editor-label-field-component>

View File

@ -35,8 +35,6 @@ import { ValidationErrorModel } from '@common/forms/validation/error-model/valid
export class DescriptionTemplateEditorFieldComponent extends BaseComponent implements OnInit, ErrorStateMatcher {
@Input() viewOnly: boolean;
@Input() form: UntypedFormGroup;
@Input() showOrdinal = true;
@Input() indexPath: string;
validationTypeEnum = ValidationType;
// isFieldMultiplicityEnabled = false;
@ -48,7 +46,7 @@ export class DescriptionTemplateEditorFieldComponent extends BaseComponent imple
@Output() delete = new EventEmitter<void>();
@Input() validationErrorModel: ValidationErrorModel;
@Input() rootPath: string;
@Input() validationRootPath: string;
readonly separatorKeysCodes: number[] = [ENTER, COMMA];
@ -96,7 +94,7 @@ export class DescriptionTemplateEditorFieldComponent extends BaseComponent imple
addNewRule() {
const rule: DescriptionTemplateRuleEditorModel = new DescriptionTemplateRuleEditorModel(this.validationErrorModel);
const ruleArray = this.form.get('visibilityRules') as UntypedFormArray;
(<UntypedFormArray>this.form.get('visibilityRules')).push(rule.buildForm({rootPath: this.rootPath + 'visibilityRules[' + ruleArray.length +'].'}));
(<UntypedFormArray>this.form.get('visibilityRules')).push(rule.buildForm({rootPath: this.validationRootPath + 'visibilityRules[' + ruleArray.length +'].'}));
}
get canApplyVisibility(): boolean {
@ -219,7 +217,7 @@ export class DescriptionTemplateEditorFieldComponent extends BaseComponent imple
}
const form = (new DescriptionTemplateFieldEditorModel(this.validationErrorModel)).fromModel(field)
.buildForm({rootPath: this.rootPath});
.buildForm({rootPath: this.validationRootPath});
const fields = this.form.parent as UntypedFormArray;

View File

@ -1,14 +0,0 @@
<mat-card *ngFor="let pageControl of form['controls']; let i=index;" class="page-card">
<mat-card-title class="page-card-title">{{'DATASET-PROFILE-EDITOR.STEPS.PAGES.PAGE-PREFIX' | translate}} {{i + 1}}</mat-card-title>
<div class="row">
<mat-form-field class="col">
<input matInput type="text" placeholder="{{'DATASET-PROFILE-EDITOR.STEPS.PAGES.PAGE-INPUT-TITLE' | translate}}"
[formControl]="pageControl.get('title')" required>
<mat-error *ngIf="pageControl.get('title').hasError('backendError')">{{pageControl.get('title').getError('backendError').message}}</mat-error>
<mat-error *ngIf="pageControl.get('title').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
<button mat-icon-button type="button" class="col-auto" (click)="removePage(i)" [disabled]="viewOnly">
<mat-icon>delete</mat-icon>
</button>
</div>
</mat-card>

View File

@ -1,7 +0,0 @@
.page-card {
margin-bottom: 1em;
.page-card-title {
text-align: center;
}
}

View File

@ -1,17 +0,0 @@
import { Component, Input } from '@angular/core';
import { UntypedFormArray } from '@angular/forms';
@Component({
selector: 'app-dataset-profile-editor-page-component',
templateUrl: './dataset-profile-editor-page.component.html',
styleUrls: ['./dataset-profile-editor-page.component.scss']
})
export class DatasetProfileEditorPageComponent {
@Input() form: UntypedFormArray;
@Input() viewOnly: boolean;
removePage(index) {
(<UntypedFormArray>this.form).removeAt(index);
}
}

View File

@ -65,7 +65,7 @@
[hasFocus]="fieldset.get('id').value === selectedFieldSetId"
[datasetProfileId]="datasetProfileId"
[validationErrorModel]="validationErrorModel"
[rootPath]="rootPath + 'fieldSets[' + i + '].'">
[validationRootPath]="validationRootPath + '.fieldSets[' + i + ']'">
</app-description-template-editor-composite-field-component>
</mat-card-content>
</mat-card>

View File

@ -29,7 +29,7 @@ export class DescriptionTemplateEditorSectionFieldSetComponent implements OnInit
@Output() addNewFieldSet = new EventEmitter<UntypedFormGroup>();
@Output() cloneFieldSet = new EventEmitter<UntypedFormGroup>();
@Input() validationErrorModel: ValidationErrorModel;
@Input() rootPath: string;
@Input() validationRootPath: string;
idprefix = "id";
@ -125,7 +125,6 @@ export class DescriptionTemplateEditorSectionFieldSetComponent implements OnInit
// return parent;
// }
private initialize() {
if (this.tocentry.type === ToCEntryType.Section) {
this.form = this.tocentry.form;

View File

@ -1,8 +1,6 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { UntypedFormArray, UntypedFormGroup } from '@angular/forms';
import { Component, Input, OnInit } from '@angular/core';
import { UntypedFormGroup } from '@angular/forms';
import { BaseComponent } from '@common/base/base.component';
import { Guid } from '@common/types/guid';
import { DescriptionTemplateFieldEditorModel, DescriptionTemplateFieldSetEditorModel, DescriptionTemplateSectionEditorModel } from '../../description-template-editor.model';
@Component({
selector: 'app-description-template-editor-section-component',
@ -13,63 +11,10 @@ import { DescriptionTemplateFieldEditorModel, DescriptionTemplateFieldSetEditorM
export class DescriptionTemplateEditorSectionComponent extends BaseComponent implements OnInit {
@Input() form: UntypedFormGroup;
@Input() indexPath: string;
@Input() viewOnly: boolean;
@Output() fieldsetAdded = new EventEmitter<String>(); //returns the id of the fieldset added
constructor() { super(); }
ngOnInit() {
}
addField() {
const fieldSet: DescriptionTemplateFieldSetEditorModel = new DescriptionTemplateFieldSetEditorModel();
fieldSet.ordinal = (this.form.get('fieldSets') as UntypedFormArray).length;
const field: DescriptionTemplateFieldEditorModel = new DescriptionTemplateFieldEditorModel();
field.id = Guid.create().toString();
field.ordinal = 0;//first field in fields
fieldSet.fields.push(field);
fieldSet.id = Guid.create().toString();
const fieldsetsArray = this.form.get('fieldSets') as UntypedFormArray;
fieldsetsArray.push(fieldSet.buildForm());
const fieldSetForm = fieldsetsArray.at(fieldsetsArray.length - 1);
//emit id inserted
if (fieldSetForm) {
const id: string = fieldSetForm.get('id').value;
this.fieldsetAdded.emit(id);
}
}
addSectioninSection() {
const section: DescriptionTemplateSectionEditorModel = new DescriptionTemplateSectionEditorModel();
//this.dataModel.sections.push(section);
(<UntypedFormArray>this.form.get('sections')).push(section.buildForm());
}
DeleteSectionInSection(index) {
//this.dataModel.sections.splice(index, 1);
(<UntypedFormArray>this.form.get('sections')).removeAt(index);
}
deleteFieldSet(index) {
//this.dataModel.fieldSets.splice(index, 1);
(<UntypedFormArray>this.form.get('fieldSets')).removeAt(index);
}
keepPageSelectionValid(pagesJson: Array<any>) {
const selectedPage = this.form.get('page').value as String;
// const pages: Array<PageEditorModel> = JsonSerializer.fromJSONArray(pagesJson, Page);
if (pagesJson.find(elem => elem.id === selectedPage) === undefined) {
this.form.get('page').reset();
}
}
getFieldTile(formGroup: UntypedFormGroup, index: number) {
if (formGroup.get('title') && formGroup.get('title').value && formGroup.get('title').value.length > 0) { return formGroup.get('title').value; }
return "Field " + (index + 1);
}
}

View File

@ -178,7 +178,15 @@
<div class="row sticky-top table-container" style="top : 7em;">
<description-template-table-of-contents class="toc-pane-container col" style="margin-bottom: 2em;" [links]="toCEntries" (itemClick)="displayItem($event)" (createEntry)="addNewEntry($event)" (removeEntry)="onRemoveEntry($event)" [itemSelected]="selectedTocEntry" [viewOnly]="formGroup.disabled" (dataNeedsRefresh)="onDataNeedsRefresh($event)" [colorizeInvalid]="colorizeInvalid">
<description-template-table-of-contents class="toc-pane-container col" style="margin-bottom: 2em;"
[links]="toCEntries"
(itemClick)="displayItem($event)"
(createEntry)="addNewEntry($event)"
(removeEntry)="onRemoveEntry($event)"
[itemSelected]="selectedTocEntry"
[viewOnly]="formGroup.disabled"
(dataNeedsRefresh)="onDataNeedsRefresh($event)"
[colorizeInvalid]="colorizeInvalid">
</description-template-table-of-contents>
</div>
</div>
@ -213,8 +221,14 @@
</div>
<div class="col-12" *ngIf="(selectedTocEntry.type === tocEntryEnumValues.Section) || (selectedTocEntry.type === tocEntryEnumValues.FieldSet)">
<app-description-template-editor-section-fieldset-component [tocentry]="selectedTocEntry" [viewOnly]="viewOnly" [datasetProfileId]="datasetProfileId" [validationErrorModel]="editorModel.validationErrorModel" [rootPath]="rootPath"
(addNewFieldSet)="addNewEntry({childType: tocEntryEnumValues.FieldSet,parent: {formGroup: $event}})" (removeFieldSet)="onRemoveEntry(_findTocEntryById($event, toCEntries))" (cloneFieldSet)="cloneFieldSet($event)" (selectedEntryId)="displayItem(_findTocEntryById($event, toCEntries))" (dataNeedsRefresh)="onDataNeedsRefresh()">
<app-description-template-editor-section-fieldset-component
[tocentry]="selectedTocEntry"
[viewOnly]="viewOnly"
[datasetProfileId]="datasetProfileId"
[validationErrorModel]="editorModel.validationErrorModel"
[validationRootPath]="selectedTocEntry.validationRootPath"
(addNewFieldSet)="addNewEntry({childType: tocEntryEnumValues.FieldSet,parent: {formGroup: $event}})" (removeFieldSet)="onRemoveEntry(_findTocEntryById($event, toCEntries))" (cloneFieldSet)="cloneFieldSet($event)" (selectedEntryId)="displayItem(_findTocEntryById($event, toCEntries))" (dataNeedsRefresh)="onDataNeedsRefresh()"
>
</app-description-template-editor-section-fieldset-component>
</div>

View File

@ -14,7 +14,7 @@ import { IsActive } from '@app/core/common/enum/is-active.enum';
import { AppPermission } from '@app/core/common/enum/permission.enum';
import { UserDescriptionTemplateRole } from '@app/core/common/enum/user-description-template-role';
import { DescriptionTemplate } from '@app/core/model/description-template/description-template';
import { DescriptionTemplatePersist } from '@app/core/model/description-template/description-template-persist';
import { DescriptionTemplatePersist, NewVersionDescriptionTemplatePersist } from '@app/core/model/description-template/description-template-persist';
import { LanguageInfo } from '@app/core/model/language-info';
import { User } from '@app/core/model/user/user';
import { AuthService } from '@app/core/services/auth/auth.service';
@ -201,13 +201,23 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
}
persistEntity(onSuccess?: (response) => void): void {
const formData = this.formService.getValue(this.formGroup.value) as DescriptionTemplatePersist;
if (this.isNew && !this.isClone && !this.isNewVersion){
const formData = this.formService.getValue(this.formGroup.value) as DescriptionTemplatePersist;
this.descriptionTemplateService.persist(formData)
.pipe(takeUntil(this._destroyed)).subscribe(
complete => onSuccess ? onSuccess(complete) : this.onCallbackSuccess(complete),
error => this.onCallbackError(error)
);
this.descriptionTemplateService.persist(formData)
.pipe(takeUntil(this._destroyed)).subscribe(
complete => onSuccess ? onSuccess(complete) : this.onCallbackSuccess(complete),
error => this.onCallbackError(error)
);
} else if (this.isNewVersion && !this.isNew && !this.isClone) {
const formData = this.formService.getValue(this.formGroup.value) as NewVersionDescriptionTemplatePersist;
this.descriptionTemplateService.newVersion(formData)
.pipe(takeUntil(this._destroyed)).subscribe(
complete => onSuccess ? onSuccess(complete) : this.onCallbackSuccess(complete),
error => this.onCallbackError(error)
);
}
}
formSubmit(): void {
@ -441,7 +451,8 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
form: pageElement,
numbering: (i + 1).toString(),
subEntriesType: ToCEntryType.Section,
subEntries: []
subEntries: [],
validationRootPath: 'definition.pages[' + i + ']'
} as ToCEntry;
const subEntries = [];
@ -452,10 +463,11 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
label: sectionElement.get('title').value,
type: ToCEntryType.Section,
form: sectionElement,
numbering: page.numbering + '.' + (subEntries.length + 1)
numbering: page.numbering + '.' + (subEntries.length + 1),
validationRootPath: page.validationRootPath + '.sections[' + i + ']'
} as ToCEntry;
const sectionItems = this.populateSections(sectionElement.get('sections') as UntypedFormArray, item.numbering);
const fieldSetItems = this.populateFieldSets(sectionElement.get('fieldSets') as UntypedFormArray, item.numbering);
const sectionItems = this.populateSections(sectionElement.get('sections') as UntypedFormArray, item.numbering, item.validationRootPath);
const fieldSetItems = this.populateFieldSets(sectionElement.get('fieldSets') as UntypedFormArray, item.numbering, item.validationRootPath);
if (sectionItems != null) {
item.subEntries = sectionItems;
@ -483,7 +495,7 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
return result;
}
private populateSections(sections: UntypedFormArray, existingNumbering: string): ToCEntry[] {
private populateSections(sections: UntypedFormArray, existingNumbering: string, validationRootPath: string): ToCEntry[] {
if (sections == null || sections.controls == null || sections.controls.length == 0) { return null; }
const result: ToCEntry[] = [];
@ -494,10 +506,11 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
label: sectionElement.get('title').value,
type: ToCEntryType.Section,
form: sectionElement,
numbering: existingNumbering + '.' + (i + 1)
numbering: existingNumbering + '.' + (i + 1),
validationRootPath: validationRootPath + '.sections[' + i + ']'
} as ToCEntry;
const sectionItems = this.populateSections(sectionElement.get('sections') as UntypedFormArray, item.numbering);
const fieldSetItems = this.populateFieldSets(sectionElement.get('fieldSets') as UntypedFormArray, item.numbering);
const sectionItems = this.populateSections(sectionElement.get('sections') as UntypedFormArray, item.numbering, item.validationRootPath);
const fieldSetItems = this.populateFieldSets(sectionElement.get('fieldSets') as UntypedFormArray, item.numbering, item.validationRootPath);
if (sectionItems != null) {
item.subEntries = sectionItems;
item.subEntriesType = ToCEntryType.Section;
@ -516,7 +529,7 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
return result;
}
private populateFieldSets(fieldSets: UntypedFormArray, existingNumbering: string): ToCEntry[] {
private populateFieldSets(fieldSets: UntypedFormArray, existingNumbering: string, validationRootPath: string): ToCEntry[] {
if (fieldSets == null || fieldSets.controls == null || fieldSets.controls.length == 0) { return null; }
const result: ToCEntry[] = [];
@ -528,7 +541,8 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
type: ToCEntryType.FieldSet,
//subEntries: this.populateSections((fieldSetElement.get('fieldSets') as FormArray), existingNumbering + '.' + i),
form: fieldSetElement,
numbering: existingNumbering + '.' + (i + 1)
numbering: existingNumbering + '.' + (i + 1),
validationRootPath: validationRootPath
} as ToCEntry)
});
@ -582,6 +596,7 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
page.id = Guid.create().toString();
if (isNaN(pages.length)) { page.ordinal = 0; } else { page.ordinal = pages.length; }
const pageForm = page.buildForm({ rootPath: 'definition.pages[' + pages.length + '].' });
console.log('definition.pages[' + pages.length + '].');
// this.dataModel.pages.push(page);
pages.push(pageForm);
@ -618,9 +633,9 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
}
//store rootPath for next levels/components
this.rootPath = 'definition.pages['+ pageIndex +'].sections[' + sectionsArray.length + '].';
this.rootPath = 'definition.pages[' + pageIndex + '].sections[' + sectionsArray.length + '].';
sectionsArray.push(section.buildForm({ rootPath: 'definition.pages['+ pageIndex +'].sections[' + sectionsArray.length + '].' }));
sectionsArray.push(section.buildForm({ rootPath: 'definition.pages[' + pageIndex + '].sections[' + sectionsArray.length + '].' }));
// this.form.updateValueAndValidity();
} else if (parent.type == ToCEntryType.Section) { //SUBSECTION OF SECTION
@ -628,15 +643,15 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
for (let j = 0; j < pages.length; j++) {
const parentSections = pages.at(j).get('sections') as UntypedFormArray;
sectionIndexes = this.findSectionIndex(parentSections, parent.id);
if (sectionIndexes && sectionIndexes.length > 0){
if (sectionIndexes && sectionIndexes.length > 0) {
pageIndex = j;
break;
}
}
let parentSectionRootPath = '';
if(sectionIndexes.length > 0){
if (sectionIndexes.length > 0) {
sectionIndexes.forEach(index => {
parentSectionRootPath = parentSectionRootPath + 'sections[' + index +'].'
parentSectionRootPath = parentSectionRootPath + 'sections[' + index + '].'
});
sectionsArray = parent.form.get('sections') as UntypedFormArray;
@ -650,9 +665,9 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
}
//store rootPath for next levels/components
this.rootPath = 'definition.pages['+ pageIndex +'].'+ parentSectionRootPath;
this.rootPath = 'definition.pages[' + pageIndex + '].' + parentSectionRootPath;
sectionsArray.push(section.buildForm({ rootPath: 'definition.pages['+ pageIndex +'].' + parentSectionRootPath + 'sections[' + sectionsArray.length + '].' }));
sectionsArray.push(section.buildForm({ rootPath: 'definition.pages[' + pageIndex + '].' + parentSectionRootPath + 'sections[' + sectionsArray.length + '].' }));
// (child.form.parent as FormArray).push(section.buildForm());
}
@ -676,15 +691,15 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
for (let j = 0; j < pages.length; j++) {
const parentSections = pages.at(j).get('sections') as UntypedFormArray;
sectionIndexes = this.findSectionIndex(parentSections, parent.id);
if (sectionIndexes && sectionIndexes.length > 0){
if (sectionIndexes && sectionIndexes.length > 0) {
pageIndex = j;
break;
}
}
let parentSectionRootPath = '';
if(sectionIndexes.length > 0){
if (sectionIndexes.length > 0) {
sectionIndexes.forEach(index => {
parentSectionRootPath = parentSectionRootPath + 'sections[' + index +'].'
parentSectionRootPath = parentSectionRootPath + 'sections[' + index + '].'
});
}
if (sectionIndexes.length > 0) {
@ -694,7 +709,7 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
field.ordinal = 0;//first filed in the fields list
const fieldSetsArray = parent.form.get('fieldSets') as UntypedFormArray
const fieldForm = field.buildForm({ rootPath: this.rootPath+ 'fields[' + 0 + '].'});
const fieldForm = field.buildForm({ rootPath: this.rootPath + 'fields[' + 0 + '].' });
//give fieldset id and ordinal
const fieldSet: DescriptionTemplateFieldSetEditorModel = new DescriptionTemplateFieldSetEditorModel(this.editorModel.validationErrorModel);
@ -707,7 +722,7 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
} catch {
fieldSet.ordinal = fieldSetsArray.length;
}
const fieldsetForm = fieldSet.buildForm({ rootPath: 'definition.pages['+ pageIndex +'].' + parentSectionRootPath + 'fieldSets[' + fieldSetsArray.length + '].' });
const fieldsetForm = fieldSet.buildForm({ rootPath: 'definition.pages[' + pageIndex + '].' + parentSectionRootPath + 'fieldSets[' + fieldSetsArray.length + '].' });
(fieldsetForm.get('fields') as UntypedFormArray).push(fieldForm);
fieldSetsArray.push(fieldsetForm);
@ -726,18 +741,18 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
this.formGroup.updateValueAndValidity();
}
private findSectionIndex(sectionFormArray: UntypedFormArray, parentId: string) : number[]{
private findSectionIndex(sectionFormArray: UntypedFormArray, parentId: string): number[] {
for (let i = 0; i < sectionFormArray?.length; i++) {
let sectionFormGroup = sectionFormArray.at(i);
let sectionId = sectionFormGroup.get('id').value;
const parentSections = sectionFormGroup.get('sections') as UntypedFormArray;
if (sectionId == parentId) {
return [i];
} else if (parentSections && parentSections.length > 0){
const indexes: number[]= this.findSectionIndex(parentSections, parentId);
if (indexes && indexes.length > 0){
} else if (parentSections && parentSections.length > 0) {
const indexes: number[] = this.findSectionIndex(parentSections, parentId);
if (indexes && indexes.length > 0) {
indexes.unshift(i);
return indexes;
}
@ -747,20 +762,20 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
return null;
}
private getUpdatedSectionFormArray(sectionFormArray: UntypedFormArray, tceId: string) : UntypedFormArray{
private getUpdatedSectionFormArray(sectionFormArray: UntypedFormArray, tceId: string): UntypedFormArray {
for (let i = 0; i < sectionFormArray?.length; i++) {
let sectionFormGroup = sectionFormArray.at(i);
let sectionId = sectionFormGroup.get('id').value;
const parentSections = sectionFormGroup.get('sections') as UntypedFormArray;
if (sectionId == tceId) {
sectionFormArray.removeAt(i);
return sectionFormArray;
// sectionFormArray.at(i).get('ordinal').patchValue(i);
} else if (parentSections && parentSections.length > 0){
} else if (parentSections && parentSections.length > 0) {
const currentSectionFormArray = this.getUpdatedSectionFormArray(parentSections, tceId);
if (currentSectionFormArray != null || currentSectionFormArray != undefined){
if (currentSectionFormArray != null || currentSectionFormArray != undefined) {
return currentSectionFormArray;
}
}
@ -904,7 +919,7 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
const parentSections = pages.at(j).get('sections') as UntypedFormArray;
const sectionFormArray = this.getUpdatedSectionFormArray(parentSections, tce.id);
if (sectionFormArray){
if (sectionFormArray) {
//update ordinal
for (let i = 0; i < sectionFormArray.length; i++) {
sectionFormArray.at(i).get('ordinal').patchValue(i);

View File

@ -103,10 +103,13 @@ export class DescriptionTemplateEditorResolver extends BaseEditorResolver {
];
const id = route.paramMap.get('id');
const cloneid = route.paramMap.get('cloneid');
const newversion = route.paramMap.get('newversionid');
if (id != null) {
return this.descriptionTemplateService.getSingle(Guid.parse(id), fieldSets).pipe(tap(x => this.breadcrumbService.addIdResolvedValue(x.id?.toString(), x.label)), takeUntil(this._destroyed));
} else if (cloneid != null) {
return this.descriptionTemplateService.clone(Guid.parse(cloneid), fieldSets).pipe(tap(x => this.breadcrumbService.addIdResolvedValue(x.id?.toString(), x.label)), takeUntil(this._destroyed));
} else if (newversion != null) {
return this.descriptionTemplateService.getSingle(Guid.parse(newversion), fieldSets).pipe(tap(x => this.breadcrumbService.addIdResolvedValue(x.id?.toString(), x.label)), takeUntil(this._destroyed));
}
}
}

View File

@ -8,6 +8,8 @@ export interface ToCEntry {
type: ToCEntryType;
form: AbstractControl;
numbering: string;
validationRootPath: string;
}

View File

@ -23,7 +23,7 @@
</div>
</div>
<app-hybrid-listing [rows]="gridRows" [columns]="gridColumns" [visibleColumns]="visibleColumns" [count]="totalElements" [offset]="currentPageNumber" [limit]="lookup.page.size" [defaultSort]="lookup.order?.items" [externalSorting]="true" (rowActivated)="onRowActivated($event)" (pageLoad)="alterPage($event)" (columnSort)="onColumnSort($event)" (columnsChanged)="onColumnsChanged($event)" [listItemTemplate]="listItemTemplate">
<app-hybrid-listing [rows]="gridRows" [columns]="gridColumns" [visibleColumns]="visibleColumns" [count]="totalElements" [offset]="currentPageNumber" [limit]="lookup.page.size" [defaultSort]="lookup.order?.items" [externalSorting]="true" (rowActivated)="onRowActivated($event, '/description-templates')" (pageLoad)="alterPage($event)" (columnSort)="onColumnSort($event)" (columnsChanged)="onColumnsChanged($event)" [listItemTemplate]="listItemTemplate">
<app-description-template-listing-filters hybrid-listing-filters [(filter)]="lookup" (filterChange)="filterChanged($event)" />
@ -95,23 +95,20 @@
<mat-icon>more_horiz</mat-icon>
</button>
<mat-menu #actionsMenu="matMenu">
<button mat-menu-item [routerLink]="['./' + row.id]">
<button mat-menu-item [routerLink]="['/description-templates/', row.id]">
<mat-icon>edit</mat-icon>{{'DESCRIPTION-TEMPLATE-LISTING.ACTIONS.EDIT' | translate}}
</button>
<button mat-menu-item [routerLink]="['./new-version/' + row.id]">
<button mat-menu-item [routerLink]="['/description-templates/new-version/', row.id]">
<mat-icon>queue</mat-icon>{{'DESCRIPTION-TEMPLATE-LISTING.ACTIONS.NEW-VERSION' | translate}}
</button>
<button mat-menu-item (click)="newVersionFromFile(row.id, row.label)">
<mat-icon>file_copy</mat-icon>{{'DESCRIPTION-TEMPLATE-LISTING.ACTIONS.NEW-VERSION-FROM-FILE' | translate}}
</button>
<button mat-menu-item [routerLink]="['./clone/' + row.id]">
<button mat-menu-item [routerLink]="['/description-templates/clone/', row.id]">
<mat-icon>content_copy</mat-icon>{{'DESCRIPTION-TEMPLATE-LISTING.ACTIONS.CLONE' | translate}}
</button>
<button mat-menu-item [routerLink]="['./versions/' + row.id]">
<button mat-menu-item [routerLink]="['/description-templates/versions/', row.groupId]">
<mat-icon>library_books</mat-icon>
{{'DESCRIPTION-TEMPLATE-LISTING.ACTIONS.VIEW-VERSIONS' | translate}}
</button>
<button mat-menu-item (click)="export(row.id)" [routerLink]="['./' + row.id]">
<button mat-menu-item (click)="export(row.id)" [routerLink]="['/description-templates/', row.id]">
<mat-icon>download</mat-icon>{{'DESCRIPTION-TEMPLATE-LISTING.ACTIONS.DOWNLOAD-XML' | translate}}
</button>
<button mat-menu-item (click)="delete(row.id)">

View File

@ -40,6 +40,7 @@ export class DescriptionTemplateListingComponent extends BaseListingComponent<De
userSettingsKey = { key: 'DescriptionTemplateListingUserSettings' };
propertiesAvailableForOrder: ColumnDefinition[];
descriptionTemplateStatuses = DescriptionTemplateStatus;
mode;
@ViewChild('descriptionTemplateStatus', { static: true }) descriptionTemplateStatus?: TemplateRef<any>;
@ViewChild('actions', { static: true }) actions?: TemplateRef<any>;
@ -50,6 +51,8 @@ export class DescriptionTemplateListingComponent extends BaseListingComponent<De
nameof<DescriptionTemplate>(x => x.label),
nameof<DescriptionTemplate>(x => x.description),
nameof<DescriptionTemplate>(x => x.status),
nameof<DescriptionTemplate>(x => x.version),
nameof<DescriptionTemplate>(x => x.groupId),
nameof<DescriptionTemplate>(x => x.updatedAt),
nameof<DescriptionTemplate>(x => x.createdAt),
nameof<DescriptionTemplate>(x => x.hash),
@ -76,6 +79,7 @@ export class DescriptionTemplateListingComponent extends BaseListingComponent<De
super(router, route, uiNotificationService, httpErrorHandlingService, queryParamsService);
// Lookup setup
// Default lookup values are defined in the user settings class.
this.mode = this.route.snapshot?.data['mode'];
this.lookup = this.initializeLookup();
}
@ -90,6 +94,7 @@ export class DescriptionTemplateListingComponent extends BaseListingComponent<De
lookup.page = { offset: 0, size: this.ITEMS_PER_PAGE };
lookup.isActive = [IsActive.Active];
lookup.order = { items: [this.toDescSortField(nameof<DescriptionTemplate>(x => x.createdAt))] };
if (this.mode && this.mode == 'versions-listing') lookup.groupIds = [Guid.parse(this.route.snapshot.paramMap.get('groupid'))]
this.updateOrderUiFields(lookup.order);
lookup.project = {
@ -116,6 +121,11 @@ export class DescriptionTemplateListingComponent extends BaseListingComponent<De
languageName: 'DESCRIPTION-TEMPLATE-LISTING.FIELDS.STATUS',
cellTemplate: this.descriptionTemplateStatus
},
{
prop: nameof<DescriptionTemplate>(x => x.version),
sortable: true,
languageName: 'DESCRIPTION-TEMPLATE-LISTING.FIELDS.VERSION'
},
{
prop: nameof<DescriptionTemplate>(x => x.createdAt),
sortable: true,

View File

@ -331,7 +331,7 @@ export class DescriptionPropertyDefinitionFieldSetItemEditorModel implements Des
const formGroup = this.formBuilder.group({});
formGroup.addControl('comment', new FormControl({ value: this.comment, disabled: disabled }, context.getValidation('comment').validators));
formGroup.addControl('ordinal', new FormControl({ value: 5, disabled: disabled }, context.getValidation('ordinal').validators));
formGroup.addControl('ordinal', new FormControl({ value: this.ordinal, disabled: disabled }, context.getValidation('ordinal').validators));
const fieldsFormGroup = this.formBuilder.group({});

View File

@ -1074,6 +1074,7 @@
"NAME": "Name",
"DESCRIPTION": "Description",
"STATUS": "Status",
"VERSION": "Version",
"UPDATED-AT": "Updated",
"CREATED-AT": "Created",
"PUBLISHED-AT": "Published",
@ -1097,7 +1098,6 @@
"CLONE": "Clone",
"DOWNLOAD-XML": "Download XML",
"NEW-VERSION": "New Version",
"NEW-VERSION-FROM-FILE": "New Version from File",
"VIEW-VERSIONS": "All Description Template Versions"
},
"IMPORT": {