diff --git a/client/core/src/lib/index.js b/client/core/src/lib/index.js index 966f25e2f..a081b5f87 100644 --- a/client/core/src/lib/index.js +++ b/client/core/src/lib/index.js @@ -5,6 +5,7 @@ import './getTemplate'; import './app'; import './interceptor'; import './aclService'; +import './storageServices'; export * from './util'; export {default as splitingRegister} from './splitingRegister'; diff --git a/client/core/src/lib/storageServices.js b/client/core/src/lib/storageServices.js new file mode 100644 index 000000000..ee64b6f0c --- /dev/null +++ b/client/core/src/lib/storageServices.js @@ -0,0 +1,66 @@ +import {module} from '../module'; + +class VnStorage { + constructor() { + this._type = ''; + this.prefix = 'vn'; + } + set type(value) { + this._type = value; + this.checkSupport(); + } + get type() { + return this._type; + } + get webStorage() { + return window[this.type]; + } + checkSupport() { + try { + let supported = (this.type in window && window[this.type] !== null); + if (supported) { + let key = '__' + Math.round(Math.random() * 1e7); + let webStorage = window[this.type]; + webStorage.setItem(key, ''); + webStorage.removeItem(key); + } + } catch (e) { + console.error('VnStorage.notification.error', e.message); + return false; + } + } + get(param) { + let toRead = this.webStorage.getItem(`${this.prefix}.${param}`); + if (toRead && toRead.startsWith('jsonObject:')) { + toRead = JSON.parse(toRead.replace('jsonObject:', '')); + } + return toRead; + } + set(param, data) { + let toStorage = typeof data === 'object' ? `jsonObject:${JSON.stringify(data)}` : data; + this.webStorage.setItem(`${this.prefix}.${param}`, toStorage); + } + remove(param) { + this.webStorage.removeItem(`${this.prefix}.${param}`); + } + clear() { + this.webStorage.clear(); + } +} + +class SessionStorage extends VnStorage { + constructor() { + super(); + this.type = 'sessionStorage'; + } +} + +class LocalStorage extends VnStorage { + constructor() { + super(); + this.type = 'localStorage'; + } +} + +module.service('sessionStorage', SessionStorage); +module.service('localStorage', LocalStorage); diff --git a/client/production/src/production-table/production-table.js b/client/production/src/production-table/production-table.js index 96ebf6c2e..91c24314f 100644 --- a/client/production/src/production-table/production-table.js +++ b/client/production/src/production-table/production-table.js @@ -32,7 +32,6 @@ export class ProductionTable { onOrder(field, order) { let reverse = order === 'DESC'; this.tickets = this.$filter('orderBy')(this.tickets, field, reverse); - this.pageTickets(); } pageTickets() { let init = (this.pageTable.filter.page - 1) * this.itemsDisplayedInList; @@ -46,9 +45,9 @@ ProductionTable.$inject = ['$filter']; ngModule.component('vnProductionTable', { template: require('./production-table.html'), bindings: { - tickets: '=', + tickets: '<', footer: '<', - checkAll: '=' + checkAll: '<' }, controller: ProductionTable });