mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 05:16:07 +00:00
Merge branch 'developer' of bitbucket.org:equilibriumito/gabinete-digital into developer
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { DespachosPageStoreService } from './despachos-page-store.service';
|
||||
|
||||
describe('DespachosPageStoreService', () => {
|
||||
let service: DespachosPageStoreService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(DespachosPageStoreService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,59 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { localstoreService } from './localstore.service'
|
||||
import { AES, enc, SHA1 } from 'crypto-js'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class DespachosPageStoreService {
|
||||
|
||||
// main data
|
||||
private _list: [] = []
|
||||
// local storage keyName
|
||||
private keyName: string;
|
||||
private _count = 0
|
||||
|
||||
constructor() {
|
||||
|
||||
this.keyName = (SHA1(this.constructor.name)).toString()
|
||||
|
||||
|
||||
setTimeout(()=>{
|
||||
let restore = localstoreService.get(this.keyName, {})
|
||||
this._list = restore.eventsList || []
|
||||
this._count = restore.count || 0
|
||||
}, 10)
|
||||
|
||||
}
|
||||
|
||||
get list() {
|
||||
return this._list || []
|
||||
}
|
||||
|
||||
get count() {
|
||||
return this._count
|
||||
}
|
||||
set count(value) {
|
||||
this._count = value
|
||||
}
|
||||
|
||||
reset(eventsList: any) {
|
||||
this._list = eventsList
|
||||
|
||||
this.count = this._list.length
|
||||
this.save(this._list)
|
||||
}
|
||||
|
||||
private save(eventsList: any) {
|
||||
setTimeout(()=>{
|
||||
localstoreService.set(this.keyName,{
|
||||
eventsList,
|
||||
count: this._list.length
|
||||
})
|
||||
}, 10)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const DespachoPageStore = new DespachosPageStoreService()
|
||||
Reference in New Issue
Block a user