Skip to content

Commit

Permalink
Merge pull request #85 from juanfranciscocis/WindowsEnviroment
Browse files Browse the repository at this point in the history
Windows enviroment
  • Loading branch information
juanfranciscocis authored Sep 27, 2024
2 parents e7651a9 + 24fe751 commit 8376315
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 17 deletions.
5 changes: 0 additions & 5 deletions src/app/pages/main_graphs/home/home.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,5 @@ <h1 class="text-6xl font-bold text-blue-500">{{ product.productObjective }}</h1>
</ion-card>
</ion-col>
</ion-row>
<ion-row class="lg:m-10 md:m-10">
<ion-col size="12" size-md="12" size-lg="12" class="flex flex-row justify-center">
<ion-button class="w-full" (click)="subscribe()">Subscribe</ion-button>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>
7 changes: 1 addition & 6 deletions src/app/pages/main_graphs/home/home.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});
}

}
13 changes: 13 additions & 0 deletions src/app/pages/settings/settings.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,25 @@
</ion-col>
</ion-row>


<app-title [title]="'Receive Push Notifications'"></app-title>
<ion-row class="lg:m-10 md:m-10">
<ion-col size="12" size-md="12" size-lg="12" class="">
<p>Receive push notifications when new data is available. Like new tests, incidents, etc.</p>
</ion-col>
<ion-col size="12" size-md="12" size-lg="12" class="flex flex-row justify-center">
<ion-button class="w-full" (click)="subscribe()">Subscribe</ion-button>
</ion-col>
</ion-row>

<ion-row>
<ion-col size="12" class="flex flex-row justify-end items-center ">
<h1 class="text-sm">Version: {{version}}</h1>
</ion-col>
</ion-row>




</ion-grid>
</ion-content>
19 changes: 18 additions & 1 deletion src/app/pages/settings/settings.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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() {
Expand Down Expand Up @@ -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);
})

}




}
32 changes: 32 additions & 0 deletions src/app/services/notification.service.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}



}
1 change: 0 additions & 1 deletion www/2757.508e833600e6e474.js

This file was deleted.

1 change: 1 addition & 0 deletions www/2757.89e28904ff3cf268.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion www/5371.6ea8dd7ee408088a.js

This file was deleted.

Loading

0 comments on commit 8376315

Please sign in to comment.