Skip to content

Commit

Permalink
fix(annotations): load the correct resource for annotations (#1588)
Browse files Browse the repository at this point in the history
  • Loading branch information
domsteinbach committed May 15, 2024
1 parent 7a2a274 commit 0f46425
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ <h4>{{ resource.res.label }}</h4>
</ng-template>
<div
class="region-property"
*ngFor="let annotation of annotationResources; trackby: trackAnnotationByFn"
*ngFor="let annotation of annotationResources; trackBy: trackAnnotationByFn"
[id]="annotation.res.id"
[class.active]="annotation.res.id === selectedRegion">
<app-properties-display [resource]="annotation" [properties]="annotation.resProps" isAnnotation="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { MatDialog } from '@angular/material/dialog';
import {
ApiResponseError,
Cardinality,
Constants,
CreateValue,
KnoraApiConnection,
ReadResource,
Expand All @@ -12,7 +13,7 @@ import {
} from '@dasch-swiss/dsp-js';
import { DspApiConnectionToken } from '@dasch-swiss/vre/shared/app-config';
import { NotificationService } from '@dasch-swiss/vre/shared/app-notification';
import { LoadResourceAction } from '@dasch-swiss/vre/shared/app-state';
import { LoadAnnotatedResourceAction, LoadResourceAction } from '@dasch-swiss/vre/shared/app-state';
import { Store } from '@ngxs/store';
import { Subscription } from 'rxjs';
import { finalize, startWith, switchMap, take } from 'rxjs/operators';
Expand Down Expand Up @@ -148,7 +149,13 @@ export class PropertyValueComponent implements OnInit {
.createValue(updateRes as UpdateResource<CreateValue>)
.pipe(
take(1),
switchMap(() => this._store.dispatch(new LoadResourceAction(resource.id))),
switchMap((): any => {
if (resource.type === Constants.Region) {
this._store.dispatch(new LoadAnnotatedResourceAction(resource.id));
} else {
this._store.dispatch(new LoadResourceAction(resource.id));
}
}),
finalize(() => {
this.loading = false;
})
Expand Down Expand Up @@ -199,9 +206,13 @@ export class PropertyValueComponent implements OnInit {
.updateValue(this._getPayload(this.index))
.pipe(
take(1),
switchMap(() =>
this._store.dispatch(new LoadResourceAction(this.propertyValueService._editModeData!.resource.id))
),
switchMap((): any => {
if (this.propertyValueService._editModeData?.resource.type === Constants.Region) {
this._store.dispatch(new LoadAnnotatedResourceAction(this.propertyValueService._editModeData!.resource.id));
} else {
this._store.dispatch(new LoadResourceAction(this.propertyValueService._editModeData!.resource.id));
}
}),
finalize(() => {
this.loading = false;
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { DspResource } from '@dasch-swiss/vre/shared/app-common';

export class GetAttachedUserAction {
static readonly type = '[Resource] Get Attached User';

Expand Down Expand Up @@ -30,3 +32,9 @@ export class LoadResourceAction {

constructor(public resourceIri: string) {}
}

export class LoadAnnotatedResourceAction {
static readonly type = '[Resource] Load annotated resource';

constructor(public regionIri: string) {}
}
22 changes: 21 additions & 1 deletion libs/vre/shared/app-state/src/lib/resource/resource.state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { Inject, Injectable } from '@angular/core';
import { KnoraApiConnection, ReadProject, ReadResource, SystemPropertyDefinition } from '@dasch-swiss/dsp-js';
import {
Constants,
KnoraApiConnection,
ReadLinkValue,
ReadProject,
ReadResource,
SystemPropertyDefinition,
} from '@dasch-swiss/dsp-js';
import { ProjectApiService, UserApiService } from '@dasch-swiss/vre/shared/app-api';
import { Common, DspResource } from '@dasch-swiss/vre/shared/app-common';
import { DspApiConnectionToken } from '@dasch-swiss/vre/shared/app-config';
Expand All @@ -10,6 +17,7 @@ import { UserSelectors } from '../user/user.selectors';
import {
GetAttachedProjectAction,
GetAttachedUserAction,
LoadAnnotatedResourceAction,
LoadResourceAction,
ToggleShowAllCommentsAction,
ToggleShowAllPropsAction,
Expand Down Expand Up @@ -147,4 +155,16 @@ export class ResourceState {
})
);
}
@Action(LoadAnnotatedResourceAction)
loadAnnotatedResource(ctx: StateContext<ReourceStateModel>, { regionIri }: LoadAnnotatedResourceAction) {
return this._dspApiConnection.v2.res.getResource(regionIri).pipe(
tap(response => {
const res = new DspResource(response as ReadResource);
res.resProps = Common.initProps(res.res);
const annotatedRepresentationIri = (res.res.properties[Constants.IsRegionOfValue] as ReadLinkValue[])[0]
.linkedResourceIri;
this.store.dispatch(new LoadResourceAction(annotatedRepresentationIri));
})
);
}
}

0 comments on commit 0f46425

Please sign in to comment.