RED-6680 run pdf events in ng zone

This commit is contained in:
Dan Percic 2023-06-16 20:01:10 +03:00
parent a3dbc8a7ca
commit 3db31d6cc0
2 changed files with 31 additions and 31 deletions

View File

@ -243,7 +243,7 @@ export class PdfProxyService {
dataElement: TextPopups.ADD_RECTANGLE, dataElement: TextPopups.ADD_RECTANGLE,
img: this.#addRedactionIcon, img: this.#addRedactionIcon,
title: this.#getTitle(ManualRedactionEntryTypes.REDACTION), title: this.#getTitle(ManualRedactionEntryTypes.REDACTION),
onClick: () => this._addRectangleManualRedaction(), onClick: () => this._ngZone.run(() => this._addRectangleManualRedaction()),
}; };
this._pdf.instance.UI.annotationPopup.add([addRectangleButton]); this._pdf.instance.UI.annotationPopup.add([addRectangleButton]);
@ -276,7 +276,7 @@ export class PdfProxyService {
dataElement: TextPopups.ADD_FALSE_POSITIVE, dataElement: TextPopups.ADD_FALSE_POSITIVE,
img: this.#falsePositiveIcon, img: this.#falsePositiveIcon,
title: this.#getTitle(ManualRedactionEntryTypes.FALSE_POSITIVE), title: this.#getTitle(ManualRedactionEntryTypes.FALSE_POSITIVE),
onClick: () => this._addManualRedactionOfType(ManualRedactionEntryTypes.FALSE_POSITIVE), onClick: () => this._ngZone.run(() => this._addManualRedactionOfType(ManualRedactionEntryTypes.FALSE_POSITIVE)),
}); });
} }
@ -286,7 +286,7 @@ export class PdfProxyService {
dataElement: TextPopups.ADD_REDACTION, dataElement: TextPopups.ADD_REDACTION,
img: this.#addRedactionIcon, img: this.#addRedactionIcon,
title: this.#getTitle(ManualRedactionEntryTypes.REDACTION), title: this.#getTitle(ManualRedactionEntryTypes.REDACTION),
onClick: () => this._addManualRedactionOfType(ManualRedactionEntryTypes.REDACTION), onClick: () => this._ngZone.run(() => this._addManualRedactionOfType(ManualRedactionEntryTypes.REDACTION)),
}); });
if (!this._iqserPermissionsService.has(ROLES.getRss)) { if (!this._iqserPermissionsService.has(ROLES.getRss)) {
@ -295,7 +295,7 @@ export class PdfProxyService {
dataElement: TextPopups.ADD_DICTIONARY, dataElement: TextPopups.ADD_DICTIONARY,
img: this.#addDictIcon, img: this.#addDictIcon,
title: this.#getTitle(ManualRedactionEntryTypes.DICTIONARY), title: this.#getTitle(ManualRedactionEntryTypes.DICTIONARY),
onClick: () => this._addManualRedactionOfType(ManualRedactionEntryTypes.DICTIONARY), onClick: () => this._ngZone.run(() => this._addManualRedactionOfType(ManualRedactionEntryTypes.DICTIONARY)),
}); });
} }
} }

View File

@ -1,4 +1,4 @@
import { Inject, Injectable } from '@angular/core'; import { Inject, Injectable, NgZone } from '@angular/core';
import { IHeaderElement, RotationTypes } from '@red/domain'; import { IHeaderElement, RotationTypes } from '@red/domain';
import { HeaderElements, HeaderElementType } from '../../file-preview/utils/constants'; import { HeaderElements, HeaderElementType } from '../../file-preview/utils/constants';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
@ -9,7 +9,6 @@ import { PdfViewer } from './pdf-viewer.service';
import { ROTATION_ACTION_BUTTONS, ROTATION_BUTTONS, ViewerEvents } from '../utils/constants'; import { ROTATION_ACTION_BUTTONS, ROTATION_BUTTONS, ViewerEvents } from '../utils/constants';
import { FilesMapService } from '@services/files/files-map.service'; import { FilesMapService } from '@services/files/files-map.service';
import { REDDocumentViewer } from './document-viewer.service'; import { REDDocumentViewer } from './document-viewer.service';
import { UserPreferenceService } from '@users/user-preference.service';
import { fromEvent, Observable, Subject } from 'rxjs'; import { fromEvent, Observable, Subject } from 'rxjs';
import { ViewerEvent, VisibilityChangedEvent } from '../utils/types'; import { ViewerEvent, VisibilityChangedEvent } from '../utils/types';
import { ReadableRedactionsService } from './readable-redactions.service'; import { ReadableRedactionsService } from './readable-redactions.service';
@ -48,7 +47,7 @@ export class ViewerHeaderService {
private readonly _rotationService: PageRotationService, private readonly _rotationService: PageRotationService,
private readonly _tooltipsService: TooltipsService, private readonly _tooltipsService: TooltipsService,
private readonly _readableRedactionsService: ReadableRedactionsService, private readonly _readableRedactionsService: ReadableRedactionsService,
private readonly _userPreferenceService: UserPreferenceService, private readonly _ngZone: NgZone,
) { ) {
this.events$ = this.#events$.asObservable(); this.events$ = this.#events$.asObservable();
} }
@ -70,9 +69,7 @@ export class ViewerHeaderService {
dataElement: HeaderElements.TOGGLE_TOOLTIPS, dataElement: HeaderElements.TOGGLE_TOOLTIPS,
title: this._tooltipsService.toggleTooltipsBtnTitle, title: this._tooltipsService.toggleTooltipsBtnTitle,
img: this._tooltipsService.toggleTooltipsBtnIcon, img: this._tooltipsService.toggleTooltipsBtnIcon,
onClick: async () => { onClick: () => this._ngZone.run(() => this._tooltipsService.toggleTooltips()),
await this._tooltipsService.toggleTooltips();
},
}; };
} }
@ -83,9 +80,7 @@ export class ViewerHeaderService {
dataElement: HeaderElements.TOGGLE_READABLE_REDACTIONS, dataElement: HeaderElements.TOGGLE_READABLE_REDACTIONS,
title: this._readableRedactionsService.toggleReadableRedactionsBtnTitle, title: this._readableRedactionsService.toggleReadableRedactionsBtnTitle,
img: this._readableRedactionsService.toggleReadableRedactionsBtnIcon, img: this._readableRedactionsService.toggleReadableRedactionsBtnIcon,
onClick: () => { onClick: () => this._ngZone.run(() => this._readableRedactionsService.toggleReadableRedactions()),
this._readableRedactionsService.toggleReadableRedactions();
},
}; };
} }
@ -94,7 +89,7 @@ export class ViewerHeaderService {
type: 'actionButton', type: 'actionButton',
title: this._translateService.instant('viewer-header.load-all-annotations'), title: this._translateService.instant('viewer-header.load-all-annotations'),
img: this._convertPath('/assets/icons/general/pdftron-action-load-all-annotations.svg'), img: this._convertPath('/assets/icons/general/pdftron-action-load-all-annotations.svg'),
onClick: () => this.#events$.next({ type: ViewerEvents.LOAD_ALL_ANNOTATIONS }), onClick: () => this._ngZone.run(() => this.#events$.next({ type: ViewerEvents.LOAD_ALL_ANNOTATIONS })),
dataElement: HeaderElements.LOAD_ALL_ANNOTATIONS, dataElement: HeaderElements.LOAD_ALL_ANNOTATIONS,
}; };
} }
@ -106,7 +101,7 @@ export class ViewerHeaderService {
dataElement: HeaderElements.CLOSE_COMPARE_BUTTON, dataElement: HeaderElements.CLOSE_COMPARE_BUTTON,
img: this._convertPath('/assets/icons/general/pdftron-action-close-compare.svg'), img: this._convertPath('/assets/icons/general/pdftron-action-close-compare.svg'),
title: 'Leave Compare Mode', title: 'Leave Compare Mode',
onClick: () => this._closeCompareMode(), onClick: () => this._ngZone.run(() => this._closeCompareMode()),
}; };
} }
@ -117,10 +112,11 @@ export class ViewerHeaderService {
dataElement: HeaderElements.ROTATE_LEFT_BUTTON, dataElement: HeaderElements.ROTATE_LEFT_BUTTON,
img: this._convertPath('/assets/icons/general/rotate-left.svg'), img: this._convertPath('/assets/icons/general/rotate-left.svg'),
title: 'Rotate page left', title: 'Rotate page left',
onClick: () => { onClick: () =>
this._rotationService.addRotation(RotationTypes.LEFT); this._ngZone.run(() => {
this.#toggleRotationActionButtons(); this._rotationService.addRotation(RotationTypes.LEFT);
}, this.#toggleRotationActionButtons();
}),
}; };
} }
@ -139,8 +135,10 @@ export class ViewerHeaderService {
margin: 0 12px; margin: 0 12px;
`; `;
paragraph.addEventListener('click', async () => { paragraph.addEventListener('click', async () => {
await this._rotationService.applyRotation(); await this._ngZone.run(async () => {
this.disable(ROTATION_ACTION_BUTTONS); await this._rotationService.applyRotation();
this.disable(ROTATION_ACTION_BUTTONS);
});
}); });
return paragraph; return paragraph;
}, },
@ -161,7 +159,7 @@ export class ViewerHeaderService {
cursor: pointer; cursor: pointer;
opacity: 0.7; opacity: 0.7;
`; `;
paragraph.addEventListener('click', () => this.#discardRotation()); paragraph.addEventListener('click', () => this._ngZone.run(() => this.#discardRotation()));
return paragraph; return paragraph;
}, },
}; };
@ -174,10 +172,11 @@ export class ViewerHeaderService {
dataElement: HeaderElements.ROTATE_RIGHT_BUTTON, dataElement: HeaderElements.ROTATE_RIGHT_BUTTON,
img: this._convertPath('/assets/icons/general/rotate-right.svg'), img: this._convertPath('/assets/icons/general/rotate-right.svg'),
title: 'Rotate page right', title: 'Rotate page right',
onClick: () => { onClick: () =>
this._rotationService.addRotation(RotationTypes.RIGHT); this._ngZone.run(() => {
this.#toggleRotationActionButtons(); this._rotationService.addRotation(RotationTypes.RIGHT);
}, this.#toggleRotationActionButtons();
}),
}; };
} }
@ -188,10 +187,11 @@ export class ViewerHeaderService {
dataElement: HeaderElements.COMPARE_BUTTON, dataElement: HeaderElements.COMPARE_BUTTON,
img: this._convertPath('/assets/icons/general/pdftron-action-compare.svg'), img: this._convertPath('/assets/icons/general/pdftron-action-compare.svg'),
title: 'Compare', title: 'Compare',
onClick: async () => { onClick: () =>
document.getElementById('compareFileInput').click(); this._ngZone.run(async () => {
this.#docBeforeCompare = await this._documentViewer.blob(); document.getElementById('compareFileInput').click();
}, this.#docBeforeCompare = await this._documentViewer.blob();
}),
}; };
} }
@ -293,7 +293,7 @@ export class ViewerHeaderService {
enableLoadAllAnnotations(): void { enableLoadAllAnnotations(): void {
this._pdf.instance.UI.updateElement(HeaderElements.LOAD_ALL_ANNOTATIONS, { this._pdf.instance.UI.updateElement(HeaderElements.LOAD_ALL_ANNOTATIONS, {
img: this._convertPath('/assets/icons/general/pdftron-action-load-all-annotations.svg'), img: this._convertPath('/assets/icons/general/pdftron-action-load-all-annotations.svg'),
onClick: () => this.#events$.next({ type: ViewerEvents.LOAD_ALL_ANNOTATIONS }), onClick: () => this._ngZone.run(() => this.#events$.next({ type: ViewerEvents.LOAD_ALL_ANNOTATIONS })),
}); });
} }