fix issue where ItemMetadataRepresentations didn't get their entity type from the item

This commit is contained in:
Art Lowel
2019-04-30 11:22:44 +02:00
parent 093a8e967b
commit 21953a07d8
9 changed files with 47 additions and 13 deletions

View File

@@ -41,7 +41,7 @@ export const relationsToRepresentations = (thisId: string, itemType: string, met
} }
return ids.findById(queryId).pipe( return ids.findById(queryId).pipe(
getSucceededRemoteData(), getSucceededRemoteData(),
map((d: RemoteData<Item>) => Object.assign(new ItemMetadataRepresentation(itemType), d.payload)) map((d: RemoteData<Item>) => Object.assign(new ItemMetadataRepresentation(), d.payload))
); );
} }
} else { } else {

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(itemType); const metadataRepresentation2 = new ItemMetadataRepresentation();
const representations = [metadataRepresentation1, metadataRepresentation2]; const representations = [metadataRepresentation1, metadataRepresentation2];
describe('MetadataRepresentationListComponent', () => { describe('MetadataRepresentationListComponent', () => {

View File

@@ -16,9 +16,15 @@ describe('ItemMetadataRepresentation', () => {
item.metadata = metadataMap; item.metadata = metadataMap;
for (const itemType of Object.keys(ItemTypeToValue)) { for (const itemType of Object.keys(ItemTypeToValue)) {
describe(`when creating an ItemMetadataRepresentation with item-type "${itemType}"`, () => { describe(`when creating an ItemMetadataRepresentation`, () => {
beforeEach(() => { beforeEach(() => {
itemMetadataRepresentation = Object.assign(new ItemMetadataRepresentation(itemType), item); item.metadata['relationship.type'] = [
Object.assign(new MetadataValue(), {
value: itemType
})
];
itemMetadataRepresentation = Object.assign(new ItemMetadataRepresentation(), item);
}); });
it('should have a representation type of item', () => { it('should have a representation type of item', () => {
@@ -30,7 +36,7 @@ describe('ItemMetadataRepresentation', () => {
}); });
it('should return the correct item type', () => { it('should return the correct item type', () => {
expect(itemMetadataRepresentation.itemType).toEqual(itemType); expect(itemMetadataRepresentation.itemType).toEqual(item.firstMetadataValue('relationship.type'));
}); });
}); });
} }

View File

@@ -7,7 +7,8 @@ import { hasValue } from '../../../../shared/empty.util';
*/ */
export const ItemTypeToValue = { export const ItemTypeToValue = {
Default: 'dc.title', Default: 'dc.title',
Person: 'dc.contributor.author' Person: 'dc.contributor.author',
OrgUnit: 'dc.title'
}; };
/** /**
@@ -18,11 +19,8 @@ export class ItemMetadataRepresentation extends Item implements MetadataRepresen
/** /**
* The type of item this item can be represented as * The type of item this item can be represented as
*/ */
itemType: string; get itemType(): string {
return this.firstMetadataValue('relationship.type');
constructor(itemType: string) {
super();
this.itemType = itemType;
} }
/** /**

View File

@@ -29,7 +29,7 @@ const mockItem: Item = Object.assign(new Item(), {
] ]
} }
}); });
const mockItemMetadataRepresentation = Object.assign(new ItemMetadataRepresentation(relationType), mockItem); const mockItemMetadataRepresentation = Object.assign(new ItemMetadataRepresentation(), mockItem);
let viewMode = ItemViewMode.Full; let viewMode = ItemViewMode.Full;
describe('ItemTypeSwitcherComponent', () => { describe('ItemTypeSwitcherComponent', () => {

View File

@@ -0,0 +1,13 @@
<ng-template #descTemplate>
<span class="text-muted">
<span *ngIf="item.allMetadata(['orgunit.identifier.description']).length > 0"
class="item-list-job-title">
<span [innerHTML]="firstMetadataValue(['orgunit.identifier.description'])"></span>
</span>
</span>
</ng-template>
<ds-truncatable [id]="item.id">
<a [routerLink]="['/items/' + item.id]"
[innerHTML]="firstMetadataValue('orgunit.identifier.name')"
[tooltip]="descTemplate"></a>
</ds-truncatable>

View File

@@ -0,0 +1,15 @@
import { ItemViewMode, rendersItemType } from '../../../../items/item-type-decorator';
import { Component } from '@angular/core';
import { TypedItemSearchResultListElementComponent } from '../typed-item-search-result-list-element.component';
import { MetadataRepresentationType } from '../../../../../core/shared/metadata-representation/metadata-representation.model';
@rendersItemType('OrgUnit', ItemViewMode.Element, MetadataRepresentationType.Item)
@Component({
selector: 'ds-orgunit-metadata-list-element',
templateUrl: './orgunit-metadata-list-element.component.html'
})
/**
* The component for displaying a list element for an item of the type OrgUnit
*/
export class OrgUnitMetadataListElementComponent extends TypedItemSearchResultListElementComponent {
}

View File

@@ -5,7 +5,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('type'); const mockItemMetadataRepresentation = new ItemMetadataRepresentation();
describe('ItemMetadataListElementComponent', () => { describe('ItemMetadataListElementComponent', () => {
let comp: ItemMetadataListElementComponent; let comp: ItemMetadataListElementComponent;

View File

@@ -10,6 +10,7 @@ import { TranslateModule } from '@ngx-translate/core';
import { NgxPaginationModule } from 'ngx-pagination'; import { NgxPaginationModule } from 'ngx-pagination';
import { ItemTypeSwitcherComponent } from './items/switcher/item-type-switcher.component'; import { ItemTypeSwitcherComponent } from './items/switcher/item-type-switcher.component';
import { OrgUnitMetadataListElementComponent } from './object-list/item-list-element/item-types/orgunit/orgunit-metadata-list-element.component';
import { TypedItemSearchResultListElementComponent } from './object-list/item-list-element/item-types/typed-item-search-result-list-element.component'; import { TypedItemSearchResultListElementComponent } from './object-list/item-list-element/item-types/typed-item-search-result-list-element.component';
import { PublicationListElementComponent } from './object-list/item-list-element/item-types/publication/publication-list-element.component'; import { PublicationListElementComponent } from './object-list/item-list-element/item-types/publication/publication-list-element.component';
import { OrgUnitListElementComponent } from './object-list/item-list-element/item-types/orgunit/orgunit-list-element.component'; import { OrgUnitListElementComponent } from './object-list/item-list-element/item-types/orgunit/orgunit-list-element.component';
@@ -247,6 +248,7 @@ const ENTRY_COMPONENTS = [
PublicationListElementComponent, PublicationListElementComponent,
PersonListElementComponent, PersonListElementComponent,
PersonMetadataListElementComponent, PersonMetadataListElementComponent,
OrgUnitMetadataListElementComponent,
OrgUnitListElementComponent, OrgUnitListElementComponent,
ProjectListElementComponent, ProjectListElementComponent,
JournalListElementComponent, JournalListElementComponent,