diff --git a/libs/vre/shared/app-common/src/index.ts b/libs/vre/shared/app-common/src/index.ts index a42ced0d53..1fc160601d 100644 --- a/libs/vre/shared/app-common/src/index.ts +++ b/libs/vre/shared/app-common/src/index.ts @@ -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'; diff --git a/libs/vre/shared/app-common/src/lib/common.ts b/libs/vre/shared/app-common/src/lib/common.ts deleted file mode 100644 index f2af8d9308..0000000000 --- a/libs/vre/shared/app-common/src/lib/common.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { - Constants, - IHasPropertyWithPropertyDefinition, - ReadResource, - ReadStillImageFileValue, -} from '@dasch-swiss/dsp-js'; -import { PropertyInfoValues } from './property-info-values.interface'; - -export class Common { - /** gather propoerties information */ - public 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), - }; - - /* - TODO Julien: I removed this part - const stillImageRepresentations = [ - new FileRepresentation( - resource.getValuesAs(Constants.HasStillImageFileValue, ReadStillImageFileValue)[0], - [] - ), - ]; - - this.representationsToDisplay = stillImageRepresentations; - - */ - // --> TODO: get regions here - - 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; - } -} diff --git a/libs/vre/shared/app-common/src/lib/generateProperty.ts b/libs/vre/shared/app-common/src/lib/generateProperty.ts new file mode 100644 index 0000000000..44246e016a --- /dev/null +++ b/libs/vre/shared/app-common/src/lib/generateProperty.ts @@ -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; + } +} diff --git a/libs/vre/shared/app-representations/src/lib/region.service.ts b/libs/vre/shared/app-representations/src/lib/region.service.ts index a8fce3ee17..827a680230 100644 --- a/libs/vre/shared/app-representations/src/lib/region.service.ts +++ b/libs/vre/shared/app-representations/src/lib/region.service.ts @@ -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'; @@ -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; }) ) diff --git a/libs/vre/shared/app-representations/src/lib/resource-fetcher.service.ts b/libs/vre/shared/app-representations/src/lib/resource-fetcher.service.ts index deb1584273..e07bc0d4f1 100644 --- a/libs/vre/shared/app-representations/src/lib/resource-fetcher.service.ts +++ b/libs/vre/shared/app-representations/src/lib/resource-fetcher.service.ts @@ -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'; @@ -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); diff --git a/libs/vre/shared/app-resource-page/src/lib/compound/compound.service.ts b/libs/vre/shared/app-resource-page/src/lib/compound/compound.service.ts index 83a0382039..50968ce3bc 100644 --- a/libs/vre/shared/app-resource-page/src/lib/compound/compound.service.ts +++ b/libs/vre/shared/app-resource-page/src/lib/compound/compound.service.ts @@ -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'; @@ -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); diff --git a/libs/vre/shared/app-resource-page/src/lib/resource-tabs.component.ts b/libs/vre/shared/app-resource-page/src/lib/resource-tabs.component.ts index 74bf89cd8f..7c848a2314 100644 --- a/libs/vre/shared/app-resource-page/src/lib/resource-tabs.component.ts +++ b/libs/vre/shared/app-resource-page/src/lib/resource-tabs.component.ts @@ -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'; @@ -18,7 +18,7 @@ import { CompoundService } from './compound/compound.service'; [(selectedIndex)]="selectedTab" (selectedTabChange)="tabChanged($event)"> - + (); @@ -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; }