mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 12:37:53 +00:00
Web notifications added
This commit is contained in:
+1
-2
@@ -84,8 +84,7 @@
|
|||||||
"serve": {
|
"serve": {
|
||||||
"builder": "@angular-devkit/build-angular:dev-server",
|
"builder": "@angular-devkit/build-angular:dev-server",
|
||||||
"options": {
|
"options": {
|
||||||
"browserTarget": "app:build",
|
"browserTarget": "app:build"
|
||||||
"proxyConfig": "src/proxy.conf.json"
|
|
||||||
},
|
},
|
||||||
"configurations": {
|
"configurations": {
|
||||||
"production": {
|
"production": {
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
if ('serviceWorker' in navigator) {
|
||||||
|
navigator.serviceWorker.register('./firebase-messaging-sw.js')
|
||||||
|
.then(function(registration) {
|
||||||
|
console.log('Registration successful, scope is:', registration.scope);
|
||||||
|
}).catch(function(err) {
|
||||||
|
console.log('Service worker registration failed, error:', err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// Scripts for firebase and firebase messaging
|
||||||
|
|
||||||
|
|
||||||
|
/* importScripts('https://www.gstatic.com/firebasejs/8.2.0/firebase-app.js');
|
||||||
|
importScripts('https://www.gstatic.com/firebasejs/8.2.0/firebase-messaging.js');
|
||||||
|
|
||||||
|
// Initialize the Firebase app in the service worker by passing the generated config
|
||||||
|
var firebaseConfig = {
|
||||||
|
apiKey: "AIzaSyAAdHmTFznCMerdT99nrewJgISRvtxPqoY",
|
||||||
|
authDomain: "gabinete-digital-2020.firebaseapp.com",
|
||||||
|
databaseURL: "https://gabinete-digital-2020.firebaseio.com",
|
||||||
|
projectId: "gabinete-digital-2020",
|
||||||
|
storageBucket: "gabinete-digital-2020.appspot.com",
|
||||||
|
messagingSenderId: "800733765231",
|
||||||
|
appId: "1:800733765231:web:28e7792ab150006513779a",
|
||||||
|
measurementId: "G-8QN4BLZ8XK"
|
||||||
|
};
|
||||||
|
|
||||||
|
firebase.initializeApp(firebaseConfig);
|
||||||
|
|
||||||
|
// Retrieve firebase messaging
|
||||||
|
const messaging = firebase.messaging();
|
||||||
|
|
||||||
|
messaging.onBackgroundMessage(function(payload) {
|
||||||
|
console.log('Received background message ', payload);
|
||||||
|
|
||||||
|
const notificationTitle = payload.notification.title;
|
||||||
|
const notificationOptions = {
|
||||||
|
body: payload.notification.body,
|
||||||
|
};
|
||||||
|
|
||||||
|
self.registration.showNotification(notificationTitle,
|
||||||
|
notificationOptions);
|
||||||
|
}); */
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { AnimationController, ModalController,Platform } from '@ionic/angular';
|
import { AnimationController, ModalController, Platform } from '@ionic/angular';
|
||||||
import { SearchPage } from 'src/app/pages/search/search.page';
|
import { SearchPage } from 'src/app/pages/search/search.page';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { LoginUserRespose } from 'src/app/models/user.model';
|
import { LoginUserRespose } from 'src/app/models/user.model';
|
||||||
@@ -28,7 +28,7 @@ export class HeaderPage implements OnInit {
|
|||||||
SessionStore = SessionStore
|
SessionStore = SessionStore
|
||||||
|
|
||||||
production = environment.production
|
production = environment.production
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private modalController: ModalController,
|
private modalController: ModalController,
|
||||||
@@ -50,39 +50,39 @@ export class HeaderPage implements OnInit {
|
|||||||
this.hideSearch();
|
this.hideSearch();
|
||||||
this.notificationLengthData();
|
this.notificationLengthData();
|
||||||
|
|
||||||
/* if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
/* if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
||||||
console.log('Notifications not supported')
|
console.log('Notifications not supported')
|
||||||
this.UpdateNotificationCount();
|
this.UpdateNotificationCount();
|
||||||
} else {
|
} else {
|
||||||
this.UpdateNotificationCount();
|
this.UpdateNotificationCount();
|
||||||
} */
|
} */
|
||||||
|
|
||||||
this.eventrigger.getObservable().subscribe((data)=>{
|
|
||||||
if(data.notification == "delete" || "recive"){
|
|
||||||
this.notificationLengthData();
|
|
||||||
console.log('Deleted notification',data )
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* UpdateNotificationCount() {
|
|
||||||
this.notificationsService.registerCallback(
|
|
||||||
'any',
|
|
||||||
() => {
|
|
||||||
setTimeout(()=>{
|
|
||||||
this.notificationLengthData();
|
|
||||||
}, 100)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
} */
|
|
||||||
|
|
||||||
notificationLengthData() {
|
ionViewWillEnter() {
|
||||||
|
this.eventrigger.getObservable().subscribe((data) => {
|
||||||
|
if (data.notification == "delete" || "recive") {
|
||||||
|
this.notificationLengthData();
|
||||||
|
console.log('Deleted notification', data)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/* UpdateNotificationCount() {
|
||||||
|
this.notificationsService.registerCallback(
|
||||||
|
'any',
|
||||||
|
() => {
|
||||||
|
setTimeout(()=>{
|
||||||
|
this.notificationLengthData();
|
||||||
|
}, 100)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
} */
|
||||||
|
|
||||||
|
notificationLengthData() {
|
||||||
this.storageservice.get("Notifications").then((value) => {
|
this.storageservice.get("Notifications").then((value) => {
|
||||||
console.log("Init get store", value)
|
console.log("Init get store", value)
|
||||||
|
|
||||||
/* var data = JSON.parse(value); */
|
/* var data = JSON.parse(value); */
|
||||||
this.notificationLength = value.length;
|
this.notificationLength = value.length;
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -173,10 +173,10 @@ export class HeaderPage implements OnInit {
|
|||||||
});
|
});
|
||||||
await modal.present();
|
await modal.present();
|
||||||
|
|
||||||
modal.onDidDismiss().then(()=>{
|
modal.onDidDismiss().then(() => {
|
||||||
this.notificationLengthData()
|
this.notificationLengthData()
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async dynamicSearch() {
|
async dynamicSearch() {
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
if ('serviceWorker' in navigator) {
|
||||||
|
navigator.serviceWorker.register('./firebase-messaging-sw.js')
|
||||||
|
.then(function(registration) {
|
||||||
|
console.log('Registration successful, scope is:', registration.scope);
|
||||||
|
}).catch(function(err) {
|
||||||
|
console.log('Service worker registration failed, error:', err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// Scripts for firebase and firebase messaging
|
||||||
|
|
||||||
|
|
||||||
|
/* importScripts('https://www.gstatic.com/firebasejs/8.2.0/firebase-app.js');
|
||||||
|
importScripts('https://www.gstatic.com/firebasejs/8.2.0/firebase-messaging.js');
|
||||||
|
|
||||||
|
// Initialize the Firebase app in the service worker by passing the generated config
|
||||||
|
var firebaseConfig = {
|
||||||
|
apiKey: "AIzaSyAAdHmTFznCMerdT99nrewJgISRvtxPqoY",
|
||||||
|
authDomain: "gabinete-digital-2020.firebaseapp.com",
|
||||||
|
databaseURL: "https://gabinete-digital-2020.firebaseio.com",
|
||||||
|
projectId: "gabinete-digital-2020",
|
||||||
|
storageBucket: "gabinete-digital-2020.appspot.com",
|
||||||
|
messagingSenderId: "800733765231",
|
||||||
|
appId: "1:800733765231:web:28e7792ab150006513779a",
|
||||||
|
measurementId: "G-8QN4BLZ8XK"
|
||||||
|
};
|
||||||
|
|
||||||
|
firebase.initializeApp(firebaseConfig);
|
||||||
|
|
||||||
|
// Retrieve firebase messaging
|
||||||
|
const messaging = firebase.messaging();
|
||||||
|
|
||||||
|
messaging.onBackgroundMessage(function(payload) {
|
||||||
|
console.log('Received background message ', payload);
|
||||||
|
|
||||||
|
const notificationTitle = payload.notification.title;
|
||||||
|
const notificationOptions = {
|
||||||
|
body: payload.notification.body,
|
||||||
|
};
|
||||||
|
|
||||||
|
self.registration.showNotification(notificationTitle,
|
||||||
|
notificationOptions);
|
||||||
|
}); */
|
||||||
Reference in New Issue
Block a user