From 7d77abe995dbeab3091a9f192e9e514471c98fdd Mon Sep 17 00:00:00 2001 From: Thiemann96 Date: Mon, 17 Feb 2020 14:47:05 +0100 Subject: [PATCH] added modal and template creation --- src/app/app.module.ts | 3 + src/pages/add-item/add-item.html | 29 ++++++++ src/pages/add-item/add-item.module.ts | 13 ++++ src/pages/add-item/add-item.scss | 3 + src/pages/add-item/add-item.ts | 38 ++++++++++ src/pages/configuration/configuration.html | 86 +++++++++++++++------- src/pages/configuration/configuration.ts | 79 +++++++++++--------- 7 files changed, 189 insertions(+), 62 deletions(-) create mode 100644 src/pages/add-item/add-item.html create mode 100644 src/pages/add-item/add-item.module.ts create mode 100644 src/pages/add-item/add-item.scss create mode 100644 src/pages/add-item/add-item.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 459c979..cfa8420 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -12,6 +12,7 @@ import { OtaWizardPageModule } from '../pages/ota-wizard/ota-wizard.module'; import { BlocklyPageModule } from '../pages/blockly/blockly.module'; import { LoggingProvider } from '../providers/logging/logging'; import { StorageProvider } from '../providers/storage/storage'; +import { AddItemPage } from '../pages/add-item/add-item'; // For AoT compilation (production builds) we need to have a factory for the loader of translation files. // @TODO: we possibly could optimize this by using a static loader in combination with webpack: @@ -23,6 +24,7 @@ export function createTranslateLoader(http: HttpClient) { @NgModule({ declarations: [ openSenseApp, + AddItemPage ], imports: [ HttpClientModule, @@ -41,6 +43,7 @@ export function createTranslateLoader(http: HttpClient) { bootstrap: [IonicApp], entryComponents: [ openSenseApp, + AddItemPage ], providers: [ StatusBar, diff --git a/src/pages/add-item/add-item.html b/src/pages/add-item/add-item.html new file mode 100644 index 0000000..dc0670e --- /dev/null +++ b/src/pages/add-item/add-item.html @@ -0,0 +1,29 @@ + + + + Add Item + + + + + + + + + + + + Title + + + + + Description + + + + + + + + \ No newline at end of file diff --git a/src/pages/add-item/add-item.module.ts b/src/pages/add-item/add-item.module.ts new file mode 100644 index 0000000..d90cd12 --- /dev/null +++ b/src/pages/add-item/add-item.module.ts @@ -0,0 +1,13 @@ +import { NgModule } from '@angular/core'; +import { IonicPageModule } from 'ionic-angular'; +import { AddItemPage } from './add-item'; + +@NgModule({ + declarations: [ + AddItemPage, + ], + imports: [ + IonicPageModule.forChild(AddItemPage), + ], +}) +export class AddItemPageModule {} diff --git a/src/pages/add-item/add-item.scss b/src/pages/add-item/add-item.scss new file mode 100644 index 0000000..e6c4e74 --- /dev/null +++ b/src/pages/add-item/add-item.scss @@ -0,0 +1,3 @@ +page-add-item { + +} diff --git a/src/pages/add-item/add-item.ts b/src/pages/add-item/add-item.ts new file mode 100644 index 0000000..fb4a8b3 --- /dev/null +++ b/src/pages/add-item/add-item.ts @@ -0,0 +1,38 @@ +import { Component } from '@angular/core'; +import { IonicPage, NavController, ViewController } from 'ionic-angular'; + +/** + * Generated class for the AddItemPage page. + * + * See https://ionicframework.com/docs/components/#navigation for more info on + * Ionic pages and navigation. + */ + +@IonicPage() +@Component({ + selector: 'page-add-item', + templateUrl: 'add-item.html', +}) +export class AddItemPage { + + title:string; + type:string; + id:string; + constructor(public navCtrl: NavController, public view: ViewController) { + } + saveSensor(){ + let newSensor = { + title:this.title, + type:this.type, + id:this.id + } + this.view.dismiss(newSensor); + } + close(){ + this.view.dismiss(); + } + ionViewDidLoad() { + console.log('ionViewDidLoad AddItemPage'); + } + +} diff --git a/src/pages/configuration/configuration.html b/src/pages/configuration/configuration.html index bed9443..ba7579e 100644 --- a/src/pages/configuration/configuration.html +++ b/src/pages/configuration/configuration.html @@ -16,16 +16,16 @@ {{'CONFIG.WIFI' | translate}} - - - SSID - - - - Password - - - + + + SSID + + + + Password + + + @@ -34,15 +34,50 @@ {{ 'CONFIG.IDS' | translate }} - - senseBoxID - - - - Temperature - - - + + + + senseBoxID + + + + + + + {{sensor.title}} + + + + + + + + + + + + + + + @@ -82,4 +112,4 @@ - + \ No newline at end of file diff --git a/src/pages/configuration/configuration.ts b/src/pages/configuration/configuration.ts index 74709f2..0a2b7e3 100644 --- a/src/pages/configuration/configuration.ts +++ b/src/pages/configuration/configuration.ts @@ -1,7 +1,8 @@ import { Component, } from '@angular/core'; -import { IonicPage, NavController, NavParams } from 'ionic-angular'; +import { IonicPage, NavController, NavParams, ModalController} from 'ionic-angular'; import { OtaWizardPage } from '../ota-wizard/ota-wizard'; import { HttpClient } from '@angular/common/http'; +import { AddItemPage } from '../add-item/add-item'; /** * Generated class for the AboutPage page. * @@ -15,6 +16,7 @@ import { HttpClient } from '@angular/common/http'; templateUrl: 'configuration.html', }) export class ConfigurationPage { + public sensors=[]; temp : string; humi : string; lux : string; @@ -26,12 +28,9 @@ export class ConfigurationPage { pressure:string; rain:string; senseboxid:string; - constructor(public navCtrl: NavController, public navParams: NavParams,private http:HttpClient) { + constructor(public navCtrl: NavController, public navParams: NavParams,private http:HttpClient,public modalCtrl:ModalController) { } - async launchOtaWizard () { - - } applyTemplate(template, properties) { var returnValue = ""; @@ -42,44 +41,56 @@ export class ConfigurationPage { var fragmentSections = templateFragments[i].split("}@", 2); returnValue += properties[fragmentSections[0]]; returnValue += fragmentSections[1]; - } + } return returnValue; } - uploadStandardSketch(){ - // possily add define statements here based on inputs given or checkboxes checked - let sketchy = "#define HDC1080\n"; + async uploadStandardSketch(){ + var values = { + SSID: this.ssid, + PASSWORD:this.pw, + INGRESS_DOMAIN:"ingress.opensensemap.org", + SENSEBOX_ID:this.senseboxid, + NUM_SENSORS:6, + TEMPERSENSOR_ID:this.temp, + RELLUFSENSOR_ID:this.humi, + BELEUCSENSOR_ID:this.lux, + UVINTESENSOR_ID:this.uv, + LUFTDRSENOSR_ID:this.pressure, + REGENMSENSOR_ID:this.rain, + PM10SENSOR_ID:this.pm10, + PM25SENSOR_ID:this.pm25 + }; this.http.get("assets/templates/homev2Wifi.tpl",{responseType:"text"}).subscribe(data=>{ - sketchy = sketchy+data; - var values = { - SSID: this.ssid, - PASSWORD:this.pw, - INGRESS_DOMAIN:"ingress.opensensemap.org", - SENSEBOX_ID:this.senseboxid, - NUM_SENSORS:6, - TEMPERSENSOR_ID:this.temp, - RELLUFSENSOR_ID:this.humi, - BELEUCSENSOR_ID:this.lux, - UVINTESENSOR_ID:this.uv, - LUFTDRSENOSR_ID:this.pressure, - REGENMSENSOR_ID:this.rain, - PM10SENSOR_ID:this.pm10, - PM25SENSOR_ID:this.pm25 - }; - sketchy = this.applyTemplate(sketchy,values); + let sketch = this.applyTemplate(data,values); + this.navCtrl.push(OtaWizardPage, { sketch }) + }) + } + + addSensor(){ + console.log("adding sensor"); + + let addModal = this.modalCtrl.create(AddItemPage); + + addModal.onDidDismiss((sensor)=>{ + if(sensor){ + this.saveSensor(sensor); + } }) - /** - * Start OTA Wizard here but with the pre defined sketch here and not with the blockly sketch - * - ** - */ - const sketch = 'void setup(){Serial.begin(9600);} void loop(){Serial.println("Working");}' - this.navCtrl.push(OtaWizardPage, { sketchy }) + addModal.present(); + + } + + saveSensor(sensor){ + this.sensors.push(sensor); } ionViewDidLoad() { - console.log('ionViewDidLoad ConfigPage'); + this.sensors =[ + {title:"Temperatur",type:"temp"}, + {title:"Temperatur",type:"temp"} + ] } }