Merge branch 'master' into w2p-65195_dynamic-component-refactoring

This commit is contained in:
lotte
2019-11-07 14:23:36 +01:00
12 changed files with 62 additions and 86 deletions

View File

@@ -1,6 +1,6 @@
dspace.dir=/dspace dspace.dir=/dspace
db.url=jdbc:postgresql://dspacedb:5432/dspace db.url=jdbc:postgresql://dspacedb:5432/dspace
dspace.hostname=dspace dspace.hostname=dspace
dspace.baseUrl=http://localhost:8080 dspace.baseUrl=http://localhost:8080/server
dspace.name=DSpace Started with Docker Compose dspace.name=DSpace Started with Docker Compose
solr.server=http://dspacesolr:8983/solr solr.server=http://dspacesolr:8983/solr

View File

@@ -236,7 +236,7 @@
"tslint": "5.11.0", "tslint": "5.11.0",
"typedoc": "^0.9.0", "typedoc": "^0.9.0",
"typescript": "^2.9.1", "typescript": "^2.9.1",
"webdriver-manager": "^12.1.6", "webdriver-manager": "^12.1.7",
"webpack": "^4.17.1", "webpack": "^4.17.1",
"webpack-bundle-analyzer": "^3.3.2", "webpack-bundle-analyzer": "^3.3.2",
"webpack-dev-middleware": "3.2.0", "webpack-dev-middleware": "3.2.0",

View File

@@ -117,9 +117,8 @@ export const getRelatedItemsByTypeLabel = (thisId: string, label: string) =>
* @param parentId The id of the parent item * @param parentId The id of the parent item
* @param itemType The type of relation this list resembles (for creating representations) * @param itemType The type of relation this list resembles (for creating representations)
* @param metadata The list of original Metadatum objects * @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) => export const relationsToRepresentations = (parentId: string, itemType: string, metadata: MetadataValue[]) =>
(source: Observable<Relationship[]>): Observable<MetadataRepresentation[]> => (source: Observable<Relationship[]>): Observable<MetadataRepresentation[]> =>
source.pipe( source.pipe(
flatMap((rels: Relationship[]) => flatMap((rels: Relationship[]) =>
@@ -139,7 +138,7 @@ export const relationsToRepresentations = (parentId: string, itemType: string, m
return leftItem.payload; return leftItem.payload;
} }
}), }),
map((item: Item) => Object.assign(new ItemMetadataRepresentation(), item)) map((item: Item) => Object.assign(new ItemMetadataRepresentation(metadatum), item))
); );
} }
} else { } else {

View File

@@ -407,7 +407,7 @@ describe('ItemComponent', () => {
representations.subscribe((reps: MetadataRepresentation[]) => { representations.subscribe((reps: MetadataRepresentation[]) => {
expect(reps[0].getValue()).toEqual('First value'); expect(reps[0].getValue()).toEqual('First value');
expect(reps[1].getValue()).toEqual('Second value'); expect(reps[1].getValue()).toEqual('Second value');
expect(reps[2].getValue()).toEqual('related item'); expect(reps[2].getValue()).toEqual('Third value');
expect(reps[3].getValue()).toEqual('Fourth value'); expect(reps[3].getValue()).toEqual('Fourth value');
}); });
}); });

View File

@@ -8,49 +8,7 @@ import { Relationship } from '../../../../core/shared/item-relationships/relatio
import { Item } from '../../../../core/shared/item.model'; import { Item } from '../../../../core/shared/item.model';
import { getRemoteDataPayload, getSucceededRemoteData } from '../../../../core/shared/operators'; import { getRemoteDataPayload, getSucceededRemoteData } from '../../../../core/shared/operators';
import { MetadataRepresentation } from '../../../../core/shared/metadata-representation/metadata-representation.model'; import { MetadataRepresentation } from '../../../../core/shared/metadata-representation/metadata-representation.model';
import { ItemMetadataRepresentation } from '../../../../core/shared/metadata-representation/item/item-metadata-representation.model'; import { compareArraysUsingIds, relationsToRepresentations } from './item-relationships-utils';
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';
/**
* 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<Relationship[]>): Observable<MetadataRepresentation[]> =>
source.pipe(
flatMap((rels: 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);
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));
}
})
)
)
);
@Component({ @Component({
selector: 'ds-item', selector: 'ds-item',

View File

@@ -7,7 +7,7 @@ import { ItemMetadataRepresentation } from '../../../core/shared/metadata-repres
const itemType = 'type'; const itemType = 'type';
const metadataRepresentation1 = new MetadatumRepresentation(itemType); const metadataRepresentation1 = new MetadatumRepresentation(itemType);
const metadataRepresentation2 = new ItemMetadataRepresentation(); const metadataRepresentation2 = new ItemMetadataRepresentation(Object.assign({}));
const representations = [metadataRepresentation1, metadataRepresentation2]; const representations = [metadataRepresentation1, metadataRepresentation2];
describe('MetadataRepresentationListComponent', () => { describe('MetadataRepresentationListComponent', () => {

View File

@@ -1,21 +1,27 @@
import { MetadataRepresentationType } from '../metadata-representation.model'; import { MetadataRepresentationType } from '../metadata-representation.model';
import { ItemMetadataRepresentation, ItemTypeToValue } from './item-metadata-representation.model'; import { ItemMetadataRepresentation } from './item-metadata-representation.model';
import { Item } from '../../item.model'; import { Item } from '../../item.model';
import { MetadataMap, MetadataValue } from '../../metadata.models'; import { MetadataValue } from '../../metadata.models';
describe('ItemMetadataRepresentation', () => { describe('ItemMetadataRepresentation', () => {
const valuePrefix = 'Test value for '; const valuePrefix = 'Test value for ';
const item = new Item(); const item = new Item();
const itemType = 'Item Type';
let itemMetadataRepresentation: ItemMetadataRepresentation; let itemMetadataRepresentation: ItemMetadataRepresentation;
const metadataMap = new MetadataMap(); item.metadata = {
for (const key of Object.keys(ItemTypeToValue)) { 'dc.title': [
metadataMap[ItemTypeToValue[key]] = [Object.assign(new MetadataValue(), { {
value: `${valuePrefix}${ItemTypeToValue[key]}` value: `${valuePrefix}dc.title`
})];
} }
item.metadata = metadataMap; ] as MetadataValue[],
'dc.contributor.author': [
{
value: `${valuePrefix}dc.contributor.author`
}
] as MetadataValue[]
};
for (const itemType of Object.keys(ItemTypeToValue)) { for (const metadataField of Object.keys(item.metadata)) {
describe(`when creating an ItemMetadataRepresentation`, () => { describe(`when creating an ItemMetadataRepresentation`, () => {
beforeEach(() => { beforeEach(() => {
item.metadata['relationship.type'] = [ item.metadata['relationship.type'] = [
@@ -23,8 +29,7 @@ describe('ItemMetadataRepresentation', () => {
value: itemType value: itemType
}) })
]; ];
itemMetadataRepresentation = Object.assign(new ItemMetadataRepresentation(item.metadata[metadataField][0]), item);
itemMetadataRepresentation = Object.assign(new ItemMetadataRepresentation(), item);
}); });
it('should have a representation type of item', () => { it('should have a representation type of item', () => {
@@ -32,7 +37,7 @@ describe('ItemMetadataRepresentation', () => {
}); });
it('should return the correct value when calling getValue', () => { it('should return the correct value when calling getValue', () => {
expect(itemMetadataRepresentation.getValue()).toEqual(`${valuePrefix}${ItemTypeToValue[itemType]}`); expect(itemMetadataRepresentation.getValue()).toEqual(`${valuePrefix}${metadataField}`);
}); });
it('should return the correct item type', () => { it('should return the correct item type', () => {

View File

@@ -1,21 +1,22 @@
import { Item } from '../../item.model'; import { Item } from '../../item.model';
import { MetadataRepresentation, MetadataRepresentationType } from '../metadata-representation.model'; import { MetadataRepresentation, MetadataRepresentationType } from '../metadata-representation.model';
import { hasValue } from '../../../../shared/empty.util'; import { MetadataValue } from '../../metadata.models';
/**
* An object to convert item types into the metadata field it should render for the item's value
*/
export const ItemTypeToValue = {
Default: 'dc.title',
Person: 'dc.contributor.author',
OrgUnit: 'dc.title'
};
/** /**
* This class determines which fields to use when rendering an Item as a metadata value. * This class determines which fields to use when rendering an Item as a metadata value.
*/ */
export class ItemMetadataRepresentation extends Item implements MetadataRepresentation { export class ItemMetadataRepresentation extends Item implements MetadataRepresentation {
/**
* The virtual metadata value representing this item
*/
virtualMetadata: MetadataValue;
constructor(virtualMetadata: MetadataValue) {
super();
this.virtualMetadata = virtualMetadata;
}
/** /**
* The type of item this item can be represented as * The type of item this item can be represented as
*/ */
@@ -34,13 +35,7 @@ export class ItemMetadataRepresentation extends Item implements MetadataRepresen
* Get the value to display, depending on the itemType * Get the value to display, depending on the itemType
*/ */
getValue(): string { getValue(): string {
let metadata; return this.virtualMetadata.value;
if (hasValue(ItemTypeToValue[this.itemType])) {
metadata = ItemTypeToValue[this.itemType];
} else {
metadata = ItemTypeToValue.Default;
}
return this.firstMetadataValue(metadata);
} }
} }

View File

@@ -4,7 +4,7 @@ import { ItemMetadataListElementComponent } from './item-metadata-list-element.c
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { ItemMetadataRepresentation } from '../../../../core/shared/metadata-representation/item/item-metadata-representation.model'; import { ItemMetadataRepresentation } from '../../../../core/shared/metadata-representation/item/item-metadata-representation.model';
const mockItemMetadataRepresentation = new ItemMetadataRepresentation(); const mockItemMetadataRepresentation = new ItemMetadataRepresentation(Object.assign({}));
describe('ItemMetadataListElementComponent', () => { describe('ItemMetadataListElementComponent', () => {
let comp: ItemMetadataListElementComponent; let comp: ItemMetadataListElementComponent;

View File

@@ -0,0 +1,17 @@
import { MetadataRepresentationListElementComponent } from '../metadata-representation-list-element.component';
import { Component, Inject } from '@angular/core';
import { ITEM } from '../../../items/switcher/item-type-switcher.component';
import { ItemMetadataRepresentation } from '../../../../core/shared/metadata-representation/item/item-metadata-representation.model';
@Component({
selector: 'ds-item-metadata-representation-list-element',
template: ''
})
/**
* An abstract class for displaying a single ItemMetadataRepresentation
*/
export class ItemMetadataRepresentationListElementComponent extends MetadataRepresentationListElementComponent {
constructor(@Inject(ITEM) public metadataRepresentation: ItemMetadataRepresentation) {
super(metadataRepresentation);
}
}

View File

@@ -144,6 +144,7 @@ import { PublicationSearchResultGridElementComponent } from './object-grid/searc
import { ListableObjectDirective } from './object-collection/shared/listable-object/listable-object.directive'; import { ListableObjectDirective } from './object-collection/shared/listable-object/listable-object.directive';
import { CommunitySearchResultGridElementComponent } from './object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component'; import { CommunitySearchResultGridElementComponent } from './object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component';
import { CollectionSearchResultGridElementComponent } from './object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component'; import { CollectionSearchResultGridElementComponent } from './object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component';
import { ItemMetadataRepresentationListElementComponent } from './object-list/metadata-representation-list-element/item/item-metadata-representation-list-element.component';
const MODULES = [ const MODULES = [
// Do NOT include UniversalModule, HttpModule, or JsonpModule here // Do NOT include UniversalModule, HttpModule, or JsonpModule here
@@ -314,7 +315,8 @@ const ENTRY_COMPONENTS = [
StartsWithTextComponent, StartsWithTextComponent,
PlainTextMetadataListElementComponent, PlainTextMetadataListElementComponent,
ItemMetadataListElementComponent, ItemMetadataListElementComponent,
MetadataRepresentationListElementComponent MetadataRepresentationListElementComponent,
ItemMetadataRepresentationListElementComponent
]; ];
const SHARED_ITEM_PAGE_COMPONENTS = [ const SHARED_ITEM_PAGE_COMPONENTS = [

View File

@@ -11355,10 +11355,10 @@ webdriver-manager@^12.0.6:
semver "^5.3.0" semver "^5.3.0"
xml2js "^0.4.17" xml2js "^0.4.17"
webdriver-manager@^12.1.6: webdriver-manager@^12.1.7:
version "12.1.6" version "12.1.7"
resolved "https://registry.yarnpkg.com/webdriver-manager/-/webdriver-manager-12.1.6.tgz#9e5410c506d1a7e0a7aa6af91ba3d5bb37f362b6" resolved "https://registry.yarnpkg.com/webdriver-manager/-/webdriver-manager-12.1.7.tgz#ed4eaee8f906b33c146e869b55e850553a1b1162"
integrity sha512-B1mOycNCrbk7xODw7Jgq/mdD3qzPxMaTsnKIQDy2nXlQoyjTrJTTD0vRpEZI9b8RibPEyQvh9zIZ0M1mpOxS3w== integrity sha512-XINj6b8CYuUYC93SG3xPkxlyUc3IJbD6Vvo75CVGuG9uzsefDzWQrhz0Lq8vbPxtb4d63CZdYophF8k8Or/YiA==
dependencies: dependencies:
adm-zip "^0.4.9" adm-zip "^0.4.9"
chalk "^1.1.1" chalk "^1.1.1"