Просмотр исходного кода

Changes on service to know the last position of the device

Jorge Baquero 7 лет назад
Родитель
Сommit
0ce9638896
3 измененных файлов: 17 добавлений и 24 удалений
  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 Просмотреть файл

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

+ 7 - 20
src/pages/main/main.ts Просмотреть файл

53
 
53
 
54
   getRootDevicePosition() {
54
   getRootDevicePosition() {
55
     let auth = this.shareService.getAuthToken();
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
   	.subscribe(
57
   	.subscribe(
58
         (data) => { // Success
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
               title: 'Error servicio',
64
               title: 'Error servicio',
68
-              subTitle: errorPos,
65
+              subTitle: error,
69
               buttons: ['OK']
66
               buttons: ['OK']
70
             });
67
             });
71
             alert.present();
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 Просмотреть файл

11
 @Injectable()
11
 @Injectable()
12
 export class VespotServiceProvider {
12
 export class VespotServiceProvider {
13
 
13
 
14
+	URL: string;
15
+
14
   constructor(public http: HttpClient) {
16
   constructor(public http: HttpClient) {
17
+	this.URL = 'http://api.vespot.com';
15
   }
18
   }
16
 
19
 
17
   getDevices(auth) {
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
   getDeviceById(auth, deviceId) {
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
   getPositionById(auth, positionId) {
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
 }