RED-7523 add value/classification to rectangles

This commit is contained in:
Dan Percic 2023-09-05 09:30:24 +03:00
parent 4aae9569af
commit 217a08f98d
3 changed files with 44 additions and 49 deletions

View File

@ -1,38 +1,38 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms'; import { FormBuilder, Validators } from '@angular/forms';
import { ISmtpConfiguration } from '@red/domain'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { BaseFormComponent, IconButtonTypes, IqserPermissionsService, LoadingService, Toaster } from '@iqser/common-ui'; import { BaseFormComponent, IconButtonTypes, IqserPermissionsService, LoadingService, Toaster } from '@iqser/common-ui';
import { ISmtpConfiguration } from '@red/domain';
import { Roles } from '@users/roles';
import { firstValueFrom } from 'rxjs';
import { AdminDialogService } from '../../../services/admin-dialog.service'; import { AdminDialogService } from '../../../services/admin-dialog.service';
import { SmtpConfigService } from '../../../services/smtp-config.service'; import { SmtpConfigService } from '../../../services/smtp-config.service';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { firstValueFrom } from 'rxjs';
import { Roles } from '@users/roles';
@Component({ @Component({
selector: 'redaction-smtp-form', selector: 'redaction-smtp-form',
templateUrl: './smtp-form.component.html', templateUrl: './smtp-form.component.html',
}) })
export class SmtpFormComponent extends BaseFormComponent implements OnInit { export class SmtpFormComponent extends BaseFormComponent implements OnInit {
#initialConfiguration: ISmtpConfiguration;
readonly iconButtonTypes = IconButtonTypes; readonly iconButtonTypes = IconButtonTypes;
private _initialConfiguration: ISmtpConfiguration;
constructor( constructor(
private readonly _formBuilder: UntypedFormBuilder, private readonly _formBuilder: FormBuilder,
private readonly _dialogService: AdminDialogService, private readonly _dialogService: AdminDialogService,
private readonly _smtpConfigService: SmtpConfigService, private readonly _smtpConfigService: SmtpConfigService,
private readonly _loadingService: LoadingService, private readonly _loadingService: LoadingService,
private readonly _toaster: Toaster, private readonly _toaster: Toaster,
private readonly _permissionsService: IqserPermissionsService, permissionsService: IqserPermissionsService,
) { ) {
super(); super();
this.form = this._getForm(); this.form = this.#getForm();
if (!_permissionsService.has(Roles.smtp.write)) { if (!permissionsService.has(Roles.smtp.write)) {
this.form.disable(); this.form.disable();
} }
} }
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
await this._loadData(); await this.#loadData();
} }
onToggleAuthentication(checked: boolean): void { onToggleAuthentication(checked: boolean): void {
@ -54,9 +54,9 @@ export class SmtpFormComponent extends BaseFormComponent implements OnInit {
async save() { async save() {
this._loadingService.start(); this._loadingService.start();
await firstValueFrom(this._smtpConfigService.updateSMTPConfiguration(this.form.getRawValue())); await firstValueFrom(this._smtpConfigService.updateSMTPConfiguration(this.form.getRawValue()));
this._initialConfiguration = this.form.getRawValue(); this.#initialConfiguration = this.form.getRawValue();
this._loadingService.stop(); this._loadingService.stop();
await this._loadData(); await this.#loadData();
} }
async testConnection() { async testConnection() {
@ -71,7 +71,7 @@ export class SmtpFormComponent extends BaseFormComponent implements OnInit {
} }
} }
private _getForm(): UntypedFormGroup { #getForm() {
return this._formBuilder.group({ return this._formBuilder.group({
host: [undefined, Validators.required], host: [undefined, Validators.required],
port: [25], port: [25],
@ -88,12 +88,12 @@ export class SmtpFormComponent extends BaseFormComponent implements OnInit {
}); });
} }
private async _loadData() { async #loadData() {
this._loadingService.start(); this._loadingService.start();
try { try {
this._initialConfiguration = await firstValueFrom(this._smtpConfigService.getCurrentSMTPConfiguration()); this.#initialConfiguration = await firstValueFrom(this._smtpConfigService.getCurrentSMTPConfiguration());
this.form.patchValue(this._initialConfiguration, { emitEvent: false }); this.form.patchValue(this.#initialConfiguration, { emitEvent: false });
} catch (e) {} } catch (e) {}
this.initialFormValue = this.form.getRawValue(); this.initialFormValue = this.form.getRawValue();

View File

@ -7,7 +7,7 @@
></div> ></div>
<div class="dialog-content redaction"> <div class="dialog-content redaction">
<div *ngIf="redactedText" class="iqser-input-group w-450"> <div *ngIf="!allRectangles && redactedText" class="iqser-input-group w-450">
<label [translate]="'edit-redaction.dialog.content.redacted-text'" class="selected-text"></label> <label [translate]="'edit-redaction.dialog.content.redacted-text'" class="selected-text"></label>
{{ redactedText }} {{ redactedText }}
</div> </div>
@ -50,7 +50,7 @@
<div class="iqser-input-group w-450"> <div class="iqser-input-group w-450">
<label [translate]="'edit-redaction.dialog.content.legal-basis'"></label> <label [translate]="'edit-redaction.dialog.content.legal-basis'"></label>
<input [value]="form.get('reason').value?.legalBasis" disabled type="text" /> <input [value]="form.controls.reason.value?.legalBasis" disabled type="text" />
</div> </div>
<div class="iqser-input-group w-450"> <div class="iqser-input-group w-450">
@ -59,6 +59,11 @@
</div> </div>
</ng-container> </ng-container>
<div *ngIf="allRectangles" class="iqser-input-group w-400">
<label [translate]="'change-legal-basis-dialog.content.classification'"></label>
<input formControlName="value" name="classification" type="text" />
</div>
<div class="iqser-input-group w-450"> <div class="iqser-input-group w-450">
<label [translate]="'edit-redaction.dialog.content.comment'"></label> <label [translate]="'edit-redaction.dialog.content.comment'"></label>
<textarea <textarea
@ -78,12 +83,11 @@
[label]="'edit-redaction.dialog.actions.save' | translate" [label]="'edit-redaction.dialog.actions.save' | translate"
[submit]="true" [submit]="true"
[type]="iconButtonTypes.primary" [type]="iconButtonTypes.primary"
> />
</iqser-icon-button>
<div [translate]="'edit-redaction.dialog.actions.cancel'" class="all-caps-label cancel" mat-dialog-close></div> <div [translate]="'edit-redaction.dialog.actions.cancel'" class="all-caps-label cancel" mat-dialog-close></div>
</div> </div>
</form> </form>
<iqser-circle-button (action)="close()" class="dialog-close" icon="iqser:close"></iqser-circle-button> <iqser-circle-button (action)="close()" class="dialog-close" icon="iqser:close" />
</section> </section>

View File

@ -1,11 +1,10 @@
import { Component, inject, OnInit } from '@angular/core'; import { Component, inject, OnInit } from '@angular/core';
import { FormBuilder } from '@angular/forms'; import { FormControl, FormGroup } from '@angular/forms';
import { DetailsRadioOption, IconButtonTypes, IqserDialogComponent } from '@iqser/common-ui'; import { DetailsRadioOption, IconButtonTypes, IqserDialogComponent } from '@iqser/common-ui';
import { Dictionary, SuperTypes } from '@red/domain'; import { Dictionary, SuperTypes } from '@red/domain';
import { ActiveDossiersService } from '@services/dossiers/active-dossiers.service'; import { ActiveDossiersService } from '@services/dossiers/active-dossiers.service';
import { DictionaryService } from '@services/entity-services/dictionary.service'; import { DictionaryService } from '@services/entity-services/dictionary.service';
import { JustificationsService } from '@services/entity-services/justifications.service'; import { JustificationsService } from '@services/entity-services/justifications.service';
import { Roles } from '@users/roles';
import { firstValueFrom } from 'rxjs'; import { firstValueFrom } from 'rxjs';
import { IMAGE_CATEGORIES } from '../../utils/constants'; import { IMAGE_CATEGORIES } from '../../utils/constants';
import { getEditRedactionOptions, RedactOrHintOption } from '../../utils/dialog-options'; import { getEditRedactionOptions, RedactOrHintOption } from '../../utils/dialog-options';
@ -21,7 +20,6 @@ export class EditRedactionDialogComponent
{ {
readonly #dossier = inject(ActiveDossiersService).find(this.data.dossierId); readonly #dossier = inject(ActiveDossiersService).find(this.data.dossierId);
readonly #applyToAllDossiers = this.data.applyToAllDossiers; readonly #applyToAllDossiers = this.data.applyToAllDossiers;
readonly roles = Roles;
readonly iconButtonTypes = IconButtonTypes; readonly iconButtonTypes = IconButtonTypes;
readonly redactedText: string; readonly redactedText: string;
readonly isModifyDictionary: boolean; readonly isModifyDictionary: boolean;
@ -29,16 +27,23 @@ export class EditRedactionDialogComponent
readonly isManualRedaction: boolean; readonly isManualRedaction: boolean;
readonly showLegalReason: boolean; readonly showLegalReason: boolean;
readonly isHint: boolean; readonly isHint: boolean;
readonly allRectangles = this.data.annotations.reduce((acc, a) => acc && a.rectangle, true);
readonly showExtras: boolean; readonly showExtras: boolean;
options: DetailsRadioOption<RedactOrHintOption>[] | undefined; options: DetailsRadioOption<RedactOrHintOption>[] | undefined;
legalOptions: LegalBasisOption[] = []; legalOptions: LegalBasisOption[] = [];
dictionaries: Dictionary[] = []; dictionaries: Dictionary[] = [];
readonly form; readonly form = new FormGroup({
reason: new FormControl<LegalBasisOption>(null),
comment: new FormControl<string>(null),
type: new FormControl<string>(this.data.annotations[0].type),
section: new FormControl<string>(this.data.annotations[0].section),
option: new FormControl<LegalBasisOption>(null),
value: new FormControl<string>(this.allRectangles ? this.data.annotations[0].value : null),
});
constructor( constructor(
private readonly _justificationsService: JustificationsService, private readonly _justificationsService: JustificationsService,
private readonly _dictionaryService: DictionaryService, private readonly _dictionaryService: DictionaryService,
private readonly _formBuilder: FormBuilder,
) { ) {
super(); super();
const annotations = this.data.annotations; const annotations = this.data.annotations;
@ -49,11 +54,10 @@ export class EditRedactionDialogComponent
this.isManualRedaction = firstEntry.type === SuperTypes.ManualRedaction; this.isManualRedaction = firstEntry.type === SuperTypes.ManualRedaction;
this.isHint = firstEntry.isHint; this.isHint = firstEntry.isHint;
this.showExtras = !(this.isImage || this.isHint); this.showExtras = !(this.isImage || this.isHint);
this.form = this.#getForm();
} }
get displayedDictionaryLabel() { get displayedDictionaryLabel() {
const selectedDictionaryType = this.form.get('type').value; const selectedDictionaryType = this.form.controls.type.value;
if (selectedDictionaryType) { if (selectedDictionaryType) {
return this.dictionaries.find(d => d.type === selectedDictionaryType)?.label ?? null; return this.dictionaries.find(d => d.type === selectedDictionaryType)?.label ?? null;
} }
@ -61,10 +65,10 @@ export class EditRedactionDialogComponent
} }
get disabled() { get disabled() {
return !this.form.get('reason').value; return !this.form.controls.reason.value;
} }
async ngOnInit(): Promise<void> { async ngOnInit() {
this.#setTypes(); this.#setTypes();
const data = await firstValueFrom(this._justificationsService.loadAll(this.#dossier.dossierTemplateId)); const data = await firstValueFrom(this._justificationsService.loadAll(this.#dossier.dossierTemplateId));
this.legalOptions = data.map(lbm => ({ this.legalOptions = data.map(lbm => ({
@ -73,26 +77,27 @@ export class EditRedactionDialogComponent
label: lbm.name, label: lbm.name,
})); }));
const reason = this.legalOptions.find(o => o.legalBasis === this.data.annotations[0].legalBasis);
this.form.patchValue({ this.form.patchValue({
reason: this.legalOptions.find(o => o.legalBasis === this.data.annotations[0].legalBasis), reason: reason,
}); });
this.legalOptions.sort((a, b) => a.label.localeCompare(b.label)); this.legalOptions.sort((a, b) => a.label.localeCompare(b.label));
} }
typeChanged() { typeChanged() {
const selectedDictionaryType = this.form.get('type').value; const selectedDictionaryType = this.form.controls.type.value;
this.#setOptions(selectedDictionaryType); this.#setOptions(selectedDictionaryType);
} }
save(): void { save() {
const value = this.form.value; const value = this.form.value;
this.close({ this.close({
legalBasis: value.reason?.legalBasis ?? '', legalBasis: value.reason?.legalBasis ?? '',
section: value.section, section: value.section,
comment: value.comment, comment: value.comment,
type: value.type, type: value.type,
value: this.#allRectangles() ? this.data.annotations[0].value : null, value: this.allRectangles ? value.value : null,
}); });
} }
@ -120,18 +125,4 @@ export class EditRedactionDialogComponent
{ emitEvent: false }, { emitEvent: false },
); );
} }
#getForm() {
return this._formBuilder.group({
reason: [null],
comment: [null],
type: [this.data.annotations[0].type],
section: [this.data.annotations[0].section],
option: [null, { disabled: true }],
});
}
#allRectangles() {
return this.data.annotations.reduce((acc, a) => acc && a.rectangle, true);
}
} }