make blueprint description template exclude by section

This commit is contained in:
amentis 2024-07-10 16:27:43 +03:00
parent 904037e2c4
commit 6744f94e9b
3 changed files with 62 additions and 38 deletions

View File

@ -3,16 +3,6 @@
<div class="col-md-10 offset-md-1"> <div class="col-md-10 offset-md-1">
<div class="row align-items-center mt-4 mb-4" *ngIf="formGroup"> <div class="row align-items-center mt-4 mb-4" *ngIf="formGroup">
<div class="col-md col-12"> <div class="col-md col-12">
<!-- <h3 *ngIf="!isFinalized && !isNewVersion && isNew">{{'PLAN-BLUEPRINT-EDITOR.TITLE.NEW' | translate}}</h3>
<h3 *ngIf="!isClone && !isNewVersion && !isNew">{{formGroup.get('label').value}}</h3>
<h3 *ngIf="isClone">
<span>{{'PLAN-BLUEPRINT-EDITOR.TITLE.CLONE' | translate}}</span>
{{formGroup.get('label').value}}
</h3>
<h3 *ngIf="isNewVersion">
<span>{{'PLAN-BLUEPRINT-EDITOR.TITLE.NEW-VERSION' | translate}}</span>
{{formGroup.get('label').value}}
</h3> -->
<app-navigation-breadcrumb /> <app-navigation-breadcrumb />
</div> </div>
<div class="col-md-auto mb-md-0 col-12 mb-2" *ngIf="!isNew && !isClone && !isNewVersion && this.editorModel.belongsToCurrentTenant != false"> <div class="col-md-auto mb-md-0 col-12 mb-2" *ngIf="!isNew && !isClone && !isNewVersion && this.editorModel.belongsToCurrentTenant != false">
@ -252,7 +242,7 @@
<div class="col-12 col-lg-6"> <div class="col-12 col-lg-6">
<mat-form-field class="w-100 mt-3"> <mat-form-field class="w-100 mt-3">
<mat-label>{{'PLAN-BLUEPRINT-EDITOR.FIELDS.DESCRIPTION-TEMPLATE' | translate}}</mat-label> <mat-label>{{'PLAN-BLUEPRINT-EDITOR.FIELDS.DESCRIPTION-TEMPLATE' | translate}}</mat-label>
<app-single-auto-complete [formControl]="descriptionTemplate.get('descriptionTemplateGroupId')" [configuration]="descriptionTempalteGroupSingleAutocompleteConfiguration" (optionActionClicked)="onPreviewDescriptionTemplate($event, sectionIndex, descriptionTemplateIndex)"></app-single-auto-complete> <app-single-auto-complete [formControl]="descriptionTemplate.get('descriptionTemplateGroupId')" [configuration]="descriptionTemplateGroupIdsConfigBySection.get(section.get('id').value)" (optionActionClicked)="onPreviewDescriptionTemplate($event, sectionIndex, descriptionTemplateIndex)" (optionSelected)="selectedDescriptionTemplate($event, section.get('id').value)"></app-single-auto-complete>
<mat-error *ngIf="descriptionTemplate.get('descriptionTemplateGroupId').hasError('backendError')">{{descriptionTemplate.get('descriptionTemplateGroupId').getError('backendError').message}}</mat-error> <mat-error *ngIf="descriptionTemplate.get('descriptionTemplateGroupId').hasError('backendError')">{{descriptionTemplate.get('descriptionTemplateGroupId').getError('backendError').message}}</mat-error>
<mat-error *ngIf="descriptionTemplate.get('descriptionTemplateGroupId').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error> <mat-error *ngIf="descriptionTemplate.get('descriptionTemplateGroupId').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field> </mat-form-field>

View File

@ -71,16 +71,8 @@ export class PlanBlueprintEditorComponent extends BaseEditor<PlanBlueprintEditor
planBlueprintExtraFieldDataType = PlanBlueprintExtraFieldDataType; planBlueprintExtraFieldDataType = PlanBlueprintExtraFieldDataType;
public planBlueprintExtraFieldDataTypeEnum = this.enumUtils.getEnumValues<PlanBlueprintExtraFieldDataType>(PlanBlueprintExtraFieldDataType); public planBlueprintExtraFieldDataTypeEnum = this.enumUtils.getEnumValues<PlanBlueprintExtraFieldDataType>(PlanBlueprintExtraFieldDataType);
public planBlueprintFieldCategoryEnum = this.enumUtils.getEnumValues<PlanBlueprintFieldCategory>(PlanBlueprintFieldCategory); public planBlueprintFieldCategoryEnum = this.enumUtils.getEnumValues<PlanBlueprintFieldCategory>(PlanBlueprintFieldCategory);
descriptionTempalteGroupSingleAutocompleteConfiguration: SingleAutoCompleteConfiguration = { public usedDescriptionTemplateGroupIdsBySection: Map<Guid, Guid[]> = new Map<Guid, Guid[]>;
initialItems: (data?: any) => this.descriptionTemplateService.query(this.descriptionTemplateService.buildDescriptionTempalteGroupAutocompleteLookup([IsActive.Active], null, null, null, this.getUsedDescriptionTemplateGroupIds())).pipe(map(x => x.items)), public descriptionTemplateGroupIdsConfigBySection: Map<Guid, SingleAutoCompleteConfiguration> = new Map<Guid, SingleAutoCompleteConfiguration>;
filterFn: (searchQuery: string, data?: any) => this.descriptionTemplateService.query(this.descriptionTemplateService.buildDescriptionTempalteGroupAutocompleteLookup([IsActive.Active], searchQuery, null, null, this.getUsedDescriptionTemplateGroupIds() ? this.getUsedDescriptionTemplateGroupIds() : null)).pipe(map(x => x.items)),
getSelectedItem: (selectedItem: any) => this.descriptionTemplateService.query(this.descriptionTemplateService.buildDescriptionTempalteGroupAutocompleteLookup([IsActive.Active, IsActive.Inactive], null, null, [selectedItem])).pipe(map(x => x.items[0])),
displayFn: (item: DescriptionTemplate) => item.label,
titleFn: (item: DescriptionTemplate) => item.label,
subtitleFn: (item: DescriptionTemplate) => item.description,
valueAssign: (item: DescriptionTemplate) => item.groupId,
popupItemActionIcon: 'visibility'
}
protected get canDelete(): boolean { protected get canDelete(): boolean {
return !this.isDeleted && !this.isNew && this.hasPermission(this.authService.permissionEnum.DeletePlanBlueprint); return !this.isDeleted && !this.isNew && this.hasPermission(this.authService.permissionEnum.DeletePlanBlueprint);
@ -188,6 +180,12 @@ export class PlanBlueprintEditorComponent extends BaseEditor<PlanBlueprintEditor
this.buildForm(); this.buildForm();
if (data && data.id) this.checkLock(data.id, LockTargetType.PlanBlueprint, 'PLAN-BLUEPRINT-EDITOR.LOCKED-DIALOG.TITLE', 'PLAN-BLUEPRINT-EDITOR.LOCKED-DIALOG.MESSAGE'); if (data && data.id) this.checkLock(data.id, LockTargetType.PlanBlueprint, 'PLAN-BLUEPRINT-EDITOR.LOCKED-DIALOG.TITLE', 'PLAN-BLUEPRINT-EDITOR.LOCKED-DIALOG.MESSAGE');
if (data && data.definition?.sections) {
const sectionWithDescriptionTemplates = data.definition.sections.filter(x => x.hasTemplates == true && x.descriptionTemplates != null && x.descriptionTemplates.length > 0) || [];
if (sectionWithDescriptionTemplates.length > 0) {
sectionWithDescriptionTemplates.forEach(section => this.descriptionTemplateGroupIdsConfigBySection.set(section.id, this.getdescriptionTemplateGroupSingleAutocompleteConfiguration(section.id)));
}
}
} catch (error) { } catch (error) {
this.logger.error('Could not parse planBlueprint item: ' + data + error); this.logger.error('Could not parse planBlueprint item: ' + data + error);
@ -424,26 +422,72 @@ export class PlanBlueprintEditorComponent extends BaseEditor<PlanBlueprintEditor
} }
} }
selectedDescriptionTemplate(descriptionTemplate: DescriptionTemplate, sectionId: Guid){
let excludedGroupIds: Guid[] = [];
if (this.usedDescriptionTemplateGroupIdsBySection.get(sectionId)){
excludedGroupIds = this.usedDescriptionTemplateGroupIdsBySection.get(sectionId);
}
if (!excludedGroupIds.includes(descriptionTemplate.groupId)) excludedGroupIds.push(descriptionTemplate.groupId);
this.usedDescriptionTemplateGroupIdsBySection.set(sectionId, excludedGroupIds);
}
addDescriptionTemplate(sectionIndex: number): void { addDescriptionTemplate(sectionIndex: number): void {
const descriptionTempaltesArray = (this.formGroup.get('definition').get('sections') as FormArray).at(sectionIndex).get('descriptionTemplates') as FormArray; const descriptionTempaltesArray = (this.formGroup.get('definition').get('sections') as FormArray).at(sectionIndex).get('descriptionTemplates') as FormArray;
descriptionTempaltesArray.push(this.editorModel.createChildDescriptionTemplate(sectionIndex, ((this.formGroup.get('definition').get('sections') as FormArray).at(sectionIndex).get('descriptionTemplates') as FormArray).length)); descriptionTempaltesArray.push(this.editorModel.createChildDescriptionTemplate(sectionIndex, ((this.formGroup.get('definition').get('sections') as FormArray).at(sectionIndex).get('descriptionTemplates') as FormArray).length));
const sectionId = (this.formGroup.get('definition').get('sections') as FormArray).at(sectionIndex).get('id').value;
if (!this.descriptionTemplateGroupIdsConfigBySection.has(sectionId)) this.descriptionTemplateGroupIdsConfigBySection.set(sectionId, this.getdescriptionTemplateGroupSingleAutocompleteConfiguration(sectionId));
} }
getUsedDescriptionTemplateGroupIds(): Guid[] { public getdescriptionTemplateGroupSingleAutocompleteConfiguration(sectionId: Guid): SingleAutoCompleteConfiguration {
return {
initialItems: (data?: any) => this.descriptionTemplateService.query(this.descriptionTemplateService.buildDescriptionTempalteGroupAutocompleteLookup([IsActive.Active], null, null, null, this.getUsedDescriptionTemplateGroupIds(sectionId))).pipe(map(x => x.items)),
filterFn: (searchQuery: string, data?: any) => this.descriptionTemplateService.query(this.descriptionTemplateService.buildDescriptionTempalteGroupAutocompleteLookup([IsActive.Active], searchQuery, null, null, this.getUsedDescriptionTemplateGroupIds(sectionId) ? this.getUsedDescriptionTemplateGroupIds(sectionId) : null)).pipe(map(x => x.items)),
getSelectedItem: (selectedItem: any) => this.descriptionTemplateService.query(this.descriptionTemplateService.buildDescriptionTempalteGroupAutocompleteLookup([IsActive.Active, IsActive.Inactive], null, null, [selectedItem])).pipe(map(x => x.items[0])),
displayFn: (item: DescriptionTemplate) => item.label,
titleFn: (item: DescriptionTemplate) => item.label,
subtitleFn: (item: DescriptionTemplate) => item.description,
valueAssign: (item: DescriptionTemplate) => item.groupId,
popupItemActionIcon: 'visibility'
};
}
getUsedDescriptionTemplateGroupIds(sectionId: Guid): Guid[] {
let excludedGroupIds: Guid[] = []; let excludedGroupIds: Guid[] = [];
(this.formGroup.get('definition').get('sections') as FormArray).controls.forEach((section, index) => { (this.formGroup.get('definition').get('sections') as FormArray).controls.forEach((section, index) => {
const descriptionTempaltesArray = (this.formGroup.get('definition').get('sections') as FormArray).at(index).get('descriptionTemplates') as FormArray; if (section.get('id').value === sectionId){
if (descriptionTempaltesArray.length > 1) { if (this.usedDescriptionTemplateGroupIdsBySection.get(sectionId)){
descriptionTempaltesArray.controls.forEach((template, index) => { excludedGroupIds = this.usedDescriptionTemplateGroupIdsBySection.get(sectionId);
if (template.get('descriptionTemplateGroupId').value != undefined) excludedGroupIds.push(template.get('descriptionTemplateGroupId').value as Guid); } else {
}) this.usedDescriptionTemplateGroupIdsBySection.set(sectionId, excludedGroupIds);
}
const descriptionTempaltesArray = (this.formGroup.get('definition').get('sections') as FormArray).at(index).get('descriptionTemplates') as FormArray;
if (descriptionTempaltesArray.length > 1) {
descriptionTempaltesArray.controls.forEach((template, index) => {
if (template.get('descriptionTemplateGroupId').value != undefined && !excludedGroupIds.includes(template.get('descriptionTemplateGroupId').value)) excludedGroupIds.push(template.get('descriptionTemplateGroupId').value as Guid);
})
this.usedDescriptionTemplateGroupIdsBySection.set(sectionId, excludedGroupIds);
}
} }
}); });
return excludedGroupIds; return excludedGroupIds;
} }
removeDescriptionTemplate(sectionIndex: number, descriptionTemplateIndex: number): void { removeDescriptionTemplate(sectionIndex: number, descriptionTemplateIndex: number): void {
const sectionId = (this.formGroup.get('definition').get('sections') as FormArray).at(sectionIndex).get('id').value;
let groupIds = this.usedDescriptionTemplateGroupIdsBySection.get(sectionId);
if (groupIds){
const descriptionTemplateGroupId = ((this.formGroup.get('definition').get('sections') as FormArray).at(sectionIndex).get('descriptionTemplates') as FormArray).at(descriptionTemplateIndex).get('descriptionTemplateGroupId').value || null;
if (groupIds.includes(descriptionTemplateGroupId)){
const index = groupIds.indexOf(descriptionTemplateGroupId, 0);
if (index > -1) {
groupIds.splice(index, 1);
this.usedDescriptionTemplateGroupIdsBySection.set(sectionId, groupIds);
}
}
}
const descriptionTempaltesArray = (this.formGroup.get('definition').get('sections') as FormArray).at(sectionIndex).get('descriptionTemplates') as FormArray; const descriptionTempaltesArray = (this.formGroup.get('definition').get('sections') as FormArray).at(sectionIndex).get('descriptionTemplates') as FormArray;
descriptionTempaltesArray.removeAt(descriptionTemplateIndex); descriptionTempaltesArray.removeAt(descriptionTemplateIndex);

View File

@ -1,6 +1,6 @@
import { HttpErrorResponse } from '@angular/common/http'; import { HttpErrorResponse } from '@angular/common/http';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { ResponseErrorCode, ResponseErrorCodeHelper } from '@app/core/common/enum/respone-error-code'; import { ResponseErrorCodeHelper } from '@app/core/common/enum/respone-error-code';
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service'; import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
@ -49,16 +49,6 @@ export class HttpErrorHandlingService {
try { try {
error.errorCode = + errorResponse.error.code; error.errorCode = + errorResponse.error.code;
} catch { } } catch { }
// if (error && error.error && error.error.error) {
// errorMsg = error.error.error;
// // } else if (error && error.message) {
// // errorMsg = error.message;
// // } else if (error) {
// // errorMsg = error;
// } else {
// errorMsg = language.instant('COMMONS.ERRORS.DEFAULT');
// }
return error; return error;
} }