Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ homePage:
pageSize: 5
# Sort record of recent submission
sortField: 'dc.date.accessioned'
#The entity types to show in the recent submission list. If not set, all entity types will be shown
entityTypes: ['Publication']
topLevelCommunityList:
# No. of communities to list per page on the home page
# This will always round to the nearest number from the list of page sizes. e.g. if you set it to 7 it'll use 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ import {
TestBed,
} from '@angular/core/testing';
import { APP_CONFIG } from '@dspace/config/app-config.interface';
import {
SortDirection,
SortOptions,
} from '@dspace/core/cache/models/sort-options.model';
import { PaginationService } from '@dspace/core/pagination/pagination.service';
import { PaginationComponentOptions } from '@dspace/core/pagination/pagination-component-options.model';
import { PaginatedSearchOptions } from '@dspace/core/shared/search/models/paginated-search-options.model';
import { PaginationServiceStub } from '@dspace/core/testing/pagination-service.stub';
import { SearchServiceStub } from '@dspace/core/testing/search-service.stub';
import { createPaginatedList } from '@dspace/core/testing/utils.test';
Expand All @@ -25,26 +19,21 @@ import { RecentItemListComponent } from './recent-item-list.component';
describe('RecentItemListComponent', () => {
let component: RecentItemListComponent;
let fixture: ComponentFixture<RecentItemListComponent>;
const emptyList = createSuccessfulRemoteDataObject(createPaginatedList([]));
let paginationService;

const emptyList = createSuccessfulRemoteDataObject(createPaginatedList([]));

const searchServiceStub = Object.assign(new SearchServiceStub(), {
search: () => of(emptyList),
/* eslint-disable no-empty,@typescript-eslint/no-empty-function */
clearDiscoveryRequests: () => {},
/* eslint-enable no-empty,@typescript-eslint/no-empty-function */
clearDiscoveryRequests: () => { },
});

paginationService = new PaginationServiceStub();
const mockSearchOptions = of(new PaginatedSearchOptions({
pagination: Object.assign(new PaginationComponentOptions(), {
id: 'search-page-configuration',
pageSize: 10,
currentPage: 1,
}),
sort: new SortOptions('dc.date.accessioned', SortDirection.DESC),
}));

const searchConfigServiceStub = {
paginatedSearchOptions: mockSearchOptions,
paginationID: 'search-page-configuration',
};

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [RecentItemListComponent],
Expand All @@ -55,24 +44,46 @@ describe('RecentItemListComponent', () => {
{ provide: APP_CONFIG, useValue: environment },
{ provide: PLATFORM_ID, useValue: 'browser' },
],
})
.compileComponents();
}).compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(RecentItemListComponent);
component = fixture.componentInstance;
fixture.detectChanges();

spyOn(paginationService, 'updateRouteWithUrl');
});

it('should create', () => {
expect(component).toBeTruthy();
});

it('should call the navigate method on the Router with view mode list parameter as a parameter when setViewMode is called', () => {
it('should load items on init', () => {
component.ngOnInit();
expect(component.itemRD$).toBeDefined();
});

it('should call paginationService.updateRouteWithUrl when onLoadMore is called', () => {

const entityTypes = environment.homePage.recentSubmissions.entityTypes;

const extraParams: Record<string, unknown> = {};

if (entityTypes?.length) {
extraParams['f.entityType'] = entityTypes.map(type => `${type},equals`);
}
component.onLoadMore();
expect(paginationService.updateRouteWithUrl).toHaveBeenCalledWith(undefined, ['search'], Object({ sortField: 'dc.date.accessioned', sortDirection: 'DESC', page: 1 }));

expect(paginationService.updateRouteWithUrl).toHaveBeenCalledWith('search-page-configuration', ['search'], { sortField: environment.homePage.recentSubmissions.sortField, sortDirection: 'DESC', page: 1 }, extraParams);
});
});

it('should clear pagination on destroy', () => {
spyOn(paginationService, 'clearPagination');

component.ngOnDestroy();

expect(paginationService.clearPagination).toHaveBeenCalledWith(component.paginationConfig.id);
});

});
27 changes: 21 additions & 6 deletions src/app/home-page/recent-item-list/recent-item-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
import { Item } from '@dspace/core/shared/item.model';
import { toDSpaceObjectListRD } from '@dspace/core/shared/operators';
import { PaginatedSearchOptions } from '@dspace/core/shared/search/models/paginated-search-options.model';
import { SearchFilter } from '@dspace/core/shared/search/models/search-filter.model';
import { ViewMode } from '@dspace/core/shared/view-mode.model';
import { setPlaceHolderAttributes } from '@dspace/shared/utils/object-list-utils';
import { TranslateModule } from '@ngx-translate/core';
Expand Down Expand Up @@ -106,12 +107,15 @@ export class RecentItemListComponent implements OnInit, OnDestroy {
if (this.appConfig.item.showAccessStatuses) {
linksToFollow.push(followLink('accessStatus'));
}
const entityTypes = this.appConfig.homePage.recentSubmissions.entityTypes;
const filters = entityTypes?.length ? [new SearchFilter('f.entityType', entityTypes, 'equals')] : [];

this.itemRD$ = this.searchService.search(
new PaginatedSearchOptions({
pagination: this.paginationConfig,
dsoTypes: [DSpaceObjectType.ITEM],
sort: this.sortConfig,
filters: filters,
}),
undefined,
undefined,
Expand All @@ -127,11 +131,23 @@ export class RecentItemListComponent implements OnInit, OnDestroy {
}

onLoadMore(): void {
this.paginationService.updateRouteWithUrl(this.searchConfigurationService.paginationID, ['search'], {
sortField: environment.homePage.recentSubmissions.sortField,
sortDirection: 'DESC' as SortDirection,
page: 1,
});
const entityTypes = this.appConfig.homePage.recentSubmissions.entityTypes;

const extraParams: Record<string, unknown> = {};

if (entityTypes?.length) {
extraParams['f.entityType'] = entityTypes.map(type => `${type},equals`);
}

this.paginationService.updateRouteWithUrl(
this.searchConfigurationService.paginationID,
['search'],
{
sortField: environment.homePage.recentSubmissions.sortField,
sortDirection: 'DESC' as SortDirection,
page: 1,
},
extraParams);
}

get placeholderFontClass(): string {
Expand All @@ -147,4 +163,3 @@ export class RecentItemListComponent implements OnInit, OnDestroy {
}

}

2 changes: 2 additions & 0 deletions src/config/default-app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ export class DefaultAppConfig implements AppConfig {
pageSize: 5,
//sort record of recent submission
sortField: 'dc.date.accessioned',
// The entity types to show in the recent submission list. If not set, all entity types will be shown
entityTypes: ['Publication'],
},
topLevelCommunityList: {
pageSize: 5,
Expand Down
5 changes: 5 additions & 0 deletions src/config/homepage-config.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export interface HomeConfig extends Config {
* sort record of recent submission
*/
sortField: string;

/**
* The entity types to show in the recent submission list. If not set, all entity types will be shown
*/
entityTypes?: string[];
}

topLevelCommunityList: {
Expand Down
2 changes: 2 additions & 0 deletions src/environments/environment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ export const environment: BuildConfig = {
pageSize: 5,
//sort record of recent submission
sortField: 'dc.date.accessioned',
// The entity types to show in the recent submission list. If not set, all entity types will be shown
entityTypes: ['Publication'],
},
topLevelCommunityList: {
pageSize: 5,
Expand Down