From 231b7e2c2eca75ef8712778717de59f80f6feca6 Mon Sep 17 00:00:00 2001 From: Michael Spalti Date: Fri, 16 Sep 2022 12:27:16 -0700 Subject: [PATCH] Added thumbnail followLinks for ds-edit-relationship-list --- .../core/data/relationship-data.service.ts | 4 +- .../edit-relationship-list.component.spec.ts | 12 +++- .../edit-relationship-list.component.ts | 27 +++++++-- .../related-items/related-items-component.ts | 17 +++++- .../related-items.component.spec.ts | 59 ++++++++++++++++++- 5 files changed, 106 insertions(+), 13 deletions(-) diff --git a/src/app/core/data/relationship-data.service.ts b/src/app/core/data/relationship-data.service.ts index 38490e9a8c..fc01880c2b 100644 --- a/src/app/core/data/relationship-data.service.ts +++ b/src/app/core/data/relationship-data.service.ts @@ -525,14 +525,14 @@ export class RelationshipDataService extends IdentifiableDataService>>; diff --git a/src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.spec.ts b/src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.spec.ts index 76c5717bb8..4cd663f0fb 100644 --- a/src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.spec.ts +++ b/src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.spec.ts @@ -31,6 +31,7 @@ import { SearchConfigurationServiceStub } from '../../../../shared/testing/searc import { ConfigurationProperty } from '../../../../core/shared/configuration-property.model'; import { Router } from '@angular/router'; import { RouterMock } from '../../../../shared/mocks/router.mock'; +import { APP_CONFIG } from '../../../../../config/app-config.interface'; let comp: EditRelationshipListComponent; let fixture: ComponentFixture; @@ -201,6 +202,12 @@ describe('EditRelationshipListComponent', () => { })) }); + const environmentUseThumbs = { + browseBy: { + showThumbnails: true + } + }; + TestBed.configureTestingModule({ imports: [SharedModule, TranslateModule.forRoot()], declarations: [EditRelationshipListComponent], @@ -217,6 +224,7 @@ describe('EditRelationshipListComponent', () => { { provide: LinkHeadService, useValue: linkHeadService }, { provide: ConfigurationDataService, useValue: configurationDataService }, { provide: SearchConfigurationService, useValue: new SearchConfigurationServiceStub() }, + { provide: APP_CONFIG, useValue: environmentUseThumbs } ], schemas: [ NO_ERRORS_SCHEMA ] @@ -259,9 +267,11 @@ describe('EditRelationshipListComponent', () => { const callArgs = relationshipService.getItemRelationshipsByLabel.calls.mostRecent().args; const findListOptions = callArgs[2]; - + const linksToFollow = callArgs[5]; expect(findListOptions.elementsPerPage).toEqual(paginationOptions.pageSize); expect(findListOptions.currentPage).toEqual(paginationOptions.currentPage); + expect(linksToFollow.linksToFollow[0].name).toEqual('thumbnail'); + }); describe('when the publication is on the left side of the relationship', () => { diff --git a/src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.ts b/src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.ts index f5a5a583d7..14a748c4b2 100644 --- a/src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.ts +++ b/src/app/item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.ts @@ -1,4 +1,4 @@ -import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core'; +import { Component, EventEmitter, Inject, Input, OnDestroy, OnInit, Output } from '@angular/core'; import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; import { LinkService } from '../../../../core/cache/builders/link.service'; import { ObjectUpdatesService } from '../../../../core/data/object-updates/object-updates.service'; @@ -29,7 +29,7 @@ import { DsDynamicLookupRelationModalComponent } from '../../../../shared/form/b import { RelationshipOptions } from '../../../../shared/form/builder/models/relationship-options.model'; import { SelectableListService } from '../../../../shared/object-list/selectable-list/selectable-list.service'; import { SearchResult } from '../../../../shared/search/models/search-result.model'; -import { followLink } from '../../../../shared/utils/follow-link-config.model'; +import { followLink, FollowLinkConfig } from '../../../../shared/utils/follow-link-config.model'; import { PaginatedList } from '../../../../core/data/paginated-list.model'; import { RemoteData } from '../../../../core/data/remote-data'; import { Collection } from '../../../../core/shared/collection.model'; @@ -39,6 +39,7 @@ import { RelationshipTypeDataService } from '../../../../core/data/relationship- import { FieldUpdate } from '../../../../core/data/object-updates/field-update.model'; import { FieldUpdates } from '../../../../core/data/object-updates/field-updates.model'; import { FieldChangeType } from '../../../../core/data/object-updates/field-change-type.model'; +import { APP_CONFIG, AppConfig } from '../../../../../config/app-config.interface'; @Component({ selector: 'ds-edit-relationship-list', @@ -138,6 +139,10 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { */ modalRef: NgbModalRef; + /** + * Determines whether to ask for the embedded item thumbnail. + */ + embedThumbnail: boolean; constructor( protected objectUpdatesService: ObjectUpdatesService, @@ -147,7 +152,9 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { protected modalService: NgbModal, protected paginationService: PaginationService, protected selectableListService: SelectableListService, + @Inject(APP_CONFIG) protected appConfig: AppConfig ) { + this.embedThumbnail = this.appConfig.browseBy.showThumbnails; } /** @@ -484,6 +491,17 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { tap(() => this.loading$.next(true)) ); + // this adds thumbnail images when required by configuration + let linksToFollow: FollowLinkConfig[]; + if (this.embedThumbnail) { + linksToFollow = [ + followLink('leftItem',{}, followLink('thumbnail')), + followLink('rightItem',{}, followLink('thumbnail')), + followLink('relationshipType') ]; + } else { + linksToFollow = [followLink('leftItem'), followLink('rightItem'), followLink('relationshipType')]; + } + this.subs.push( observableCombineLatest([ currentPagination$, @@ -496,12 +514,11 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy { currentItemIsLeftItem ? this.relationshipType.leftwardType : this.relationshipType.rightwardType, { elementsPerPage: currentPagination.pageSize, - currentPage: currentPagination.currentPage, + currentPage: currentPagination.currentPage }, false, true, - followLink('leftItem'), - followLink('rightItem'), + ...linksToFollow )), ).subscribe((rd: RemoteData>) => { this.relationshipsRd$.next(rd); diff --git a/src/app/item-page/simple/related-items/related-items-component.ts b/src/app/item-page/simple/related-items/related-items-component.ts index 490a745533..b58a86d2da 100644 --- a/src/app/item-page/simple/related-items/related-items-component.ts +++ b/src/app/item-page/simple/related-items/related-items-component.ts @@ -1,4 +1,4 @@ -import { Component, ElementRef, Input } from '@angular/core'; +import { Component, ElementRef, Inject, Input } from '@angular/core'; import { Item } from '../../../core/shared/item.model'; import { Observable } from 'rxjs'; import { RemoteData } from '../../../core/data/remote-data'; @@ -8,6 +8,7 @@ import { RelationshipDataService } from '../../../core/data/relationship-data.se import { AbstractIncrementalListComponent } from '../abstract-incremental-list/abstract-incremental-list.component'; import { FindListOptions } from '../../../core/data/find-list-options.model'; import { setPlaceHolderFontSize } from '../../../shared/utils/object-list-utils'; +import { APP_CONFIG, AppConfig } from '../../../../config/app-config.interface'; @Component({ selector: 'ds-related-items', @@ -55,8 +56,17 @@ export class RelatedItemsComponent extends AbstractIncrementalListComponent>> { - return this.relationshipService.getRelatedItemsByLabel(this.parentItem, this.relationType, Object.assign(this.options, { elementsPerPage: this.incrementBy, currentPage: page, embedThumbnail: true })); + return this.relationshipService.getRelatedItemsByLabel(this.parentItem, this.relationType, Object.assign(this.options, + { elementsPerPage: this.incrementBy, currentPage: page, embedThumbnail: this.embedThumbnail })); } } diff --git a/src/app/item-page/simple/related-items/related-items.component.spec.ts b/src/app/item-page/simple/related-items/related-items.component.spec.ts index 75453b5b14..89ad1685e5 100644 --- a/src/app/item-page/simple/related-items/related-items.component.spec.ts +++ b/src/app/item-page/simple/related-items/related-items.component.spec.ts @@ -10,6 +10,7 @@ import { TranslateModule } from '@ngx-translate/core'; import { VarDirective } from '../../../shared/utils/var.directive'; import { of as observableOf } from 'rxjs'; import { createPaginatedList } from '../../../shared/testing/utils.test'; +import { APP_CONFIG } from '../../../../config/app-config.interface'; const parentItem: Item = Object.assign(new Item(), { bundles: createSuccessfulRemoteDataObject$(createPaginatedList([])), @@ -30,6 +31,18 @@ const mockItems = [mockItem1, mockItem2]; const relationType = 'isItemOfItem'; let relationshipService: RelationshipDataService; +const environmentUseThumbs = { + browseBy: { + showThumbnails: true + } +}; + +const enviromentNoThumbs = { + browseBy: { + showThumbnails: false + } +}; + describe('RelatedItemsComponent', () => { let comp: RelatedItemsComponent; let fixture: ComponentFixture; @@ -45,7 +58,8 @@ describe('RelatedItemsComponent', () => { imports: [TranslateModule.forRoot()], declarations: [RelatedItemsComponent, VarDirective], providers: [ - { provide: RelationshipDataService, useValue: relationshipService } + { provide: RelationshipDataService, useValue: relationshipService }, + { provide: APP_CONFIG, useValue: environmentUseThumbs } ], schemas: [NO_ERRORS_SCHEMA] }).overrideComponent(RelatedItemsComponent, { @@ -82,9 +96,11 @@ describe('RelatedItemsComponent', () => { it('should call relationship-service\'s getRelatedItemsByLabel with the correct arguments (second page)', () => { expect(relationshipService.getRelatedItemsByLabel).toHaveBeenCalledWith(parentItem, relationType, Object.assign(comp.options, { elementsPerPage: comp.incrementBy, - currentPage: 2 + currentPage: 2, + embedThumbnail: true })); }); + }); describe('when decrease is called', () => { @@ -100,3 +116,42 @@ describe('RelatedItemsComponent', () => { }); }); +describe('RelatedItemsComponent', () => { + let comp: RelatedItemsComponent; + let fixture: ComponentFixture; + + beforeEach(waitForAsync(() => { + relationshipService = jasmine.createSpyObj('relationshipService', + { + getRelatedItemsByLabel: createSuccessfulRemoteDataObject$(createPaginatedList(mockItems)), + } + ); + + TestBed.configureTestingModule({ + imports: [TranslateModule.forRoot()], + declarations: [RelatedItemsComponent, VarDirective], + providers: [ + {provide: RelationshipDataService, useValue: relationshipService}, + {provide: APP_CONFIG, useValue: enviromentNoThumbs} + ], + schemas: [NO_ERRORS_SCHEMA] + }).overrideComponent(RelatedItemsComponent, { + set: {changeDetection: ChangeDetectionStrategy.Default} + }).compileComponents(); + })); + + beforeEach(waitForAsync(() => { + fixture = TestBed.createComponent(RelatedItemsComponent); + comp = fixture.componentInstance; + comp.parentItem = parentItem; + comp.relationType = relationType; + fixture.detectChanges(); + })); + it('should call relationship-service\'s getRelatedItemsByLabel with the correct arguments (second page)', () => { + expect(relationshipService.getRelatedItemsByLabel).toHaveBeenCalledWith(parentItem, relationType, Object.assign(comp.options, { + elementsPerPage: comp.incrementBy, + currentPage: 2, + embedThumbnail: false + })); + }); +});