forked from rero/rero-ils-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
document: display 'part of' in brief views
* Moves 'part of' template and code to a new component in shared library. This component is used in detailed and brief views. * Closes rero/rero-ils#1596. Co-Authored-by: Alicia Zangger <[email protected]>
- Loading branch information
Alicia Zangger
committed
Feb 3, 2021
1 parent
6fef162
commit 430fb87
Showing
9 changed files
with
224 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
projects/shared/src/lib/view/brief/part-of/part-of.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<!-- | ||
RERO ILS UI | ||
Copyright (C) 2021 RERO | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published by | ||
the Free Software Foundation, version 3 of the License. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
--> | ||
|
||
<ng-container *ngIf="isBrief; else detailedView"> | ||
<ng-container *ngIf="record.metadata.partOf; else seriesStatement"> | ||
<!-- part of --> | ||
<ng-container *ngFor="let partOf of record.metadata.partOf; let i = index"> | ||
<ng-container *ngIf="partOf.document.pid | getRecord: 'documents' : 'object' : '': { 'Content-Type': 'application/rero+json' } | async as hostDocument"> | ||
<div class="mb-0"> | ||
{{ getPartOfLabel(hostDocument) }}: | ||
<a id="{{'doc-part-of-' + i}}" [routerLink]="['/records', 'documents', 'detail', partOf.document.pid]"> | ||
{{ getShortMainTitle(hostDocument.metadata.title) }} | ||
</a> | ||
<ng-container *ngIf="partOf.numbering"> | ||
<span>;</span> | ||
<ul class="list-unstyled mb-0 ml-1"> | ||
<li *ngFor="let numbering of partOf.numbering"> | ||
<span id="{{'doc-part-of-numbering-' + i}}" *ngIf="formatNumbering(numbering) as num">{{ num }}</span> | ||
</li> | ||
</ul> | ||
</ng-container> | ||
</div> | ||
</ng-container> | ||
</ng-container> | ||
</ng-container> | ||
<ng-template #seriesStatement> | ||
<!-- SERIES STATEMENT --> | ||
<ng-container *ngIf="record.metadata.seriesStatement"> | ||
{{ 'Series statement' | translate }}: | ||
<ng-container *ngFor="let serie of getStatement(record.metadata.seriesStatement); last as isLast; let i = index"> | ||
<span id="{{'doc-series-statement-' + i}}">{{ serie.value }}</span> | ||
<span *ngIf="!isLast">; </span> | ||
</ng-container> | ||
</ng-container> | ||
</ng-template> | ||
</ng-container> | ||
<ng-template #detailedView> | ||
<ng-container *ngIf="record.metadata.partOf"> | ||
<!-- part of --> | ||
<ng-container *ngFor="let document of record.metadata.partOf; let i = index"> | ||
<ng-container *ngIf="document.document.pid | getRecord: 'documents' : 'object' : '': { 'Content-Type': 'application/rero+json' } | async as hostDocument"> | ||
<dl class="row mb-0"> | ||
<dt id="{{'doc-part-of-label-' + i}}" class="col-auto"> | ||
{{ getPartOfLabel(hostDocument) }} | ||
</dt> | ||
<dd class="col mb-0"> | ||
<div class="row"> | ||
<a id="{{'doc-part-of-' + i}}" [routerLink]="['/records', 'documents', 'detail', document.document.pid]"> | ||
{{ getShortMainTitle(hostDocument.metadata.title) }} | ||
</a> | ||
<ng-container *ngIf="document.numbering"> | ||
<span>;</span> | ||
<ul class="list-unstyled mb-0 ml-1"> | ||
<li *ngFor="let numbering of document.numbering"> | ||
<span id="{{'doc-part-of-numbering-' + i}}" *ngIf="formatNumbering(numbering) as num">{{ num }}</span> | ||
</li> | ||
</ul> | ||
</ng-container> | ||
</div> | ||
</dd> | ||
</dl> | ||
</ng-container> | ||
</ng-container> | ||
</ng-container> | ||
</ng-template> |
25 changes: 25 additions & 0 deletions
25
projects/shared/src/lib/view/brief/part-of/part-of.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { PartOfComponent } from './part-of.component'; | ||
|
||
describe('PartOfComponent', () => { | ||
let component: PartOfComponent; | ||
let fixture: ComponentFixture<PartOfComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [ PartOfComponent ] | ||
}) | ||
.compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(PartOfComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
110 changes: 110 additions & 0 deletions
110
projects/shared/src/lib/view/brief/part-of/part-of.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { Component, Input } from '@angular/core'; | ||
import { TranslateService } from '@ngx-translate/core'; | ||
|
||
@Component({ | ||
selector: 'shared-part-of', | ||
templateUrl: './part-of.component.html' | ||
}) | ||
export class PartOfComponent { | ||
|
||
/** Document */ | ||
@Input() record: any; | ||
|
||
/** Is it brief or detailed view? */ | ||
@Input() isBrief = true; | ||
|
||
/** Css class for dd in template */ | ||
ddCssClass = 'col-sm-6 col-md-8 mb-0'; | ||
|
||
/** constructor | ||
* @param _translateService - TranslateService to translate some strings. | ||
*/ | ||
constructor( | ||
private _translateService: TranslateService | ||
) { } | ||
|
||
/** | ||
* Get "part of" label from host document type | ||
* @param hostDocument - host document | ||
* @return corresponding translated label | ||
*/ | ||
getPartOfLabel(hostDocument: any) { | ||
switch (hostDocument.metadata.issuance.subtype) { | ||
case 'periodical': | ||
return this._translateService.instant('Journal'); | ||
case 'monographicSeries': | ||
return this._translateService.instant('Series'); | ||
default: | ||
return this._translateService.instant('Published in'); | ||
} | ||
} | ||
|
||
/** | ||
* Get short main title | ||
* @param titles - document titles | ||
* @return - main title to display | ||
*/ | ||
getShortMainTitle(titles: any) { | ||
const bfTitles: Array<any> = titles.filter((title: any) => title.type === 'bf:Title'); | ||
for (const bfTitle of bfTitles) { | ||
for (const mainTitle of bfTitle.mainTitle) { | ||
if (!mainTitle.language) { | ||
return mainTitle.value; | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Format "part of" numbering for display | ||
* | ||
* @param num: numbering to format | ||
* @return formatted numbering (example: 2020, vol. 2, nr. 3, p. 302) | ||
*/ | ||
formatNumbering(num: any) { | ||
const numbering = []; | ||
if (num.year) { | ||
numbering.push(num.year); | ||
} | ||
if (num.volume) { | ||
const volume = [this._translateService.instant('vol'), num.volume]; | ||
numbering.push(volume.join('. ')); | ||
} | ||
if (num.issue) { | ||
const issue = [this._translateService.instant('nr'), num.issue]; | ||
numbering.push(issue.join('. ')); | ||
} | ||
if (num.pages) { | ||
const pages = [this._translateService.instant('p'), num.pages]; | ||
numbering.push(pages.join('. ')); | ||
} | ||
return numbering.join(', '); | ||
} | ||
|
||
/** | ||
* Get list of document edition statement | ||
* @return array - edition statement | ||
*/ | ||
getStatement(statements: any) { | ||
if (null === statements) { | ||
return []; | ||
} | ||
const results = []; | ||
statements.forEach((element: any) => { | ||
if ('_text' in element) { | ||
const elementText = element._text; | ||
const keys = Object.keys(elementText); | ||
const indexDefault = keys.indexOf('default'); | ||
if (indexDefault > -1) { | ||
results.push(elementText.default); | ||
keys.splice(indexDefault, 1); | ||
} | ||
|
||
keys.forEach(key => { | ||
results.push(elementText[key]); | ||
}); | ||
} | ||
}); | ||
return results; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters