Skip to content
This repository was archived by the owner on May 26, 2026. It is now read-only.

Commit f433051

Browse files
committed
[upstream] feat(layout): use pagination controls in components with lists
1 parent 0636137 commit f433051

16 files changed

Lines changed: 142 additions & 137 deletions

apps/datahub/src/app/organization/organization-details/organization-details.component.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,16 @@ import {
1111
CatalogRecord,
1212
Organization,
1313
} from '@geonetwork-ui/common/domain/model/record'
14-
import {
15-
ButtonComponent,
16-
PreviousNextButtonsComponent,
17-
} from '@geonetwork-ui/ui/inputs'
1814
import { TranslateModule } from '@ngx-translate/core'
1915
import {
2016
BlockListComponent,
21-
CarouselComponent,
2217
MaxLinesComponent,
18+
PreviousNextButtonsComponent,
2319
} from '@geonetwork-ui/ui/layout'
2420
import { LetDirective } from '@ngrx/component'
2521
import {
2622
ErrorComponent,
2723
ErrorType,
28-
LinkCardComponent,
2924
RelatedRecordCardComponent,
3025
UiElementsModule,
3126
} from '@geonetwork-ui/ui/elements'
@@ -57,12 +52,8 @@ import { startWith } from 'rxjs/operators'
5752
standalone: true,
5853
imports: [
5954
CommonModule,
60-
ButtonComponent,
6155
TranslateModule,
62-
CarouselComponent,
63-
BlockListComponent,
6456
LetDirective,
65-
LinkCardComponent,
6657
PreviousNextButtonsComponent,
6758
UiElementsModule,
6859
UiSearchModule,

apps/datahub/src/app/record/record-apis/record-apis.component.html

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
record.metadata.api
77
</p>
88
<gn-ui-previous-next-buttons
9-
*ngIf="hasPagination"
10-
[isFirst]="isFirstStep"
11-
[isLast]="isLastStep"
12-
(directionButtonClicked)="changeStepOrPage($event)"
9+
*ngIf="carousel.pagesCount > 1"
10+
[listComponent]="carousel"
1311
></gn-ui-previous-next-buttons>
1412
</div>
15-
<gn-ui-carousel (currentStepChange)="updateView()" containerClass="gap-4 py-10">
13+
<gn-ui-carousel
14+
(currentStepChange)="updateView()"
15+
containerClass="gap-4 py-10"
16+
#carousel
17+
>
1618
<gn-ui-api-card
1719
*ngFor="let link of apiLinks$ | async"
1820
[title]="link.name"

apps/datahub/src/app/record/record-apis/record-apis.component.ts

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import {
77
} from '@angular/core'
88
import { DatasetServiceDistribution } from '@geonetwork-ui/common/domain/model/record'
99
import { MdViewFacade } from '@geonetwork-ui/feature/record'
10-
import { CarouselComponent } from '@geonetwork-ui/ui/layout'
11-
import { PreviousNextButtonsComponent } from '@geonetwork-ui/ui/inputs'
10+
import {
11+
CarouselComponent,
12+
PreviousNextButtonsComponent,
13+
} from '@geonetwork-ui/ui/layout'
1214
import {
1315
ApiCardComponent,
1416
RecordApiFormComponent,
@@ -58,22 +60,10 @@ export class RecordApisComponent implements OnInit {
5860
this.selectedApiLink = undefined
5961
}
6062

61-
get hasPagination() {
62-
return this.carousel?.stepsCount > 1
63-
}
64-
6563
updateView() {
6664
this.changeDetector.detectChanges()
6765
}
6866

69-
get isFirstStep() {
70-
return this.carousel?.isFirstStep
71-
}
72-
73-
get isLastStep() {
74-
return this.carousel?.isLastStep
75-
}
76-
7767
openRecordApiForm(link: DatasetServiceDistribution) {
7868
this.selectedApiLink = link
7969
this.setStyle(link)
@@ -88,12 +78,4 @@ export class RecordApisComponent implements OnInit {
8878
this.maxHeight = link === undefined ? '0px' : '500px'
8979
this.opacity = link === undefined ? 0 : 1
9080
}
91-
92-
changeStepOrPage(direction: string) {
93-
if (direction === 'next') {
94-
this.carousel?.slideToNext()
95-
} else {
96-
this.carousel?.slideToPrevious()
97-
}
98-
}
9981
}

apps/datahub/src/app/record/record-otherlinks/record-otherlinks.component.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
record.metadata.links
77
</p>
88
<gn-ui-previous-next-buttons
9-
*ngIf="hasPagination"
10-
[isFirst]="isFirstStepOrPage"
11-
[isLast]="isLastStepOrPage"
12-
(directionButtonClicked)="changeStepOrPage($event)"
9+
*ngIf="paginableElement.pagesCount > 1"
10+
[listComponent]="paginableElement"
1311
></gn-ui-previous-next-buttons>
1412
</div>
1513
<ng-container *ngrxLet="otherLinks$ as otherLinks">

apps/datahub/src/app/record/record-otherlinks/record-otherlinks.component.ts

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ import {
66
ViewChild,
77
} from '@angular/core'
88
import { MdViewFacade } from '@geonetwork-ui/feature/record'
9-
import { BlockListComponent, CarouselComponent } from '@geonetwork-ui/ui/layout'
10-
import { PreviousNextButtonsComponent } from '@geonetwork-ui/ui/inputs'
9+
import {
10+
BlockListComponent,
11+
CarouselComponent,
12+
Paginable,
13+
PreviousNextButtonsComponent,
14+
} from '@geonetwork-ui/ui/layout'
1115
import { CommonModule } from '@angular/common'
1216
import { LinkCardComponent } from '@geonetwork-ui/ui/elements'
1317
import { LetDirective } from '@ngrx/component'
@@ -34,34 +38,15 @@ export class RecordOtherlinksComponent implements AfterViewInit {
3438

3539
@ViewChild(CarouselComponent) carousel: CarouselComponent
3640
@ViewChild(BlockListComponent) list: BlockListComponent
41+
get paginableElement(): Paginable {
42+
return this.carousel || this.list
43+
}
3744

3845
constructor(
3946
public facade: MdViewFacade,
4047
private changeDetector: ChangeDetectorRef
4148
) {}
4249

43-
get isFirstStepOrPage() {
44-
return this.carousel?.isFirstStep ?? this.list?.isFirstPage ?? true
45-
}
46-
47-
get isLastStepOrPage() {
48-
return this.carousel?.isLastStep ?? this.list?.isLastPage ?? false
49-
}
50-
51-
get hasPagination() {
52-
return (this.carousel?.stepsCount || this.list?.pagesCount) > 1
53-
}
54-
55-
changeStepOrPage(direction: string) {
56-
if (direction === 'next') {
57-
this.list?.nextPage()
58-
this.carousel?.slideToNext()
59-
} else {
60-
this.carousel?.slideToPrevious()
61-
this.list?.previousPage()
62-
}
63-
}
64-
6550
updateView() {
6651
this.changeDetector.detectChanges()
6752
}

apps/metadata-editor/src/app/records/records-list.component.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
></gn-ui-results-table-container>
88

99
<div class="px-5 py-5 flex justify-center gap-8 items-baseline">
10-
<gn-ui-pagination-buttons
11-
[currentPage]="searchFacade.currentPage$ | async"
12-
[totalPages]="searchFacade.totalPages$ | async"
13-
(newCurrentPageEvent)="paginate($event)"
14-
></gn-ui-pagination-buttons>
10+
<gn-ui-pagination-buttons [listComponent]="this"></gn-ui-pagination-buttons>
1511
</div>
1612
</div>

apps/metadata-editor/src/app/records/records-list.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Router } from '@angular/router'
1010
import { BehaviorSubject } from 'rxjs'
1111
import { datasetRecordsFixture } from '@geonetwork-ui/common/fixtures'
1212
import { MockBuilder } from 'ng-mocks'
13-
import { PaginationButtonsComponent } from '@geonetwork-ui/ui/elements'
13+
import { PaginationButtonsComponent } from '@geonetwork-ui/ui/layout'
1414

1515
const results = [{ md: true }]
1616
const currentPage = 5

apps/metadata-editor/src/app/records/records-list.component.ts

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ import {
88
SearchService,
99
} from '@geonetwork-ui/feature/search'
1010
import { UiSearchModule } from '@geonetwork-ui/ui/search'
11-
import {
12-
PaginationButtonsComponent,
13-
UiElementsModule,
14-
} from '@geonetwork-ui/ui/elements'
11+
import { UiElementsModule } from '@geonetwork-ui/ui/elements'
1512
import { TranslateModule } from '@ngx-translate/core'
1613
import { UiInputsModule } from '@geonetwork-ui/ui/inputs'
14+
import { Paginable, PaginationButtonsComponent } from '@geonetwork-ui/ui/layout'
1715

1816
export const allSearchFields = [
1917
'uuid',
@@ -41,7 +39,7 @@ export const allSearchFields = [
4139
PaginationButtonsComponent,
4240
],
4341
})
44-
export class RecordsListComponent implements OnInit {
42+
export class RecordsListComponent implements OnInit, Paginable {
4543
constructor(
4644
private router: Router,
4745
public searchFacade: SearchFacade,
@@ -51,10 +49,13 @@ export class RecordsListComponent implements OnInit {
5149
ngOnInit(): void {
5250
this.searchFacade.setConfigRequestFields(allSearchFields)
5351
this.searchFacade.setPageSize(15)
54-
}
5552

56-
paginate(page: number) {
57-
this.searchService.setPage(page)
53+
this.searchFacade.currentPage$.subscribe((page) => {
54+
this.currentPage_ = page
55+
})
56+
this.searchFacade.totalPages$.subscribe((total) => {
57+
this.totalPages_ = total
58+
})
5859
}
5960

6061
editRecord(record: CatalogRecord) {
@@ -64,4 +65,31 @@ export class RecordsListComponent implements OnInit {
6465
duplicateRecord(record: CatalogRecord) {
6566
this.router.navigate(['/duplicate', record.uniqueIdentifier])
6667
}
68+
69+
// these are 0 based
70+
totalPages_: number
71+
currentPage_: number
72+
73+
// Paginable API
74+
get isFirstPage() {
75+
return this.currentPage_ === 0
76+
}
77+
get isLastPage() {
78+
return this.currentPage_ === this.totalPages_ - 1
79+
}
80+
get pagesCount() {
81+
return this.totalPages_
82+
}
83+
get currentPage() {
84+
return this.currentPage_ + 1 // this is 1-based for the Paginable API
85+
}
86+
goToPage(page: number) {
87+
this.searchService.setPage(page - 1)
88+
}
89+
goToNextPage() {
90+
this.searchService.setPage(this.currentPage_ + 1)
91+
}
92+
goToPrevPage() {
93+
this.searchService.setPage(this.currentPage_ - 1)
94+
}
6795
}

libs/feature/catalog/src/lib/organisations/organisations.component.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,5 @@
2626
</gn-ui-content-ghost>
2727
</div>
2828
<div class="py-20">
29-
<gn-ui-pagination
30-
[currentPage]="currentPage$ | async"
31-
[nPages]="totalPages"
32-
(newCurrentPageEvent)="setCurrentPage($event)"
33-
></gn-ui-pagination>
29+
<gn-ui-pagination [listComponent]="this"></gn-ui-pagination>
3430
</div>

libs/feature/catalog/src/lib/organisations/organisations.component.ts

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@ import { OrganizationsServiceInterface } from '@geonetwork-ui/common/domain/orga
1414
import { SortByField } from '@geonetwork-ui/common/domain/model/search'
1515
import { createFuzzyFilter } from '@geonetwork-ui/util/shared'
1616
import { ORGANIZATION_PAGE_URL_TOKEN } from '../organization-url.token'
17-
import {
18-
ContentGhostComponent,
19-
PaginationComponent,
20-
} from '@geonetwork-ui/ui/elements'
17+
import { ContentGhostComponent } from '@geonetwork-ui/ui/elements'
2118
import { CommonModule } from '@angular/common'
2219
import {
2320
OrganisationPreviewComponent,
2421
OrganisationsFilterComponent,
2522
OrganisationsResultComponent,
2623
} from '@geonetwork-ui/ui/catalog'
24+
import { Paginable, PaginationComponent } from '@geonetwork-ui/ui/layout'
2725

2826
@Component({
2927
selector: 'gn-ui-organisations',
@@ -40,7 +38,7 @@ import {
4038
PaginationComponent,
4139
],
4240
})
43-
export class OrganisationsComponent {
41+
export class OrganisationsComponent implements Paginable {
4442
@Input() itemsOnPage = 12
4543
@Output() orgSelect = new EventEmitter<Organization>()
4644

@@ -89,10 +87,6 @@ export class OrganisationsComponent {
8987
)
9088
)
9189

92-
protected setCurrentPage(page: number): void {
93-
this.currentPage$.next(page)
94-
}
95-
9690
protected setFilterBy(value: string): void {
9791
this.currentPage$.next(1)
9892
this.filterBy$.next(value)
@@ -140,4 +134,27 @@ export class OrganisationsComponent {
140134
if (!this.urlTemplate) return null
141135
return this.urlTemplate.replace('${name}', organisation.name)
142136
}
137+
138+
// Paginable API
139+
get isFirstPage() {
140+
return this.currentPage === 1
141+
}
142+
get isLastPage() {
143+
return this.currentPage === this.totalPages
144+
}
145+
get pagesCount() {
146+
return this.totalPages
147+
}
148+
get currentPage() {
149+
return this.currentPage$.value
150+
}
151+
goToPage(index: number) {
152+
this.currentPage$.next(index)
153+
}
154+
goToNextPage() {
155+
this.goToPage(this.currentPage - 1)
156+
}
157+
goToPrevPage() {
158+
this.goToPage(this.currentPage + 1)
159+
}
143160
}

0 commit comments

Comments
 (0)