2018-09-11 16:38:23 +02:00
|
|
|
import { ViewChild } from '@angular/core';
|
|
|
|
import { Title } from '@angular/platform-browser';
|
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2018-11-02 11:41:03 +01:00
|
|
|
import { MatTableDataSource, MatTable, MatSort, MatPaginator, MatSnackBar } from '@angular/material';
|
2018-09-11 16:38:23 +02:00
|
|
|
import { BaseViewModel } from './base-view-model';
|
2018-11-02 11:41:03 +01:00
|
|
|
import { BaseViewComponent } from './base-view';
|
2018-09-11 16:38:23 +02:00
|
|
|
|
2018-11-02 11:41:03 +01:00
|
|
|
export abstract class ListViewBaseComponent<V extends BaseViewModel> extends BaseViewComponent {
|
2018-09-11 16:38:23 +02:00
|
|
|
/**
|
|
|
|
* The data source for a table. Requires to be initialised with a BaseViewModel
|
|
|
|
*/
|
|
|
|
public dataSource: MatTableDataSource<V>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The table itself
|
|
|
|
*/
|
|
|
|
@ViewChild(MatTable)
|
|
|
|
protected table: MatTable<V>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Table paginator
|
|
|
|
*/
|
|
|
|
@ViewChild(MatPaginator)
|
|
|
|
protected paginator: MatPaginator;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sorter for a table
|
|
|
|
*/
|
|
|
|
@ViewChild(MatSort)
|
|
|
|
protected sort: MatSort;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor for list view bases
|
|
|
|
* @param titleService the title serivce
|
|
|
|
* @param translate the translate service
|
2018-11-02 11:41:03 +01:00
|
|
|
* @param matSnackBar
|
2018-09-11 16:38:23 +02:00
|
|
|
*/
|
2018-11-02 11:41:03 +01:00
|
|
|
public constructor(titleService: Title, translate: TranslateService, matSnackBar: MatSnackBar) {
|
|
|
|
super(titleService, translate, matSnackBar);
|
2018-09-11 16:38:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Children need to call this in their init-function.
|
|
|
|
* Calling these three functions in the constructor of this class
|
|
|
|
* would be too early, resulting in non-paginated tables
|
|
|
|
*/
|
|
|
|
public initTable(): void {
|
|
|
|
this.dataSource = new MatTableDataSource();
|
|
|
|
this.dataSource.paginator = this.paginator;
|
|
|
|
this.dataSource.sort = this.sort;
|
|
|
|
}
|
|
|
|
}
|