fixed change detection bug on description-editor with prefill

This commit is contained in:
Sofia Papacharalampous 2024-06-03 15:51:48 +03:00
parent 1ae6d6a20a
commit 6659efd1e1
1 changed files with 11 additions and 11 deletions

View File

@ -1,5 +1,5 @@
import { DatePipe } from '@angular/common';
import { Component, OnInit, ViewChild } from '@angular/core';
import { ChangeDetectorRef, Component, OnInit, ViewChild } from '@angular/core';
import { AbstractControl, UntypedFormArray, UntypedFormGroup } from '@angular/forms';
import { MatDialog } from '@angular/material/dialog';
import { Title } from '@angular/platform-browser';
@ -18,18 +18,18 @@ import { AuthService } from '@app/core/services/auth/auth.service';
import { ConfigurationService } from '@app/core/services/configuration/configuration.service';
import { DescriptionTemplateService } from '@app/core/services/description-template/description-template.service';
import { DescriptionService } from '@app/core/services/description/description.service';
import { DmpService } from '@app/core/services/dmp/dmp.service';
import { FileTransformerService } from '@app/core/services/file-transformer/file-transformer.service';
import { LockService } from '@app/core/services/lock/lock.service';
import { LoggingService } from '@app/core/services/logging/logging-service';
import { AnalyticsService } from '@app/core/services/matomo/analytics-service';
import {
SnackBarNotificationLevel,
UiNotificationService
} from '@app/core/services/notification/ui-notification-service';
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
import { FileUtils } from '@app/core/services/utilities/file-utils.service';
import { QueryParamsService } from '@app/core/services/utilities/query-params.service';
import { VisibilityRulesService } from '@app/ui/description/editor/description-form/visibility-rules/visibility-rules.service';
import { BreadcrumbService } from '@app/ui/misc/breadcrumb/breadcrumb.service';
import { BaseEditor } from '@common/base/base-editor';
import { FormService } from '@common/forms/form-service';
import { FormValidationErrorsDialogComponent } from '@common/forms/form-validation-errors-dialog/form-validation-errors-dialog.component';
@ -48,8 +48,6 @@ import { ToCEntry } from './table-of-contents/models/toc-entry';
import { ToCEntryType } from './table-of-contents/models/toc-entry-type.enum';
import { TableOfContentsValidationService } from './table-of-contents/services/table-of-contents-validation-service';
import { TableOfContentsComponent } from './table-of-contents/table-of-contents.component';
import { AnalyticsService } from '@app/core/services/matomo/analytics-service';
import { BreadcrumbService } from '@app/ui/misc/breadcrumb/breadcrumb.service';
@Component({
selector: 'app-description-editor-component',
@ -98,14 +96,13 @@ export class DescriptionEditorComponent extends BaseEditor<DescriptionEditorMode
private logger: LoggingService,
private descriptionEditorService: DescriptionEditorService,
private descriptionTemplateService: DescriptionTemplateService,
private fileUtils: FileUtils,
private dmpService: DmpService,
public visibilityRulesService: VisibilityRulesService,
public fileTransformerService: FileTransformerService,
public tocValidationService: TableOfContentsValidationService,
public titleService: Title,
private analyticsService: AnalyticsService,
private breadcrumbService: BreadcrumbService
private breadcrumbService: BreadcrumbService,
private changeDetectorRef: ChangeDetectorRef
) {
const descriptionLabel: string = route.snapshot.data['entity']?.label;
if (descriptionLabel) {
@ -141,7 +138,8 @@ export class DescriptionEditorComponent extends BaseEditor<DescriptionEditorMode
if (itemId != null && newDmpId == null) {
this.checkLock(this.item.id, LockTargetType.Description, 'DESCRIPTION-EDITOR.LOCKED-DIALOG.TITLE', 'DESCRIPTION-EDITOR.LOCKED-DIALOG.MESSAGE');
} else if (dmpId != null && dmpSectionId != null) {
}
else if (dmpId != null && dmpSectionId != null) {
this.isNew = true;
const dialogRef = this.dialog.open(PrefillDescriptionDialogComponent, {
width: '590px',
@ -155,14 +153,16 @@ export class DescriptionEditorComponent extends BaseEditor<DescriptionEditorMode
});
dialogRef.afterClosed().subscribe((result: Description) => {
if (result) {
this.breadcrumbService.addIdResolvedValue(`${result.dmp.id}/${result.id}`, "this is new");
this.titleService.setTitle(result.label);
result.dmp = this.item.dmp;
result.dmpDescriptionTemplate = this.item.dmpDescriptionTemplate;
const sectionId = this.item.dmpDescriptionTemplate.sectionId;
result.dmpDescriptionTemplate = this.item.dmp.dmpDescriptionTemplates.find(x => x.sectionId == sectionId && x.descriptionTemplateGroupId == result.descriptionTemplate.groupId);
this.prepareForm(result);
this.changeDetectorRef.markForCheck();
}
})
}