Merge pull request #4534 from GabrielInTheWorld/util-fixes

Adjusts pagination's listener to default code style.
This commit is contained in:
Finn Stutzenstein 2019-03-25 16:18:00 +01:00 committed by GitHub
commit da553b129a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 39 additions and 35 deletions

View File

@ -38,12 +38,12 @@ export abstract class ListViewBaseComponent<V extends BaseViewModel, M extends B
* Holds the key for the storage.
* This is by default the component's name.
*/
private storageKey: string;
private paginationStorageKey: string;
/**
* Holds the value from local storage with the 'Paginator' key.
*/
private storageObject = {};
private paginationStorageObject: { [key: string]: number };
/**
* The table itself
@ -82,17 +82,17 @@ export abstract class ListViewBaseComponent<V extends BaseViewModel, M extends B
titleService: Title,
translate: TranslateService,
matSnackBar: MatSnackBar,
protected route: ActivatedRoute,
private storage: StorageService,
protected route?: ActivatedRoute,
protected storage?: StorageService,
public filterService?: BaseFilterListService<M, V>,
public sortService?: BaseSortListService<V>
) {
super(titleService, translate, matSnackBar);
this.selectedRows = [];
try {
this.storageKey = (<Type<any>>route.component).name;
this.paginationStorageKey = (<Type<any>>route.component).name;
} catch (e) {
this.storageKey = '';
this.paginationStorageKey = '';
}
}
@ -101,7 +101,7 @@ export abstract class ListViewBaseComponent<V extends BaseViewModel, M extends B
* Calling these three functions in the constructor of this class
* would be too early, resulting in non-paginated tables
*/
public async initTable(): Promise<void> {
public initTable(): void {
this.dataSource = new MatTableDataSource();
this.dataSource.paginator = this.paginator;
// Set the initial page settings.
@ -173,13 +173,13 @@ export abstract class ListViewBaseComponent<V extends BaseViewModel, M extends B
private async initializePagination(): Promise<void> {
// If the storage is not available - like in history mode - do nothing.
if (this.storage) {
this.storageObject = (await this.storage.get('Pagination')) || {};
this.paginationStorageObject = (await this.storage.get('Pagination')) || {};
// Set the number of items per page -- by default to 25.
this.paginator.pageSize = this.storageObject[this.storageKey] || 25;
this.paginator.pageSize = this.paginationStorageObject[this.paginationStorageKey] || 25;
// Subscription to page change events, like size, index.
this.subscriptions.push(
this.paginator.page.subscribe(async (event: PageEvent) => {
await this.setPageSettings(event.pageSize);
this.paginator.page.subscribe((event: PageEvent) => {
this.setPageSettings(event.pageSize);
})
);
}
@ -191,8 +191,10 @@ export abstract class ListViewBaseComponent<V extends BaseViewModel, M extends B
* @param size is the new page size.
*/
public async setPageSettings(size: number): Promise<void> {
this.storageObject[this.storageKey] = size;
await this.storage.set('Pagination', this.storageObject);
if (this.paginationStorageObject) {
this.paginationStorageObject[this.paginationStorageKey] = size;
await this.storage.set('Pagination', this.paginationStorageObject);
}
}
/**

View File

@ -51,7 +51,7 @@ export class HistoryListComponent extends ListViewBaseComponent<ViewHistory, His
private router: Router,
private operator: OperatorService
) {
super(titleService, translate, matSnackBar, null, null);
super(titleService, translate, matSnackBar);
}
/**

View File

@ -88,11 +88,11 @@ export class MediafileListComponent extends ListViewBaseComponent<ViewMediafile,
*/
public constructor(
titleService: Title,
matSnackBar: MatSnackBar,
storage: StorageService,
protected translate: TranslateService,
matSnackBar: MatSnackBar,
route: ActivatedRoute,
storage: StorageService,
private router: Router,
protected route: ActivatedRoute,
private repo: MediafileRepositoryService,
private mediaManage: MediaManageService,
private promptService: PromptService,

View File

@ -63,10 +63,10 @@ export class MotionBlockDetailComponent extends ListViewBaseComponent<ViewMotion
titleService: Title,
protected translate: TranslateService,
matSnackBar: MatSnackBar,
route: ActivatedRoute,
storage: StorageService,
private operator: OperatorService,
private router: Router,
protected route: ActivatedRoute,
private repo: MotionBlockRepositoryService,
private motionRepo: MotionRepositoryService,
private promptService: PromptService

View File

@ -81,9 +81,9 @@ export class MotionBlockListComponent extends ListViewBaseComponent<ViewMotionBl
titleService: Title,
translate: TranslateService,
matSnackBar: MatSnackBar,
route: ActivatedRoute,
storage: StorageService,
private router: Router,
protected route: ActivatedRoute,
private repo: MotionBlockRepositoryService,
private agendaRepo: ItemRepositoryService,
private formBuilder: FormBuilder,

View File

@ -89,11 +89,11 @@ export class MotionListComponent extends ListViewBaseComponent<ViewMotion, Motio
titleService: Title,
protected translate: TranslateService, // protected required for ng-translate-extract
matSnackBar: MatSnackBar,
sortService: MotionSortListService,
filterService: MotionFilterListService,
route: ActivatedRoute,
storage: StorageService,
filterService: MotionFilterListService,
sortService: MotionSortListService,
private router: Router,
protected route: ActivatedRoute,
private configService: ConfigService,
private tagRepo: TagRepositoryService,
private motionBlockRepo: MotionBlockRepositoryService,

View File

@ -45,12 +45,12 @@ export class WorkflowListComponent extends ListViewBaseComponent<ViewWorkflow, W
*/
public constructor(
titleService: Title,
matSnackBar: MatSnackBar,
storage: StorageService,
protected translate: TranslateService,
matSnackBar: MatSnackBar,
route: ActivatedRoute,
storage: StorageService,
private dialog: MatDialog,
private router: Router,
protected route: ActivatedRoute,
private workflowRepo: WorkflowRepositoryService,
private promptService: PromptService
) {

View File

@ -1,15 +1,17 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { Title } from '@angular/platform-browser';
import { Tag } from 'app/shared/models/core/tag';
import { ListViewBaseComponent } from '../../../base/list-view-base';
import { TagRepositoryService } from 'app/core/repositories/tags/tag-repository.service';
import { ViewTag } from '../../models/view-tag';
import { FormGroup, FormControl, Validators } from '@angular/forms';
import { PromptService } from 'app/core/ui-services/prompt.service';
import { MatSnackBar } from '@angular/material';
import { StorageService } from 'app/core/core-services/storage.service';
import { ActivatedRoute } from '@angular/router';
import { MatSnackBar } from '@angular/material';
import { TranslateService } from '@ngx-translate/core';
import { Tag } from 'app/shared/models/core/tag';
import { TagRepositoryService } from 'app/core/repositories/tags/tag-repository.service';
import { PromptService } from 'app/core/ui-services/prompt.service';
import { StorageService } from 'app/core/core-services/storage.service';
import { ListViewBaseComponent } from '../../../base/list-view-base';
import { ViewTag } from '../../models/view-tag';
/**
* Listview for the complete lsit of available Tags
@ -43,8 +45,8 @@ export class TagListComponent extends ListViewBaseComponent<ViewTag, Tag> implem
titleService: Title,
protected translate: TranslateService, // protected required for ng-translate-extract
matSnackBar: MatSnackBar,
storage: StorageService,
route: ActivatedRoute,
storage: StorageService,
private repo: TagRepositoryService,
private promptService: PromptService
) {

View File

@ -134,12 +134,12 @@ export class UserListComponent extends ListViewBaseComponent<ViewUser, User> imp
titleService: Title,
protected translate: TranslateService, // protected required for ng-translate-extract
matSnackBar: MatSnackBar,
route: ActivatedRoute,
storage: StorageService,
private repo: UserRepositoryService,
private groupRepo: GroupRepositoryService,
private choiceService: ChoiceService,
private router: Router,
protected route: ActivatedRoute,
private operator: OperatorService,
private vp: ViewportService,
protected csvExport: CsvExportService,