RED-6680 fix annotation deselecting while selected

This commit is contained in:
Dan Percic 2023-07-07 19:56:12 +03:00
parent a93527e963
commit b22e47cec3
2 changed files with 78 additions and 69 deletions

View File

@ -37,6 +37,7 @@ import { Roles } from '@users/roles';
import { AnnotationActionsService } from './annotation-actions.service';
import { getCurrentUser } from '@iqser/common-ui/lib/users';
import { BASE_HREF_FN, isJustOne, shareDistinctLast } from '@iqser/common-ui/lib/utils';
import { NGXLogger } from 'ngx-logger';
import Annotation = Core.Annotations.Annotation;
import Quad = Core.Math.Quad;
@ -55,7 +56,7 @@ export class PdfProxyService {
readonly redactTextRequested$ = new Subject<ManualRedactionEntryWrapper>();
readonly currentUser = getCurrentUser<User>();
readonly pageChanged$ = this._pdf.pageChanged$.pipe(
tap(() => this.#handleCustomActions()),
tap(() => this.#handleExcludedPageActions()),
tap(() => this._pdf.resetAnnotationActions()),
shareDistinctLast(),
);
@ -80,6 +81,7 @@ export class PdfProxyService {
private readonly _documentViewer: REDDocumentViewer,
private readonly _annotationManager: REDAnnotationManager,
private readonly _pdf: PdfViewer,
private readonly _logger: NGXLogger,
private readonly _state: FilePreviewStateService,
private readonly _multiSelectService: MultiSelectService,
private readonly _listingService: AnnotationsListingService,
@ -88,15 +90,29 @@ export class PdfProxyService {
) {
effect(
() => {
this.canPerformActions();
const canPerformActions = this.canPerformActions();
this._pdf.isCompareMode();
this.#handleCustomActions();
this.#configureTextPopup();
this.#deactivateMultiSelect();
this.#handleExcludedPageActions();
if (canPerformActions) {
this.#enableActions();
} else {
this.#disableActions();
this.#deactivateMultiSelect();
}
},
{ allowSignalWrites: true },
);
effect(() => {
if (this._viewModeService.isRedacted()) {
this._viewerHeaderService.enable([HeaderElements.TOGGLE_READABLE_REDACTIONS]);
} else {
this._viewerHeaderService.disable([HeaderElements.TOGGLE_READABLE_REDACTIONS]);
}
});
}
get #annotationSelected$() {
@ -146,42 +162,41 @@ export class PdfProxyService {
}
#configureTextPopup() {
if (this._state.file().isApproved) {
this._pdf.configureTextPopups([]);
}
const popups: IHeaderElement[] = [];
// Adding directly to the false-positive dict is only available in dev-mode
if (this._userPreferenceService.areDevFeaturesEnabled) {
popups.push({
type: 'actionButton',
dataElement: TextPopups.ADD_FALSE_POSITIVE,
img: this.#falsePositiveIcon,
title: this.#getTitle(ManualRedactionEntryTypes.FALSE_POSITIVE),
onClick: () => this._ngZone.run(() => this.#addManualRedactionOfType(ManualRedactionEntryTypes.FALSE_POSITIVE)),
});
}
if (!this._state.file().isApproved) {
// Adding directly to the false-positive dict is only available in dev-mode
if (this._userPreferenceService.areDevFeaturesEnabled) {
popups.push({
type: 'actionButton',
dataElement: TextPopups.ADD_FALSE_POSITIVE,
img: this.#falsePositiveIcon,
title: this.#getTitle(ManualRedactionEntryTypes.FALSE_POSITIVE),
onClick: () => this._ngZone.run(() => this.#addManualRedactionOfType(ManualRedactionEntryTypes.FALSE_POSITIVE)),
});
}
const isApprover = this._permissionsService.isApprover(this._state.dossier());
if (this._iqserPermissionsService.has(Roles.redactions.write) && isApprover) {
popups.push({
type: 'actionButton',
dataElement: TextPopups.REDACT_TEXT,
img: this.#addRedactionIcon,
title: this.#getTitle(ManualRedactionEntryTypes.REDACT),
onClick: () => this._ngZone.run(() => this.#redactText(ManualRedactionEntryTypes.REDACT)),
});
popups.push({
type: 'actionButton',
dataElement: TextPopups.ADD_HINT,
img: this.#addHintIcon,
title: this.#getTitle(ManualRedactionEntryTypes.HINT),
onClick: () => this._ngZone.run(() => this.#redactText(ManualRedactionEntryTypes.HINT)),
});
}
const isApprover = this._permissionsService.isApprover(this._state.dossier());
if (this._iqserPermissionsService.has(Roles.redactions.write) && isApprover) {
popups.push({
type: 'actionButton',
dataElement: TextPopups.REDACT_TEXT,
img: this.#addRedactionIcon,
title: this.#getTitle(ManualRedactionEntryTypes.REDACT),
onClick: () => this._ngZone.run(() => this.#redactText(ManualRedactionEntryTypes.REDACT)),
});
popups.push({
type: 'actionButton',
dataElement: TextPopups.ADD_HINT,
img: this.#addHintIcon,
title: this.#getTitle(ManualRedactionEntryTypes.HINT),
onClick: () => this._ngZone.run(() => this.#redactText(ManualRedactionEntryTypes.HINT)),
});
}
this._pdf.configureTextPopups(popups);
return this.#handleCustomActions();
}
#addManualRedactionOfType(type: ManualRedactionEntryType) {
@ -198,46 +213,37 @@ export class PdfProxyService {
this.redactTextRequested$.next({ manualRedactionEntry, type });
}
#handleCustomActions() {
#handleExcludedPageActions() {
const isCurrentPageExcluded = this._state.file().isPageExcluded(this._pdf.currentPage());
if (this._viewModeService.isRedacted()) {
this._viewerHeaderService.enable([HeaderElements.TOGGLE_READABLE_REDACTIONS]);
} else {
this._viewerHeaderService.disable([HeaderElements.TOGGLE_READABLE_REDACTIONS]);
}
if (isCurrentPageExcluded) {
let textPopupElementsToDisable = [...TEXT_POPUPS_TO_TOGGLE];
let headerElementsToDisable = [...HEADER_ITEMS_TO_TOGGLE];
if (this.canPerformActions()) {
this._pdf.enable(ALLOWED_ACTIONS_WHEN_PAGE_EXCLUDED);
this._viewerHeaderService.enable(ALLOWED_ACTIONS_WHEN_PAGE_EXCLUDED as HeaderElementType[]);
textPopupElementsToDisable = textPopupElementsToDisable.filter(
element => !ALLOWED_ACTIONS_WHEN_PAGE_EXCLUDED.includes(element),
);
headerElementsToDisable = headerElementsToDisable.filter(element => !ALLOWED_ACTIONS_WHEN_PAGE_EXCLUDED.includes(element));
}
this._pdf.disable(textPopupElementsToDisable);
this._viewerHeaderService.disable(headerElementsToDisable);
if (!isCurrentPageExcluded) {
return;
}
if (!this.canPerformActions()) {
this._pdf.instance.UI.disableTools([AnnotationToolNames.AnnotationCreateRectangle]);
this._pdf.disable(TEXT_POPUPS_TO_TOGGLE);
this._viewerHeaderService.disable(HEADER_ITEMS_TO_TOGGLE);
return;
let textPopupElementsToDisable = [...TEXT_POPUPS_TO_TOGGLE];
let headerElementsToDisable = [...HEADER_ITEMS_TO_TOGGLE];
if (this.canPerformActions()) {
this._pdf.enable(ALLOWED_ACTIONS_WHEN_PAGE_EXCLUDED);
this._viewerHeaderService.enable(ALLOWED_ACTIONS_WHEN_PAGE_EXCLUDED as HeaderElementType[]);
textPopupElementsToDisable = textPopupElementsToDisable.filter(
element => !ALLOWED_ACTIONS_WHEN_PAGE_EXCLUDED.includes(element),
);
headerElementsToDisable = headerElementsToDisable.filter(element => !ALLOWED_ACTIONS_WHEN_PAGE_EXCLUDED.includes(element));
}
try {
this._pdf.instance.UI.enableTools([AnnotationToolNames.AnnotationCreateRectangle]);
} catch (e) {
// happens
}
this._pdf.disable(textPopupElementsToDisable);
this._viewerHeaderService.disable(headerElementsToDisable);
}
#disableActions() {
this._pdf.instance.UI.disableTools([AnnotationToolNames.AnnotationCreateRectangle]);
this._pdf.disable(TEXT_POPUPS_TO_TOGGLE);
this._viewerHeaderService.disable(HEADER_ITEMS_TO_TOGGLE);
}
#enableActions() {
this._pdf.instance.UI.enableTools([AnnotationToolNames.AnnotationCreateRectangle]);
this._pdf.enable(TEXT_POPUPS_TO_TOGGLE);
this._viewerHeaderService.enable(HEADER_ITEMS_TO_TOGGLE);
@ -263,6 +269,7 @@ export class PdfProxyService {
}
#deactivateMultiSelect() {
this._logger.info('[PDF] Deactivating multi-select');
this._multiSelectService.deactivate();
this._annotationManager.deselect();
this.handleAnnotationSelected([]);

View File

@ -75,9 +75,11 @@ export class REDAnnotationManager {
deselect(annotations?: List | List<AnnotationWrapper>): void;
deselect(argument?: string | AnnotationWrapper | List | List<AnnotationWrapper>) {
if (!argument) {
this.#logger.info('[ANNOTATIONS] Deselect all');
return this.#manager.deselectAllAnnotations();
}
this.#logger.info('[ANNOTATIONS] Deselecting: ', argument);
const ann = isStringOrWrapper(argument) ? [this.#getById(argument)] : this.#getByIds(argument);
this.#manager.deselectAnnotations(ann);
}