diff --git a/client/src/app/site/agenda/components/agenda-list/agenda-list.component.ts b/client/src/app/site/agenda/components/agenda-list/agenda-list.component.ts index 68df26fa7..b42c5c3b9 100644 --- a/client/src/app/site/agenda/components/agenda-list/agenda-list.component.ts +++ b/client/src/app/site/agenda/components/agenda-list/agenda-list.component.ts @@ -20,6 +20,7 @@ import { ViewportService } from 'app/core/ui-services/viewport.service'; import { ViewItem } from '../../models/view-item'; import { ProjectorElementBuildDeskriptor } from 'app/site/base/projectable'; import { _ } from 'app/core/translate/translation-marker'; +import { StorageService } from 'app/core/core-services/storage.service'; /** * List view for the agenda. @@ -90,8 +91,9 @@ export class AgendaListComponent extends ListViewBaseComponent i titleService: Title, protected translate: TranslateService, // protected required for ng-translate-extract matSnackBar: MatSnackBar, + storage: StorageService, private operator: OperatorService, - private route: ActivatedRoute, + protected route: ActivatedRoute, private router: Router, private repo: ItemRepositoryService, private promptService: PromptService, @@ -104,7 +106,7 @@ export class AgendaListComponent extends ListViewBaseComponent i private agendaPdfService: AgendaPdfService, private pdfService: PdfDocumentService ) { - super(titleService, translate, matSnackBar, filterService); + super(titleService, translate, matSnackBar, route, storage, filterService); // activate multiSelect mode for this listview this.canMultiSelect = true; diff --git a/client/src/app/site/assignments/assignment-list/assignment-list.component.ts b/client/src/app/site/assignments/assignment-list/assignment-list.component.ts index 84085f453..d7232eda7 100644 --- a/client/src/app/site/assignments/assignment-list/assignment-list.component.ts +++ b/client/src/app/site/assignments/assignment-list/assignment-list.component.ts @@ -10,6 +10,8 @@ import { AssignmentRepositoryService } from 'app/core/repositories/assignments/a import { ListViewBaseComponent } from '../../base/list-view-base'; import { PromptService } from 'app/core/ui-services/prompt.service'; import { ViewAssignment } from '../models/view-assignment'; +import { StorageService } from 'app/core/core-services/storage.service'; +import { ActivatedRoute } from '@angular/router'; /** * Listview for the assignments @@ -33,6 +35,8 @@ export class AssignmentListComponent extends ListViewBaseComponent extends BaseViewComponent { +export abstract class ListViewBaseComponent extends BaseViewComponent + implements OnDestroy { /** * The data source for a table. Requires to be initialized with a BaseViewModel */ @@ -31,6 +34,17 @@ export abstract class ListViewBaseComponent, public sortService?: BaseSortListService ) { super(titleService, translate, matSnackBar); this.selectedRows = []; + try { + this.storageKey = (>route.component).name; + } catch (e) { + this.storageKey = ''; + } } /** @@ -80,10 +101,12 @@ export abstract class ListViewBaseComponent { this.dataSource = new MatTableDataSource(); this.dataSource.paginator = this.paginator; + // Set the initial page settings. if (this.dataSource.paginator) { + this.initializePagination(); this.dataSource.paginator._intl.itemsPerPageLabel = this.translate.instant('items per page'); } if (this.filterService) { @@ -144,6 +167,34 @@ export abstract class ListViewBaseComponent { + // If the storage is not available - like in history mode - do nothing. + if (this.storage) { + this.storageObject = (await this.storage.get('Pagination')) || {}; + // Set the number of items per page -- by default to 25. + this.paginator.pageSize = this.storageObject[this.storageKey] || 25; + // Subscription to page change events, like size, index. + this.subscriptions.push( + this.paginator.page.subscribe(async (event: PageEvent) => { + await this.setPageSettings(event.pageSize); + }) + ); + } + } + + /** + * Function to set the new selected page size in the browser's local storage. + * + * @param size is the new page size. + */ + public async setPageSettings(size: number): Promise { + this.storageObject[this.storageKey] = size; + await this.storage.set('Pagination', this.storageObject); + } + /** * Default click action on selecting an item. In multiselect modus, * this just adds/removes from a selection, else it performs a {@link singleSelectAction} diff --git a/client/src/app/site/history/components/history-list/history-list.component.ts b/client/src/app/site/history/components/history-list/history-list.component.ts index b50ecd3ce..6bbc87c34 100644 --- a/client/src/app/site/history/components/history-list/history-list.component.ts +++ b/client/src/app/site/history/components/history-list/history-list.component.ts @@ -51,7 +51,7 @@ export class HistoryListComponent extends ListViewBaseComponent implem titleService: Title, protected translate: TranslateService, // protected required for ng-translate-extract matSnackBar: MatSnackBar, + storage: StorageService, + route: ActivatedRoute, private repo: TagRepositoryService, private promptService: PromptService ) { - super(titleService, translate, matSnackBar); + super(titleService, translate, matSnackBar, route, storage); } /** diff --git a/client/src/app/site/users/components/user-list/user-list.component.ts b/client/src/app/site/users/components/user-list/user-list.component.ts index e6d8f8e02..2dfb1f0ab 100644 --- a/client/src/app/site/users/components/user-list/user-list.component.ts +++ b/client/src/app/site/users/components/user-list/user-list.component.ts @@ -20,6 +20,7 @@ import { ViewUser } from '../../models/view-user'; import { ViewGroup } from '../../models/view-group'; import { genders, User } from 'app/shared/models/users/user'; import { _ } from 'app/core/translate/translation-marker'; +import { StorageService } from 'app/core/core-services/storage.service'; /** * Interface for the short editing dialog. @@ -133,11 +134,12 @@ export class UserListComponent extends ListViewBaseComponent imp titleService: Title, protected translate: TranslateService, // protected required for ng-translate-extract matSnackBar: MatSnackBar, + storage: StorageService, private repo: UserRepositoryService, private groupRepo: GroupRepositoryService, private choiceService: ChoiceService, private router: Router, - private route: ActivatedRoute, + protected route: ActivatedRoute, private operator: OperatorService, private vp: ViewportService, protected csvExport: CsvExportService, @@ -148,7 +150,7 @@ export class UserListComponent extends ListViewBaseComponent imp private userPdf: UserPdfExportService, private dialog: MatDialog ) { - super(titleService, translate, matSnackBar, filterService, sortService); + super(titleService, translate, matSnackBar, route, storage, filterService, sortService); // enable multiSelect for this listView this.canMultiSelect = true;