Skip to content

Commit

Permalink
fix: resource can load by itself
Browse files Browse the repository at this point in the history
  • Loading branch information
derschnee68 committed Apr 30, 2024
1 parent 3e3b263 commit db1870d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ResourceClassIriService } from './resource-class-iri.service';
selector: 'app-create-resource-page',
template: ` <h3>Create new resource of type: {{ (resClass$ | async)?.label }}</h3>
<app-create-resource-form
*ngIf="resourceClassIriService.resourceClassIri$ | async as classIri"
*ngIf="resourceClassIriService.resourceClassIriFromParamSubject.asObservable() | async as classIri"
[resourceType]="(resClass$ | async)?.label"
[resourceClassIri]="classIri"
[projectIri]="projectIri"
Expand All @@ -40,7 +40,7 @@ export class CreateResourcePageComponent {

resClass$ = combineLatest([
this.projectOntologies$.pipe(filter(v => Object.keys(v).length !== 0)),
this.resourceClassIriService.resourceClassIri$,
this.resourceClassIriService.resourceClassIriFromParamSubject.asObservable(),
this.resourceClassIriService.ontoId$,
]).pipe(
map(([projectOntologies, classId, ontoId]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -10,7 +11,7 @@ import { propertiesTypeMapping } from './resource-payloads-mapping';
selector: 'app-existing-property-value',
template: `
<app-property-value-switcher
*ngIf="resourceClassIriService.resourceClassIri$ | async as resClassIri"
*ngIf="resourceClassIri$ | async as resClassIri"
[myProperty]="prop"
[formArray]="formArray"
[resourceClassIri]="resClassIri"
Expand All @@ -30,6 +31,10 @@ export class ExistingPropertyValueComponent implements OnChanges {
public resourceClassIriService: ResourceClassIriService
) {}

resourceClassIri$ = this.resourceClassIriService.resourceClassIriFromParamSubject
.asObservable()
.pipe(filter(v => v !== null));

ngOnChanges() {
this.formArray = this._fb.array(
this.prop.values.map(value => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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<string | null>(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);
});
}
}

0 comments on commit db1870d

Please sign in to comment.