Skip to content

Commit

Permalink
feat: support simple page option
Browse files Browse the repository at this point in the history
  • Loading branch information
ZOTBLX committed May 19, 2024
1 parent 840d408 commit 88a2e37
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/portal/src/app/base/left-side-nav/group/group.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,18 @@ <h2 class="custom-h2">{{ 'GROUP.GROUP' | translate }}</h2>
[clrDgPageSize]="pageSize"
[(clrDgPage)]="currentPage"
[clrDgTotalItems]="totalCount">
<clr-dg-page-size [clrPageSizeOptions]="[15, 25, 50]">{{
'PAGINATION.PAGE_SIZE' | translate
}}</clr-dg-page-size>
<clr-dg-page-size
[clrPageSizeOptions]="pageSizeOptions"
>{{
'PAGINATION.PAGE_SIZE' | translate
}}</clr-dg-page-size
>
<input
type="number"
min="1"
[(ngModel)]="newPageSize"
placeholder="Enter custom page size" />
<button (click)="addPageSize()">Add</button>
<span *ngIf="totalCount">
{{ pagination.firstItem + 1 }} -
{{ pagination.lastItem + 1 }}
Expand Down
34 changes: 34 additions & 0 deletions src/portal/src/app/base/left-side-nav/group/group.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export class GroupComponent implements OnInit, OnDestroy {
groups: UserGroup[] = [];
currentPage: number = 1;
totalCount: number = 0;
pageSizeOptions: number[] = [15, 25, 50];
// user input
newPageSize: number;
pageSize: number = getPageSizeFromLocalStorage(
PageSizeMapKeys.SYSTEM_GROUP_COMPONENT
);
Expand Down Expand Up @@ -125,6 +128,7 @@ export class GroupComponent implements OnInit, OnDestroy {
}
);
}
this.loadPageSizeOptions();
}
ngOnDestroy(): void {
this.delSub.unsubscribe();
Expand Down Expand Up @@ -293,6 +297,36 @@ export class GroupComponent implements OnInit, OnDestroy {
this.loadData();
}
}

// load page size options from the local storage if set
loadPageSizeOptions() {
const additionalSizes = JSON.parse(
localStorage.getItem('pageSizeOptions')
);
if (additionalSizes) {
this.pageSizeOptions = [
...this.pageSizeOptions,
...additionalSizes,
];
}
}

addPageSize() {
if (
this.newPageSize &&
!this.pageSizeOptions.includes(this.newPageSize)
) {
this.pageSizeOptions.push(this.newPageSize);
// sort the page size options array
this.pageSizeOptions.sort((a, b) => a - b);
// save new options into local storage
localStorage.setItem(
'pageSizeOptions',
JSON.stringify(this.pageSizeOptions)
);
}
}

get canAddGroup(): boolean {
return this.session.currentUser.has_admin_role;
}
Expand Down
3 changes: 2 additions & 1 deletion src/portal/src/app/base/left-side-nav/group/group.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { SharedModule } from '../../../shared/shared.module';
import { GroupComponent } from './group.component';
import { AddGroupModalComponent } from './add-group-modal/add-group-modal.component';
Expand All @@ -11,7 +12,7 @@ const routes: Routes = [
},
];
@NgModule({
imports: [SharedModule, RouterModule.forChild(routes)],
imports: [SharedModule, RouterModule.forChild(routes), FormsModule],
declarations: [GroupComponent, AddGroupModalComponent],
})
export class GroupModule {}

0 comments on commit 88a2e37

Please sign in to comment.