diff --git a/src/app/+item-page/simple/item-types/publication/publication.component.html b/src/app/+item-page/simple/item-types/publication/publication.component.html index aae269cdbe..b61fa6bbc1 100644 --- a/src/app/+item-page/simple/item-types/publication/publication.component.html +++ b/src/app/+item-page/simple/item-types/publication/publication.component.html @@ -29,7 +29,7 @@
+ [representations]="(authors$ | async)?.payload?.page"> ; + authors$: Observable>>; /** * The projects related to this publication @@ -41,16 +40,10 @@ export class PublicationComponent extends ItemComponent implements OnInit { journalIssues$: Observable>>; ngOnInit(): void { - super.ngOnInit(); + this.authors$ = this.buildRepresentations('Person', 'dc.contributor.author', 'isAuthorOfPublication'); - if (this.resolvedRelsAndTypes$) { - - this.authors$ = this.buildRepresentations('Person', 'dc.contributor.author'); - - this.projects$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isProjectOfPublication'); - this.orgUnits$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isOrgUnitOfPublication'); - this.journalIssues$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isJournalIssueOfPublication'); - - } + this.projects$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isProjectOfPublication'); + this.orgUnits$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isOrgUnitOfPublication'); + this.journalIssues$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isJournalIssueOfPublication'); } } diff --git a/src/app/+item-page/simple/item-types/shared/item.component.ts b/src/app/+item-page/simple/item-types/shared/item.component.ts index e3b9ce59a8..18aa229611 100644 --- a/src/app/+item-page/simple/item-types/shared/item.component.ts +++ b/src/app/+item-page/simple/item-types/shared/item.component.ts @@ -1,20 +1,16 @@ -import { Component, Inject, OnInit } from '@angular/core'; +import { Component, Inject } from '@angular/core'; import { Observable , zip as observableZip, combineLatest as observableCombineLatest } from 'rxjs'; -import { distinctUntilChanged, filter, flatMap, map } from 'rxjs/operators'; -import { ItemDataService } from '../../../../core/data/item-data.service'; +import { filter, flatMap, map } from 'rxjs/operators'; import { PaginatedList } from '../../../../core/data/paginated-list'; import { RemoteData } from '../../../../core/data/remote-data'; -import { RelationshipType } from '../../../../core/shared/item-relationships/relationship-type.model'; import { Relationship } from '../../../../core/shared/item-relationships/relationship.model'; import { Item } from '../../../../core/shared/item.model'; -import { getRemoteDataPayload, getSucceededRemoteData } from '../../../../core/shared/operators'; import { ITEM } from '../../../../shared/items/switcher/item-type-switcher.component'; import { MetadataRepresentation } from '../../../../core/shared/metadata-representation/metadata-representation.model'; import { ItemMetadataRepresentation } from '../../../../core/shared/metadata-representation/item/item-metadata-representation.model'; import { MetadatumRepresentation } from '../../../../core/shared/metadata-representation/metadatum/metadatum-representation.model'; import { of } from 'rxjs/internal/observable/of'; import { MetadataValue } from '../../../../core/shared/metadata.models'; -import { compareArraysUsingIds } from './item-relationships-utils'; import { RelationshipService } from '../../../../core/data/relationship.service'; /** @@ -24,15 +20,15 @@ import { RelationshipService } from '../../../../core/data/relationship.service' * @param metadata The list of original Metadatum objects */ export const relationsToRepresentations = (thisId: string, itemType: string, metadata: MetadataValue[]) => - (source: Observable): Observable => + (source: Observable>>): Observable>> => source.pipe( - flatMap((rels: Relationship[]) => + flatMap((relRD: RemoteData>) => observableZip( ...metadata .map((metadatum: any) => Object.assign(new MetadataValue(), metadatum)) .map((metadatum: MetadataValue) => { if (metadatum.isVirtual) { - const matchingRels = rels.filter((rel: Relationship) => ('' + rel.id) === metadatum.virtualValue); + const matchingRels = relRD.payload.page.filter((rel: Relationship) => ('' + rel.id) === metadatum.virtualValue); if (matchingRels.length > 0) { const matchingRel = matchingRels[0]; return observableCombineLatest(matchingRel.leftItem, matchingRel.rightItem).pipe( @@ -51,6 +47,8 @@ export const relationsToRepresentations = (thisId: string, itemType: string, met return of(Object.assign(new MetadatumRepresentation(itemType), metadatum)); } }) + ).pipe( + map((representations: MetadataRepresentation[]) => Object.assign(relRD, { payload: { page: representations } })) ) ) ); @@ -62,59 +60,25 @@ export const relationsToRepresentations = (thisId: string, itemType: string, met /** * A generic component for displaying metadata and relations of an item */ -export class ItemComponent implements OnInit { - /** - * Resolved relationships and types together in one observable - */ - resolvedRelsAndTypes$: Observable<[Relationship[], RelationshipType[]]>; +export class ItemComponent { constructor( @Inject(ITEM) public item: Item, public relationshipService: RelationshipService ) {} - ngOnInit(): void { - const relationships$ = this.item.relationships; - if (relationships$) { - const relsCurrentPage$ = relationships$.pipe( - filter((rd: RemoteData>) => rd.hasSucceeded), - getRemoteDataPayload(), - map((pl: PaginatedList) => pl.page), - distinctUntilChanged(compareArraysUsingIds()) - ); - - const relTypesCurrentPage$ = relsCurrentPage$.pipe( - flatMap((rels: Relationship[]) => - observableZip(...rels.map((rel: Relationship) => rel.relationshipType)).pipe( - map(([...arr]: Array>) => arr.map((d: RemoteData) => d.payload)) - ) - ), - distinctUntilChanged(compareArraysUsingIds()) - ); - - this.resolvedRelsAndTypes$ = observableCombineLatest( - relsCurrentPage$, - relTypesCurrentPage$ - ); - } - } - /** * Build a list of MetadataRepresentations for the current item. This combines all metadata and relationships of a * certain type. * @param itemType The type of item we're building representations of. Used for matching templates. * @param metadataField The metadata field that resembles the item type. + * @param relationshipLabel The label to use to fetch relationships to create MetadataRepresentations for. */ - buildRepresentations(itemType: string, metadataField: string): Observable { + buildRepresentations(itemType: string, metadataField: string, relationshipLabel: string): Observable>> { const metadata = this.item.findMetadataSortedByPlace(metadataField); - const relsCurrentPage$ = this.item.relationships.pipe( - getSucceededRemoteData(), - getRemoteDataPayload(), - map((pl: PaginatedList) => pl.page), - distinctUntilChanged(compareArraysUsingIds()) - ); + const relationships$ = this.relationshipService.getItemRelationshipsByLabel(this.item, relationshipLabel); - return relsCurrentPage$.pipe( + return relationships$.pipe( relationsToRepresentations(this.item.id, itemType, metadata) ); } diff --git a/src/app/entity-groups/journal-entities/item-pages/journal-issue/journal-issue.component.html b/src/app/entity-groups/journal-entities/item-pages/journal-issue/journal-issue.component.html index eebd3e03c8..b69827cd96 100644 --- a/src/app/entity-groups/journal-entities/item-pages/journal-issue/journal-issue.component.html +++ b/src/app/entity-groups/journal-entities/item-pages/journal-issue/journal-issue.component.html @@ -29,12 +29,12 @@
; + volumes$: Observable>>; /** * The publications related to this journal issue */ - publications$: Observable; + publications$: Observable>>; ngOnInit(): void { - super.ngOnInit(); - - if (isNotEmpty(this.resolvedRelsAndTypes$)) { - this.volumes$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isJournalVolumeOfIssue') - ); - this.publications$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isPublicationOfJournalIssue') - ); - } + this.volumes$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isJournalVolumeOfIssue'); + this.publications$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isPublicationOfJournalIssue'); } } diff --git a/src/app/entity-groups/journal-entities/item-pages/journal-volume/journal-volume.component.html b/src/app/entity-groups/journal-entities/item-pages/journal-volume/journal-volume.component.html index 83626c7ae7..902b0e9d73 100644 --- a/src/app/entity-groups/journal-entities/item-pages/journal-volume/journal-volume.component.html +++ b/src/app/entity-groups/journal-entities/item-pages/journal-volume/journal-volume.component.html @@ -17,11 +17,11 @@
; + journals$: Observable>>; /** * The journal issues related to this journal volume */ - issues$: Observable; + issues$: Observable>>; ngOnInit(): void { - super.ngOnInit(); - - if (isNotEmpty(this.resolvedRelsAndTypes$)) { - this.journals$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isJournalOfVolume') - ); - this.issues$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isIssueOfJournalVolume') - ); - } + this.journals$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isJournalOfVolume'); + this.issues$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isIssueOfJournalVolume'); } } diff --git a/src/app/entity-groups/journal-entities/item-pages/journal/journal.component.html b/src/app/entity-groups/journal-entities/item-pages/journal/journal.component.html index a82d3c5df6..ee212d9be6 100644 --- a/src/app/entity-groups/journal-entities/item-pages/journal/journal.component.html +++ b/src/app/entity-groups/journal-entities/item-pages/journal/journal.component.html @@ -21,7 +21,7 @@
; + volumes$: Observable>>; ngOnInit(): void { - super.ngOnInit(); - - if (isNotEmpty(this.resolvedRelsAndTypes$)) { - this.volumes$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isVolumeOfJournal') - ); - } + this.volumes$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isVolumeOfJournal'); } } diff --git a/src/app/entity-groups/research-entities/item-pages/orgunit/orgunit.component.html b/src/app/entity-groups/research-entities/item-pages/orgunit/orgunit.component.html index 92ac3eac30..91e9fa0374 100644 --- a/src/app/entity-groups/research-entities/item-pages/orgunit/orgunit.component.html +++ b/src/app/entity-groups/research-entities/item-pages/orgunit/orgunit.component.html @@ -25,15 +25,15 @@
; + people$: Observable>>; /** * The projects related to this organisation unit */ - projects$: Observable; + projects$: Observable>>; /** * The publications related to this organisation unit */ - publications$: Observable; + publications$: Observable>>; ngOnInit(): void { - super.ngOnInit(); - - if (isNotEmpty(this.resolvedRelsAndTypes$)) { - this.people$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isPersonOfOrgUnit') - ); - - this.projects$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isProjectOfOrgUnit') - ); - - this.publications$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isPublicationOfOrgUnit') - ); - } - }} + this.people$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isPersonOfOrgUnit'); + this.projects$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isProjectOfOrgUnit'); + this.publications$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isPublicationOfOrgUnit'); + } +} diff --git a/src/app/entity-groups/research-entities/item-pages/person/person.component.html b/src/app/entity-groups/research-entities/item-pages/person/person.component.html index 04d7b9e062..ba6b83bbf6 100644 --- a/src/app/entity-groups/research-entities/item-pages/person/person.component.html +++ b/src/app/entity-groups/research-entities/item-pages/person/person.component.html @@ -25,11 +25,11 @@
; + publications$: Observable>>; /** * The projects related to this person */ - projects$: Observable; + projects$: Observable>>; /** * The organisation units related to this person */ - orgUnits$: Observable; + orgUnits$: Observable>>; - /** - * The applied fixed filter - */ - fixedFilter$: Observable; - - /** - * The query used for applying the fixed filter - */ - fixedFilterQuery: string; - - constructor( - @Inject(ITEM) public item: Item, - public relationshipService: RelationshipService, - private fixedFilterService: SearchFixedFilterService - ) { - super(item, relationshipService); - } ngOnInit(): void { - super.ngOnInit(); - - if (isNotEmpty(this.resolvedRelsAndTypes$)) { - this.publications$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isPublicationOfAuthor') - ); - - this.projects$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isProjectOfPerson') - ); - - this.orgUnits$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isOrgUnitOfPerson') - ); - - this.fixedFilterQuery = this.fixedFilterService.getQueryByRelations('isAuthorOfPublication', this.item.id); - this.fixedFilter$ = observableOf('publication'); - } + this.publications$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isPublicationOfAuthor'); + this.projects$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isProjectOfPerson'); + this.orgUnits$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isOrgUnitOfPerson'); } } diff --git a/src/app/entity-groups/research-entities/item-pages/project/project.component.html b/src/app/entity-groups/research-entities/item-pages/project/project.component.html index 4e9a130b8c..c6eb0690ce 100644 --- a/src/app/entity-groups/research-entities/item-pages/project/project.component.html +++ b/src/app/entity-groups/research-entities/item-pages/project/project.component.html @@ -12,7 +12,7 @@ + [representations]="(contributors$ | async)?.payload?.page">
; + contributors$: Observable>>; /** * The people related to this project */ - people$: Observable; + people$: Observable>>; /** * The publications related to this project */ - publications$: Observable; + publications$: Observable>>; /** * The organisation units related to this project */ - orgUnits$: Observable; + orgUnits$: Observable>>; ngOnInit(): void { - super.ngOnInit(); + this.contributors$ = this.buildRepresentations('OrgUnit', 'project.contributor.other', 'isOrgUnitOfProject'); - if (isNotEmpty(this.resolvedRelsAndTypes$)) { - this.contributors$ = this.buildRepresentations('OrgUnit', 'project.contributor.other'); - - this.people$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isPersonOfProject') - ); - - this.publications$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isPublicationOfProject') - ); - - this.orgUnits$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isOrgUnitOfProject') - ); - } + this.people$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isPersonOfProject'); + this.publications$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isPublicationOfProject'); + this.orgUnits$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isOrgUnitOfProject'); } }