mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 13:02:56 +00:00
Despacho store created and added to despacho page on share file
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { DespachoStoreService } from './despacho-store.service';
|
||||
|
||||
describe('DespachoStoreService', () => {
|
||||
let service: DespachoStoreService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(DespachoStoreService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,58 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { localstoreService } from './localstore.service'
|
||||
import { AES, enc, SHA1 } from 'crypto-js'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class DespachoStoreService {
|
||||
|
||||
// main data
|
||||
private _list: Event[]
|
||||
// local storage keyName
|
||||
private keyName: string;
|
||||
private _count = 0
|
||||
|
||||
constructor() {
|
||||
|
||||
this.keyName = (SHA1(this.constructor.name+ 'home/eventSource')).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
|
||||
})
|
||||
}, 10)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const DespachoStore = new DespachoStoreService()
|
||||
Reference in New Issue
Block a user