From 635b50ed27eac2de77119b9d8e91b947cc5ce62d Mon Sep 17 00:00:00 2001 From: Whizel Date: Sun, 7 Apr 2019 01:38:29 +0200 Subject: [PATCH] Changed when we post --- .../src/app/home-page/home-page.component.css | 5 +- .../src/app/home-page/home-page.component.ts | 57 ++++++++++++------- .../app/result-page/result-page.component.ts | 50 +++++++++++++++- .../app/services/my-battery-info.service.ts | 4 +- .../src/app/services/my-camera-service.ts | 1 - 5 files changed, 90 insertions(+), 27 deletions(-) diff --git a/client/Nightr/src/app/home-page/home-page.component.css b/client/Nightr/src/app/home-page/home-page.component.css index 18496f5..990379e 100644 --- a/client/Nightr/src/app/home-page/home-page.component.css +++ b/client/Nightr/src/app/home-page/home-page.component.css @@ -1,5 +1,6 @@ .float-btn-container { - margin-top: 35%; - margin-left: 20%; + width: 50%; + left: 90%; + top: 160%; } diff --git a/client/Nightr/src/app/home-page/home-page.component.ts b/client/Nightr/src/app/home-page/home-page.component.ts index 56b788d..9e63ad2 100644 --- a/client/Nightr/src/app/home-page/home-page.component.ts +++ b/client/Nightr/src/app/home-page/home-page.component.ts @@ -1,9 +1,11 @@ import { Component, OnInit } from "@angular/core"; import * as dialogs from "tns-core-modules/ui/dialogs"; -import { MyHttpPostService } from '../services/my-http-post-service' import { RouterExtensions } from "nativescript-angular/router"; import { TouchGestureEventData, GestureEventData } from 'tns-core-modules/ui/gestures' -import { isEnabled, enableLocationRequest, getCurrentLocation, watchLocation, distance, clearWatch } from "nativescript-geolocation"; +import { isEnabled, enableLocationRequest, getCurrentLocation, watchLocation, distance, clearWatch, Location } from "nativescript-geolocation"; + +import { MyHttpPostService } from '../services/my-http-post-service'' + @Component({ selector: "home-page", @@ -13,17 +15,37 @@ import { isEnabled, enableLocationRequest, getCurrentLocation, watchLocation, di providers: [MyHttpPostService] }) export class HomePageComponent implements OnInit { - public user: string = ""; - public pass: string = ""; returnMessage: string = ""; + myReturnJSON: Object; + locationData: Location; + myPicture: String; + image: any; + flat_earth: boolean; + in_australia: boolean; - constructor(private myHttpPostSerivce: MyHttpPostService, private routerExtensions: RouterExtensions) { } + constructor(private myHttpPostSerivce: MyHttpPostService, + private routerExtensions: RouterExtensions, + ) { } - public onTap(args: GestureEventData): any { + ngOnInit(): void { + } + + public onTap(args: GestureEventData): void { this.routerExtensions.navigateByUrl("/result-page"); - this.submit(); - dialogs.confirm("Should be result").then(result => { - console.log("Dialog result: " + result); + /* return this.cameraService.takePicture(). + then(picture => { + this.image = JSON.stringify(picture); + //console.log('this is picture in json', JSON.stringify(picture)); + this.getLocation(); + }) */ + } + + /* public getLocation(): any { + this.geoLocationService.getLocation().then(location => { + this.locationData = location; + //console.log('this is locationData', this.locationData); + this.submit(); + }).catch(error => { }); } @@ -32,18 +54,13 @@ export class HomePageComponent implements OnInit { } private makePostRequest(): void { - console.log('Reached makepostRequest'); this.myHttpPostSerivce - .postData({ username: this.user, password: this.pass }) + .postData({ position: this.locationData, image: this.image, flat_earth: true, in_australia: true, }) .subscribe(res => { - console.log('This is res', res); - this.returnMessage = (res).json.data.username; + //console.log('This is res', res); + this.myReturnJSON = res; + console.log('THis is myreturnJSON', this.myReturnJSON); + this.routerExtensions.navigateByUrl("/result-page"); }); - } - - ngOnInit(): void { - } - goBack(): void { - this.routerExtensions.back(); - } + } */ } diff --git a/client/Nightr/src/app/result-page/result-page.component.ts b/client/Nightr/src/app/result-page/result-page.component.ts index a764430..4648e59 100644 --- a/client/Nightr/src/app/result-page/result-page.component.ts +++ b/client/Nightr/src/app/result-page/result-page.component.ts @@ -1,5 +1,11 @@ import { Component, OnInit } from '@angular/core'; + +import { MyHttpPostService } from '../services/my-http-post-service' +import { MyGeoLocationService} from '../services/my-geo-location.service'; +import { MyBatteryInfoService } from '../services/my-battery-info.service'; +import { MyCameraService } from '../services/my-camera-service' import { RouterExtensions } from 'nativescript-angular/router'; +import { Location } from 'nativescript-geolocation'; @Component({ selector: 'result-page', @@ -8,12 +14,52 @@ import { RouterExtensions } from 'nativescript-angular/router'; moduleId: module.id, }) export class ResultPageComponent implements OnInit { + returnMessage: string = ""; + myReturnJSON: Object; + locationData: Location; + myPicture: String; + image: any; + flat_earth: boolean; + in_australia: boolean; - constructor(private routerExtensions: RouterExtensions) { } + constructor(private myHttpPostSerivce: MyHttpPostService, + private routerExtensions: RouterExtensions, + private geoLocationService: MyGeoLocationService, + private batterInfoService: MyBatteryInfoService, + private cameraService: MyCameraService, + ) { } - ngOnInit(): void { + ngOnInit(): Promise { + return this.cameraService.takePicture(). + then(picture => { + this.image = JSON.stringify(picture); + //console.log('this is picture in json', JSON.stringify(picture)); + this.getLocation(); + }) } + public getLocation(): any { + this.geoLocationService.getLocation().then(location => { + this.locationData = location; + //console.log('this is locationData', this.locationData); + this.submit(); + }).catch(error => { + }); +} +public submit(): void { + this.makePostRequest(); +} + +private makePostRequest(): void { + this.myHttpPostSerivce + .postData({ position: this.locationData, image: this.image, flat_earth: true, in_australia: true, }) + .subscribe(res => { + //console.log('This is res', res); + this.myReturnJSON = res; + console.log('THis is myreturnJSON', this.myReturnJSON); + }); +} + goBack(): void { this.routerExtensions.back(); } diff --git a/client/Nightr/src/app/services/my-battery-info.service.ts b/client/Nightr/src/app/services/my-battery-info.service.ts index 424327f..b508718 100644 --- a/client/Nightr/src/app/services/my-battery-info.service.ts +++ b/client/Nightr/src/app/services/my-battery-info.service.ts @@ -7,7 +7,7 @@ import { ios as iosUtils } from "tns-core-modules/utils/utils"; }) export class MyBatteryInfoService { - public getBatteryLife() { + /* public getBatteryLife() { if (iosApp){ iosUtils.getter(UIDevice, UIDevice.currentDevice).batteryMonitoringEnabled = true; let battery = +(iosUtils.getter(UIDevice, UIDevice.currentDevice).batteryLevel * 100); @@ -18,5 +18,5 @@ export class MyBatteryInfoService { let percent = (level / scale) * 100.0; }); } -} +} */ } diff --git a/client/Nightr/src/app/services/my-camera-service.ts b/client/Nightr/src/app/services/my-camera-service.ts index a6a4f14..96325ef 100644 --- a/client/Nightr/src/app/services/my-camera-service.ts +++ b/client/Nightr/src/app/services/my-camera-service.ts @@ -20,7 +20,6 @@ export class MyCameraService { src.fromAsset(imageAsset).then( (source) => { resolve(source.toBase64String("png", 75)); - alert("Image uploaded"); } ); }