Skip to content

Commit 7c9c733

Browse files
Add pagination and total to examine dashboard (#19847)
* Add pagination and total to examine dashboard * fix name and localization --------- Co-authored-by: Lan Nguyen Thuy <[email protected]>
1 parent a630feb commit 7c9c733

File tree

2 files changed

+68
-4
lines changed

2 files changed

+68
-4
lines changed

src/Umbraco.Web.UI.Client/src/packages/core/utils/pagination-manager/pagination.manager.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,22 @@ export class UmbPaginationManager extends EventTarget {
138138
const skip = Math.max(0, (this.#currentPage.getValue() - 1) * this.#pageSize.getValue());
139139
this.#skip.setValue(skip);
140140
}
141+
142+
/**
143+
* Gets the index of the first item on the current page (for display).
144+
* @returns {number}
145+
* @memberof UmbPaginationManager
146+
*/
147+
public getDisplayStart(): number {
148+
return this.getSkip() + 1;
149+
}
150+
151+
/**
152+
* Gets the index of the last item on the current page (for display).
153+
* @returns {number}
154+
* @memberof UmbPaginationManager
155+
*/
156+
public getDisplayEnd(): number {
157+
return Math.min(this.getSkip() + this.getPageSize(), this.getTotalItems());
158+
}
141159
}

src/Umbraco.Web.UI.Client/src/packages/search/examine-management-dashboard/views/section-view-examine-searchers.ts

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { UmbModalRouteRegistrationController } from '@umbraco-cms/backoffice/rou
88
import { SearcherService } from '@umbraco-cms/backoffice/external/backend-api';
99
import { UmbLitElement, umbFocus } from '@umbraco-cms/backoffice/lit-element';
1010
import { tryExecute } from '@umbraco-cms/backoffice/resources';
11+
import { UmbPaginationManager } from '@umbraco-cms/backoffice/utils';
12+
import type { UUIPaginationEvent } from '@umbraco-cms/backoffice/external/uui';
1113

1214
interface ExposedSearchResultField {
1315
name: string;
@@ -34,6 +36,17 @@ export class UmbDashboardExamineSearcherElement extends UmbLitElement {
3436
@state()
3537
private _workspacePath = 'aa';
3638

39+
@state()
40+
_totalPages = 1;
41+
42+
@state()
43+
_currentPage = 1;
44+
45+
@state()
46+
_totalNumberOfResults = 0;
47+
48+
#paginationManager = new UmbPaginationManager();
49+
3750
private _onKeyPress(e: KeyboardEvent) {
3851
if (e.key == 'Enter') {
3952
this._onSearch();
@@ -44,6 +57,12 @@ export class UmbDashboardExamineSearcherElement extends UmbLitElement {
4457

4558
constructor() {
4659
super();
60+
61+
this.#paginationManager.setPageSize(100);
62+
63+
this.observe(this.#paginationManager.currentPage, (number) => (this._currentPage = number));
64+
this.observe(this.#paginationManager.totalPages, (number) => (this._totalPages = number));
65+
4766
new UmbModalRouteRegistrationController(this, UMB_WORKSPACE_MODAL)
4867
.addAdditionalPath(':entityType')
4968
.onSetup((routingInfo) => {
@@ -64,13 +83,15 @@ export class UmbDashboardExamineSearcherElement extends UmbLitElement {
6483
path: { searcherName: this.searcherName },
6584
query: {
6685
term: this._searchInput.value,
67-
take: 100,
68-
skip: 0,
86+
take: this.#paginationManager.getPageSize(),
87+
skip: this.#paginationManager.getSkip(),
6988
},
7089
}),
7190
);
7291

7392
this._searchResults = data?.items ?? [];
93+
this.#paginationManager.setTotalItems(data.total);
94+
this._totalNumberOfResults = data.total;
7495
this._updateFieldFilter();
7596
this._searchLoading = false;
7697
}
@@ -158,13 +179,29 @@ export class UmbDashboardExamineSearcherElement extends UmbLitElement {
158179
}
159180
}
160181

182+
#onPageChange(event: UUIPaginationEvent) {
183+
this.#paginationManager.setCurrentPageNumber(event.target?.current);
184+
this._onSearch();
185+
}
186+
161187
private renderSearchResults() {
162188
if (this._searchLoading) return html`<uui-loader></uui-loader>`;
163189
if (!this._searchResults) return nothing;
164190
if (!this._searchResults.length) {
165191
return html`<p>${this.localize.term('examineManagement_noResults')}</p>`;
166192
}
167-
return html`<div class="table-container">
193+
return html`
194+
<div>
195+
${this.localize.term(
196+
'examineManagement_searchResultsFound',
197+
this.#paginationManager.getDisplayStart(),
198+
this.#paginationManager.getDisplayEnd(),
199+
this._totalNumberOfResults,
200+
this._currentPage,
201+
this._totalPages,
202+
)}
203+
</div>
204+
<div class="table-container">
168205
<uui-scroll-container>
169206
<uui-table class="search">
170207
<uui-table-head>
@@ -212,7 +249,16 @@ export class UmbDashboardExamineSearcherElement extends UmbLitElement {
212249
</uui-tag>
213250
</uui-icon-registry-essential>
214251
</button>
215-
</div>`;
252+
</div>
253+
<uui-pagination
254+
.total=${this._totalPages}
255+
.current=${this._currentPage}
256+
firstlabel=${this.localize.term('general_first')}
257+
previouslabel=${this.localize.term('general_previous')}
258+
nextlabel=${this.localize.term('general_next')}
259+
lastlabel=${this.localize.term('general_last')}
260+
@change=${this.#onPageChange}></uui-pagination>
261+
`;
216262
}
217263

218264
renderHeadCells() {

0 commit comments

Comments
 (0)