Add organisation push notification page
This commit is contained in:
parent
02f1d95b52
commit
7ef690a6a8
5 changed files with 132 additions and 1 deletions
|
@ -15,6 +15,7 @@ import { DashboardCustomerComponent } from './dashboard-customer.component';
|
|||
import { AccountEditComponent } from './account-edit.component';
|
||||
import { AddDataComponent } from './add-data.component';
|
||||
import { FeedbackComponent } from './feedback.component';
|
||||
import { SendPushNotificationComponent } from './send-push-notification.component';
|
||||
import { TransactionLogComponent } from './transaction-log.component';
|
||||
import { CategoryMonthComponent } from './category-month.component';
|
||||
import { PayrollLogComponent } from './payroll-log.component';
|
||||
|
@ -85,6 +86,7 @@ import { environment } from '../../environments/environment';
|
|||
MapComponent,
|
||||
TrailMapComponent,
|
||||
FeedbackComponent,
|
||||
SendPushNotificationComponent,
|
||||
GraphWidget,
|
||||
OrgBarSnippetComponent,
|
||||
CustBarSnippetComponent,
|
||||
|
|
|
@ -19,6 +19,7 @@ import { MapComponent } from './map.component';
|
|||
import { TrailMapComponent } from './trail-map.component';
|
||||
import { MoreStuffComponent } from './more-graphs-and-tables.component';
|
||||
import { SuppliersComponent } from './suppliers.component';
|
||||
import { SendPushNotificationComponent } from './send-push-notification.component';
|
||||
|
||||
// Using child path to allow for FullLayout theming
|
||||
const routes: Routes = [
|
||||
|
@ -50,6 +51,11 @@ const routes: Routes = [
|
|||
component: AddDataComponent,
|
||||
data: { title: 'Record Transaction' },
|
||||
},
|
||||
{
|
||||
path: 'notify',
|
||||
component: SendPushNotificationComponent,
|
||||
data: { title: 'Send Message' },
|
||||
},
|
||||
{
|
||||
path: 'leaderboard',
|
||||
component: LeaderboardComponent,
|
||||
|
|
38
src/app/dashboard/send-push-notification.component.html
Normal file
38
src/app/dashboard/send-push-notification.component.html
Normal 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>
|
75
src/app/dashboard/send-push-notification.component.ts
Normal file
75
src/app/dashboard/send-push-notification.component.ts
Normal 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';
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
|
@ -92,12 +92,22 @@ export class ApiService {
|
|||
data.package_name = 'Foodloop Web';
|
||||
data.version_code = 'dev';
|
||||
data.version_number = 'dev';
|
||||
return this.http.post<any>(
|
||||
console.log(this.apiUrl + '/feedback');
|
||||
return this.http.post<any>(
|
||||
this.apiUrl + '/feedback',
|
||||
data
|
||||
);
|
||||
}
|
||||
|
||||
// Sends push notifications
|
||||
|
||||
public sendMessage(data) {
|
||||
return this.http.post<any>(
|
||||
this.apiUrl + '/send-message',
|
||||
data
|
||||
);
|
||||
}
|
||||
|
||||
// gets transaction list for log
|
||||
|
||||
public transList(data) {
|
||||
|
|
Reference in a new issue