mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
add web notification popup
This commit is contained in:
@@ -18,6 +18,7 @@ import { ExpedienteGdStore } from '../store/expedientegd-store.service';
|
||||
import { InativityService } from '../services/inativity.service';
|
||||
import { SessionStore } from '../store/session.service';
|
||||
import { StorageService } from '../services/storage.service';
|
||||
import { WebNotificationPopupService } from '../services/notification/web-notification-popup.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-home',
|
||||
@@ -72,7 +73,10 @@ export class HomePage implements OnInit {
|
||||
public documentCounterService: DocumentCounterService,
|
||||
private despachoRule: DespachoService,
|
||||
private inativityService: InativityService,
|
||||
private storageService: StorageService,) {
|
||||
private storageService: StorageService,
|
||||
private webNotificationPopupService: WebNotificationPopupService) {
|
||||
|
||||
this.webNotificationPopupService.askNotificationPermission()
|
||||
|
||||
this.router.events.subscribe((val) => {
|
||||
document.querySelectorAll('ion-modal').forEach((e: any) => e.remove())
|
||||
@@ -176,6 +180,8 @@ export class HomePage implements OnInit {
|
||||
|
||||
synchro.registerCallback('Notification', (DataArray)=> {
|
||||
|
||||
this.webNotificationPopupService.sendNotification(DataArray.Object)
|
||||
|
||||
this.storageService.get('Notifications').then((data)=>{
|
||||
data.push(DataArray)
|
||||
this.storageService.store("Notifications", data)
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { WebNotificationPopupService } from './web-notification-popup.service';
|
||||
|
||||
describe('WebNotificationPopupService', () => {
|
||||
let service: WebNotificationPopupService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(WebNotificationPopupService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,47 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class WebNotificationPopupService {
|
||||
|
||||
constructor() { }
|
||||
|
||||
|
||||
askNotificationPermission() {
|
||||
|
||||
// function to actually ask the permissions
|
||||
function handlePermission(permission) {}
|
||||
|
||||
// Let's check if the browser supports notifications
|
||||
if (!('Notification' in window)) {
|
||||
console.log("This browser does not support notifications.");
|
||||
} else {
|
||||
if(this.checkNotificationPromise()) {
|
||||
Notification.requestPermission()
|
||||
.then((permission) => {
|
||||
handlePermission(permission);
|
||||
})
|
||||
} else {
|
||||
Notification.requestPermission(function(permission) {
|
||||
handlePermission(permission);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private checkNotificationPromise() {
|
||||
try {
|
||||
Notification.requestPermission().then();
|
||||
} catch(e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
sendNotification(message) {
|
||||
var n = new Notification(message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user