Add organisation push notification page

This commit is contained in:
Ben Goldsworthy 2020-11-01 18:05:20 +00:00
parent 02f1d95b52
commit 7ef690a6a8
5 changed files with 132 additions and 1 deletions

View file

@ -15,6 +15,7 @@ import { DashboardCustomerComponent } from './dashboard-customer.component';
import { AccountEditComponent } from './account-edit.component'; import { AccountEditComponent } from './account-edit.component';
import { AddDataComponent } from './add-data.component'; import { AddDataComponent } from './add-data.component';
import { FeedbackComponent } from './feedback.component'; import { FeedbackComponent } from './feedback.component';
import { SendPushNotificationComponent } from './send-push-notification.component';
import { TransactionLogComponent } from './transaction-log.component'; import { TransactionLogComponent } from './transaction-log.component';
import { CategoryMonthComponent } from './category-month.component'; import { CategoryMonthComponent } from './category-month.component';
import { PayrollLogComponent } from './payroll-log.component'; import { PayrollLogComponent } from './payroll-log.component';
@ -85,6 +86,7 @@ import { environment } from '../../environments/environment';
MapComponent, MapComponent,
TrailMapComponent, TrailMapComponent,
FeedbackComponent, FeedbackComponent,
SendPushNotificationComponent,
GraphWidget, GraphWidget,
OrgBarSnippetComponent, OrgBarSnippetComponent,
CustBarSnippetComponent, CustBarSnippetComponent,

View file

@ -19,6 +19,7 @@ import { MapComponent } from './map.component';
import { TrailMapComponent } from './trail-map.component'; import { TrailMapComponent } from './trail-map.component';
import { MoreStuffComponent } from './more-graphs-and-tables.component'; import { MoreStuffComponent } from './more-graphs-and-tables.component';
import { SuppliersComponent } from './suppliers.component'; import { SuppliersComponent } from './suppliers.component';
import { SendPushNotificationComponent } from './send-push-notification.component';
// Using child path to allow for FullLayout theming // Using child path to allow for FullLayout theming
const routes: Routes = [ const routes: Routes = [
@ -50,6 +51,11 @@ const routes: Routes = [
component: AddDataComponent, component: AddDataComponent,
data: { title: 'Record Transaction' }, data: { title: 'Record Transaction' },
}, },
{
path: 'notify',
component: SendPushNotificationComponent,
data: { title: 'Send Message' },
},
{ {
path: 'leaderboard', path: 'leaderboard',
component: LeaderboardComponent, component: LeaderboardComponent,

View file

@ -0,0 +1,38 @@
<div class="animated fadeIn">
<div class="row">
<div class="col-lg-6 col-md-8">
<div class="card">
<div class="card-header">
<strong>Send Message</strong>
<small>Required Data marked in <strong>bold</strong>.</small>
</div>
<form class="form-horizontal" [formGroup]="sendMessageForm" (ngSubmit)="onSubmit()">
<div class="card-block">
<div class="form-group row">
<label class="col-md-3 form-control-label" for="text-input"><strong>Enter Message Here</strong></label>
<div class="col-md-9">
<textarea rows="7" class="form-control" formControlName="messagetext"></textarea>
<span class="help-block">Please enter your message in this textbox.</span>
</div>
</div>
<div class="form-group row">
<div class="col-md-9">
<div [ngSwitch]="sendMessageFormStatus">
<div *ngSwitchCase="'success'" class="alert alert-success" role="alert">
Your message has been sent successfully!
</div>
<div *ngSwitchCase="'send_failed'" class="alert alert-danger" role="alert">
{{sendMessageFormStatusError}}
</div>
</div>
</div>
</div>
</div>
<div class="card-footer">
<button type="submit" [disabled]="!sendMessageForm.valid" class="btn btn-sm btn-primary"><i class="fa fa-dot-circle-o"></i> Send</button>
</div>
</form>
</div>
</div>
</div><!--/.row-->
</div>

View file

@ -0,0 +1,75 @@
import { Component, OnInit } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { ApiService } from '../providers/api-service';
@Component({
templateUrl: 'send-push-notification.component.html',
})
export class SendPushNotificationComponent implements OnInit {
sendMessageForm: FormGroup;
loggedInEmail: string;
username: any;
noEmail = false;
sendMessageFormStatus: any;
sendMessageFormStatusError = 'Error received, please try again.';
constructor(private api: ApiService) {
this.sendMessageForm = new FormGroup({
messagetext: new FormControl('', Validators.required),
});
}
ngOnInit(): void {
if (localStorage.getItem('email')) {
this.loggedInEmail = localStorage.getItem('email');
}
if (!this.loggedInEmail) {
console.log('email not found in storage');
this.api.accountFullLoad().subscribe(
result => {
console.log(result);
this.sendMessageForm.patchValue({
email: result.email,
});
this.api.setUserInfo( result.email, result.display_name || result.name );
},
error => {
console.log( error._body );
this.noEmail = true;
}
);
}
}
onSubmit(): void {
console.log(this.sendMessageForm.value);
this.api
.sendMessage(this.sendMessageForm.value)
.subscribe(
result => {
if ( result.success === true ) {
console.log('Successful Upload');
this.sendMessageFormStatus = 'success';
this.sendMessageForm.patchValue({
messagetext: '',
});
} else {
console.log('Upload Error');
this.sendMessageFormStatusError = JSON.stringify(result.status) + 'Error, ' + JSON.stringify(result.message);
this.sendMessageFormStatus = 'send_failed';
}
},
error => {
console.log('Upload Error');
try {
this.sendMessageFormStatusError = '"' + error.error.error + '" Error, ' + error.error.message;
} catch (e) {
this.sendMessageFormStatusError = 'There was a server error, please try again later.';
}
this.sendMessageFormStatus = 'send_failed';
}
);
}
}

View file

@ -92,12 +92,22 @@ export class ApiService {
data.package_name = 'Foodloop Web'; data.package_name = 'Foodloop Web';
data.version_code = 'dev'; data.version_code = 'dev';
data.version_number = 'dev'; data.version_number = 'dev';
return this.http.post<any>( console.log(this.apiUrl + '/feedback');
return this.http.post<any>(
this.apiUrl + '/feedback', this.apiUrl + '/feedback',
data data
); );
} }
// Sends push notifications
public sendMessage(data) {
return this.http.post<any>(
this.apiUrl + '/send-message',
data
);
}
// gets transaction list for log // gets transaction list for log
public transList(data) { public transList(data) {