Skip to content

Commit c8484be

Browse files
FrancescoMolinaroAndrea Barbasso
authored andcommitted
Merged in UXP-34-carousel-pagination (pull request #2)
UXP-34 carousel pagination Approved-by: Andrea Barbasso
2 parents 34d0e93 + d735287 commit c8484be

7 files changed

Lines changed: 264 additions & 90 deletions

File tree

src/app/shared/carousel/carousel-options.model.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { SortDirection } from '../../core/cache/models/sort-options.model';
2+
13
export interface CarouselOptions {
24
/**
35
* The title of the item
@@ -58,4 +60,27 @@ export interface CarouselOptions {
5860
* Classes to be applied to the bundle
5961
*/
6062
bundle: string;
63+
64+
/**
65+
* The discovery configuration name for search results
66+
*/
67+
discoveryConfiguration: string;
68+
/**
69+
* The search sortOrder
70+
*/
71+
order: string;
72+
/**
73+
* The search sortField
74+
*/
75+
sortField: string;
76+
77+
/**
78+
* The search sort direction
79+
*/
80+
sortDirection: SortDirection;
81+
82+
/**
83+
* The number of items to be searched
84+
*/
85+
numberOfItems: number;
6186
}

src/app/shared/carousel/carousel.component.html

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<ngb-carousel #carousel [interval]="2000" (slide)="onSlide($event)" class="ds-carousel">
2-
<ng-template ngbSlide *ngFor="let item of items; let i = index; let last = last">
2+
<ng-template ngbSlide *ngFor="let item of currentPageItems(); let i = index; let last = last">
33
<ng-container *ngIf="getItemLink(item.indexableObject); let currentLink; else carouselContent">
44
<a *ngIf="internalLinkService.isLinkInternal(currentLink)" [routerLink]="internalLinkService.getRelativePath(currentLink)">
55
<ng-container *ngTemplateOutlet="carouselContent"></ng-container>
@@ -39,3 +39,38 @@
3939
<i class="fas fa-pause" *ngIf="!paused"></i>
4040
</button>
4141
</div>
42+
<div class="mt-4 w-100 d-flex justify-content-center align-items-center" *ngIf="totalPages > 1">
43+
<button (click)="previousPage()" [disabled]="currentPage === 1" class="prev border-0 bg-transparent">
44+
<i class="fa fa-arrow-left"></i>
45+
</button>
46+
<button
47+
*ngFor="let page of pages()"
48+
class="number"
49+
(click)="changePage(page)"
50+
style="border: none; background: none; margin: 0 5px"
51+
[style.color]="page === currentPage ? '#000000' : '#7c7c7c'">
52+
{{ page < 10 ? '0' + page : page }}
53+
</button>
54+
<button (click)="nextPage()" [disabled]="currentPage === pages().length" class="next border-0 bg-transparent">
55+
<i class="fa fa-arrow-right"></i>
56+
</button>
57+
</div>
58+
59+
<div
60+
class="carousel-content-wrapper"
61+
[ngStyle]="{
62+
'height': carouselOptions.keepAspectRatio ? null : carouselOptions.carouselHeightPx + 'px',
63+
'aspect-ratio': carouselOptions.keepAspectRatio ? carouselOptions.aspectRatio : null
64+
}"
65+
*ngIf="(isLoading$ | async)"
66+
>
67+
<a
68+
href="#"
69+
target="_blank"
70+
class="img-container-el">
71+
<div class="picsum-img-wrapper flex-column">
72+
<img class="img-fluid" src="assets/images/replacement_image.svg">
73+
{{'loading.default' | translate}}
74+
</div>
75+
</a>
76+
</div>

src/app/shared/carousel/carousel.component.spec.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ import { createPaginatedList } from '../testing/utils.test';
3535
import { ItemSearchResult } from '../object-collection/shared/item-search-result.model';
3636
import { BitstreamFormat } from '../../core/shared/bitstream-format.model';
3737
import { CarouselOptions } from './carousel-options.model';
38-
import { InternalLinkService } from 'src/app/core/services/internal-link.service';
38+
import { SortDirection } from '../../core/cache/models/sort-options.model';
39+
import { SearchManager } from '../../core/browse/search-manager';
40+
import { toRemoteData } from '../../browse-by/browse-by-metadata-page/browse-by-metadata-page.component.spec';
41+
import { InternalLinkService } from '../../core/services/internal-link.service';
3942

4043
describe('CarouselComponent', () => {
4144
let component: CarouselComponent;
@@ -64,7 +67,12 @@ describe('CarouselComponent', () => {
6467
aspectRatio: 1,
6568
captionStyle: '',
6669
titleStyle: '',
67-
bundle: 'ORIGINAL'
70+
bundle: 'ORIGINAL',
71+
discoveryConfiguration: 'person',
72+
sortField: 'testField',
73+
sortDirection: SortDirection.DESC,
74+
numberOfItems: 5,
75+
order: 'testOrder'
6876
};
6977

7078
const firstItemResult = Object.assign(new ItemSearchResult(), {
@@ -154,6 +162,10 @@ describe('CarouselComponent', () => {
154162
}))
155163
});
156164

165+
const mockSearchManager = {
166+
search: (options: any) => toRemoteData([firstItemResult])
167+
};
168+
157169
beforeEach(waitForAsync(() => {
158170
notificationService = new NotificationsServiceStub();
159171
TestBed.configureTestingModule({
@@ -169,8 +181,8 @@ describe('CarouselComponent', () => {
169181
providers: [
170182
CarouselComponent,
171183
{ provide: ObjectCacheService, useValue: {} },
172-
{ provide: InternalLinkService, useValue: {} },
173-
{ provide: UUIDService, useValue: {} },
184+
{ provide: InternalLinkService, useValue: {} },
185+
{ provide: UUIDService, useValue: {} },
174186
{ provide: Store, useValue: {} },
175187
{ provide: RemoteDataBuildService, useValue: {} },
176188
{ provide: HALEndpointService, useValue: {} },
@@ -180,6 +192,7 @@ describe('CarouselComponent', () => {
180192
{ provide: DefaultChangeAnalyzer, useValue: {} },
181193
{ provide: BitstreamDataService, useValue: mockBitstreamDataService },
182194
{ provide: NativeWindowService, useValue: new NativeWindowRef() },
195+
{ provide: SearchManager, useValue: mockSearchManager },
183196
],
184197
schemas: [NO_ERRORS_SCHEMA]
185198
}).compileComponents();
@@ -190,7 +203,6 @@ describe('CarouselComponent', () => {
190203
fixture = TestBed.createComponent(CarouselComponent);
191204
component = fixture.componentInstance;
192205
mockBitstreamDataService.findAllByItemAndBundleName.and.returnValue(createSuccessfulRemoteDataObject$(createPaginatedList([mockBitstream1])));
193-
component.items = [firstItemResult];
194206
component.carouselOptions = carouselOptions;
195207

196208
fixture.detectChanges();
@@ -224,7 +236,6 @@ describe('CarouselComponent', () => {
224236
fixture = TestBed.createComponent(CarouselComponent);
225237
component = fixture.componentInstance;
226238
mockBitstreamDataService.findAllByItemAndBundleName.and.returnValue(createSuccessfulRemoteDataObject$(createPaginatedList([mockBitstream2])));
227-
component.items = [secondItemResult];
228239
component.carouselOptions = carouselOptions;
229240

230241
fixture.detectChanges();

0 commit comments

Comments
 (0)