From ab998f7b6dffbe461d830d3696cb46491ad6afb0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 23 Feb 2018 14:36:16 +0100 Subject: Improve admin tables --- .../src/app/shared/misc/delete-button.component.html | 2 +- .../src/app/shared/misc/delete-button.component.ts | 3 ++- client/src/app/shared/rest/rest-table.ts | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) (limited to 'client/src/app/shared') diff --git a/client/src/app/shared/misc/delete-button.component.html b/client/src/app/shared/misc/delete-button.component.html index 3db483882..d49de294a 100644 --- a/client/src/app/shared/misc/delete-button.component.html +++ b/client/src/app/shared/misc/delete-button.component.html @@ -1,4 +1,4 @@ - Delete + {{ label }} diff --git a/client/src/app/shared/misc/delete-button.component.ts b/client/src/app/shared/misc/delete-button.component.ts index e04039f69..2ffd98212 100644 --- a/client/src/app/shared/misc/delete-button.component.ts +++ b/client/src/app/shared/misc/delete-button.component.ts @@ -1,4 +1,4 @@ -import { Component } from '@angular/core' +import { Component, Input } from '@angular/core' @Component({ selector: 'my-delete-button', @@ -7,4 +7,5 @@ import { Component } from '@angular/core' }) export class DeleteButtonComponent { + @Input() label = 'Delete' } diff --git a/client/src/app/shared/rest/rest-table.ts b/client/src/app/shared/rest/rest-table.ts index d04d91c68..165fc4e45 100644 --- a/client/src/app/shared/rest/rest-table.ts +++ b/client/src/app/shared/rest/rest-table.ts @@ -4,13 +4,28 @@ import { SortMeta } from 'primeng/components/common/sortmeta' import { RestPagination } from './rest-pagination' export abstract class RestTable { + abstract totalRecords: number abstract rowsPerPage: number abstract sort: SortMeta abstract pagination: RestPagination + private sortLocalStorageKey = 'rest-table-sort-' + this.constructor.name + protected abstract loadData (): void + loadSort () { + const result = localStorage.getItem(this.sortLocalStorageKey) + + if (result) { + try { + this.sort = JSON.parse(result) + } catch (err) { + console.error('Cannot load sort of local storage key ' + this.sortLocalStorageKey, err) + } + } + } + loadLazy (event: LazyLoadEvent) { this.sort = { order: event.sortOrder, @@ -23,6 +38,11 @@ export abstract class RestTable { } this.loadData() + this.saveSort() + } + + saveSort () { + localStorage.setItem(this.sortLocalStorageKey, JSON.stringify(this.sort)) } } -- cgit v1.2.3