Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: display all properties in compound resource #1654

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/vre/shared/app-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export * from './lib/resource.service';
export * from './lib/custom-regex';
export * from './lib/dsp-resource';
export * from './lib/property-info-values.interface';
export * from './lib/common';
export * from './lib/generateProperty';
export * from './lib/directives/mat-autocomplete-options-scroll.directive';
export * from './lib/form-validators/at-least-one-string-required.validator';
export * from './lib/form-validators/array-length-greater-than-zero-validator';
68 changes: 0 additions & 68 deletions libs/vre/shared/app-common/src/lib/common.ts

This file was deleted.

74 changes: 74 additions & 0 deletions libs/vre/shared/app-common/src/lib/generateProperty.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import {
Constants,
IHasPropertyWithPropertyDefinition,
ReadResource,
ReadStillImageFileValue,
} from '@dasch-swiss/dsp-js';
import { PropertyInfoValues } from './property-info-values.interface';

/**
* Contains every changes needed for displaying properties without bug.
* It mainly removes unwanted property
*/
export class GenerateProperty {
public static commonProperty(resource: ReadResource) {
return this._initProps(resource)
.filter(prop => !prop.propDef['isLinkProperty'])
.filter(prop => !prop.propDef.subPropertyOf.includes('http://api.knora.org/ontology/knora-api/v2#hasFileValue'));
}

public static incomingRessourceProperty(resource: ReadResource) {
return this._initProps(resource).filter(
v => v.propDef.id !== 'http://api.knora.org/ontology/knora-api/v2#hasStillImageFileValue'
);
}

public static regionProperty(resource: ReadResource) {
return this._initProps(resource).filter(
v => v.propDef.objectType !== 'http://api.knora.org/ontology/knora-api/v2#Representation'
);
}

private static _initProps(resource: ReadResource): PropertyInfoValues[] {
let props = resource.entityInfo.classes[resource.type]
.getResourcePropertiesList()
.map((prop: IHasPropertyWithPropertyDefinition) => {
let propInfoAndValues: PropertyInfoValues;

switch (prop.propertyDefinition.objectType) {
case Constants.StillImageFileValue:
propInfoAndValues = {
propDef: prop.propertyDefinition,
guiDef: prop,
values: resource.getValuesAs(prop.propertyIndex, ReadStillImageFileValue),
};
break;

default:
// the object type is none from above
propInfoAndValues = {
propDef: prop.propertyDefinition,
guiDef: prop,
values: resource.getValues(prop.propertyIndex),
};
}
return propInfoAndValues;
});

// sort properties by guiOrder
props = props
.filter(prop => prop.propDef.objectType !== Constants.GeomValue)
.sort((a, b) => (a.guiDef.guiOrder > b.guiDef.guiOrder ? 1 : -1))
// to get equal results on all browser engines which implements sorting in different way
// properties list has to be sorted again, pushing all "has..." properties to the bottom
// TODO FOLLOWING LINE IS A BUG ARRAY-CALLBACK-RETURN SHOULDNT BE DISABLED
// eslint-disable-next-line array-callback-return
.sort(a => {
if (a.guiDef.guiOrder === undefined) {
return 1;
}
});

return props;
}
}
4 changes: 2 additions & 2 deletions libs/vre/shared/app-representations/src/lib/region.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ChangeDetectorRef, Injectable } from '@angular/core';
import { ReadResourceSequence } from '@dasch-swiss/dsp-js';
import { Common, DspResource } from '@dasch-swiss/vre/shared/app-common';
import { DspResource, GenerateProperty } from '@dasch-swiss/vre/shared/app-common';
import { IncomingService } from '@dasch-swiss/vre/shared/app-common-to-move';
import { BehaviorSubject, of } from 'rxjs';
import { map, switchMap, take } from 'rxjs/operators';
Expand Down Expand Up @@ -65,7 +65,7 @@ export class RegionService {
map(regions =>
(regions as ReadResourceSequence).resources.map(_resource => {
const z = new DspResource(_resource);
z.resProps = Common.initProps(_resource);
z.resProps = GenerateProperty.regionProperty(_resource);
return z;
})
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Inject, Injectable } from '@angular/core';
import { KnoraApiConnection, ReadResource, SystemPropertyDefinition } from '@dasch-swiss/dsp-js';
import { Common, DspResource } from '@dasch-swiss/vre/shared/app-common';
import { DspResource, GenerateProperty } from '@dasch-swiss/vre/shared/app-common';
import { DspApiConnectionToken } from '@dasch-swiss/vre/shared/app-config';
import { SetCurrentResourceAction } from '@dasch-swiss/vre/shared/app-state';
import { Store } from '@ngxs/store';
Expand Down Expand Up @@ -43,7 +43,7 @@ export class ResourceFetcherService {
return this._dspApiConnection.v2.res.getResource(this._resourceIri).pipe(
map(response => {
const res = new DspResource(response as ReadResource);
res.resProps = Common.initProps(res.res);
res.resProps = GenerateProperty.commonProperty(res.res);

// gather system property information
res.systemProps = res.res.entityInfo.getPropertyDefinitionsByType(SystemPropertyDefinition);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ChangeDetectorRef, Inject, Injectable } from '@angular/core';
import { KnoraApiConnection, ReadResource, ReadResourceSequence, SystemPropertyDefinition } from '@dasch-swiss/dsp-js';
import { Common, DspCompoundPosition, DspResource } from '@dasch-swiss/vre/shared/app-common';
import { DspCompoundPosition, DspResource, GenerateProperty } from '@dasch-swiss/vre/shared/app-common';
import { IncomingService } from '@dasch-swiss/vre/shared/app-common-to-move';
import { DspApiConnectionToken } from '@dasch-swiss/vre/shared/app-config';
import { NotificationService } from '@dasch-swiss/vre/shared/app-notification';
Expand Down Expand Up @@ -71,12 +71,7 @@ export class CompoundService {
const response = res as ReadResource;

const incomingResource = new DspResource(response);
incomingResource.resProps = Common.initProps(response).filter(
v =>
v.values.length > 0 &&
v.propDef.label &&
v.propDef.id !== 'http://api.knora.org/ontology/knora-api/v2#hasStillImageFileValue'
);
incomingResource.resProps = GenerateProperty.incomingRessourceProperty(response);
incomingResource.systemProps =
incomingResource.res.entityInfo.getPropertyDefinitionsByType(SystemPropertyDefinition);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, Input, OnChanges, OnDestroy, OnInit } from '@angular/core';
import { MatTabChangeEvent } from '@angular/material/tabs';
import { ActivatedRoute } from '@angular/router';
import { Constants } from '@dasch-swiss/dsp-js';
import { DspResource, PropertyInfoValues } from '@dasch-swiss/vre/shared/app-common';
import { DspResource } from '@dasch-swiss/vre/shared/app-common';
import { RouteConstants } from '@dasch-swiss/vre/shared/app-config';
import { RegionService } from '@dasch-swiss/vre/shared/app-representations';
import { Subject } from 'rxjs';
Expand All @@ -18,7 +18,7 @@ import { CompoundService } from './compound/compound.service';
[(selectedIndex)]="selectedTab"
(selectedTabChange)="tabChanged($event)">
<mat-tab #matTabProperties [label]="'appLabels.resource.properties' | translate">
<app-properties-display *ngIf="resourceProperties" [resource]="resource" [properties]="resourceProperties" />
<app-properties-display *ngIf="resource" [resource]="resource" [properties]="resource.resProps" />
</mat-tab>

<mat-tab
Expand Down Expand Up @@ -47,7 +47,6 @@ export class ResourceTabsComponent implements OnInit, OnChanges, OnDestroy {
@Input({ required: true }) resource!: DspResource;

selectedTab = 0;
resourceProperties!: PropertyInfoValues[];
annotationTabSelected = false;

private ngUnsubscribe = new Subject<void>();
Expand All @@ -73,10 +72,6 @@ export class ResourceTabsComponent implements OnInit, OnChanges, OnDestroy {
}

ngOnChanges() {
this.resourceProperties = this.resource.resProps
.filter(prop => !prop.propDef['isLinkProperty'])
.filter(prop => !prop.propDef.subPropertyOf.includes('http://api.knora.org/ontology/knora-api/v2#hasFileValue'));

this.selectedTab = 0;
}

Expand Down
Loading