src/pages/feedback/feedback.ts
selector | page-feedback |
templateUrl | feedback.html |
Properties |
|
Methods |
constructor(navCtrl: NavController, navParams: NavParams, viewCtrl: ViewController, fb: FormBuilder, http: HttpClient, alertController: AlertController)
|
||||||||||||||||||||||||||||
Defined in src/pages/feedback/feedback.ts:57
|
||||||||||||||||||||||||||||
Upon construction, the form and its validation is initialized
Parameters :
|
Public closeModal |
closeModal()
|
Defined in src/pages/feedback/feedback.ts:89
|
Called when the Back button is pressed
Returns :
void
|
onSubmit |
onSubmit()
|
Defined in src/pages/feedback/feedback.ts:109
|
Called when the Send Feedback button is pressed. Sends message and alerts user.
Returns :
void
|
postMessage | ||||||||||||
postMessage(name: , feedType: , message: )
|
||||||||||||
Defined in src/pages/feedback/feedback.ts:125
|
||||||||||||
Uses POST to post the paramters to the server URL indicated
Parameters :
Returns :
void
|
presentAlert |
presentAlert()
|
Defined in src/pages/feedback/feedback.ts:96
|
Presents a model that indicates that the feedback is sent
Returns :
void
|
Public alertController |
alertController:
|
Type : AlertController
|
Defined in src/pages/feedback/feedback.ts:69
|
Allows for alerts to appear
|
defaultFeedType |
defaultFeedType:
|
Type : string
|
Default value : 'General Feedback'
|
Defined in src/pages/feedback/feedback.ts:49
|
The default select element option as required |
feedType |
feedType:
|
Type : string[]
|
Default value : [
'General Feedback',
'Bug',
'Feature Request'
]
|
Defined in src/pages/feedback/feedback.ts:40
|
The array of options for the "Feedback type" select element |
myGroup |
myGroup:
|
Default value : new FormGroup({
name: new FormControl(),
message: new FormControl()
})
|
Defined in src/pages/feedback/feedback.ts:54
|
The objects that compose the Feedback form is in the FormGroup object |
Public navCtrl |
navCtrl:
|
Type : NavController
|
Defined in src/pages/feedback/feedback.ts:68
|
Controls navigation
|
Public navParams |
navParams:
|
Type : NavParams
|
Defined in src/pages/feedback/feedback.ts:68
|
Controls parameters passed in during navigation
|
submitted |
submitted:
|
Default value : false
|
Defined in src/pages/feedback/feedback.ts:35
|
Evaluates to true when the email server returns a success code |
Public viewCtrl |
viewCtrl:
|
Type : ViewController
|
Defined in src/pages/feedback/feedback.ts:68
|
Controls the current view
|
import { HttpClient } from '@angular/common/http';
import { Component } from '@angular/core';
import { NavController, NavParams, ViewController, AlertController } from 'ionic-angular';
import { FormGroup, FormControl, FormBuilder, Validators } from '@angular/forms';
@Component({
selector: 'page-feedback',
templateUrl: 'feedback.html',
})
export class FeedbackPage {
/**
* Evaluates to true when the email server returns a success code
*/
submitted = false;
/**
* The array of options for the "Feedback type" select element
*/
feedType: string[] = [
'General Feedback',
'Bug',
'Feature Request'
];
/**
* The default select element option as required
*/
defaultFeedType = 'General Feedback';
/**
* The objects that compose the Feedback form is in the FormGroup object
*/
myGroup = new FormGroup({
name: new FormControl(),
message: new FormControl()
});
/**
* Upon construction, the form and its validation is initialized
* @param navCtrl Controls navigation
* @param navParams Controls parameters passed in during navigation
* @param viewCtrl Controls the current view
* @param fb Provides the service to build a form
* @param http Provides the service to handle HTTP requests
* @param alertController Allows for alerts to appear
*/
constructor(public navCtrl: NavController, public navParams: NavParams, public viewCtrl: ViewController,
private fb: FormBuilder, private http: HttpClient, public alertController: AlertController) {
this.myGroup = this.fb.group({
'feedType': new FormControl(null),
'name': ['', Validators.compose([Validators.required, Validators.minLength(1)])],
'message': ['', Validators.compose([Validators.required, Validators.minLength(1)])]
});
this.myGroup.controls['feedType'].setValue(this.defaultFeedType, {onlySelf: true});
}
/**
* @ignore
*/
ionViewDidLoad() {
console.log('ionViewDidLoad FeedbackPage');
}
/**
* Called when the Back button is pressed
*/
public closeModal(){
this.viewCtrl.dismiss();
}
/**
* Presents a model that indicates that the feedback is sent
*/
presentAlert() {
let alert = this.alertController.create({
title: 'Feedback sent!',
subTitle: 'Thanks, we truly appreciate it!',
buttons: ['Sure']
})
alert.present();
}
/**
* Called when the Send Feedback button is pressed. Sends message and alerts user.
*/
onSubmit() {
const senderName = this.myGroup.get('name').value;
const senderFeedType = this.myGroup.get('feedType').value;
const senderMessage = this.myGroup.get('message').value;
this.presentAlert();
this.myGroup.reset();
this.postMessage(senderName, senderFeedType, senderMessage);
}
/**
* Uses POST to post the paramters to the server URL indicated
* @param name The sender's name
* @param feedType The sender's specified feedback type
* @param message The sender's message
*/
postMessage(name, feedType, message) {
console.log('Name: ' + name + ' Type: ' + feedType + ' Msg: ' + message);
let messageToSend = 'Feedback type: ' + feedType + '\n' + message;
this.http.post('https://us-central1-testproject-ee885.cloudfunctions.net/app/sendmail',
{'subject': name, 'text': messageToSend, 'email': "Email unavailable"}
).subscribe(data1 => {
console.log(data1);
if (data1 == 'sent') {
this.submitted = true;
}
});
}
}
<!-- /**
* File Name: feedback.html
* Version Number: v1.1
* Author: Orisha Orrie, Tobias Bester
* Project Name: Ninshiki
* Organization: Software Sharks
* User Manual: Refer to https://github.com/OrishaOrrie/SoftwareSharks/blob/master/Documentation/User%20Manual.pdf
* Update History:
* ------------------------------------------
* Date Author Description
* 20/07/2018 Orisha Created component
* 15/08/2018 Tobias Added backend functionality
* 18/09/2018 Orisha Fixed layout
* ------------------------------------------
* Functional Description:
* This page includes ways to contact the Bramhope group or Sfotware Sharks in order to
* report any issues. Issues can be reported either through github or through email.
*/ -->
<ion-header>
<ion-navbar>
<ion-title>Send Feedback</ion-title>
<ion-buttons end>
<button ion-button (click)="closeModal()">Back</button>
</ion-buttons>
</ion-navbar>
</ion-header>
<ion-content padding>
<p class = " instructions">
Please tell us anything you like, don't like, or really hate, and then do the same but specifically about this app, thanks!
</p>
<form [formGroup]="myGroup" *ngIf="!submitted" >
<!-- Type of feedback can be 'General Feedback', 'Bug', 'Feature Request' -->
<ion-item class="inputs">
<ion-label class = 'bob' color="secondary" stacked>Select feedback type</ion-label>
<ion-select required formControlName="feedType">
<ion-option *ngFor="let f of feedType" [value]="f">{{ f }}</ion-option>
</ion-select>
</ion-item>
<ion-item class="inputs">
<ion-label class = 'bob' color="secondary" stacked>Full Name</ion-label>
<ion-input id="name" type="text" placeholder="Enter your full name" required formControlName="name"></ion-input>
</ion-item>
<ion-item class="inputs">
<ion-label class = 'bob' color="secondary" stacked>Message</ion-label>
<ion-textarea id="message" type="text" placeholder="Enter your message" required formControlName="message"></ion-textarea>
</ion-item>
</form>
<button ion-button full round color= "tertiary" [hidden]="!myGroup.valid" (click)="onSubmit()">Send</button>
</ion-content>