diff --git a/src/app/dashboard/dashboard.module.ts b/src/app/dashboard/dashboard.module.ts index 7c232cb..9e3a8b7 100644 --- a/src/app/dashboard/dashboard.module.ts +++ b/src/app/dashboard/dashboard.module.ts @@ -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, diff --git a/src/app/dashboard/dashboard.routing.ts b/src/app/dashboard/dashboard.routing.ts index 9a8d5fe..7689784 100644 --- a/src/app/dashboard/dashboard.routing.ts +++ b/src/app/dashboard/dashboard.routing.ts @@ -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, diff --git a/src/app/dashboard/send-push-notification.component.html b/src/app/dashboard/send-push-notification.component.html new file mode 100644 index 0000000..326eb74 --- /dev/null +++ b/src/app/dashboard/send-push-notification.component.html @@ -0,0 +1,38 @@ +
+
+
+
+
+ Send Message + Required Data marked in bold. +
+
+
+
+ +
+ + Please enter your message in this textbox. +
+
+
+
+
+ + +
+
+
+
+ +
+
+
+
+
diff --git a/src/app/dashboard/send-push-notification.component.ts b/src/app/dashboard/send-push-notification.component.ts new file mode 100644 index 0000000..865f2f0 --- /dev/null +++ b/src/app/dashboard/send-push-notification.component.ts @@ -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'; + } + ); + } +} diff --git a/src/app/providers/api-service.ts b/src/app/providers/api-service.ts index 8307371..865a397 100644 --- a/src/app/providers/api-service.ts +++ b/src/app/providers/api-service.ts @@ -92,12 +92,22 @@ export class ApiService { data.package_name = 'Foodloop Web'; data.version_code = 'dev'; data.version_number = 'dev'; - return this.http.post( + console.log(this.apiUrl + '/feedback'); + return this.http.post( this.apiUrl + '/feedback', data ); } + // Sends push notifications + + public sendMessage(data) { + return this.http.post( + this.apiUrl + '/send-message', + data + ); + } + // gets transaction list for log public transList(data) {