Added thumbnail followLinks for ds-edit-relationship-list

This commit is contained in:
Michael Spalti
2022-09-16 12:27:16 -07:00
parent 4b62fb2db4
commit 231b7e2c2e
5 changed files with 106 additions and 13 deletions

View File

@@ -525,14 +525,14 @@ export class RelationshipDataService extends IdentifiableDataService<Relationshi
{ {
fieldName: 'relatedItem', fieldName: 'relatedItem',
fieldValue: itemId, fieldValue: itemId,
}, }
); );
}); });
return this.searchBy( return this.searchBy(
'byItemsAndType', 'byItemsAndType',
{ {
searchParams: searchParams, searchParams: searchParams
}, },
) as Observable<RemoteData<PaginatedList<Relationship>>>; ) as Observable<RemoteData<PaginatedList<Relationship>>>;

View File

@@ -31,6 +31,7 @@ import { SearchConfigurationServiceStub } from '../../../../shared/testing/searc
import { ConfigurationProperty } from '../../../../core/shared/configuration-property.model'; import { ConfigurationProperty } from '../../../../core/shared/configuration-property.model';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { RouterMock } from '../../../../shared/mocks/router.mock'; import { RouterMock } from '../../../../shared/mocks/router.mock';
import { APP_CONFIG } from '../../../../../config/app-config.interface';
let comp: EditRelationshipListComponent; let comp: EditRelationshipListComponent;
let fixture: ComponentFixture<EditRelationshipListComponent>; let fixture: ComponentFixture<EditRelationshipListComponent>;
@@ -201,6 +202,12 @@ describe('EditRelationshipListComponent', () => {
})) }))
}); });
const environmentUseThumbs = {
browseBy: {
showThumbnails: true
}
};
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [SharedModule, TranslateModule.forRoot()], imports: [SharedModule, TranslateModule.forRoot()],
declarations: [EditRelationshipListComponent], declarations: [EditRelationshipListComponent],
@@ -217,6 +224,7 @@ describe('EditRelationshipListComponent', () => {
{ provide: LinkHeadService, useValue: linkHeadService }, { provide: LinkHeadService, useValue: linkHeadService },
{ provide: ConfigurationDataService, useValue: configurationDataService }, { provide: ConfigurationDataService, useValue: configurationDataService },
{ provide: SearchConfigurationService, useValue: new SearchConfigurationServiceStub() }, { provide: SearchConfigurationService, useValue: new SearchConfigurationServiceStub() },
{ provide: APP_CONFIG, useValue: environmentUseThumbs }
], schemas: [ ], schemas: [
NO_ERRORS_SCHEMA NO_ERRORS_SCHEMA
] ]
@@ -259,9 +267,11 @@ describe('EditRelationshipListComponent', () => {
const callArgs = relationshipService.getItemRelationshipsByLabel.calls.mostRecent().args; const callArgs = relationshipService.getItemRelationshipsByLabel.calls.mostRecent().args;
const findListOptions = callArgs[2]; const findListOptions = callArgs[2];
const linksToFollow = callArgs[5];
expect(findListOptions.elementsPerPage).toEqual(paginationOptions.pageSize); expect(findListOptions.elementsPerPage).toEqual(paginationOptions.pageSize);
expect(findListOptions.currentPage).toEqual(paginationOptions.currentPage); 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', () => { describe('when the publication is on the left side of the relationship', () => {

View File

@@ -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 { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { LinkService } from '../../../../core/cache/builders/link.service'; import { LinkService } from '../../../../core/cache/builders/link.service';
import { ObjectUpdatesService } from '../../../../core/data/object-updates/object-updates.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 { RelationshipOptions } from '../../../../shared/form/builder/models/relationship-options.model';
import { SelectableListService } from '../../../../shared/object-list/selectable-list/selectable-list.service'; import { SelectableListService } from '../../../../shared/object-list/selectable-list/selectable-list.service';
import { SearchResult } from '../../../../shared/search/models/search-result.model'; 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 { PaginatedList } from '../../../../core/data/paginated-list.model';
import { RemoteData } from '../../../../core/data/remote-data'; import { RemoteData } from '../../../../core/data/remote-data';
import { Collection } from '../../../../core/shared/collection.model'; 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 { FieldUpdate } from '../../../../core/data/object-updates/field-update.model';
import { FieldUpdates } from '../../../../core/data/object-updates/field-updates.model'; import { FieldUpdates } from '../../../../core/data/object-updates/field-updates.model';
import { FieldChangeType } from '../../../../core/data/object-updates/field-change-type.model'; import { FieldChangeType } from '../../../../core/data/object-updates/field-change-type.model';
import { APP_CONFIG, AppConfig } from '../../../../../config/app-config.interface';
@Component({ @Component({
selector: 'ds-edit-relationship-list', selector: 'ds-edit-relationship-list',
@@ -138,6 +139,10 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
*/ */
modalRef: NgbModalRef; modalRef: NgbModalRef;
/**
* Determines whether to ask for the embedded item thumbnail.
*/
embedThumbnail: boolean;
constructor( constructor(
protected objectUpdatesService: ObjectUpdatesService, protected objectUpdatesService: ObjectUpdatesService,
@@ -147,7 +152,9 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
protected modalService: NgbModal, protected modalService: NgbModal,
protected paginationService: PaginationService, protected paginationService: PaginationService,
protected selectableListService: SelectableListService, 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)) tap(() => this.loading$.next(true))
); );
// this adds thumbnail images when required by configuration
let linksToFollow: FollowLinkConfig<Relationship>[];
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( this.subs.push(
observableCombineLatest([ observableCombineLatest([
currentPagination$, currentPagination$,
@@ -496,12 +514,11 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
currentItemIsLeftItem ? this.relationshipType.leftwardType : this.relationshipType.rightwardType, currentItemIsLeftItem ? this.relationshipType.leftwardType : this.relationshipType.rightwardType,
{ {
elementsPerPage: currentPagination.pageSize, elementsPerPage: currentPagination.pageSize,
currentPage: currentPagination.currentPage, currentPage: currentPagination.currentPage
}, },
false, false,
true, true,
followLink('leftItem'), ...linksToFollow
followLink('rightItem'),
)), )),
).subscribe((rd: RemoteData<PaginatedList<Relationship>>) => { ).subscribe((rd: RemoteData<PaginatedList<Relationship>>) => {
this.relationshipsRd$.next(rd); this.relationshipsRd$.next(rd);

View File

@@ -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 { Item } from '../../../core/shared/item.model';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { RemoteData } from '../../../core/data/remote-data'; 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 { AbstractIncrementalListComponent } from '../abstract-incremental-list/abstract-incremental-list.component';
import { FindListOptions } from '../../../core/data/find-list-options.model'; import { FindListOptions } from '../../../core/data/find-list-options.model';
import { setPlaceHolderFontSize } from '../../../shared/utils/object-list-utils'; import { setPlaceHolderFontSize } from '../../../shared/utils/object-list-utils';
import { APP_CONFIG, AppConfig } from '../../../../config/app-config.interface';
@Component({ @Component({
selector: 'ds-related-items', selector: 'ds-related-items',
@@ -55,8 +56,17 @@ export class RelatedItemsComponent extends AbstractIncrementalListComponent<Obse
*/ */
viewMode = ViewMode.ListElement; viewMode = ViewMode.ListElement;
constructor(public relationshipService: RelationshipDataService, protected elementRef: ElementRef) { /**
* Determines whether to request embedded thumbnail.
*/
embedThumbnail: boolean;
constructor(public relationshipService: RelationshipDataService,
protected elementRef: ElementRef,
@Inject(APP_CONFIG) protected appConfig: AppConfig
) {
super(); super();
this.embedThumbnail = this.appConfig.browseBy.showThumbnails;
} }
ngOnInit(): void { ngOnInit(): void {
@@ -70,6 +80,7 @@ export class RelatedItemsComponent extends AbstractIncrementalListComponent<Obse
* @param page The page to fetch * @param page The page to fetch
*/ */
getPage(page: number): Observable<RemoteData<PaginatedList<Item>>> { getPage(page: number): Observable<RemoteData<PaginatedList<Item>>> {
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 }));
} }
} }

View File

@@ -10,6 +10,7 @@ import { TranslateModule } from '@ngx-translate/core';
import { VarDirective } from '../../../shared/utils/var.directive'; import { VarDirective } from '../../../shared/utils/var.directive';
import { of as observableOf } from 'rxjs'; import { of as observableOf } from 'rxjs';
import { createPaginatedList } from '../../../shared/testing/utils.test'; import { createPaginatedList } from '../../../shared/testing/utils.test';
import { APP_CONFIG } from '../../../../config/app-config.interface';
const parentItem: Item = Object.assign(new Item(), { const parentItem: Item = Object.assign(new Item(), {
bundles: createSuccessfulRemoteDataObject$(createPaginatedList([])), bundles: createSuccessfulRemoteDataObject$(createPaginatedList([])),
@@ -30,6 +31,18 @@ const mockItems = [mockItem1, mockItem2];
const relationType = 'isItemOfItem'; const relationType = 'isItemOfItem';
let relationshipService: RelationshipDataService; let relationshipService: RelationshipDataService;
const environmentUseThumbs = {
browseBy: {
showThumbnails: true
}
};
const enviromentNoThumbs = {
browseBy: {
showThumbnails: false
}
};
describe('RelatedItemsComponent', () => { describe('RelatedItemsComponent', () => {
let comp: RelatedItemsComponent; let comp: RelatedItemsComponent;
let fixture: ComponentFixture<RelatedItemsComponent>; let fixture: ComponentFixture<RelatedItemsComponent>;
@@ -45,7 +58,8 @@ describe('RelatedItemsComponent', () => {
imports: [TranslateModule.forRoot()], imports: [TranslateModule.forRoot()],
declarations: [RelatedItemsComponent, VarDirective], declarations: [RelatedItemsComponent, VarDirective],
providers: [ providers: [
{ provide: RelationshipDataService, useValue: relationshipService } { provide: RelationshipDataService, useValue: relationshipService },
{ provide: APP_CONFIG, useValue: environmentUseThumbs }
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
}).overrideComponent(RelatedItemsComponent, { }).overrideComponent(RelatedItemsComponent, {
@@ -82,9 +96,11 @@ describe('RelatedItemsComponent', () => {
it('should call relationship-service\'s getRelatedItemsByLabel with the correct arguments (second page)', () => { it('should call relationship-service\'s getRelatedItemsByLabel with the correct arguments (second page)', () => {
expect(relationshipService.getRelatedItemsByLabel).toHaveBeenCalledWith(parentItem, relationType, Object.assign(comp.options, { expect(relationshipService.getRelatedItemsByLabel).toHaveBeenCalledWith(parentItem, relationType, Object.assign(comp.options, {
elementsPerPage: comp.incrementBy, elementsPerPage: comp.incrementBy,
currentPage: 2 currentPage: 2,
embedThumbnail: true
})); }));
}); });
}); });
describe('when decrease is called', () => { describe('when decrease is called', () => {
@@ -100,3 +116,42 @@ describe('RelatedItemsComponent', () => {
}); });
}); });
describe('RelatedItemsComponent', () => {
let comp: RelatedItemsComponent;
let fixture: ComponentFixture<RelatedItemsComponent>;
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
}));
});
});