File

src/pages/feedback/feedback.ts

Metadata

selector page-feedback
templateUrl feedback.html

Index

Properties
Methods

Constructor

constructor(navCtrl: NavController, navParams: NavParams, viewCtrl: ViewController, fb: FormBuilder, http: HttpClient, alertController: AlertController)

Upon construction, the form and its validation is initialized

Parameters :
Name Type Optional Description
navCtrl NavController No

Controls navigation

navParams NavParams No

Controls parameters passed in during navigation

viewCtrl ViewController No

Controls the current view

fb FormBuilder No

Provides the service to build a form

http HttpClient No

Provides the service to handle HTTP requests

alertController AlertController No

Allows for alerts to appear

Methods

Public closeModal
closeModal()

Called when the Back button is pressed

Returns : void
onSubmit
onSubmit()

Called when the Send Feedback button is pressed. Sends message and alerts user.

Returns : void
postMessage
postMessage(name: , feedType: , message: )

Uses POST to post the paramters to the server URL indicated

Parameters :
Name Optional Description
name No

The sender's name

feedType No

The sender's specified feedback type

message No

The sender's message

Returns : void
presentAlert
presentAlert()

Presents a model that indicates that the feedback is sent

Returns : void

Properties

Public alertController
alertController: AlertController
Type : AlertController
Allows for alerts to appear
defaultFeedType
defaultFeedType: string
Type : string
Default value : 'General Feedback'

The default select element option as required

feedType
feedType: string[]
Type : string[]
Default value : [ 'General Feedback', 'Bug', 'Feature Request' ]

The array of options for the "Feedback type" select element

myGroup
myGroup:
Default value : new FormGroup({ name: new FormControl(), message: new FormControl() })

The objects that compose the Feedback form is in the FormGroup object

Public navCtrl
navCtrl: NavController
Type : NavController
Controls navigation
Public navParams
navParams: NavParams
Type : NavParams
Controls parameters passed in during navigation
submitted
submitted:
Default value : false

Evaluates to true when the email server returns a success code

Public viewCtrl
viewCtrl: ViewController
Type : ViewController
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>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""