wip has references

This commit is contained in:
Edi Cziszter 2022-01-17 14:20:14 +02:00
parent c8f19f68e0
commit 409454972d
6 changed files with 21 additions and 17 deletions

View File

@ -88,8 +88,8 @@
></iqser-circle-button> ></iqser-circle-button>
<iqser-circle-button <iqser-circle-button
(action)="annotationReferencesService.show(annotations)" (action)="annotationReferencesService.show()"
*ngIf="referencesButtonEnabled" *ngIf="(annotationReferencesService.hasReferences$ | async) && !multiSelectService.isActive"
[tooltipPosition]="tooltipPosition" [tooltipPosition]="tooltipPosition"
[tooltip]="'annotation-actions.see-references.label' | translate" [tooltip]="'annotation-actions.see-references.label' | translate"
[type]="buttonType" [type]="buttonType"

View File

@ -41,7 +41,6 @@ export class AnnotationActionsComponent implements OnChanges {
@Input() @Required() file!: File; @Input() @Required() file!: File;
@Output() annotationsChanged = new EventEmitter<AnnotationWrapper>(); @Output() annotationsChanged = new EventEmitter<AnnotationWrapper>();
annotationPermissions: AnnotationPermissions; annotationPermissions: AnnotationPermissions;
referencesButtonEnabled = false;
constructor( constructor(
private readonly _manualAnnotationService: ManualAnnotationService, private readonly _manualAnnotationService: ManualAnnotationService,
@ -64,8 +63,7 @@ export class AnnotationActionsComponent implements OnChanges {
@Input() @Input()
set annotations(value: AnnotationWrapper[]) { set annotations(value: AnnotationWrapper[]) {
this._annotations = value.filter(a => a !== undefined); this._annotations = value.filter(a => a !== undefined);
this.referencesButtonEnabled = this.annotationReferencesService.setAnnotation(this._annotations);
this.annotationReferencesService.hasReferences(this._annotations) && !this.multiSelectService.isActive;
} }
get viewerAnnotations() { get viewerAnnotations() {

View File

@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core'; import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, Output } from '@angular/core';
import { AnnotationWrapper } from '@models/file/annotation.wrapper'; import { AnnotationWrapper } from '@models/file/annotation.wrapper';
import { AnnotationReferencesService } from '../../services/annotation-references.service'; import { AnnotationReferencesService } from '../../services/annotation-references.service';
import { File } from '@red/domain'; import { File } from '@red/domain';
@ -23,7 +23,7 @@ export class AnnotationReferencesDialogComponent implements OnChanges {
constructor(readonly annotationReferencesService: AnnotationReferencesService) {} constructor(readonly annotationReferencesService: AnnotationReferencesService) {}
ngOnChanges(changes: SimpleChanges): void { ngOnChanges(): void {
this.annotationReferences = this.fileData.allAnnotations.filter(a => this.annotation.reference.includes(a.annotationId)); this.annotationReferences = this.fileData.allAnnotations.filter(a => this.annotation.reference.includes(a.annotationId));
} }
} }

View File

@ -44,11 +44,11 @@
<redaction-annotation-details [annotation]="annotation"></redaction-annotation-details> <redaction-annotation-details [annotation]="annotation"></redaction-annotation-details>
</div> </div>
<ng-container *ngIf="annotationReferencesService.annotation$ | async as annotation"> <ng-container *ngIf="annotationReferencesService.showReferences$ | async">
<redaction-annotation-references-dialog <redaction-annotation-references-dialog
(referenceClicked)="referenceClicked($event)" (referenceClicked)="referenceClicked($event)"
*ngIf="annotationReferencesService.hasReferences([annotation])" *ngIf="annotationReferencesService.hasReferences$ | async"
[annotation]="annotation" [annotation]="annotationReferencesService.annotation$ | async"
[fileData]="fileData" [fileData]="fileData"
[file]="file" [file]="file"
></redaction-annotation-references-dialog> ></redaction-annotation-references-dialog>

View File

@ -56,7 +56,7 @@ export class AnnotationsListComponent implements OnChanges {
referenceClicked(annotation: AnnotationWrapper): void { referenceClicked(annotation: AnnotationWrapper): void {
this.annotationClicked(annotation, null); this.annotationClicked(annotation, null);
if (this._filterService.filtersEnabled('primaryFilters')) { if (this._filterService.filtersEnabled('primaryFilters')) {
this._filterService.toggleFilter('primaryFilters', annotation.superType); this._filterService.toggleFilter('primaryFilters', annotation.superType, true);
} }
} }

View File

@ -2,25 +2,31 @@ import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs'; import { BehaviorSubject, Observable } from 'rxjs';
import { shareDistinctLast } from '@iqser/common-ui'; import { shareDistinctLast } from '@iqser/common-ui';
import { AnnotationWrapper } from '@models/file/annotation.wrapper'; import { AnnotationWrapper } from '@models/file/annotation.wrapper';
import { map } from 'rxjs/operators';
@Injectable() @Injectable()
export class AnnotationReferencesService { export class AnnotationReferencesService {
readonly annotation$: Observable<AnnotationWrapper>; readonly annotation$: Observable<AnnotationWrapper>;
private readonly _annotation$ = new BehaviorSubject(null); readonly hasReferences$: Observable<boolean>;
readonly showReferences$: Observable<boolean>;
private readonly _annotation$: BehaviorSubject<AnnotationWrapper> = new BehaviorSubject<AnnotationWrapper>(null);
private readonly _showReferences$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
constructor() { constructor() {
this.annotation$ = this._annotation$.asObservable().pipe(shareDistinctLast()); this.annotation$ = this._annotation$.asObservable().pipe(shareDistinctLast());
this.showReferences$ = this._showReferences$.asObservable().pipe(shareDistinctLast());
this.hasReferences$ = this.annotation$.pipe(map(annotation => !!annotation.reference && annotation.reference.length !== 0));
} }
hasReferences(annotations: AnnotationWrapper[]): boolean { setAnnotation(annotation: AnnotationWrapper[]): void {
return !!annotations[0].reference && annotations[0].reference.length !== 0; this._annotation$.next(annotation[0]);
} }
show(annotations: AnnotationWrapper[]) { show() {
this._annotation$.next(annotations[0]); this._showReferences$.next(true);
} }
hide() { hide() {
this._annotation$.next(null); this._showReferences$.next(false);
} }
} }