mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
header change
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { NotificationHolderService } from './notification-holder.service';
|
||||
|
||||
describe('NotificationHolderService', () => {
|
||||
let service: NotificationHolderService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(NotificationHolderService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,118 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { StorageService } from '../services/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()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user