diff --git a/apps/red-ui/src/app/modules/dossier/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.html b/apps/red-ui/src/app/modules/dossier/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.html index 46db18d59..00e585c58 100644 --- a/apps/red-ui/src/app/modules/dossier/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.html +++ b/apps/red-ui/src/app/modules/dossier/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.html @@ -1,5 +1,5 @@
-
+
@@ -54,7 +54,7 @@
- +
@@ -74,11 +74,11 @@
-
- +
diff --git a/apps/red-ui/src/app/modules/dossier/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.ts b/apps/red-ui/src/app/modules/dossier/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.ts index bb1727d50..ccb2c63ae 100644 --- a/apps/red-ui/src/app/modules/dossier/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.ts +++ b/apps/red-ui/src/app/modules/dossier/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.ts @@ -1,4 +1,4 @@ -import { Component, Inject, OnInit } from '@angular/core'; +import { Component, Inject, Injector, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { AppStateService } from '@state/app-state.service'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; @@ -9,6 +9,7 @@ import { PermissionsService } from '@services/permissions.service'; import { JustificationsService } from '@services/entity-services/justifications.service'; import { Dictionary, Dossier, File, IAddRedactionRequest } from '@red/domain'; import { DossiersService } from '@services/entity-services/dossiers.service'; +import { BaseDialogComponent } from '@iqser/common-ui'; import { DictionaryService } from '@shared/services/dictionary.service'; export interface LegalBasisOption { @@ -22,9 +23,7 @@ export interface LegalBasisOption { templateUrl: './manual-annotation-dialog.component.html', styleUrls: ['./manual-annotation-dialog.component.scss'], }) -export class ManualAnnotationDialogComponent implements OnInit { - redactionForm: FormGroup; - +export class ManualAnnotationDialogComponent extends BaseDialogComponent implements OnInit { isDocumentAdmin: boolean; isDictionaryRequest: boolean; isFalsePositiveRequest: boolean; @@ -43,15 +42,21 @@ export class ManualAnnotationDialogComponent implements OnInit { private readonly _dossiersService: DossiersService, private readonly _dictionaryService: DictionaryService, public dialogRef: MatDialogRef, + protected readonly _injector: Injector, + protected readonly _dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: { manualRedactionEntryWrapper: ManualRedactionEntryWrapper; file: File }, ) { + super(_injector, _dialogRef); this._dossier = this._dossiersService.find(this.data.file.dossierId); this.isDocumentAdmin = this._permissionsService.isApprover(this._dossier); this.isFalsePositiveRequest = this.data.manualRedactionEntryWrapper.type === 'FALSE_POSITIVE'; this.isDictionaryRequest = this.data.manualRedactionEntryWrapper.type === 'DICTIONARY' || this.isFalsePositiveRequest; - this.redactionForm = this._getForm(); + this.form = this._getForm(); + this.initialFormValue = this.form.getRawValue(); + + this.possibleDictionaries = this._possibleDictionaries; } get title() { @@ -59,7 +64,7 @@ export class ManualAnnotationDialogComponent implements OnInit { } get displayedDictionaryLabel() { - const dictType = this.redactionForm.get('dictionary').value; + const dictType = this.form.get('dictionary').value; if (dictType) { return this.possibleDictionaries.find(d => d.type === dictType).label; } @@ -92,6 +97,7 @@ export class ManualAnnotationDialogComponent implements OnInit { } async ngOnInit() { + super.ngOnInit(); this.possibleDictionaries = await this._getPossibleDictionaries(); const data = await this._justificationsService.getForDossierTemplate(this._dossier.dossierTemplateId).toPromise(); @@ -104,11 +110,11 @@ export class ManualAnnotationDialogComponent implements OnInit { this.legalOptions.sort((a, b) => a.label.localeCompare(b.label)); } - handleAddRedaction() { + save() { this._enhanceManualRedaction(this.data.manualRedactionEntryWrapper.manualRedactionEntry); this._manualAnnotationService.addAnnotation(this.data.manualRedactionEntryWrapper.manualRedactionEntry, this.data.file).subscribe( - response => this.dialogRef.close(new ManualAnnotationResponse(this.data.manualRedactionEntryWrapper, response)), - () => this.dialogRef.close(), + response => this._dialogRef.close(new ManualAnnotationResponse(this.data.manualRedactionEntryWrapper, response)), + () => this._dialogRef.close(), ); } @@ -133,8 +139,8 @@ export class ManualAnnotationDialogComponent implements OnInit { } private _enhanceManualRedaction(addRedactionRequest: IAddRedactionRequest) { - const legalOption: LegalBasisOption = this.redactionForm.get('reason').value; - addRedactionRequest.type = this.redactionForm.get('dictionary').value; + const legalOption: LegalBasisOption = this.form.get('reason').value; + addRedactionRequest.type = this.form.get('dictionary').value; if (legalOption) { addRedactionRequest.reason = legalOption.description; addRedactionRequest.legalBasis = legalOption.legalBasis; @@ -146,11 +152,13 @@ export class ManualAnnotationDialogComponent implements OnInit { if (!addRedactionRequest.reason) { addRedactionRequest.reason = 'Dictionary Request'; } - const commentValue = this.redactionForm.get('comment').value; + const commentValue = this.form.get('comment').value; addRedactionRequest.comment = commentValue ? { text: commentValue } : null; - addRedactionRequest.section = this.redactionForm.get('section').value; - addRedactionRequest.value = addRedactionRequest.rectangle - ? this.redactionForm.get('classification').value - : addRedactionRequest.value; + addRedactionRequest.section = this.form.get('section').value; + addRedactionRequest.value = addRedactionRequest.rectangle ? this.form.get('classification').value : addRedactionRequest.value; + } + + get disabled() { + return this.form.invalid; } }