Skip to content

Commit e4229e3

Browse files
94481: Use DSONameService to determine the title for the Item page
1 parent e4f483c commit e4229e3

3 files changed

Lines changed: 25 additions & 26 deletions

File tree

src/app/core/breadcrumbs/dso-name.service.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Injectable } from '@angular/core';
2-
import { hasValue } from '../../shared/empty.util';
2+
import { hasValue, isEmpty } from '../../shared/empty.util';
33
import { DSpaceObject } from '../shared/dspace-object.model';
44
import { TranslateService } from '@ngx-translate/core';
55

@@ -27,7 +27,15 @@ export class DSONameService {
2727
*/
2828
private readonly factories = {
2929
Person: (dso: DSpaceObject): string => {
30-
return `${dso.firstMetadataValue('person.familyName')}, ${dso.firstMetadataValue('person.givenName')}`;
30+
const familyName = dso.firstMetadataValue('person.familyName');
31+
const givenName = dso.firstMetadataValue('person.givenName');
32+
if (isEmpty(familyName) && isEmpty(givenName)) {
33+
return dso.firstMetadataValue('dc.title') || dso.name;
34+
} else if (isEmpty(familyName) || isEmpty(givenName)) {
35+
return familyName || givenName;
36+
} else {
37+
return `${familyName}, ${givenName}`;
38+
}
3139
},
3240
OrgUnit: (dso: DSpaceObject): string => {
3341
return dso.firstMetadataValue('organization.legalName');
@@ -52,7 +60,7 @@ export class DSONameService {
5260
if (hasValue(match)) {
5361
return this.factories[match](dso);
5462
} else {
55-
return this.factories.Default(dso);
63+
return this.factories.Default(dso);
5664
}
5765
}
5866

src/app/item-page/simple/field-components/specific-field/title/item-page-title-field.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ <h2 class="item-page-title-field">
22
<div *ngIf="item.firstMetadataValue('dspace.entity.type') as type">
33
{{ type.toLowerCase() + '.page.titleprefix' | translate }}
44
</div>
5-
<ds-metadata-values [mdValues]="item?.allMetadata(fields)"></ds-metadata-values>
5+
<span class="dont-break-out">{{ dsoNameService.getName(item) }}</span>
66
</h2>
Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,25 @@
11
import { Component, Input } from '@angular/core';
22

33
import { Item } from '../../../../../core/shared/item.model';
4-
import { ItemPageFieldComponent } from '../item-page-field.component';
4+
import { DSONameService } from '../../../../../core/breadcrumbs/dso-name.service';
55

66
@Component({
7-
selector: 'ds-item-page-title-field',
8-
templateUrl: './item-page-title-field.component.html'
7+
selector: 'ds-item-page-title-field',
8+
templateUrl: './item-page-title-field.component.html'
99
})
1010
/**
11-
* This component is used for displaying the title (dc.title) of an item
11+
* This component is used for displaying the title (defined by the {@link DSONameService}) of an item
1212
*/
13-
export class ItemPageTitleFieldComponent extends ItemPageFieldComponent {
13+
export class ItemPageTitleFieldComponent {
1414

15-
/**
16-
* The item to display metadata for
17-
*/
18-
@Input() item: Item;
15+
/**
16+
* The item to display metadata for
17+
*/
18+
@Input() item: Item;
1919

20-
/**
21-
* Separator string between multiple values of the metadata fields defined
22-
* @type {string}
23-
*/
24-
separator: string;
25-
26-
/**
27-
* Fields (schema.element.qualifier) used to render their values.
28-
* In this component, we want to display values for metadata 'dc.title'
29-
*/
30-
fields: string[] = [
31-
'dc.title'
32-
];
20+
constructor(
21+
public dsoNameService: DSONameService,
22+
) {
23+
}
3324

3425
}

0 commit comments

Comments
 (0)