Skip to content
Snippets Groups Projects
Commit 21953a07 authored by Art Lowel's avatar Art Lowel
Browse files

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

parent 093a8e96
No related branches found
No related tags found
No related merge requests found
Showing
with 47 additions and 13 deletions
......@@ -41,7 +41,7 @@ export const relationsToRepresentations = (thisId: string, itemType: string, met
}
return ids.findById(queryId).pipe(
getSucceededRemoteData(),
map((d: RemoteData<Item>) => Object.assign(new ItemMetadataRepresentation(itemType), d.payload))
map((d: RemoteData<Item>) => Object.assign(new ItemMetadataRepresentation(), d.payload))
);
}
} else {
......
......@@ -7,7 +7,7 @@ import { ItemMetadataRepresentation } from '../../../core/shared/metadata-repres
const itemType = 'type';
const metadataRepresentation1 = new MetadatumRepresentation(itemType);
const metadataRepresentation2 = new ItemMetadataRepresentation(itemType);
const metadataRepresentation2 = new ItemMetadataRepresentation();
const representations = [metadataRepresentation1, metadataRepresentation2];
describe('MetadataRepresentationListComponent', () => {
......
......@@ -16,9 +16,15 @@ describe('ItemMetadataRepresentation', () => {
item.metadata = metadataMap;
for (const itemType of Object.keys(ItemTypeToValue)) {
describe(`when creating an ItemMetadataRepresentation with item-type "${itemType}"`, () => {
describe(`when creating an ItemMetadataRepresentation`, () => {
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', () => {
......@@ -30,7 +36,7 @@ describe('ItemMetadataRepresentation', () => {
});
it('should return the correct item type', () => {
expect(itemMetadataRepresentation.itemType).toEqual(itemType);
expect(itemMetadataRepresentation.itemType).toEqual(item.firstMetadataValue('relationship.type'));
});
});
}
......
......@@ -7,7 +7,8 @@ import { hasValue } from '../../../../shared/empty.util';
*/
export const ItemTypeToValue = {
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
*/
itemType: string;
constructor(itemType: string) {
super();
this.itemType = itemType;
get itemType(): string {
return this.firstMetadataValue('relationship.type');
}
/**
......
......@@ -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;
describe('ItemTypeSwitcherComponent', () => {
......
<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>
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 {
}
......@@ -5,7 +5,7 @@ import { ItemMetadataListElementComponent } from './item-metadata-list-element.c
import { By } from '@angular/platform-browser';
import { ItemMetadataRepresentation } from '../../../../core/shared/metadata-representation/item/item-metadata-representation.model';
const mockItemMetadataRepresentation = new ItemMetadataRepresentation('type');
const mockItemMetadataRepresentation = new ItemMetadataRepresentation();
describe('ItemMetadataListElementComponent', () => {
let comp: ItemMetadataListElementComponent;
......
......@@ -10,6 +10,7 @@ import { TranslateModule } from '@ngx-translate/core';
import { NgxPaginationModule } from 'ngx-pagination';
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 { 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';
......@@ -247,6 +248,7 @@ const ENTRY_COMPONENTS = [
PublicationListElementComponent,
PersonListElementComponent,
PersonMetadataListElementComponent,
OrgUnitMetadataListElementComponent,
OrgUnitListElementComponent,
ProjectListElementComponent,
JournalListElementComponent,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment