mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
62339: itemIds to item remotedata in relationships
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
import { ChangeDetectionStrategy, Component, Inject, OnInit } from '@angular/core';
|
||||
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { ItemDataService } from '../../../../core/data/item-data.service';
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import {
|
||||
DEFAULT_ITEM_TYPE, ItemViewMode,
|
||||
rendersItemType
|
||||
} from '../../../../shared/items/item-type-decorator';
|
||||
import { ITEM } from '../../../../shared/items/switcher/item-type-switcher.component';
|
||||
import { ItemComponent } from '../shared/item.component';
|
||||
import { MetadataRepresentation } from '../../../../core/shared/metadata-representation/metadata-representation.model';
|
||||
import { filterRelationsByTypeLabel, relationsToItems } from '../shared/item-relationships-utils';
|
||||
@@ -40,33 +38,26 @@ export class PublicationComponent extends ItemComponent implements OnInit {
|
||||
*/
|
||||
journalIssues$: Observable<Item[]>;
|
||||
|
||||
constructor(
|
||||
@Inject(ITEM) public item: Item,
|
||||
private ids: ItemDataService
|
||||
) {
|
||||
super(item);
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
super.ngOnInit();
|
||||
|
||||
if (this.resolvedRelsAndTypes$) {
|
||||
|
||||
this.authors$ = this.buildRepresentations('Person', 'dc.contributor.author', this.ids);
|
||||
this.authors$ = this.buildRepresentations('Person', 'dc.contributor.author');
|
||||
|
||||
this.projects$ = this.resolvedRelsAndTypes$.pipe(
|
||||
filterRelationsByTypeLabel('isProjectOfPublication'),
|
||||
relationsToItems(this.item.id, this.ids)
|
||||
relationsToItems(this.item.id)
|
||||
);
|
||||
|
||||
this.orgUnits$ = this.resolvedRelsAndTypes$.pipe(
|
||||
filterRelationsByTypeLabel('isOrgUnitOfPublication'),
|
||||
relationsToItems(this.item.id, this.ids)
|
||||
relationsToItems(this.item.id)
|
||||
);
|
||||
|
||||
this.journalIssues$ = this.resolvedRelsAndTypes$.pipe(
|
||||
filterRelationsByTypeLabel('isJournalIssueOfPublication'),
|
||||
relationsToItems(this.item.id, this.ids)
|
||||
relationsToItems(this.item.id)
|
||||
);
|
||||
|
||||
}
|
||||
|
@@ -3,10 +3,8 @@ import { Observable } from 'rxjs/internal/Observable';
|
||||
import { Relationship } from '../../../../core/shared/item-relationships/relationship.model';
|
||||
import { RelationshipType } from '../../../../core/shared/item-relationships/relationship-type.model';
|
||||
import { distinctUntilChanged, flatMap, map } from 'rxjs/operators';
|
||||
import { zip as observableZip } from 'rxjs';
|
||||
import { ItemDataService } from '../../../../core/data/item-data.service';
|
||||
import { zip as observableZip, combineLatest as observableCombineLatest } from 'rxjs';
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import { RemoteData } from '../../../../core/data/remote-data';
|
||||
|
||||
/**
|
||||
* Operator for comparing arrays using a mapping function
|
||||
@@ -55,26 +53,25 @@ export const filterRelationsByTypeLabel = (label: string) =>
|
||||
/**
|
||||
* Operator for turning a list of relationships into a list of the relevant items
|
||||
* @param {string} thisId The item's id of which the relations belong to
|
||||
* @param {ItemDataService} ids The ItemDataService to fetch items from the REST API
|
||||
* @returns {(source: Observable<Relationship[]>) => Observable<Item[]>}
|
||||
*/
|
||||
export const relationsToItems = (thisId: string, ids: ItemDataService) =>
|
||||
export const relationsToItems = (thisId: string) =>
|
||||
(source: Observable<Relationship[]>): Observable<Item[]> =>
|
||||
source.pipe(
|
||||
flatMap((rels: Relationship[]) =>
|
||||
observableZip(
|
||||
...rels.map((rel: Relationship) => {
|
||||
let queryId = rel.leftId;
|
||||
if (rel.leftId === thisId) {
|
||||
queryId = rel.rightId;
|
||||
}
|
||||
return ids.findById(queryId);
|
||||
})
|
||||
...rels.map((rel: Relationship) => observableCombineLatest(rel.leftItem, rel.rightItem))
|
||||
)
|
||||
),
|
||||
map((arr: Array<RemoteData<Item>>) =>
|
||||
map((arr) =>
|
||||
arr
|
||||
.filter((d: RemoteData<Item>) => d.hasSucceeded)
|
||||
.map((d: RemoteData<Item>) => d.payload)),
|
||||
.filter(([leftItem, rightItem]) => leftItem.hasSucceeded && rightItem.hasSucceeded)
|
||||
.map(([leftItem, rightItem]) => {
|
||||
if (leftItem.payload.id === thisId) {
|
||||
return rightItem.payload;
|
||||
} else if (rightItem.payload.id === thisId) {
|
||||
return leftItem.payload;
|
||||
}
|
||||
})),
|
||||
distinctUntilChanged(compareArraysUsingIds()),
|
||||
);
|
||||
|
@@ -23,7 +23,7 @@ import { compareArraysUsingIds } from './item-relationships-utils';
|
||||
* @param metadata The list of original Metadatum objects
|
||||
* @param ids The ItemDataService to use for fetching Items from the Rest API
|
||||
*/
|
||||
export const relationsToRepresentations = (thisId: string, itemType: string, metadata: MetadataValue[], ids: ItemDataService) =>
|
||||
export const relationsToRepresentations = (thisId: string, itemType: string, metadata: MetadataValue[]) =>
|
||||
(source: Observable<Relationship[]>): Observable<MetadataRepresentation[]> =>
|
||||
source.pipe(
|
||||
flatMap((rels: Relationship[]) =>
|
||||
@@ -35,13 +35,16 @@ export const relationsToRepresentations = (thisId: string, itemType: string, met
|
||||
const matchingRels = rels.filter((rel: Relationship) => ('' + rel.id) === metadatum.virtualValue);
|
||||
if (matchingRels.length > 0) {
|
||||
const matchingRel = matchingRels[0];
|
||||
let queryId = matchingRel.leftId;
|
||||
if (matchingRel.leftId === thisId) {
|
||||
queryId = matchingRel.rightId;
|
||||
return observableCombineLatest(matchingRel.leftItem, matchingRel.rightItem).pipe(
|
||||
filter(([leftItem, rightItem]) => leftItem.hasSucceeded && rightItem.hasSucceeded),
|
||||
map(([leftItem, rightItem]) => {
|
||||
if (leftItem.payload.id === thisId) {
|
||||
return rightItem.payload;
|
||||
} else if (rightItem.payload.id === thisId) {
|
||||
return leftItem.payload;
|
||||
}
|
||||
return ids.findById(queryId).pipe(
|
||||
getSucceededRemoteData(),
|
||||
map((d: RemoteData<Item>) => Object.assign(new ItemMetadataRepresentation(), d.payload))
|
||||
}),
|
||||
map((item: Item) => Object.assign(new ItemMetadataRepresentation(), item))
|
||||
);
|
||||
}
|
||||
} else {
|
||||
@@ -102,7 +105,7 @@ export class ItemComponent implements OnInit {
|
||||
* @param metadataField The metadata field that resembles the item type.
|
||||
* @param itemDataService ItemDataService to turn relations into items.
|
||||
*/
|
||||
buildRepresentations(itemType: string, metadataField: string, itemDataService: ItemDataService): Observable<MetadataRepresentation[]> {
|
||||
buildRepresentations(itemType: string, metadataField: string): Observable<MetadataRepresentation[]> {
|
||||
const metadata = this.item.findMetadataSortedByPlace(metadataField);
|
||||
const relsCurrentPage$ = this.item.relationships.pipe(
|
||||
getSucceededRemoteData(),
|
||||
@@ -112,7 +115,7 @@ export class ItemComponent implements OnInit {
|
||||
);
|
||||
|
||||
return relsCurrentPage$.pipe(
|
||||
relationsToRepresentations(this.item.id, itemType, metadata, itemDataService)
|
||||
relationsToRepresentations(this.item.id, itemType, metadata)
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -18,17 +18,13 @@ export class NormalizedRelationship extends NormalizedObject<Relationship> {
|
||||
@autoserialize
|
||||
id: string;
|
||||
|
||||
/**
|
||||
* The identifier of the Item to the left side of this Relationship
|
||||
*/
|
||||
@autoserialize
|
||||
leftId: string;
|
||||
@relationship(ResourceType.Item, false)
|
||||
leftItem: string;
|
||||
|
||||
/**
|
||||
* The identifier of the Item to the right side of this Relationship
|
||||
*/
|
||||
@autoserialize
|
||||
rightId: string;
|
||||
@relationship(ResourceType.Item, false)
|
||||
rightItem: string;
|
||||
|
||||
/**
|
||||
* The place of the Item to the left side of this Relationship
|
||||
|
@@ -3,6 +3,7 @@ import { CacheableObject } from '../../cache/object-cache.reducer';
|
||||
import { RemoteData } from '../../data/remote-data';
|
||||
import { ResourceType } from '../resource-type';
|
||||
import { RelationshipType } from './relationship-type.model';
|
||||
import { Item } from '../item.model';
|
||||
|
||||
/**
|
||||
* Describes a Relationship between two Items
|
||||
@@ -28,15 +29,9 @@ export class Relationship implements CacheableObject {
|
||||
*/
|
||||
id: string;
|
||||
|
||||
/**
|
||||
* The identifier of the Item to the left side of this Relationship
|
||||
*/
|
||||
leftId: string;
|
||||
leftItem: Observable<RemoteData<Item>>;
|
||||
|
||||
/**
|
||||
* The identifier of the Item to the right side of this Relationship
|
||||
*/
|
||||
rightId: string;
|
||||
rightItem: Observable<RemoteData<Item>>;
|
||||
|
||||
/**
|
||||
* The place of the Item to the left side of this Relationship
|
||||
|
@@ -1,9 +1,7 @@
|
||||
import { Component, Inject } from '@angular/core';
|
||||
import { Component } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { ItemDataService } from '../../../../core/data/item-data.service';
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import { ItemViewMode, rendersItemType } from '../../../../shared/items/item-type-decorator';
|
||||
import { ITEM } from '../../../../shared/items/switcher/item-type-switcher.component';
|
||||
import { isNotEmpty } from '../../../../shared/empty.util';
|
||||
import { ItemComponent } from '../../../../+item-page/simple/item-types/shared/item.component';
|
||||
import {
|
||||
@@ -31,23 +29,17 @@ export class JournalIssueComponent extends ItemComponent {
|
||||
*/
|
||||
publications$: Observable<Item[]>;
|
||||
|
||||
constructor(
|
||||
@Inject(ITEM) public item: Item,
|
||||
private ids: ItemDataService
|
||||
) {
|
||||
super(item);
|
||||
}
|
||||
ngOnInit(): void {
|
||||
super.ngOnInit();
|
||||
|
||||
if (isNotEmpty(this.resolvedRelsAndTypes$)) {
|
||||
this.volumes$ = this.resolvedRelsAndTypes$.pipe(
|
||||
filterRelationsByTypeLabel('isJournalVolumeOfIssue'),
|
||||
relationsToItems(this.item.id, this.ids)
|
||||
relationsToItems(this.item.id)
|
||||
);
|
||||
this.publications$ = this.resolvedRelsAndTypes$.pipe(
|
||||
filterRelationsByTypeLabel('isPublicationOfJournalIssue'),
|
||||
relationsToItems(this.item.id, this.ids)
|
||||
relationsToItems(this.item.id)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,7 @@
|
||||
import { Component, Inject } from '@angular/core';
|
||||
import { Component } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { ItemDataService } from '../../../../core/data/item-data.service';
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import { ItemViewMode, rendersItemType } from '../../../../shared/items/item-type-decorator';
|
||||
import { ITEM } from '../../../../shared/items/switcher/item-type-switcher.component';
|
||||
import { isNotEmpty } from '../../../../shared/empty.util';
|
||||
import { ItemComponent } from '../../../../+item-page/simple/item-types/shared/item.component';
|
||||
import {
|
||||
@@ -31,23 +29,17 @@ export class JournalVolumeComponent extends ItemComponent {
|
||||
*/
|
||||
issues$: Observable<Item[]>;
|
||||
|
||||
constructor(
|
||||
@Inject(ITEM) public item: Item,
|
||||
private ids: ItemDataService
|
||||
) {
|
||||
super(item);
|
||||
}
|
||||
ngOnInit(): void {
|
||||
super.ngOnInit();
|
||||
|
||||
if (isNotEmpty(this.resolvedRelsAndTypes$)) {
|
||||
this.journals$ = this.resolvedRelsAndTypes$.pipe(
|
||||
filterRelationsByTypeLabel('isJournalOfVolume'),
|
||||
relationsToItems(this.item.id, this.ids)
|
||||
relationsToItems(this.item.id)
|
||||
);
|
||||
this.issues$ = this.resolvedRelsAndTypes$.pipe(
|
||||
filterRelationsByTypeLabel('isIssueOfJournalVolume'),
|
||||
relationsToItems(this.item.id, this.ids)
|
||||
relationsToItems(this.item.id)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,7 @@
|
||||
import { Component, Inject } from '@angular/core';
|
||||
import { Component } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { ItemDataService } from '../../../../core/data/item-data.service';
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import { ItemViewMode, rendersItemType } from '../../../../shared/items/item-type-decorator';
|
||||
import { ITEM } from '../../../../shared/items/switcher/item-type-switcher.component';
|
||||
import { isNotEmpty } from '../../../../shared/empty.util';
|
||||
import { ItemComponent } from '../../../../+item-page/simple/item-types/shared/item.component';
|
||||
import {
|
||||
@@ -26,19 +24,13 @@ export class JournalComponent extends ItemComponent {
|
||||
*/
|
||||
volumes$: Observable<Item[]>;
|
||||
|
||||
constructor(
|
||||
@Inject(ITEM) public item: Item,
|
||||
private ids: ItemDataService
|
||||
) {
|
||||
super(item);
|
||||
}
|
||||
ngOnInit(): void {
|
||||
super.ngOnInit();
|
||||
|
||||
if (isNotEmpty(this.resolvedRelsAndTypes$)) {
|
||||
this.volumes$ = this.resolvedRelsAndTypes$.pipe(
|
||||
filterRelationsByTypeLabel('isVolumeOfJournal'),
|
||||
relationsToItems(this.item.id, this.ids)
|
||||
relationsToItems(this.item.id)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,7 @@
|
||||
import { Component, Inject, OnInit } from '@angular/core';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { ItemDataService } from '../../../../core/data/item-data.service';
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import { ItemViewMode, rendersItemType } from '../../../../shared/items/item-type-decorator';
|
||||
import { ITEM } from '../../../../shared/items/switcher/item-type-switcher.component';
|
||||
import { isNotEmpty } from '../../../../shared/empty.util';
|
||||
import { ItemComponent } from '../../../../+item-page/simple/item-types/shared/item.component';
|
||||
import {
|
||||
@@ -36,30 +34,23 @@ export class OrgunitComponent extends ItemComponent implements OnInit {
|
||||
*/
|
||||
publications$: Observable<Item[]>;
|
||||
|
||||
constructor(
|
||||
@Inject(ITEM) public item: Item,
|
||||
private ids: ItemDataService
|
||||
) {
|
||||
super(item);
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
super.ngOnInit();
|
||||
|
||||
if (isNotEmpty(this.resolvedRelsAndTypes$)) {
|
||||
this.people$ = this.resolvedRelsAndTypes$.pipe(
|
||||
filterRelationsByTypeLabel('isPersonOfOrgUnit'),
|
||||
relationsToItems(this.item.id, this.ids)
|
||||
relationsToItems(this.item.id)
|
||||
);
|
||||
|
||||
this.projects$ = this.resolvedRelsAndTypes$.pipe(
|
||||
filterRelationsByTypeLabel('isProjectOfOrgUnit'),
|
||||
relationsToItems(this.item.id, this.ids)
|
||||
relationsToItems(this.item.id)
|
||||
);
|
||||
|
||||
this.publications$ = this.resolvedRelsAndTypes$.pipe(
|
||||
filterRelationsByTypeLabel('isPublicationOfOrgUnit'),
|
||||
relationsToItems(this.item.id, this.ids)
|
||||
relationsToItems(this.item.id)
|
||||
);
|
||||
}
|
||||
}}
|
||||
|
@@ -1,6 +1,5 @@
|
||||
import { Component, Inject } from '@angular/core';
|
||||
import { Observable , of as observableOf } from 'rxjs';
|
||||
import { ItemDataService } from '../../../../core/data/item-data.service';
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import { ItemViewMode, rendersItemType } from '../../../../shared/items/item-type-decorator';
|
||||
import { ITEM } from '../../../../shared/items/switcher/item-type-switcher.component';
|
||||
@@ -49,7 +48,6 @@ export class PersonComponent extends ItemComponent {
|
||||
|
||||
constructor(
|
||||
@Inject(ITEM) public item: Item,
|
||||
private ids: ItemDataService,
|
||||
private fixedFilterService: SearchFixedFilterService
|
||||
) {
|
||||
super(item);
|
||||
@@ -60,17 +58,17 @@ export class PersonComponent extends ItemComponent {
|
||||
if (isNotEmpty(this.resolvedRelsAndTypes$)) {
|
||||
this.publications$ = this.resolvedRelsAndTypes$.pipe(
|
||||
filterRelationsByTypeLabel('isPublicationOfAuthor'),
|
||||
relationsToItems(this.item.id, this.ids)
|
||||
relationsToItems(this.item.id)
|
||||
);
|
||||
|
||||
this.projects$ = this.resolvedRelsAndTypes$.pipe(
|
||||
filterRelationsByTypeLabel('isProjectOfPerson'),
|
||||
relationsToItems(this.item.id, this.ids)
|
||||
relationsToItems(this.item.id)
|
||||
);
|
||||
|
||||
this.orgUnits$ = this.resolvedRelsAndTypes$.pipe(
|
||||
filterRelationsByTypeLabel('isOrgUnitOfPerson'),
|
||||
relationsToItems(this.item.id, this.ids)
|
||||
relationsToItems(this.item.id)
|
||||
);
|
||||
|
||||
this.fixedFilterQuery = this.fixedFilterService.getQueryByRelations('isAuthorOfPublication', this.item.id);
|
||||
|
@@ -1,9 +1,7 @@
|
||||
import { Component, Inject, OnInit } from '@angular/core';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { ItemDataService } from '../../../../core/data/item-data.service';
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import { ItemViewMode, rendersItemType } from '../../../../shared/items/item-type-decorator';
|
||||
import { ITEM } from '../../../../shared/items/switcher/item-type-switcher.component';
|
||||
import { isNotEmpty } from '../../../../shared/empty.util';
|
||||
import { ItemComponent } from '../../../../+item-page/simple/item-types/shared/item.component';
|
||||
import {
|
||||
@@ -36,30 +34,23 @@ export class ProjectComponent extends ItemComponent implements OnInit {
|
||||
*/
|
||||
orgUnits$: Observable<Item[]>;
|
||||
|
||||
constructor(
|
||||
@Inject(ITEM) public item: Item,
|
||||
private ids: ItemDataService
|
||||
) {
|
||||
super(item);
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
super.ngOnInit();
|
||||
|
||||
if (isNotEmpty(this.resolvedRelsAndTypes$)) {
|
||||
this.people$ = this.resolvedRelsAndTypes$.pipe(
|
||||
filterRelationsByTypeLabel('isPersonOfProject'),
|
||||
relationsToItems(this.item.id, this.ids)
|
||||
relationsToItems(this.item.id)
|
||||
);
|
||||
|
||||
this.publications$ = this.resolvedRelsAndTypes$.pipe(
|
||||
filterRelationsByTypeLabel('isPublicationOfProject'),
|
||||
relationsToItems(this.item.id, this.ids)
|
||||
relationsToItems(this.item.id)
|
||||
);
|
||||
|
||||
this.orgUnits$ = this.resolvedRelsAndTypes$.pipe(
|
||||
filterRelationsByTypeLabel('isOrgUnitOfProject'),
|
||||
relationsToItems(this.item.id, this.ids)
|
||||
relationsToItems(this.item.id)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user