diff --git a/libs/vre/shared/app-resource-properties/src/lib/create-resource-page.component.ts b/libs/vre/shared/app-resource-properties/src/lib/create-resource-page.component.ts index fb765847bd..1761b82907 100644 --- a/libs/vre/shared/app-resource-properties/src/lib/create-resource-page.component.ts +++ b/libs/vre/shared/app-resource-properties/src/lib/create-resource-page.component.ts @@ -14,7 +14,7 @@ import { ResourceClassIriService } from './resource-class-iri.service'; selector: 'app-create-resource-page', template: `

Create new resource of type: {{ (resClass$ | async)?.label }}

Object.keys(v).length !== 0)), - this.resourceClassIriService.resourceClassIri$, + this.resourceClassIriService.resourceClassIriFromParamSubject.asObservable(), this.resourceClassIriService.ontoId$, ]).pipe( map(([projectOntologies, classId, ontoId]) => { diff --git a/libs/vre/shared/app-resource-properties/src/lib/existing-property-value.component.ts b/libs/vre/shared/app-resource-properties/src/lib/existing-property-value.component.ts index 4ee4827ea1..8bdf9c493c 100644 --- a/libs/vre/shared/app-resource-properties/src/lib/existing-property-value.component.ts +++ b/libs/vre/shared/app-resource-properties/src/lib/existing-property-value.component.ts @@ -2,6 +2,7 @@ import { Component, Input, OnChanges } from '@angular/core'; import { AbstractControl, FormBuilder } from '@angular/forms'; import { ReadResource } from '@dasch-swiss/dsp-js'; import { PropertyInfoValues } from '@dasch-swiss/vre/shared/app-common'; +import { filter } from 'rxjs/operators'; import { FormValueArray } from './form-value-array.type'; import { ResourceClassIriService } from './resource-class-iri.service'; import { propertiesTypeMapping } from './resource-payloads-mapping'; @@ -10,7 +11,7 @@ import { propertiesTypeMapping } from './resource-payloads-mapping'; selector: 'app-existing-property-value', template: ` v !== null)); + ngOnChanges() { this.formArray = this._fb.array( this.prop.values.map(value => { diff --git a/libs/vre/shared/app-resource-properties/src/lib/resource-class-iri.service.ts b/libs/vre/shared/app-resource-properties/src/lib/resource-class-iri.service.ts index 668b3fdb2c..2a9df7d001 100644 --- a/libs/vre/shared/app-resource-properties/src/lib/resource-class-iri.service.ts +++ b/libs/vre/shared/app-resource-properties/src/lib/resource-class-iri.service.ts @@ -1,10 +1,13 @@ -import { Injectable } from '@angular/core'; +import { Inject, Injectable } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; -import { RouteConstants } from '@dasch-swiss/vre/shared/app-config'; +import { KnoraApiConnection, ReadResource } from '@dasch-swiss/dsp-js'; +import { ResourceService } from '@dasch-swiss/vre/shared/app-common'; +import { DspApiConnectionToken, RouteConstants } from '@dasch-swiss/vre/shared/app-config'; import { OntologyService } from '@dasch-swiss/vre/shared/app-helper-services'; import { ProjectsSelectors } from '@dasch-swiss/vre/shared/app-state'; import { Store } from '@ngxs/store'; -import { filter, map } from 'rxjs/operators'; +import { BehaviorSubject, race } from 'rxjs'; +import { filter, map, switchMap, take } from 'rxjs/operators'; @Injectable() export class ResourceClassIriService { @@ -26,9 +29,33 @@ export class ResourceClassIriService { }) ); + resourceClassIriFromRoute$ = this._route.params.pipe( + filter(params => params[RouteConstants.resourceParameter] !== undefined), + switchMap(params => + this._dspApiConnection.v2.res.getResource( + this._resourceService.getResourceIri( + params[RouteConstants.projectParameter], + params[RouteConstants.resourceParameter] + ) + ) + ), + map(v => Object.values((v as ReadResource).entityInfo.classes)[0].id) + ); + + resourceClassIriFromParamSubject = new BehaviorSubject(null); + constructor( private _store: Store, private _route: ActivatedRoute, - private _ontologyService: OntologyService - ) {} + private _ontologyService: OntologyService, + private _resourceService: ResourceService, + @Inject(DspApiConnectionToken) + private _dspApiConnection: KnoraApiConnection + ) { + race([this.resourceClassIriFromRoute$, this.resourceClassIri$]) + .pipe(take(1)) + .subscribe(v => { + this.resourceClassIriFromParamSubject.next(v); + }); + } }