add support for multiple metadata fields to the MetadataRepresentationListComponent

This commit is contained in:
Samuel
2021-05-25 11:51:19 +02:00
parent 7e129f282f
commit 21686c86df
6 changed files with 19 additions and 11 deletions

View File

@@ -21,7 +21,7 @@
<ds-metadata-representation-list class="ds-item-page-mixed-author-field" <ds-metadata-representation-list class="ds-item-page-mixed-author-field"
[parentItem]="object" [parentItem]="object"
[itemType]="'Person'" [itemType]="'Person'"
[metadataField]="'dc.contributor.author'" [metadataFields]="['dc.contributor.author', 'dc.creator']"
[label]="'relationships.isAuthorOf' | translate"> [label]="'relationships.isAuthorOf' | translate">
</ds-metadata-representation-list> </ds-metadata-representation-list>
<ds-generic-item-page-field [item]="object" <ds-generic-item-page-field [item]="object"

View File

@@ -21,7 +21,7 @@
<ds-metadata-representation-list class="ds-item-page-mixed-author-field" <ds-metadata-representation-list class="ds-item-page-mixed-author-field"
[parentItem]="object" [parentItem]="object"
[itemType]="'Person'" [itemType]="'Person'"
[metadataField]="'dc.contributor.author'" [metadataFields]="['dc.contributor.author', 'dc.creator']"
[label]="'relationships.isAuthorOf' | translate"> [label]="'relationships.isAuthorOf' | translate">
</ds-metadata-representation-list> </ds-metadata-representation-list>
<ds-generic-item-page-field [item]="object" <ds-generic-item-page-field [item]="object"

View File

@@ -11,7 +11,7 @@ import { VarDirective } from '../../../shared/utils/var.directive';
import { of as observableOf } from 'rxjs'; import { of as observableOf } from 'rxjs';
const itemType = 'Person'; const itemType = 'Person';
const metadataField = 'dc.contributor.author'; const metadataFields = ['dc.contributor.author', 'dc.creator'];
const parentItem: Item = Object.assign(new Item(), { const parentItem: Item = Object.assign(new Item(), {
id: 'parent-item', id: 'parent-item',
metadata: { metadata: {
@@ -28,6 +28,14 @@ const parentItem: Item = Object.assign(new Item(), {
place: 1 place: 1
} }
], ],
'dc.creator': [
{
language: null,
value: 'Related Creator with authority',
authority: 'virtual::related-creator',
place: 3,
},
],
'dc.title': [ 'dc.title': [
{ {
language: null, language: null,
@@ -81,13 +89,13 @@ describe('MetadataRepresentationListComponent', () => {
comp = fixture.componentInstance; comp = fixture.componentInstance;
comp.parentItem = parentItem; comp.parentItem = parentItem;
comp.itemType = itemType; comp.itemType = itemType;
comp.metadataField = metadataField; comp.metadataFields = metadataFields;
fixture.detectChanges(); fixture.detectChanges();
})); }));
it('should load 2 ds-metadata-representation-loader components', () => { it('should load 3 ds-metadata-representation-loader components', () => {
const fields = fixture.debugElement.queryAll(By.css('ds-metadata-representation-loader')); const fields = fixture.debugElement.queryAll(By.css('ds-metadata-representation-loader'));
expect(fields.length).toBe(2); expect(fields.length).toBe(3);
}); });
it('should contain one page of items', () => { it('should contain one page of items', () => {

View File

@@ -42,7 +42,7 @@ export class MetadataRepresentationListComponent extends AbstractIncrementalList
/** /**
* The metadata field to use for fetching metadata from the item * The metadata field to use for fetching metadata from the item
*/ */
@Input() metadataField: string; @Input() metadataFields: string[];
/** /**
* An i18n label to use as a title for the list * An i18n label to use as a title for the list
@@ -70,7 +70,7 @@ export class MetadataRepresentationListComponent extends AbstractIncrementalList
* @param page The page to fetch * @param page The page to fetch
*/ */
getPage(page: number): Observable<MetadataRepresentation[]> { getPage(page: number): Observable<MetadataRepresentation[]> {
const metadata = this.parentItem.findMetadataSortedByPlace(this.metadataField); const metadata = this.parentItem.findMetadataSortedByPlace(this.metadataFields);
this.total = metadata.length; this.total = metadata.length;
return this.resolveMetadataRepresentations(metadata, page); return this.resolveMetadataRepresentations(metadata, page);
} }

View File

@@ -163,8 +163,8 @@ export class DSpaceObject extends ListableObject implements CacheableObject {
* Find metadata on a specific field and order all of them using their "place" property. * Find metadata on a specific field and order all of them using their "place" property.
* @param key * @param key
*/ */
findMetadataSortedByPlace(key: string): MetadataValue[] { findMetadataSortedByPlace(keyOrKeys: string | string[]): MetadataValue[] {
return this.allMetadata([key]).sort((a: MetadataValue, b: MetadataValue) => { return this.allMetadata(keyOrKeys).sort((a: MetadataValue, b: MetadataValue) => {
if (hasNoValue(a.place) && hasNoValue(b.place)) { if (hasNoValue(a.place) && hasNoValue(b.place)) {
return 0; return 0;
} }

View File

@@ -18,7 +18,7 @@
<ds-metadata-representation-list <ds-metadata-representation-list
[parentItem]="object" [parentItem]="object"
[itemType]="'OrgUnit'" [itemType]="'OrgUnit'"
[metadataField]="'project.contributor.other'" [metadataFields]="['project.contributor.other']"
[label]="'project.page.contributor' | translate"> [label]="'project.page.contributor' | translate">
</ds-metadata-representation-list> </ds-metadata-representation-list>
<ds-generic-item-page-field [item]="object" <ds-generic-item-page-field [item]="object"