RED-7346: bulk-local edit redactions

This commit is contained in:
Adina Țeudan 2024-09-26 14:31:11 +03:00
parent 5bb7c780a1
commit 6bbe992940
15 changed files with 140 additions and 156 deletions

View File

@ -6,8 +6,8 @@
class="dialog-header heading-l"
></div>
<div class="dialog-content redaction" [class.fixed-height]="isRedacted && isImage">
<div class="iqser-input-group" *ngIf="!isImage && redactedTexts.length && !allRectangles">
<div [class.fixed-height]="isRedacted && isImage" class="dialog-content redaction">
<div *ngIf="!isImage && redactedTexts.length && !allRectangles" class="iqser-input-group">
<redaction-selected-annotations-table
[columns]="tableColumns"
[data]="tableData"
@ -15,7 +15,13 @@
></redaction-selected-annotations-table>
</div>
<div *ngIf="!isManualRedaction" class="iqser-input-group w-450" [class.required]="!form.controls.type.disabled">
<iqser-details-radio
*ngIf="!isImage && annotations.length === 1"
[options]="options"
formControlName="option"
></iqser-details-radio>
<div *ngIf="!isManualRedaction" [class.required]="!form.controls.type.disabled" class="iqser-input-group w-450">
<label [translate]="'edit-redaction.dialog.content.type'"></label>
<mat-form-field>

View File

@ -5,7 +5,6 @@ import { MatDialogClose } from '@angular/material/dialog';
import { MatFormField } from '@angular/material/form-field';
import { MatOption, MatSelect, MatSelectTrigger } from '@angular/material/select';
import { MatTooltip } from '@angular/material/tooltip';
import { DetailsRadioOption } from '@common-ui/inputs/details-radio/details-radio-option';
import {
CircleButtonComponent,
HasScrollbarDirective,
@ -26,10 +25,11 @@ import {
SelectedAnnotationsTableComponent,
ValueColumn,
} from '../../components/selected-annotations-table/selected-annotations-table.component';
import { DialogHelpModeKeys } from '../../utils/constants';
import { getEditRedactionOptions } from '../../utils/dialog-options';
import { EditRedactionData, EditRedactResult, RedactOrHintOption } from '../../utils/dialog-types';
import { EditRedactionData, EditRedactionOption, EditRedactResult } from '../../utils/dialog-types';
import { LegalBasisOption } from '../manual-redaction-dialog/manual-annotation-dialog.component';
import { DetailsRadioComponent } from '@common-ui/inputs/details-radio/details-radio.component';
import { DetailsRadioOption } from '@common-ui/inputs/details-radio/details-radio-option';
interface TypeSelectOptions {
type: string;
@ -58,18 +58,16 @@ interface TypeSelectOptions {
HelpButtonComponent,
MatDialogClose,
HasScrollbarDirective,
DetailsRadioComponent,
],
})
export class EditRedactionDialogComponent
extends IqserDialogComponent<EditRedactionDialogComponent, EditRedactionData, EditRedactResult>
implements OnInit
{
readonly #dossier = inject(ActiveDossiersService).find(this.data.dossierId);
readonly #applyToAllDossiers = this.data.applyToAllDossiers;
protected readonly roles = Roles;
readonly ignoredKeys = ['option', 'comment'];
readonly annotations = this.data.annotations;
readonly iconButtonTypes = IconButtonTypes;
readonly isModifyDictionary = this.annotations.every(annotation => annotation.isModifyDictionary);
readonly isImage = this.annotations.reduce((acc, next) => acc && next.isImage, true);
readonly redactedTexts = !this.isImage ? this.annotations.map(annotation => annotation.value).filter(value => !!value) : null;
readonly isManualRedaction = this.annotations.some(annotation => annotation.type === SuperTypes.ManualRedaction);
@ -82,13 +80,15 @@ export class EditRedactionDialogComponent
{ label: redaction.value, bold: true },
{ label: redaction.typeLabel },
]);
options: DetailsRadioOption<RedactOrHintOption>[] | undefined;
options = getEditRedactionOptions();
legalOptions: LegalBasisOption[] = [];
dictionaries: Dictionary[] = [];
typeSelectOptions: TypeSelectOptions[] = [];
readonly form = this.#getForm();
hasTypeChanged = false;
initialReasonDisabled = this.someSkipped;
protected readonly roles = Roles;
readonly #dossier = inject(ActiveDossiersService).find(this.data.dossierId);
constructor(
private readonly _justificationsService: JustificationsService,
@ -144,16 +144,6 @@ export class EditRedactionDialogComponent
return this.annotations.length > 1;
}
get helpButtonKey() {
if (this.isHint) {
return DialogHelpModeKeys.HINT_EDIT;
}
if (this.someSkipped) {
return DialogHelpModeKeys.SKIPPED_EDIT;
}
return DialogHelpModeKeys.REDACTION_EDIT;
}
get sameType() {
return this.annotations.every(annotation => annotation.type === this.annotations[0].type);
}
@ -179,7 +169,6 @@ export class EditRedactionDialogComponent
typeChanged() {
const selectedDictionaryType = this.form.controls.type.value;
this.#setOptions(selectedDictionaryType);
const initialReason = this.form.get('type').value === this.initialFormValue.type && !this.initialReasonDisabled;
if (this.redactBasedTypes.includes(selectedDictionaryType) || initialReason) {
@ -193,7 +182,7 @@ export class EditRedactionDialogComponent
} else {
this.form.controls.reason.disable();
}
this.form.patchValue({ reason: null, option: null });
this.form.patchValue({ reason: null });
}
save() {
@ -206,6 +195,7 @@ export class EditRedactionDialogComponent
comment: value.comment,
type: value.type,
value: this.allRectangles ? value.value : null,
option: value.option.value,
});
}
@ -230,22 +220,6 @@ export class EditRedactionDialogComponent
}
}
#setOptions(type: string, reasonChanged = false) {
const selectedDictionary = this.dictionaries.find(d => d.type === type);
this.options = getEditRedactionOptions(
this.#dossier.dossierName,
this.#applyToAllDossiers,
!!selectedDictionary?.dossierDictionaryOnly,
this.isModifyDictionary,
);
this.form.patchValue(
{
option: !this.isModifyDictionary || reasonChanged ? this.options[0] : this.options[1],
},
{ emitEvent: false },
);
}
#getForm() {
const sameSection = this.annotations.every(annotation => annotation.section === this.annotations[0].section);
return new FormGroup({
@ -256,7 +230,7 @@ export class EditRedactionDialogComponent
disabled: this.isImported,
}),
section: new FormControl<string>({ value: sameSection ? this.annotations[0].section : null, disabled: this.isImported }),
option: new FormControl<LegalBasisOption>(null),
option: new FormControl<DetailsRadioOption<EditRedactionOption>>(this.options[0]),
value: new FormControl<string>(this.allRectangles ? this.annotations[0].value : null),
});
}

View File

@ -24,7 +24,6 @@ import {
SelectedAnnotationsTableComponent,
ValueColumn,
} from '../../components/selected-annotations-table/selected-annotations-table.component';
import { DialogHelpModeKeys } from '../../utils/constants';
import { getRemoveRedactionOptions } from '../../utils/dialog-options';
import {
RemoveRedactionData,

View File

@ -9,6 +9,7 @@ import {
DictionaryEntryTypes,
EarmarkOperation,
type IBulkLocalRemoveRequest,
IBulkRecategorizationRequest,
ILegalBasisChangeRequest,
IRecategorizationRequest,
IRectangle,
@ -34,6 +35,7 @@ import {
EditRedactionData,
EditRedactResult,
ForceAnnotationOptions,
RedactOrHintOptions,
RemoveRedactionData,
RemoveRedactionOptions,
RemoveRedactionPermissions,
@ -108,13 +110,11 @@ export class AnnotationActionsService {
}
async editRedaction(annotations: AnnotationWrapper[]) {
const { dossierId, dossierTemplateId, fileId, file } = this._state;
const { dossierId, fileId } = this._state;
const includeUnprocessed = annotations.every(annotation => this.#includeUnprocessed(annotation, true));
const dossierTemplate = this._dossierTemplatesService.find(dossierTemplateId);
const data = {
annotations,
dossierId,
applyToAllDossiers: dossierTemplate.applyDictionaryUpdatesToAllDossiersByDefault,
};
const result = await this.#getEditRedactionDialog(data).result();
@ -122,22 +122,38 @@ export class AnnotationActionsService {
return;
}
const recategorizeBody: List<IRecategorizationRequest> = annotations.map(annotation => {
const body: IRecategorizationRequest = {
annotationId: annotation.id,
type: result.type ?? annotation.type,
comment: result.comment,
};
if (!this.#isDocumine) {
return {
...body,
legalBasis: result.legalBasis,
section: result.section ?? annotation.section,
value: result.value ?? annotation.value,
let recategorizeBody: List<IRecategorizationRequest> | IBulkRecategorizationRequest;
if (result.option === RedactOrHintOptions.ONLY_HERE) {
recategorizeBody = annotations.map(annotation => {
const body: IRecategorizationRequest = {
annotationId: annotation.id,
type: result.type ?? annotation.type,
comment: result.comment,
};
}
return body;
});
if (!this.#isDocumine) {
return {
...body,
legalBasis: result.legalBasis,
section: result.section ?? annotation.section,
value: result.value ?? annotation.value,
};
}
return body;
});
} else {
const originTypes = annotations.map(a => a.type);
const originLegalBases = annotations.map(a => a.legalBasis);
recategorizeBody = {
value: annotations[0].value,
type: result.type,
legalBasis: result.legalBasis,
section: result.section,
originTypes,
originLegalBases,
rectangle: false,
};
}
await this.#processObsAndEmit(
this._manualRedactionService
@ -147,6 +163,7 @@ export class AnnotationActionsService {
fileId,
this.#getChangedFields(annotations, result),
includeUnprocessed,
result.option === RedactOrHintOptions.IN_DOCUMENT,
)
.pipe(log()),
);

View File

@ -9,6 +9,7 @@ import type {
DictionaryActions,
IAddRedactionRequest,
IBulkLocalRemoveRequest,
IBulkRecategorizationRequest,
ILegalBasisChangeRequest,
IManualAddResponse,
IRecategorizationRequest,
@ -71,15 +72,16 @@ export class ManualRedactionService extends GenericService<IManualAddResponse> {
}
recategorizeRedactions(
body: List<IRecategorizationRequest>,
body: List<IRecategorizationRequest> | IBulkRecategorizationRequest,
dossierId: string,
fileId: string,
successMessageParameters?: {
[key: string]: string;
},
includeUnprocessed = false,
bulkLocal = false,
) {
return this.recategorize(body, dossierId, fileId, includeUnprocessed).pipe(
return this.#recategorize(body, dossierId, fileId, includeUnprocessed, bulkLocal).pipe(
this.#showToast('recategorize-annotation', false, successMessageParameters),
);
}
@ -118,7 +120,7 @@ export class ManualRedactionService extends GenericService<IManualAddResponse> {
includeUnprocessed = false,
bulkLocal = false,
) {
return this.remove(body, dossierId, fileId, includeUnprocessed, bulkLocal).pipe(
return this.#remove(body, dossierId, fileId, includeUnprocessed, bulkLocal).pipe(
this.#showToast(!isHint ? 'remove' : 'remove-hint', removeFromDictionary),
);
}
@ -141,30 +143,11 @@ export class ManualRedactionService extends GenericService<IManualAddResponse> {
return this._post(bulkLocal ? body[0] : body, `${bulkPath}/add/${dossierId}/${fileId}`).pipe(this.#log('Add', body));
}
recategorize(body: List<IRecategorizationRequest>, dossierId: string, fileId: string, includeUnprocessed = false) {
return this._post(body, `${this.#bulkRedaction}/recategorize/${dossierId}/${fileId}?includeUnprocessed=${includeUnprocessed}`).pipe(
this.#log('Recategorize', body),
);
}
undo(annotationIds: List, dossierId: string, fileId: string) {
const url = `${this._defaultModelPath}/bulk/undo/${dossierId}/${fileId}`;
return super.delete(annotationIds, url).pipe(this.#log('Undo', annotationIds));
}
remove(
body: List<IRemoveRedactionRequest> | IBulkLocalRemoveRequest,
dossierId: string,
fileId: string,
includeUnprocessed = false,
bulkLocal = false,
) {
const bulkPath = bulkLocal ? this.#bulkLocal : this.#bulkRedaction;
return this._post(body, `${bulkPath}/remove/${dossierId}/${fileId}?includeUnprocessed=${includeUnprocessed}`).pipe(
this.#log('Remove', body),
);
}
forceRedaction(body: List<ILegalBasisChangeRequest>, dossierId: string, fileId: string) {
return this._post(body, `${this.#bulkRedaction}/force/${dossierId}/${fileId}`).pipe(this.#log('Force redaction', body));
}
@ -175,6 +158,32 @@ export class ManualRedactionService extends GenericService<IManualAddResponse> {
);
}
#recategorize(
body: List<IRecategorizationRequest> | IBulkRecategorizationRequest,
dossierId: string,
fileId: string,
includeUnprocessed = false,
bulkLocal = false,
) {
const bulkPath = bulkLocal ? this.#bulkLocal : this.#bulkRedaction;
return this._post(body, `${bulkPath}/recategorize/${dossierId}/${fileId}?includeUnprocessed=${includeUnprocessed}`).pipe(
this.#log('Recategorize', body),
);
}
#remove(
body: List<IRemoveRedactionRequest> | IBulkLocalRemoveRequest,
dossierId: string,
fileId: string,
includeUnprocessed = false,
bulkLocal = false,
) {
const bulkPath = bulkLocal ? this.#bulkLocal : this.#bulkRedaction;
return this._post(body, `${bulkPath}/remove/${dossierId}/${fileId}?includeUnprocessed=${includeUnprocessed}`).pipe(
this.#log('Remove', body),
);
}
#log(action: string, body: unknown) {
return tap(response => {
this._logger.info(`[MANUAL-REDACTIONS] ${action} `, body, response);

View File

@ -19,16 +19,6 @@ export const ActionsHelpModeKeys = {
'hint-image': 'hint',
} as const;
export const DialogHelpModeKeys = {
REDACTION_EDIT: 'redaction_edit',
REDACTION_REMOVE: 'redaction_remove',
SKIPPED_EDIT: 'skipped_edit',
SKIPPED_REMOVE: 'skipped_remove',
RECOMMENDATION_REMOVE: 'recommendation_remove',
HINT_EDIT: 'hint_edit',
HINT_REMOVE: 'hint_remove',
} as const;
export const ALL_HOTKEYS: List = ['Escape', 'F', 'f', 'ArrowUp', 'ArrowDown', 'H', 'h'] as const;
export const HeaderElements = {

View File

@ -7,6 +7,7 @@ import { removeAnnotationTranslations } from '@translations/remove-annotation-tr
import { removeRedactionTranslations } from '@translations/remove-redaction-translations';
import { resizeRedactionTranslations } from '@translations/resize-redaction-translations';
import {
EditRedactionOption,
ForceAnnotationOption,
RedactOrHintOption,
RedactOrHintOptions,
@ -22,36 +23,21 @@ const DOCUMENT_ICON = 'iqser:document';
const FOLDER_ICON = 'red:folder';
const REMOVE_FROM_DICT_ICON = 'red:remove-from-dict';
export const getEditRedactionOptions = (
dossierName: string,
applyToAllDossiers: boolean,
dossierDictionaryOnly: boolean,
isModifyDictionary: boolean,
): DetailsRadioOption<RedactOrHintOption>[] => {
const options: DetailsRadioOption<RedactOrHintOption>[] = [
export const getEditRedactionOptions = (): DetailsRadioOption<EditRedactionOption>[] => {
return [
{
label: editRedactionTranslations.onlyHere.label,
description: editRedactionTranslations.onlyHere.description,
icon: PIN_ICON,
value: ResizeOptions.ONLY_HERE,
value: RedactOrHintOptions.ONLY_HERE,
},
{
label: editRedactionTranslations.inDocument.label,
description: editRedactionTranslations.inDocument.description,
icon: DOCUMENT_ICON,
value: RedactOrHintOptions.IN_DOCUMENT,
},
];
if (isModifyDictionary) {
options.push({
label: editRedactionTranslations.inDossier.label,
description: editRedactionTranslations.inDossier.description,
descriptionParams: { dossierName: dossierName },
icon: FOLDER_ICON,
value: ResizeOptions.IN_DOSSIER,
extraOption: {
label: editRedactionTranslations.inDossier.extraOptionLabel,
checked: applyToAllDossiers,
hidden: dossierDictionaryOnly,
disabled: true,
},
});
}
return options;
};
export const getRedactOrHintOptions = (
@ -71,7 +57,7 @@ export const getRedactOrHintOptions = (
label: translations.onlyHere.label,
description: translations.onlyHere.description,
icon: PIN_ICON,
value: ResizeOptions.ONLY_HERE,
value: RedactOrHintOptions.ONLY_HERE,
});
}
@ -84,7 +70,7 @@ export const getRedactOrHintOptions = (
label: redactTextTranslations.inDocument.label,
description: redactTextTranslations.inDocument.description,
icon: DOCUMENT_ICON,
value: ResizeOptions.IN_DOCUMENT,
value: RedactOrHintOptions.IN_DOCUMENT,
});
}
@ -93,7 +79,7 @@ export const getRedactOrHintOptions = (
description: translations.inDossier.description,
descriptionParams: { dossierName: dossier.dossierName },
icon: FOLDER_ICON,
value: ResizeOptions.IN_DOSSIER,
value: RedactOrHintOptions.IN_DOSSIER,
disabled: isPageExcluded,
extraOption: {
label: translations.inDossier.extraOptionLabel,
@ -119,7 +105,7 @@ export const getResizeRedactionOptions = (
label: translations.onlyHere.label,
description: translations.onlyHere.description,
icon: PIN_ICON,
value: RedactOrHintOptions.ONLY_HERE,
value: ResizeOptions.ONLY_HERE,
},
];
@ -135,7 +121,7 @@ export const getResizeRedactionOptions = (
disabled: !dictBasedType || redaction.hasBeenRecategorized,
tooltip: !dictBasedType ? translations.inDossier.tooltip : null,
icon: FOLDER_ICON,
value: RedactOrHintOptions.IN_DOSSIER,
value: ResizeOptions.IN_DOSSIER,
extraOption: {
label: translations.inDossier.extraOptionLabel,
checked: applyToAllDossiers,

View File

@ -3,6 +3,13 @@ import { AnnotationWrapper } from '@models/file/annotation.wrapper';
import { ManualRedactionEntryWrapper } from '@models/file/manual-redaction-entry.wrapper';
import { Dictionary, Dossier, File, IAddRedactionRequest, IManualRedactionEntry } from '@red/domain';
export const EditRedactionOptions = {
ONLY_HERE: 'ONLY_HERE',
IN_DOCUMENT: 'IN_DOCUMENT',
} as const;
export type EditRedactionOption = keyof typeof EditRedactionOptions;
export const RedactOrHintOptions = {
ONLY_HERE: 'ONLY_HERE',
IN_DOCUMENT: 'IN_DOCUMENT',
@ -45,7 +52,6 @@ export interface RedactTextData {
export interface EditRedactionData {
annotations: AnnotationWrapper[];
dossierId: string;
applyToAllDossiers: boolean;
isApprover?: boolean;
}
@ -58,7 +64,9 @@ export interface RedactTextResult {
bulkLocal?: boolean;
}
export type RedactRecommendationData = EditRedactionData;
export type RedactRecommendationData = EditRedactionData & {
applyToAllDossiers: boolean;
};
export interface RedactRecommendationResult {
redaction: IAddRedactionRequest;
@ -72,6 +80,7 @@ export interface EditRedactResult {
comment: string;
type: string;
value: string;
option: EditRedactionOption;
}
export type AddHintResult = RedactTextResult;

View File

@ -25,20 +25,13 @@ export const redactTextTranslations: Record<'onlyHere' | 'inDocument' | 'inDossi
},
} as const;
export const editRedactionTranslations: Record<'onlyHere' | 'inDossier', DialogOption> = {
export const editRedactionTranslations: Record<'onlyHere' | 'inDocument', DialogOption> = {
onlyHere: {
label: _('edit-redaction.dialog.content.options.only-here.label'),
description: _('edit-redaction.dialog.content.options.only-here.description'),
},
inDossier: {
label: _('edit-redaction.dialog.content.options.in-dossier.label'),
description: _('edit-redaction.dialog.content.options.in-dossier.description'),
extraOptionLabel: _('edit-redaction.dialog.content.options.in-dossier.extraOptionLabel'),
inDocument: {
label: _('edit-redaction.dialog.content.options.in-document.label'),
description: _('edit-redaction.dialog.content.options.in-document.description'),
},
} as const;
export const editRedactionLabelsTranslations = {
redactedText: _('edit-redaction.dialog.content.redacted-text'),
customRectangle: _('edit-redaction.dialog.content.custom-rectangle'),
imported: _('edit-redaction.dialog.content.imported'),
} as const;

View File

@ -27,8 +27,6 @@ export function mainGuard(): AsyncGuard {
const logger = inject(NGXLogger);
logger.info('[ROUTES] Main resolver started...');
console.log('main guard');
const router = inject(Router);
inject(FeaturesService).loadConfig();
if (inject(IqserPermissionsService).has(Roles.dossiers.read)) {

View File

@ -1284,14 +1284,11 @@
"content": {
"comment": "Kommentar",
"comment-placeholder": "Bemerkungen oder Notizen hinzufügen...",
"custom-rectangle": "Bereichsschwärzung",
"imported": "Importierte Schwärzung",
"legal-basis": "Rechtsgrundlage",
"options": {
"in-dossier": {
"description": "Schwärzung in jedem Dokument in {dossierName} bearbeiten.",
"extraOptionLabel": "In alle aktiven und zukünftigen Dossiers übernehmen",
"label": "Typ in Dossier ändern"
"in-document": {
"description": "",
"label": ""
},
"only-here": {
"description": "Bearbeiten Sie die Schwärzung nur an dieser Stelle im Dokument.",

View File

@ -1284,18 +1284,15 @@
"content": {
"comment": "Comment",
"comment-placeholder": "Add remarks or notes...",
"custom-rectangle": "Custom Rectangle",
"imported": "Imported Redaction",
"legal-basis": "Legal basis",
"options": {
"in-dossier": {
"description": "Edit redaction in every document in {dossierName}.",
"extraOptionLabel": "Apply to all active and future dossiers",
"label": "Change type in dossier"
"in-document": {
"description": "Edit redaction of all linked occurrences of the term in this document.",
"label": "Change in document"
},
"only-here": {
"description": "Edit redaction only at this position in this document.",
"label": "Change type only here"
"label": "Change only here"
}
},
"reason": "Reason",

View File

@ -1284,13 +1284,10 @@
"content": {
"comment": "Comment",
"comment-placeholder": "Add remarks or mentions...",
"custom-rectangle": "",
"imported": "",
"legal-basis": "",
"options": {
"in-dossier": {
"in-document": {
"description": "",
"extraOptionLabel": "",
"label": ""
},
"only-here": {

View File

@ -1284,13 +1284,10 @@
"content": {
"comment": "Comment",
"comment-placeholder": "Add remarks or mentions...",
"custom-rectangle": "",
"imported": "",
"legal-basis": "",
"options": {
"in-dossier": {
"in-document": {
"description": "",
"extraOptionLabel": "",
"label": ""
},
"only-here": {

View File

@ -6,3 +6,18 @@ export interface IRecategorizationRequest {
readonly section?: string;
readonly value?: string;
}
export interface IBulkRecategorizationRequest {
readonly value: string;
readonly type: string;
readonly legalBasis: string;
readonly section: string;
readonly originTypes: string[];
readonly originLegalBases: string[];
readonly rectangle: boolean;
readonly position?: {
readonly rectangle: number[];
readonly pageNumber: number;
};
readonly pageNumbers?: number[];
}