Add push notification and device token management.

This commit is contained in:
Ben Goldsworthy 2020-11-30 17:32:56 +00:00
parent a829f73e6d
commit 854571da6e
6 changed files with 74 additions and 30 deletions

View file

@ -10,9 +10,9 @@
<div class="card-block">
<div class="form-group row">
<label class="col-md-3 form-control-label" for="select-input"><strong>Select Recipients</strong></label>
<select required class="form-control" type="text" formControlName="devicetokens" multiple>
<option *ngFor="let deviceToken of deviceTokenIdList" [ngValue]="deviceTokenList[deviceToken].token">
{{ deviceTokenList[deviceToken].user }} <{{deviceTokenList[deviceToken].token}}>
<select required class="form-control" type="text" formControlName="topic">
<option *ngFor="let topic of topicIdList" [ngValue]="topicList[topic].name">
{{ topicList[topic].name }} <strong>({{topicList[topic].numberOfSubscribers}} subscribers)</strong>
</option>
</select>
</div>

View file

@ -13,24 +13,23 @@ export class SendPushNotificationComponent implements OnInit {
noEmail = false;
sendMessageFormStatus: any;
sendMessageFormStatusError = 'Error received, please try again.';
deviceTokenList: any;
deviceTokenIdList: any;
topicList: any;
topicIdList: any;
constructor(private api: ApiService) {
this.api.getDeviceTokens().subscribe(
this.api.getTopics().subscribe(
result => {
console.log(result);
this.deviceTokenList = result.tokens;
this.deviceTokenIdList = Object.keys(this.deviceTokenList);
this.topicList = result.topics;
this.topicIdList = Object.keys(this.topicList);
},
error => {
console.log("Couldn't get device token");
console.log("Couldn't get topics");
console.log(error._body);
}
);
this.sendMessageForm = new FormGroup({
messagetext: new FormControl('', Validators.required),
devicetokens: new FormControl('', Validators.required),
topic: new FormControl('', Validators.required),
});
}
@ -58,7 +57,6 @@ export class SendPushNotificationComponent implements OnInit {
}
onSubmit(): void {
console.log(this.sendMessageForm.value);
this.api
.sendMessage(this.sendMessageForm.value)
.subscribe(