mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 12:37:53 +00:00
separate notification responsability
This commit is contained in:
+4
-4
@@ -1,13 +1,13 @@
|
|||||||
import { TestBed } from '@angular/core/testing';
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
import { NotificationsStoreService } from './notifications-store.service';
|
import { NotificationHolderService } from './notification-holder.service';
|
||||||
|
|
||||||
describe('NotificationsStoreService', () => {
|
describe('NotificationHolderService', () => {
|
||||||
let service: NotificationsStoreService;
|
let service: NotificationHolderService;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({});
|
TestBed.configureTestingModule({});
|
||||||
service = TestBed.inject(NotificationsStoreService);
|
service = TestBed.inject(NotificationHolderService);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be created', () => {
|
it('should be created', () => {
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { StorageService } from '../storage.service';
|
||||||
|
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class NotificationHolderService {
|
||||||
|
|
||||||
|
notificationList = []
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private storageService: StorageService,
|
||||||
|
) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.restore()
|
||||||
|
} catch(error) {}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
restore() {
|
||||||
|
this.storageService.get("Notifications").then((store) => {
|
||||||
|
if(Array.isArray(store)) {
|
||||||
|
this.notificationList = store
|
||||||
|
}
|
||||||
|
}).catch((error) => {})
|
||||||
|
}
|
||||||
|
|
||||||
|
save() {
|
||||||
|
this.storageService.store("Notifications", this.notificationList)
|
||||||
|
}
|
||||||
|
|
||||||
|
addNotification(notification) {
|
||||||
|
|
||||||
|
const element = notification
|
||||||
|
const i = this.notificationList.length + 1
|
||||||
|
|
||||||
|
let notificationObject;
|
||||||
|
if (element.notification) {
|
||||||
|
|
||||||
|
notificationObject = {
|
||||||
|
index: i,
|
||||||
|
title: element.notification.title,
|
||||||
|
Service: element.data.Service,
|
||||||
|
Object: element.data.Object,
|
||||||
|
IdObject: element.data.IdObject,
|
||||||
|
FolderId: element.data.FolderId,
|
||||||
|
body: element.notification.body,
|
||||||
|
dateInit: this.getFormatedTime(element.data.dateInit),
|
||||||
|
dateEnd: this.getFormatedTime(element.data.dateEnd),
|
||||||
|
Location: element.data.Location,
|
||||||
|
TypeAgenda: element.data.TypeAgenda,
|
||||||
|
Role: element.data.Role,
|
||||||
|
Status: element.data.Status,
|
||||||
|
read: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (element.data) {
|
||||||
|
notificationObject = {
|
||||||
|
index: i,
|
||||||
|
title: element.title,
|
||||||
|
Service: element.data.Service,
|
||||||
|
Object: element.data.Object,
|
||||||
|
IdObject: element.data.IdObject,
|
||||||
|
FolderId: element.data.FolderId,
|
||||||
|
body: element.body,
|
||||||
|
dateInit: this.getFormatedTime(element.data.dateInit),
|
||||||
|
dateEnd: this.getFormatedTime(element.data.dateEnd),
|
||||||
|
Location: element.data.Location,
|
||||||
|
TypeAgenda: element.data.TypeAgenda,
|
||||||
|
Role: element.data.Role,
|
||||||
|
Status: element.data.Status,
|
||||||
|
read: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
{
|
||||||
|
notificationObject = {
|
||||||
|
FolderId: element.FolderId,
|
||||||
|
IdObject: element.IdObject,
|
||||||
|
Location: element.Location,
|
||||||
|
Object: element.Object,
|
||||||
|
Role: element.Role,
|
||||||
|
Service: element.Service,
|
||||||
|
Status: element.Status,
|
||||||
|
TypeAgenda: element.TypeAgenda,
|
||||||
|
body: element.body,
|
||||||
|
dateEnd: element.dateEnd,
|
||||||
|
dateInit: element.dateInit,
|
||||||
|
index: element.index,
|
||||||
|
title: element.title,
|
||||||
|
read: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.notificationList.push(notificationObject)
|
||||||
|
this.save()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
getFormatedTime(dateString) {
|
||||||
|
var date = new Date(dateString);
|
||||||
|
var hours = date.getHours() /* > 12 ? date.getHours() - 12 : date.getHours() */;
|
||||||
|
var am_pm = date.getHours() >= 12 ? "pm" : "am";
|
||||||
|
var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
|
||||||
|
let time = hours + ":" + minutes /* + " " + am_pm */;
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
removeNotification(notification) {
|
||||||
|
this.notificationList = this.notificationList.filter( (e) => {
|
||||||
|
return e.index != notification.index
|
||||||
|
})
|
||||||
|
this.save()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
import { Injectable } from '@angular/core';
|
|
||||||
|
|
||||||
@Injectable({
|
|
||||||
providedIn: 'root'
|
|
||||||
})
|
|
||||||
export class NotificationsStoreService {
|
|
||||||
|
|
||||||
constructor() { }
|
|
||||||
}
|
|
||||||
@@ -149,14 +149,19 @@ export class HeaderPage implements OnInit {
|
|||||||
|
|
||||||
console.log('Get notification data',)
|
console.log('Get notification data',)
|
||||||
|
|
||||||
this.notificationLength = value.length;
|
this.zone.run(() => {
|
||||||
console.log('Call notification data', this.notificationLength)
|
this.notificationLength = value.length;
|
||||||
|
console.log('Call notification data', this.notificationLength)
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
console.error('header storage get notification', error)
|
this.zone.run(() => {
|
||||||
this.notificationLength = 0;
|
console.error('header storage get notification', error)
|
||||||
|
this.notificationLength = 0;
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
console.error('header storage get notification', error)
|
console.error('header storage get notification', error)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user