From 72fb18d92fd65c6a7f8fc789308cd21b80031449 Mon Sep 17 00:00:00 2001 From: Art Lowel Date: Tue, 8 Jan 2019 13:12:12 +0100 Subject: [PATCH 1/2] Add virtual metadata fields for journals --- resources/i18n/en.json | 16 ++++- src/app/+item-page/item-page.module.ts | 4 +- .../journal-issue.component.html | 9 +++ .../journal/journal.component.html | 9 +++ .../entity-types/person/person.component.html | 11 ++-- .../publication/publication.component.html | 21 +++++++ .../related-entities-search.component.html | 6 ++ .../related-entities-search.component.spec.ts | 56 ++++++++++++++++++ .../related-entities-search.component.ts | 59 +++++++++++++++++++ .../search-fixed-filter.service.ts | 9 +++ src/app/+search-page/search-page.module.ts | 2 +- 11 files changed, 191 insertions(+), 11 deletions(-) create mode 100644 src/app/+item-page/simple/related-entities/related-entities-search/related-entities-search.component.html create mode 100644 src/app/+item-page/simple/related-entities/related-entities-search/related-entities-search.component.spec.ts create mode 100644 src/app/+item-page/simple/related-entities/related-entities-search/related-entities-search.component.ts diff --git a/resources/i18n/en.json b/resources/i18n/en.json index 667d5132ba..5d85b79279 100644 --- a/resources/i18n/en.json +++ b/resources/i18n/en.json @@ -32,6 +32,8 @@ "uri": "URI", "files": "Files", "collections": "Collections", + "subject": "Keywords", + "citation": "Citation", "filesection": { "download": "Download", "name": "Name:", @@ -95,7 +97,8 @@ "page": { "issn": "ISSN", "publisher": "Publisher", - "description": "Description" + "description": "Description", + "editor": "Editor-in-Chief" } }, "journalvolume": { @@ -110,7 +113,16 @@ "number": "Number", "issuedate": "Issue Date", "description": "Description", - "keyword": "Keywords" + "keyword": "Keywords", + "journal-title": "Journal Title", + "journal-issn": "Journal ISSN" + } + }, + "publication": { + "page": { + "journal-title": "Journal Title", + "journal-issn": "Journal ISSN", + "volume-title": "Volume Title" } }, "nav": { diff --git a/src/app/+item-page/item-page.module.ts b/src/app/+item-page/item-page.module.ts index 2103a548c1..44ccbacf82 100644 --- a/src/app/+item-page/item-page.module.ts +++ b/src/app/+item-page/item-page.module.ts @@ -29,6 +29,7 @@ import { JournalComponent } from './simple/entity-types/journal/journal.componen import { JournalVolumeComponent } from './simple/entity-types/journal-volume/journal-volume.component'; import { JournalIssueComponent } from './simple/entity-types/journal-issue/journal-issue.component'; import { EntityComponent } from './simple/entity-types/shared/entity.component'; +import { RelatedEntitiesSearchComponent } from './simple/related-entities/related-entities-search/related-entities-search.component'; @NgModule({ imports: [ @@ -61,7 +62,8 @@ import { EntityComponent } from './simple/entity-types/shared/entity.component'; GenericItemPageFieldComponent, JournalComponent, JournalIssueComponent, - JournalVolumeComponent + JournalVolumeComponent, + RelatedEntitiesSearchComponent ], entryComponents: [ PublicationComponent, diff --git a/src/app/+item-page/simple/entity-types/journal-issue/journal-issue.component.html b/src/app/+item-page/simple/entity-types/journal-issue/journal-issue.component.html index 73fee41f8f..d83b4ed9b8 100644 --- a/src/app/+item-page/simple/entity-types/journal-issue/journal-issue.component.html +++ b/src/app/+item-page/simple/entity-types/journal-issue/journal-issue.component.html @@ -14,6 +14,14 @@ [fields]="['journalissue.issuedate']" [label]="'journalissue.page.issuedate'"> + + + +
diff --git a/src/app/+item-page/simple/entity-types/journal/journal.component.html b/src/app/+item-page/simple/entity-types/journal/journal.component.html index b02000a9e4..df50f613fb 100644 --- a/src/app/+item-page/simple/entity-types/journal/journal.component.html +++ b/src/app/+item-page/simple/entity-types/journal/journal.component.html @@ -14,6 +14,10 @@ [fields]="['journal.publisher']" [label]="'journal.page.publisher'"> + +
+
+ + +
diff --git a/src/app/+item-page/simple/entity-types/person/person.component.html b/src/app/+item-page/simple/entity-types/person/person.component.html index 548f46624d..fdc03c36a8 100644 --- a/src/app/+item-page/simple/entity-types/person/person.component.html +++ b/src/app/+item-page/simple/entity-types/person/person.component.html @@ -50,12 +50,9 @@ -
- - +
+ +
diff --git a/src/app/+item-page/simple/entity-types/publication/publication.component.html b/src/app/+item-page/simple/entity-types/publication/publication.component.html index 84cd5a151b..2df7f0e53e 100644 --- a/src/app/+item-page/simple/entity-types/publication/publication.component.html +++ b/src/app/+item-page/simple/entity-types/publication/publication.component.html @@ -7,6 +7,18 @@ + + + + + +
+ + + +
diff --git a/src/app/+item-page/simple/related-entities/related-entities-search/related-entities-search.component.html b/src/app/+item-page/simple/related-entities/related-entities-search/related-entities-search.component.html new file mode 100644 index 0000000000..9ec082db73 --- /dev/null +++ b/src/app/+item-page/simple/related-entities/related-entities-search/related-entities-search.component.html @@ -0,0 +1,6 @@ + + diff --git a/src/app/+item-page/simple/related-entities/related-entities-search/related-entities-search.component.spec.ts b/src/app/+item-page/simple/related-entities/related-entities-search/related-entities-search.component.spec.ts new file mode 100644 index 0000000000..e76a9cf3d0 --- /dev/null +++ b/src/app/+item-page/simple/related-entities/related-entities-search/related-entities-search.component.spec.ts @@ -0,0 +1,56 @@ +import { RelatedEntitiesSearchComponent } from './related-entities-search.component'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { NoopAnimationsModule } from '@angular/platform-browser/animations'; +import { TranslateModule } from '@ngx-translate/core'; +import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { FormsModule } from '@angular/forms'; +import { SearchFixedFilterService } from '../../../../+search-page/search-filters/search-filter/search-fixed-filter.service'; +import { Item } from '../../../../core/shared/item.model'; + +describe('RelatedEntitiesSearchComponent', () => { + let comp: RelatedEntitiesSearchComponent; + let fixture: ComponentFixture; + let fixedFilterService: SearchFixedFilterService; + + const mockItem = Object.assign(new Item(), { + id: 'id1' + }); + const mockRelationType = 'publicationsOfAuthor'; + const mockRelationEntityType = 'publication'; + const mockFilter= `f.${mockRelationType}=${mockItem.id}`; + const fixedFilterServiceStub = { + getFilterByRelation: () => mockFilter + }; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [TranslateModule.forRoot(), NoopAnimationsModule, FormsModule], + declarations: [RelatedEntitiesSearchComponent], + providers: [ + { provide: SearchFixedFilterService, useValue: fixedFilterServiceStub } + ], + schemas: [NO_ERRORS_SCHEMA] + }).compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(RelatedEntitiesSearchComponent); + comp = fixture.componentInstance; + fixedFilterService = (comp as any).fixedFilterService; + comp.relationType = mockRelationType; + comp.item = mockItem; + comp.relationEntityType = mockRelationEntityType; + fixture.detectChanges(); + }); + + it('should create a fixedFilter', () => { + expect(comp.fixedFilter).toEqual(mockFilter); + }); + + it('should create a fixedFilter$', () => { + comp.fixedFilter$.subscribe((fixedFilter) => { + expect(fixedFilter).toEqual(mockRelationEntityType); + }) + }); + +}); diff --git a/src/app/+item-page/simple/related-entities/related-entities-search/related-entities-search.component.ts b/src/app/+item-page/simple/related-entities/related-entities-search/related-entities-search.component.ts new file mode 100644 index 0000000000..7d835cfd68 --- /dev/null +++ b/src/app/+item-page/simple/related-entities/related-entities-search/related-entities-search.component.ts @@ -0,0 +1,59 @@ +import { Component, Input, OnInit } from '@angular/core'; +import { Observable } from 'rxjs'; +import { Item } from '../../../../core/shared/item.model'; +import { SearchFixedFilterService } from '../../../../+search-page/search-filters/search-filter/search-fixed-filter.service'; +import { isNotEmpty } from '../../../../shared/empty.util'; +import { of } from 'rxjs/internal/observable/of'; + +@Component({ + selector: 'ds-related-entities-search', + templateUrl: './related-entities-search.component.html' +}) +export class RelatedEntitiesSearchComponent implements OnInit { + + /** + * The type of relationship to fetch items for + * e.g. 'isAuthorOfPublication' + */ + @Input() relationType: string; + + /** + * The item to render relationships for + */ + @Input() item: Item; + + /** + * The entity type of the relationship items to be displayed + * e.g. 'publication' + * This determines the title of the search results (if search is enabled) + */ + @Input() relationEntityType: string; + + /** + * Whether or not the search bar and title should be displayed (defaults to true) + * @type {boolean} + */ + @Input() searchEnabled = true; + + /** + * The ratio of the sidebar's width compared to the search results (1-12) (defaults to 4) + * @type {number} + */ + @Input() sideBarWidth = 4; + + fixedFilter: string; + fixedFilter$: Observable; + + constructor(private fixedFilterService: SearchFixedFilterService) { + } + + ngOnInit(): void { + if (isNotEmpty(this.relationType) && isNotEmpty(this.item)) { + this.fixedFilter = this.fixedFilterService.getFilterByRelation(this.relationType, this.item.id); + } + if (isNotEmpty(this.relationEntityType)) { + this.fixedFilter$ = of(this.relationEntityType); + } + } + +} diff --git a/src/app/+search-page/search-filters/search-filter/search-fixed-filter.service.ts b/src/app/+search-page/search-filters/search-filter/search-fixed-filter.service.ts index 8f8997e63c..bf812fe4cc 100644 --- a/src/app/+search-page/search-filters/search-filter/search-fixed-filter.service.ts +++ b/src/app/+search-page/search-filters/search-filter/search-fixed-filter.service.ts @@ -73,4 +73,13 @@ export class SearchFixedFilterService { return `query=relation.${relationType}:${itemUUID}`; } + /** + * Get the filter for a relation with the item's UUID + * @param relationType The type of relation e.g. 'isAuthorOfPublication' + * @param itemUUID The item's UUID + */ + getFilterByRelation(relationType: string, itemUUID: string): string { + return `f.${relationType}=${itemUUID}`; + } + } diff --git a/src/app/+search-page/search-page.module.ts b/src/app/+search-page/search-page.module.ts index 658c32d27e..b32e504966 100644 --- a/src/app/+search-page/search-page.module.ts +++ b/src/app/+search-page/search-page.module.ts @@ -91,7 +91,7 @@ const effects = [ SearchBooleanFilterComponent, ], exports: [ - FilteredSearchPageComponent + FilteredSearchPageComponent, ] }) From 16576a77912a47e482a217d2ec2ff6a8bc0efd2d Mon Sep 17 00:00:00 2001 From: Art Lowel Date: Tue, 8 Jan 2019 16:51:43 +0100 Subject: [PATCH 2/2] Add typedocs to RelatedEntitiesSearchComponent --- .../related-entities-search.component.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/app/+item-page/simple/related-entities/related-entities-search/related-entities-search.component.ts b/src/app/+item-page/simple/related-entities/related-entities-search/related-entities-search.component.ts index 7d835cfd68..672655a8b8 100644 --- a/src/app/+item-page/simple/related-entities/related-entities-search/related-entities-search.component.ts +++ b/src/app/+item-page/simple/related-entities/related-entities-search/related-entities-search.component.ts @@ -9,6 +9,11 @@ import { of } from 'rxjs/internal/observable/of'; selector: 'ds-related-entities-search', templateUrl: './related-entities-search.component.html' }) +/** + * A component to show related items as search results. + * Related items can be facetted, or queried using an + * optional search box. + */ export class RelatedEntitiesSearchComponent implements OnInit { /**