File

src/pages/utilities/utilities.ts

Description

Generated class for the UtilitiesPage page.

See https://ionicframework.com/docs/components/#navigation for more info on Ionic pages and navigation.

Metadata

selector page-utilities
templateUrl utilities.html

Index

Properties
Methods

Methods

alertSing
alertSing()
Returns : void
openModal
openModal()

Opens the About page modal

Returns : void

Properties

empty_bucket
empty_bucket: number
Type : number
Default value : 2.0
filled_bucket
filled_bucket: number
Type : number
Default value : 10.0
hello
hello:
Default value : (() => { if (!this.empty_bucket || !this.filled_bucket || !this.single_item) { return 'Weight inputs cannot be empty'; } if (this.empty_bucket <= 0 || this.filled_bucket <= 0 || this.single_item <= 0 ) { return 'Weight value must be a positive value'; } if (this.single_item - this.filled_bucket > 0) { return 'Single item cannot weigh more than a filled bucket'; } if (this.empty_bucket - this.filled_bucket >= 0) { return 'Empty bucket cannot weigh more than a filled bucket'; } return 'Total items: ' + Math.floor((this.filled_bucket - this.empty_bucket) / this.single_item); })

Determines what is the resulting weight value to be displayed. Handles invalid input values by returning appropriate validation messages

Math
Math: Math
Type : Math
Default value : Math

An instance of the JavaScript Math class required to use the floor function

single_item
single_item: number
Type : number
Default value : 1.0
import { Component } from '@angular/core';
import { NavController, NavParams, AlertController} from 'ionic-angular';
import { ModalController } from 'ionic-angular';
// import { ContactPage } from '../contact/contact';
import { AboutPage } from '../about/about';



/**
 * Generated class for the UtilitiesPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */
      
@Component({
  selector: 'page-utilities',
  templateUrl: 'utilities.html',
})
export class UtilitiesPage {
  
  /**
   * An instance of the JavaScript Math class required to use the floor function
   */
  Math: Math = Math;
  
  single_item = 1.0;
  empty_bucket = 2.0;
  filled_bucket = 10.0;
  
  /**
   * Determines what is the resulting weight value to be displayed. Handles invalid input values by returning
   * appropriate validation messages
   * @returns A string value that is displayed in the result card on the page
   */
  hello = (() => {
    if (!this.empty_bucket || !this.filled_bucket || !this.single_item) {
        return 'Weight inputs cannot be empty';
      }

    if (this.empty_bucket <= 0 || this.filled_bucket <= 0 || this.single_item <= 0 ) {
        return 'Weight value must be a positive value';
    }

    if (this.single_item - this.filled_bucket > 0) {
      return 'Single item cannot weigh more than a filled bucket';
    }

    if (this.empty_bucket - this.filled_bucket >= 0) {
      return 'Empty bucket cannot weigh more than a filled bucket';
    }

    return 'Total items: ' + Math.floor((this.filled_bucket - this.empty_bucket) / this.single_item);
  });

  /**
   * @ignore
   */
  constructor(public navCtrl: NavController, public navParams: NavParams, 
    public alertCtrl: AlertController, public modalCtrl : ModalController) {

  }

  /**
   * Opens the About page modal
   */
  openModal() {
    var data = { message : 'hello world' };
    var homePage = this.modalCtrl.create(AboutPage,data);
    homePage.present();
  }

  /**
   * @ignore
   */
  ionViewDidLoad() {
    console.log('ionViewDidLoad UtilitiesPage');
  }  
  alertSing()
  {
    let alert = this.alertCtrl.create({
      title: 'Instructions',
      message:`
      <ol>
        <li>Weigh a single item and then enter the weight of the single item under "Weight Single Item"</li>
        <li>Weigh the empty bucket and then enter the weight of the empty bucket under "Weight Empty Bucket"</li>
        <li>Weigh the filled bucket which contains the items and then enter the weight of the filled bucket under "Weight Filled Bucket"</li>
        
      </ol>`,
      buttons: ['OK']
    });
    alert.present();
  }

}
<!-- /**
* File Name:       utilities.html
* Version Number:  v1.1
* Author:          Orisha Orrie
* 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
* 18/09/2018   Orisha	  Fixed layout
* 18/09/2018   Orisha   Added functionality
* ------------------------------------------
* Functional Description:
*  The page to calculate the amount of items in a box. 
*/ -->

<!--
  Generated template for the UtilitiesPage page.

  See http://ionicframework.com/docs/components/#navigation for more info on
  Ionic pages and navigation.
-->
<ion-header>

  <ion-navbar>
  

    <ion-title>Item calculator</ion-title>
    <ion-buttons end>
        <button ion-button icon-only (click) ="alertSing()"  >
         <ion-icon name="information-circle" style="color: white"></ion-icon>
       </button>
      </ion-buttons>
    <ion-buttons end>
        <button ion-button icon-only (click) ="openModal()"  >
         <ion-icon name="help-circle" style="color: white"></ion-icon>
       </button>
      </ion-buttons>

      
  </ion-navbar>
  

</ion-header>

<ion-content padding >
  <h1 style="color: black; ">Calculate total items</h1>
<!--Values are entered here and validation occurs in the .ts file-->
<br>
    <ion-card class = "inputFormat">
      <ion-card-content>
        <ion-item class="inputs">
        <ion-label  class="bob" stacked>Weight Single Item  </ion-label>
          <ion-input id="single"  type="number" required placeholder="Single Item" [(ngModel)]="single_item" min=0></ion-input> 
        
        </ion-item>
      </ion-card-content>
    </ion-card>  
<ion-card class = "inputFormat">
    <ion-card-content>
  <ion-item class = "inputs">
    <ion-label class="bob" stacked>Weight Empty Bucket</ion-label>
    <ion-input id="empty" type="number" required placeholder="Empty bucket" [(ngModel)]="empty_bucket" min=0></ion-input>
  </ion-item>
</ion-card-content>
</ion-card>
<ion-card class = "inputFormat">
    <ion-card-content>
      <ion-item class = "inputs">
        <ion-label class="bob" stacked>Weight Filled Bucket</ion-label>
        <ion-input id="filled" type="number" required placeholder="Filled bucket" [(ngModel)]="filled_bucket"  min=0></ion-input>
      </ion-item>
</ion-card-content>
</ion-card>
 <br>

 <!--Card to display the results-->
<ion-card class = "result">
  <ion-card-content class="result__amount">
    {{ hello() }}
  </ion-card-content>
</ion-card>
</ion-content>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""