Skip to content

Commit

Permalink
Merge branch 'main' into feature/dev-4504-page-is-not-refreshed-after…
Browse files Browse the repository at this point in the history
…-resource-is-erased-or-deleted
  • Loading branch information
derschnee68 authored Feb 26, 2025
2 parents 02d120f + 768f687 commit f50c0bc
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ import { CompoundService } from './compound.service';
})
export class CompoundSliderComponent {
get compoundNavigation() {
return this.compoungService.compoundPosition;
return this.compoundService.compoundPosition!;
}

openPage(page: number) {
this.compoungService.openPage(page);
this.compoundService.openPage(page);
}

constructor(public compoungService: CompoundService) {}
constructor(public compoundService: CompoundService) {}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ChangeDetectorRef, Inject, Injectable } from '@angular/core';
import { KnoraApiConnection, ReadResource, ReadResourceSequence, SystemPropertyDefinition } from '@dasch-swiss/dsp-js';
import { DspApiConnectionToken } from '@dasch-swiss/vre/core/config';
import { AppError } from '@dasch-swiss/vre/core/error-handler';
import { GetAttachedProjectAction, GetAttachedUserAction } from '@dasch-swiss/vre/core/state';
import { RegionService } from '@dasch-swiss/vre/resource-editor/representations';
import { DspCompoundPosition, DspResource, GenerateProperty } from '@dasch-swiss/vre/shared/app-common';
Expand All @@ -13,12 +14,12 @@ import { BehaviorSubject } from 'rxjs';
*/
@Injectable()
export class CompoundService {
compoundPosition!: DspCompoundPosition;
compoundPosition?: DspCompoundPosition;

incomingResource = new BehaviorSubject<DspResource | undefined>(undefined);
incomingResource$ = this.incomingResource.asObservable();

private _resource!: DspResource;
private _resource?: DspResource;

constructor(
@Inject(DspApiConnectionToken)
Expand All @@ -35,23 +36,33 @@ export class CompoundService {
this.openPage(_compound.page);
}

reset() {
this.compoundPosition = undefined;
this._resource = undefined;
this.incomingResource.next(undefined);
}

openPage(page: number) {
if (!this.compoundPosition) {
throw new AppError('Compound position is not set');
}

this.compoundPosition.page = page;
this._loadIncomingResourcesPage();
this._loadIncomingResourcesPage(this.compoundPosition);
}

private _loadIncomingResourcesPage(): void {
private _loadIncomingResourcesPage(compoundPosition: DspCompoundPosition): void {
this._incomingService
.getStillImageRepresentationsForCompoundResource(this._resource.res.id, this.compoundPosition.offset)
.getStillImageRepresentationsForCompoundResource(this._resource!.res.id, compoundPosition.offset)
.subscribe(res => {
const incomingImageRepresentations = res as ReadResourceSequence;

if (incomingImageRepresentations.resources.length === 0) {
this.incomingResource.next(undefined);
return;
}
this._resource.incomingRepresentations = incomingImageRepresentations.resources;
this._loadIncomingResource(this._resource.incomingRepresentations[this.compoundPosition.position].id);
this._resource!.incomingRepresentations = incomingImageRepresentations.resources;
this._loadIncomingResource(this._resource!.incomingRepresentations[compoundPosition.position].id);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ export class ResourceFetcherComponent implements OnChanges, OnDestroy {
});
}

/**
* Reload the editor with the new resource.
* Note: The double detection is necessary to reload the entire editor.
* @param resource
* @private
*/
private _reloadEditor(resource: DspResource) {
this.resource = resource;
this._cdr.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { CompoundService } from './compound/compound.service';
<app-annotation-tab *ngIf="regionsCount > 0" [resource]="resource" />
</mat-tab>
<mat-tab label="Segments" *ngIf="segmentsService.segments && segmentsService.segments.length > 0">
<mat-tab label="Segments" *ngIf="segmentsService.segments.length > 0">
<ng-template matTabLabel>
<span [matBadge]="segmentsService.segments.length" matBadgeColor="primary" matBadgeOverlap="false">
Segments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { CompoundService } from './compound/compound.service';
export class ResourceComponent implements OnChanges {
@Input({ required: true }) resource!: DspResource;
representationsToDisplay!: ReadFileValue;
isCompoundNavigation = false;
isCompoundNavigation!: boolean;
resourceIsObjectWithoutRepresentation!: boolean;

constructor(
Expand All @@ -40,6 +40,9 @@ export class ResourceComponent implements OnChanges {
) {}

ngOnChanges() {
this._compoundService.reset();
this.isCompoundNavigation = false;

this.resourceIsObjectWithoutRepresentation = this._isObjectWithoutRepresentation(this.resource);
this._onInit(this.resource);
}
Expand Down

0 comments on commit f50c0bc

Please sign in to comment.