RED-6316: Fixed showing rotation buttons

This commit is contained in:
Adina Țeudan 2023-03-16 20:17:38 +02:00
parent d7d8f6784a
commit 10e011a311
3 changed files with 25 additions and 21 deletions

View File

@ -262,7 +262,7 @@ export class FilePreviewScreenComponent
ngOnDetach() {
this._viewerHeaderService.resetCompareButtons();
this._viewerHeaderService.enableLoadAllAnnotations();
this._viewerHeaderService.enableLoadAllAnnotations(); // Reset the button state (since the viewer is reused between files)
super.ngOnDetach();
this._changeRef.markForCheck();
}
@ -691,12 +691,12 @@ export class FilePreviewScreenComponent
.subscribe();
this.addActiveScreenSubscription = this._readableRedactionsService.active$.pipe(switchMap(() => this.updateViewMode())).subscribe();
this.addActiveScreenSubscription = this._viewModeService.viewMode$
this.addActiveScreenSubscription = combineLatest([this._viewModeService.viewMode$, this._documentViewer.loaded$, this.state.file$])
.pipe(
tap(viewMode =>
tap(([viewMode]) =>
viewMode === 'STANDARD' || viewMode === 'TEXT_HIGHLIGHTS'
? this._viewerHeaderService.enableRotationButtons()
: this._viewerHeaderService.disableRotationButtons(),
? this._viewerHeaderService.updateRotationButtons(true)
: this._viewerHeaderService.updateRotationButtons(false),
),
)
.subscribe();

View File

@ -2,7 +2,7 @@ import { Inject, Injectable } from '@angular/core';
import { IHeaderElement, RotationTypes } from '@red/domain';
import { HeaderElements, HeaderElementType } from '../../file-preview/utils/constants';
import { TranslateService } from '@ngx-translate/core';
import { BASE_HREF_FN, BaseHrefFn, IqserPermissionsService } from '@iqser/common-ui';
import { BASE_HREF_FN, BaseHrefFn } from '@iqser/common-ui';
import { TooltipsService } from './tooltips.service';
import { PageRotationService } from './page-rotation.service';
import { PdfViewer } from './pdf-viewer.service';
@ -13,8 +13,8 @@ import { UserPreferenceService } from '@users/user-preference.service';
import { fromEvent, Observable, Subject } from 'rxjs';
import { ViewerEvent, VisibilityChangedEvent } from '../utils/types';
import { ReadableRedactionsService } from './readable-redactions.service';
import { ROLES } from '@users/roles';
import { filter, map, tap } from 'rxjs/operators';
import { PermissionsService } from '@services/permissions.service';
const divider: IHeaderElement = {
type: 'divider',
@ -23,6 +23,7 @@ const divider: IHeaderElement = {
@Injectable()
export class ViewerHeaderService {
readonly events$: Observable<ViewerEvent>;
toggleLoadAnnotations$: Observable<boolean>;
#buttons: Map<HeaderElementType, IHeaderElement>;
readonly #config = new Map<HeaderElementType, boolean>([
[HeaderElements.SHAPE_TOOL_GROUP_BUTTON, true],
@ -38,7 +39,6 @@ export class ViewerHeaderService {
]);
#docBeforeCompare: Blob;
readonly #events$ = new Subject<ViewerEvent>();
toggleLoadAnnotations$: Observable<boolean>;
constructor(
@Inject(BASE_HREF_FN) private readonly _convertPath: BaseHrefFn,
@ -50,7 +50,7 @@ export class ViewerHeaderService {
private readonly _tooltipsService: TooltipsService,
private readonly _readableRedactionsService: ReadableRedactionsService,
private readonly _userPreferenceService: UserPreferenceService,
private readonly _iqserPermissionsService: IqserPermissionsService,
private readonly _permissionsService: PermissionsService,
) {
this.events$ = this.#events$.asObservable();
}
@ -169,11 +169,6 @@ export class ViewerHeaderService {
};
}
#discardRotation(): void {
this._rotationService.discardRotation();
this.disable(ROTATION_ACTION_BUTTONS);
}
private get _rotateRight(): IHeaderElement {
return {
type: 'actionButton',
@ -304,22 +299,27 @@ export class ViewerHeaderService {
});
}
enableRotationButtons(): void {
if (this._iqserPermissionsService.has(ROLES.files.rotatePage)) {
updateRotationButtons(show: boolean): void {
const { dossierId, fileId } = this._pdf;
const file = this._filesMapService.get(dossierId, fileId);
if (show && this._permissionsService.canRotatePage(file)) {
this.enable(ROTATION_BUTTONS);
} else {
this.disable(ROTATION_BUTTONS);
this.#discardRotation();
}
}
disableRotationButtons(): void {
this.disable(ROTATION_BUTTONS);
this.#discardRotation();
}
resetCompareButtons() {
this.disable([HeaderElements.CLOSE_COMPARE_BUTTON]);
this.enable([HeaderElements.COMPARE_BUTTON]);
}
#discardRotation(): void {
this._rotationService.discardRotation();
this.disable(ROTATION_ACTION_BUTTONS);
}
#toggleRotationActionButtons() {
if (this._rotationService.hasRotations) {
this.enable(ROTATION_ACTION_BUTTONS);

View File

@ -349,6 +349,10 @@ export class PermissionsService {
);
}
canRotatePage(file: File) {
return this.isFileAssignee(file) && this._iqserPermissionsService.has(ROLES.files.rotatePage);
}
canDownloadRedactedFile() {
return this._iqserPermissionsService.has(ROLES.files.processDownload);
}