Quellcode durchsuchen

Changes on service to know the last position of the device

Jorge Baquero vor 7 Jahren
Ursprung
Commit
0ce9638896
3 geänderte Dateien mit 17 neuen und 24 gelöschten Zeilen
  1. 1 1
      src/pages/main/main.html
  2. 7 20
      src/pages/main/main.ts
  3. 9 3
      src/providers/vespot-service/vespot-service.ts

+ 1 - 1
src/pages/main/main.html Datei anzeigen

@@ -1,4 +1,4 @@
1
-<ion-menu [content]="vespotMenu" menuType="push">
1
+<ion-menu [content]="vespotMenu" >
2 2
   <ion-header>
3 3
     <ion-toolbar>
4 4
       <ion-title>Menu</ion-title>

+ 7 - 20
src/pages/main/main.ts Datei anzeigen

@@ -53,32 +53,19 @@ export class Main {
53 53
 
54 54
   getRootDevicePosition() {
55 55
     let auth = this.shareService.getAuthToken();
56
-    this.vespotService.getDeviceById(auth, this.shareService.getRootDevice().id)
56
+    this.vespotService.getPositionByDeviceId(auth, this.shareService.getRootDevice().id)
57 57
   	.subscribe(
58 58
         (data) => { // Success
59
-          this.vespotService.getPositionById(auth, data[0].positionId)
60
-        	.subscribe(
61
-              (dataPos) => { // Success
62
-                this.rootPosition = dataPos[0];
63
-                this.loadMap();
64
-              },
65
-              (errorPos) =>{
66
-                let alert = this.alertCtrl.create({
59
+			this.rootPosition = data[0];
60
+            this.loadMap();
61
+        },
62
+        (error) =>{
63
+			let alert = this.alertCtrl.create({
67 64
               title: 'Error servicio',
68
-              subTitle: errorPos,
65
+              subTitle: error,
69 66
               buttons: ['OK']
70 67
             });
71 68
             alert.present();
72
-              }
73
-            );
74
-        },
75
-        (error) =>{
76
-          /*let alert = this.alertCtrl.create({
77
-        title: 'Advertencia',
78
-        subTitle: 'Error al acceder al servicio',
79
-        buttons: ['OK']
80
-      });
81
-      alert.present();*/
82 69
         }
83 70
       );
84 71
   }

+ 9 - 3
src/providers/vespot-service/vespot-service.ts Datei anzeigen

@@ -11,19 +11,25 @@ import { Injectable } from '@angular/core';
11 11
 @Injectable()
12 12
 export class VespotServiceProvider {
13 13
 
14
+	URL: string;
15
+
14 16
   constructor(public http: HttpClient) {
17
+	this.URL = 'http://api.vespot.com';
15 18
   }
16 19
 
17 20
   getDevices(auth) {
18
-    return this.http.get('http://api.vespot.com/devices', {headers: new HttpHeaders().set('Authorization', 'Basic ' + btoa(auth))});
21
+    return this.http.get(this.URL + '/devices', {headers: new HttpHeaders().set('Authorization', 'Basic ' + btoa(auth))});
19 22
   }
20 23
 
21 24
   getDeviceById(auth, deviceId) {
22
-    return this.http.get('http://api.vespot.com/devices?id=' + deviceId, {headers: new HttpHeaders().set('Authorization', 'Basic ' + btoa(auth))});
25
+    return this.http.get(this.URL + '/devices?id=' + deviceId, {headers: new HttpHeaders().set('Authorization', 'Basic ' + btoa(auth))});
23 26
   }
24 27
 
25 28
   getPositionById(auth, positionId) {
26
-    return this.http.get('http://api.vespot.com/positions?positionId=' + positionId, {headers: new HttpHeaders().set('Authorization', 'Basic ' + btoa(auth))});
29
+    return this.http.get(this.URL + '/positions?positionId=' + positionId, {headers: new HttpHeaders().set('Authorization', 'Basic ' + btoa(auth))});
27 30
   }
28 31
 
32
+  getPositionByDeviceId(auth, deviceId) {
33
+    return this.http.get(this.URL + '/positions/lastdeviceposition?deviceId=' + deviceId, {headers: new HttpHeaders().set('Authorization', 'Basic ' + btoa(auth))});
34
+  }
29 35
 }