mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
64574: Further refactoring of item-component, mantis publication and JSDocs
This commit is contained in:
@@ -7,13 +7,13 @@ import { hasNoValue, hasValue } from '../../../../shared/empty.util';
|
||||
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, filter, flatMap, map, switchMap, tap } from 'rxjs/operators';
|
||||
import { of as observableOf, zip as observableZip, combineLatest as observableCombineLatest } from 'rxjs';
|
||||
import { ItemDataService } from '../../../../core/data/item-data.service';
|
||||
import { distinctUntilChanged, filter, flatMap, map, switchMap } from 'rxjs/operators';
|
||||
import { zip as observableZip, combineLatest as observableCombineLatest } from 'rxjs';
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
import { RemoteData } from '../../../../core/data/remote-data';
|
||||
import { RelationshipService } from '../../../../core/data/relationship.service';
|
||||
import { PaginatedList } from '../../../../core/data/paginated-list';
|
||||
import { of } from 'rxjs/internal/observable/of';
|
||||
|
||||
/**
|
||||
* Operator for comparing arrays using a mapping function
|
||||
@@ -100,6 +100,12 @@ export const relationsToItems = (thisId: string) =>
|
||||
distinctUntilChanged(compareArraysUsingIds()),
|
||||
);
|
||||
|
||||
/**
|
||||
* Operator for turning a paginated list of relationships into a paginated list of the relevant items
|
||||
* The result is wrapped in the original RemoteData and PaginatedList
|
||||
* @param {string} thisId The item's id of which the relations belong to
|
||||
* @returns {(source: Observable<Relationship[]>) => Observable<Item[]>}
|
||||
*/
|
||||
export const paginatedRelationsToItems = (thisId: string) =>
|
||||
(source: Observable<RemoteData<PaginatedList<Relationship>>>): Observable<RemoteData<PaginatedList<Item>>> =>
|
||||
source.pipe(
|
||||
@@ -128,39 +134,27 @@ export const paginatedRelationsToItems = (thisId: string) =>
|
||||
})
|
||||
);
|
||||
|
||||
/**
|
||||
* Operator for turning a list of relationships and their relationship-types into a list of relevant items by relationship label
|
||||
* @param thisId The item's id of which the relations belong to
|
||||
* @param label The label of the relationship-type to filter on
|
||||
* @param side Filter only on one side of the relationship (for example: child-parent relationships)
|
||||
*/
|
||||
export const getRelatedItemsByTypeLabel = (thisId: string, label: string) =>
|
||||
(source: Observable<[Relationship[], RelationshipType[]]>): Observable<Item[]> =>
|
||||
source.pipe(
|
||||
filterRelationsByTypeLabel(label, thisId),
|
||||
relationsToItems(thisId)
|
||||
);
|
||||
|
||||
/**
|
||||
* Operator for turning a list of relationships into a list of metadatarepresentations given the original metadata
|
||||
* The result is wrapped in the original RemoteData and PaginatedList
|
||||
* @param parentId The id of the parent item
|
||||
* @param itemType The type of relation this list resembles (for creating representations)
|
||||
* @param metadata The list of original Metadatum objects
|
||||
* @param ids The ItemDataService to use for fetching Items from the Rest API
|
||||
*/
|
||||
export const relationsToRepresentations = (parentId: string, itemType: string, metadata: MetadataValue[], ids: ItemDataService) =>
|
||||
(source: Observable<Relationship[]>): Observable<MetadataRepresentation[]> =>
|
||||
export const relationsToRepresentations = (parentId: string, itemType: string, metadata: MetadataValue[]) =>
|
||||
(source: Observable<RemoteData<PaginatedList<Relationship>>>): Observable<RemoteData<PaginatedList<MetadataRepresentation>>> =>
|
||||
source.pipe(
|
||||
flatMap((rels: Relationship[]) =>
|
||||
flatMap((relRD: RemoteData<PaginatedList<Relationship>>) =>
|
||||
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(
|
||||
filter(([leftItem, rightItem]) => leftItem.hasSucceeded && rightItem.hasSucceeded),
|
||||
map(([leftItem, rightItem]) => {
|
||||
if (leftItem.payload.id === parentId) {
|
||||
return rightItem.payload;
|
||||
@@ -172,9 +166,12 @@ export const relationsToRepresentations = (parentId: string, itemType: string, m
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return observableOf(Object.assign(new MetadatumRepresentation(itemType), metadatum));
|
||||
return of(Object.assign(new MetadatumRepresentation(itemType), metadatum));
|
||||
}
|
||||
})
|
||||
).pipe(
|
||||
distinctUntilChanged(compareArraysUsingIds()),
|
||||
map((representations: MetadataRepresentation[]) => Object.assign(relRD, { payload: { page: representations } }))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
@@ -1,57 +1,12 @@
|
||||
import { Component, Inject } from '@angular/core';
|
||||
import { Observable , zip as observableZip, combineLatest as observableCombineLatest } from 'rxjs';
|
||||
import { filter, flatMap, map } from 'rxjs/operators';
|
||||
import { Observable } from 'rxjs';
|
||||
import { PaginatedList } from '../../../../core/data/paginated-list';
|
||||
import { RemoteData } from '../../../../core/data/remote-data';
|
||||
import { Relationship } from '../../../../core/shared/item-relationships/relationship.model';
|
||||
import { Item } from '../../../../core/shared/item.model';
|
||||
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 { RelationshipService } from '../../../../core/data/relationship.service';
|
||||
|
||||
/**
|
||||
* Operator for turning a list of relationships into a list of metadatarepresentations given the original metadata
|
||||
* @param thisId The id of the parent item
|
||||
* @param itemType The type of relation this list resembles (for creating representations)
|
||||
* @param metadata The list of original Metadatum objects
|
||||
*/
|
||||
export const relationsToRepresentations = (thisId: string, itemType: string, metadata: MetadataValue[]) =>
|
||||
(source: Observable<RemoteData<PaginatedList<Relationship>>>): Observable<RemoteData<PaginatedList<MetadataRepresentation>>> =>
|
||||
source.pipe(
|
||||
flatMap((relRD: RemoteData<PaginatedList<Relationship>>) =>
|
||||
observableZip(
|
||||
...metadata
|
||||
.map((metadatum: any) => Object.assign(new MetadataValue(), metadatum))
|
||||
.map((metadatum: MetadataValue) => {
|
||||
if (metadatum.isVirtual) {
|
||||
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(
|
||||
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;
|
||||
}
|
||||
}),
|
||||
map((item: Item) => Object.assign(new ItemMetadataRepresentation(), item))
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return of(Object.assign(new MetadatumRepresentation(itemType), metadatum));
|
||||
}
|
||||
})
|
||||
).pipe(
|
||||
map((representations: MetadataRepresentation[]) => Object.assign(relRD, { payload: { page: representations } }))
|
||||
)
|
||||
)
|
||||
);
|
||||
import { relationsToRepresentations } from './item-relationships-utils';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-item',
|
||||
|
@@ -62,19 +62,19 @@
|
||||
<div class="row">
|
||||
<div class="col-12 col-md-4" *ngIf="projects$ | async">
|
||||
<ds-related-items
|
||||
[items]="projects$ | async"
|
||||
[items]="(projects$ | async)?.payload?.page"
|
||||
[label]="'relationships.isProjectOf' | translate">
|
||||
</ds-related-items>
|
||||
</div>
|
||||
<div class="col-12 col-md-4" *ngIf="orgUnits$ | async">
|
||||
<ds-related-items
|
||||
[items]="orgUnits$ | async"
|
||||
[items]="(orgUnits$ | async)?.payload?.page"
|
||||
[label]="'relationships.isOrgUnitOf' | translate">
|
||||
</ds-related-items>
|
||||
</div>
|
||||
<div class="col-12 col-md-4" *ngIf="journalIssues$ | async">
|
||||
<ds-related-items
|
||||
[items]="journalIssues$ | async"
|
||||
[items]="(journalIssues$ | async)?.payload?.page"
|
||||
[label]="'relationships.isJournalIssueOf' | translate">
|
||||
</ds-related-items>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user