Changed when we post

This commit is contained in:
Viktor Søndergaard 2019-04-07 01:38:29 +02:00
parent 4634409738
commit 635b50ed27
5 changed files with 90 additions and 27 deletions

View File

@ -1,5 +1,6 @@
.float-btn-container
{
margin-top: 35%;
margin-left: 20%;
width: 50%;
left: 90%;
top: 160%;
}

View File

@ -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 = (<any>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();
}
} */
}

View File

@ -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<void> {
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();
}

View File

@ -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;
});
}
}
} */
}

View File

@ -20,7 +20,6 @@ export class MyCameraService {
src.fromAsset(imageAsset).then(
(source) => {
resolve(source.toBase64String("png", 75));
alert("Image uploaded");
}
);
}