diff --git a/src/app/pages/main_graphs/home/home.page.html b/src/app/pages/main_graphs/home/home.page.html
index 3c8001e..31233db 100644
--- a/src/app/pages/main_graphs/home/home.page.html
+++ b/src/app/pages/main_graphs/home/home.page.html
@@ -10,10 +10,5 @@
{{ product.productObjective }}
-
-
- Subscribe
-
-
diff --git a/src/app/pages/main_graphs/home/home.page.ts b/src/app/pages/main_graphs/home/home.page.ts
index a441a01..ede67b3 100644
--- a/src/app/pages/main_graphs/home/home.page.ts
+++ b/src/app/pages/main_graphs/home/home.page.ts
@@ -84,10 +84,5 @@ export class HomePage {
this.router.navigate(['/graph-data-for'], {queryParams: {product: productObjective}});
}
- subscribe() {
- webpushr('fetch_id',function (sid: string) {
- //save id to database
- console.log('webpushr subscriber id: ' + sid)
- });
- }
+
}
diff --git a/src/app/pages/settings/settings.page.html b/src/app/pages/settings/settings.page.html
index 60f58d5..3b5cb9f 100644
--- a/src/app/pages/settings/settings.page.html
+++ b/src/app/pages/settings/settings.page.html
@@ -65,6 +65,17 @@
+
+
+
+
+ Receive push notifications when new data is available. Like new tests, incidents, etc.
+
+
+ Subscribe
+
+
+
Version: {{version}}
@@ -72,5 +83,7 @@ Version: {{version}}
+
+
diff --git a/src/app/pages/settings/settings.page.ts b/src/app/pages/settings/settings.page.ts
index 425f939..68ba8b7 100644
--- a/src/app/pages/settings/settings.page.ts
+++ b/src/app/pages/settings/settings.page.ts
@@ -5,7 +5,9 @@ import {AlertController, LoadingController} from "@ionic/angular";
import {GithubService} from "../../services/github.service";
import {User} from "../../interfaces/user";
import {GitSyncData} from "../../interfaces/git-sync-data";
+import { NotificationService } from 'src/app/services/notification.service';
+declare var webpushr: any;
@Component({
selector: 'app-settings',
@@ -26,7 +28,8 @@ export class SettingsPage implements OnInit {
private router:Router,
private alertCtrl:AlertController,
private githubService: GithubService,
- private loadingCtrl: LoadingController
+ private loadingCtrl: LoadingController,
+ private notificationService: NotificationService
) { }
ngOnInit() {
@@ -122,4 +125,18 @@ export class SettingsPage implements OnInit {
});
}
+
+ async subscribe() {
+ webpushr('fetch_id',async (sid: string) => {
+ //save id to database
+ console.log('webpushr subscriber id: ' + sid)
+ // @ts-ignore
+ await this.notificationService.saveNotificationID(this.user,sid);
+ })
+
+ }
+
+
+
+
}
diff --git a/src/app/services/notification.service.ts b/src/app/services/notification.service.ts
new file mode 100644
index 0000000..356b4d7
--- /dev/null
+++ b/src/app/services/notification.service.ts
@@ -0,0 +1,32 @@
+import { Injectable } from '@angular/core';
+import {User} from "../interfaces/user";
+import {Firestore, doc, getDoc, setDoc } from '@angular/fire/firestore';
+
+@Injectable({
+ providedIn: 'root'
+})
+export class NotificationService {
+
+ constructor(
+ private firestore: Firestore,
+ ) { }
+
+ async saveNotificationID(user: User, id: string) {
+ // @ts-ignore
+ const docRef = doc(this.firestore, 'users', user.uid);
+ const docSnap = await getDoc(docRef);
+ if (docSnap.exists()) {
+ const data = docSnap.data();
+ //@ts-ignore
+ data.notificationID = id;
+ await setDoc(docRef, data);
+ return true;
+ } else {
+ console.log('No such document!');
+ return false;
+ }
+ }
+
+
+
+}