created storage services
This commit is contained in:
parent
d19ebe0c8c
commit
dce3ae7520
|
@ -5,6 +5,7 @@ import './getTemplate';
|
||||||
import './app';
|
import './app';
|
||||||
import './interceptor';
|
import './interceptor';
|
||||||
import './aclService';
|
import './aclService';
|
||||||
|
import './storageServices';
|
||||||
|
|
||||||
export * from './util';
|
export * from './util';
|
||||||
export {default as splitingRegister} from './splitingRegister';
|
export {default as splitingRegister} from './splitingRegister';
|
||||||
|
|
|
@ -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);
|
|
@ -32,7 +32,6 @@ export class ProductionTable {
|
||||||
onOrder(field, order) {
|
onOrder(field, order) {
|
||||||
let reverse = order === 'DESC';
|
let reverse = order === 'DESC';
|
||||||
this.tickets = this.$filter('orderBy')(this.tickets, field, reverse);
|
this.tickets = this.$filter('orderBy')(this.tickets, field, reverse);
|
||||||
this.pageTickets();
|
|
||||||
}
|
}
|
||||||
pageTickets() {
|
pageTickets() {
|
||||||
let init = (this.pageTable.filter.page - 1) * this.itemsDisplayedInList;
|
let init = (this.pageTable.filter.page - 1) * this.itemsDisplayedInList;
|
||||||
|
@ -46,9 +45,9 @@ ProductionTable.$inject = ['$filter'];
|
||||||
ngModule.component('vnProductionTable', {
|
ngModule.component('vnProductionTable', {
|
||||||
template: require('./production-table.html'),
|
template: require('./production-table.html'),
|
||||||
bindings: {
|
bindings: {
|
||||||
tickets: '=',
|
tickets: '<',
|
||||||
footer: '<',
|
footer: '<',
|
||||||
checkAll: '='
|
checkAll: '<'
|
||||||
},
|
},
|
||||||
controller: ProductionTable
|
controller: ProductionTable
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue