Skip to content

Commit

Permalink
[front] add itemsPerPage in localStorage fix #358
Browse files Browse the repository at this point in the history
  • Loading branch information
t8g committed Aug 28, 2017
1 parent e8e5c0f commit a3ce0f8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion client/src/app/data-table/data-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { StorageService } from '../storage.service';
export class DataTableComponent implements OnInit, OnChanges {
page: any[];
filters: any = {};
itemsPerPage = 10;
sortedState: { key: string, reverse: boolean } = { key: '', reverse: false };
unfilteredData: any[];
lang: string;
Expand All @@ -23,6 +22,8 @@ export class DataTableComponent implements OnInit, OnChanges {
@Input() cols: any[];
@Input() editedId: string;
@Output() onFilter = new EventEmitter<any>();
@Output() onItemsPerPageChange = new EventEmitter<number>();
@Input() itemsPerPage: number = 10;
@Input() feature: string;

constructor(
Expand Down Expand Up @@ -87,6 +88,7 @@ export class DataTableComponent implements OnInit, OnChanges {
}

pageChanged($event) {
if (this.itemsPerPage !== $event.itemsPerPage) this.onItemsPerPageChange.emit($event.itemsPerPage);
this.itemsPerPage = $event.itemsPerPage;
this.calculPage($event.page);
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/isari-list/isari-list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

<isari-spinner *ngIf="loading"></isari-spinner>

<isari-data-table *ngIf="!loading" (onFilter)="filtered($event)" [data]="data" [cols]="selectedColumns" [editedId]="editedId" [feature]="feature"></isari-data-table>
<isari-data-table *ngIf="!loading" (onFilter)="filtered($event)" (onItemsPerPageChange)="storeItemsPerPage($event)" [itemsPerPage]="itemsPerPage" [data]="data" [cols]="selectedColumns" [editedId]="editedId" [feature]="feature"></isari-data-table>
</md-card>

<router-outlet name="editor"></router-outlet>
Expand Down
10 changes: 9 additions & 1 deletion client/src/app/isari-list/isari-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class IsariListComponent implements OnInit {
activityType: string;
activityTypeLabel: string;
canCreate = false;
itemsPerPage: number;

constructor (
private userService: UserService,
Expand Down Expand Up @@ -79,7 +80,7 @@ export class IsariListComponent implements OnInit {
const dateFilters = this.storageService.get('dateFilters', this.feature) || {};
//We removed the adding today's date as defautl startDate
//This mask a bug: the setValue doesnot properly update the date fields
// when not reloading completely the page (type of activity switch)
// when not reloading completely the page (type of activity switch)
this.dateForm.controls['startDate'].setValue(dateFilters['startDate'] || '');
this.dateForm.controls['endDate'].setValue(dateFilters['endDate'] || '');

Expand All @@ -94,6 +95,9 @@ export class IsariListComponent implements OnInit {
this.loadDatas();
}

// set itemsPerPage
this.itemsPerPage = this.storageService.get('itemsPerPage', this.feature) || 10;

});

this.isariDataService.getEnum('activityTypes')
Expand Down Expand Up @@ -134,6 +138,10 @@ export class IsariListComponent implements OnInit {
this.loadDatas();
}

storeItemsPerPage(itemsPerPage) {
this.storageService.save(itemsPerPage, 'itemsPerPage', this.feature);
}

filtered($event) {
this.filteredData = $event.data;
}
Expand Down

0 comments on commit a3ce0f8

Please sign in to comment.