Jorge Baquero 7 лет назад
Родитель
Сommit
86559ecac3

+ 1 - 0
config.xml Просмотреть файл

88
         <variable name="ANDROID_SUPPORT_V4_VERSION" value="24.1.0" />
88
         <variable name="ANDROID_SUPPORT_V4_VERSION" value="24.1.0" />
89
     </plugin>
89
     </plugin>
90
     <allow-navigation href="http://192.168.0.7:8100" />
90
     <allow-navigation href="http://192.168.0.7:8100" />
91
+    <plugin name="cordova-sqlite-storage" spec="^2.2.1" />
91
 </widget>
92
 </widget>

+ 13 - 0
package-lock.json Просмотреть файл

1344
       "resolved": "https://registry.npmjs.org/cordova-plugin-whitelist/-/cordova-plugin-whitelist-1.3.3.tgz",
1344
       "resolved": "https://registry.npmjs.org/cordova-plugin-whitelist/-/cordova-plugin-whitelist-1.3.3.tgz",
1345
       "integrity": "sha1-tehezbv+Wu3tQKG/TuI3LmfZb7Q="
1345
       "integrity": "sha1-tehezbv+Wu3tQKG/TuI3LmfZb7Q="
1346
     },
1346
     },
1347
+    "cordova-sqlite-storage": {
1348
+      "version": "2.2.1",
1349
+      "resolved": "https://registry.npmjs.org/cordova-sqlite-storage/-/cordova-sqlite-storage-2.2.1.tgz",
1350
+      "integrity": "sha512-NVaUtq5XDhbdV62lQiEEW/1WOyZYfNKKhEaFJZsvKsZ6461re4E85AvJCaPSo5dD91Qi/3WG5mwR/M1ixrfSww==",
1351
+      "requires": {
1352
+        "cordova-sqlite-storage-dependencies": "1.1.0"
1353
+      }
1354
+    },
1355
+    "cordova-sqlite-storage-dependencies": {
1356
+      "version": "1.1.0",
1357
+      "resolved": "https://registry.npmjs.org/cordova-sqlite-storage-dependencies/-/cordova-sqlite-storage-dependencies-1.1.0.tgz",
1358
+      "integrity": "sha512-mtV0v6KuB7/9gfZdKiyBeFl1KPc/erMXMKAvnSFwszktm47HNmHJJ/05Fbc+YvQbccAXJ3QB/ElItWWqJorblg=="
1359
+    },
1347
     "core-util-is": {
1360
     "core-util-is": {
1348
       "version": "1.0.2",
1361
       "version": "1.0.2",
1349
       "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
1362
       "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",

+ 4 - 2
package.json Просмотреть файл

24
     "@ionic-native/google-maps": "^4.5.3",
24
     "@ionic-native/google-maps": "^4.5.3",
25
     "@ionic-native/splash-screen": "4.4.0",
25
     "@ionic-native/splash-screen": "4.4.0",
26
     "@ionic-native/status-bar": "4.4.0",
26
     "@ionic-native/status-bar": "4.4.0",
27
-    "@ionic/storage": "2.1.3",
27
+    "@ionic/storage": "^2.1.3",
28
     "cordova-android": "7.0.0",
28
     "cordova-android": "7.0.0",
29
     "cordova-plugin-device": "^2.0.1",
29
     "cordova-plugin-device": "^2.0.1",
30
     "cordova-plugin-googlemaps": "^2.2.5",
30
     "cordova-plugin-googlemaps": "^2.2.5",
32
     "cordova-plugin-ionic-webview": "^1.1.16",
32
     "cordova-plugin-ionic-webview": "^1.1.16",
33
     "cordova-plugin-splashscreen": "^5.0.2",
33
     "cordova-plugin-splashscreen": "^5.0.2",
34
     "cordova-plugin-whitelist": "^1.3.3",
34
     "cordova-plugin-whitelist": "^1.3.3",
35
+    "cordova-sqlite-storage": "^2.2.1",
35
     "ionic-angular": "3.9.2",
36
     "ionic-angular": "3.9.2",
36
     "ionicons": "3.0.0",
37
     "ionicons": "3.0.0",
37
     "rxjs": "5.5.2",
38
     "rxjs": "5.5.2",
54
         "API_KEY_FOR_ANDROID": "AIzaSyBFA53YiCYfP25i360xJ32gDDusW7zHrBk",
55
         "API_KEY_FOR_ANDROID": "AIzaSyBFA53YiCYfP25i360xJ32gDDusW7zHrBk",
55
         "PLAY_SERVICES_VERSION": "11.8.0",
56
         "PLAY_SERVICES_VERSION": "11.8.0",
56
         "ANDROID_SUPPORT_V4_VERSION": "24.1.0"
57
         "ANDROID_SUPPORT_V4_VERSION": "24.1.0"
57
-      }
58
+      },
59
+      "cordova-sqlite-storage": {}
58
     },
60
     },
59
     "platforms": [
61
     "platforms": [
60
       "android"
62
       "android"

+ 3 - 1
src/app/app.module.ts Просмотреть файл

5
 import { StatusBar } from '@ionic-native/status-bar';
5
 import { StatusBar } from '@ionic-native/status-bar';
6
 import { HttpClientModule } from '@angular/common/http';
6
 import { HttpClientModule } from '@angular/common/http';
7
 import { GoogleMaps } from '@ionic-native/google-maps';
7
 import { GoogleMaps } from '@ionic-native/google-maps';
8
+import { IonicStorageModule } from '@ionic/storage';
8
 
9
 
9
 import { MyApp } from './app.component';
10
 import { MyApp } from './app.component';
10
 import { HomePage } from '../pages/home/home';
11
 import { HomePage } from '../pages/home/home';
25
   imports: [
26
   imports: [
26
     BrowserModule,
27
     BrowserModule,
27
     HttpClientModule,
28
     HttpClientModule,
28
-    IonicModule.forRoot(MyApp)
29
+    IonicModule.forRoot(MyApp),
30
+    IonicStorageModule.forRoot()
29
   ],
31
   ],
30
   bootstrap: [IonicApp],
32
   bootstrap: [IonicApp],
31
   entryComponents: [
33
   entryComponents: [

+ 1 - 1
src/pages/devices/devices.html Просмотреть файл

1
 <ion-header>
1
 <ion-header>
2
   <ion-navbar>
2
   <ion-navbar>
3
-    <ion-title>Selecciona tu dispositivo por defecto</ion-title>
3
+    <ion-title>Dispositivo por Defecto</ion-title>
4
   </ion-navbar>
4
   </ion-navbar>
5
 </ion-header>
5
 </ion-header>
6
 
6
 

+ 5 - 1
src/pages/devices/devices.ts Просмотреть файл

1
 import { Component } from '@angular/core';
1
 import { Component } from '@angular/core';
2
 import { IonicPage, NavController} from 'ionic-angular';
2
 import { IonicPage, NavController} from 'ionic-angular';
3
+import { Storage } from '@ionic/storage';
3
 
4
 
4
 import { ShareService } from '../../services/share/share';
5
 import { ShareService } from '../../services/share/share';
5
 
6
 
19
 export class DevicesPage {
20
 export class DevicesPage {
20
 
21
 
21
   private devices;
22
   private devices;
22
-  constructor(public navCtrl: NavController, public shareService: ShareService) {
23
+  constructor(public navCtrl: NavController,
24
+    public shareService: ShareService,
25
+    private storage: Storage) {
23
     this.devices = this.shareService.getDevices();
26
     this.devices = this.shareService.getDevices();
24
     //alert(this.devices.length);
27
     //alert(this.devices.length);
25
   }
28
   }
30
 
33
 
31
   selectRadio(device) {
34
   selectRadio(device) {
32
     this.shareService.setRootDevice(device);
35
     this.shareService.setRootDevice(device);
36
+    this.storage.set('rootDevice', device.id);
33
     this.navCtrl.pop();
37
     this.navCtrl.pop();
34
   }
38
   }
35
 
39
 

+ 8 - 2
src/pages/home/home.html Просмотреть файл

11
 
11
 
12
   <ion-item>
12
   <ion-item>
13
     <ion-label floating>Usuario</ion-label>
13
     <ion-label floating>Usuario</ion-label>
14
-    <ion-input type="text" [(ngModel)]="user" value="baquerojorge@gmail.com"></ion-input>
14
+    <!--<ion-input type="text" [(ngModel)]="user" value="baquerojorge@gmail.com"></ion-input>-->
15
+    <ion-input type="text" [(ngModel)]="user"></ion-input>
15
   </ion-item>
16
   </ion-item>
16
 
17
 
17
   <ion-item>
18
   <ion-item>
18
     <ion-label floating>Contraseña</ion-label>
19
     <ion-label floating>Contraseña</ion-label>
19
-    <ion-input type="password" [(ngModel)]="password" value="hiphop2008"></ion-input>
20
+    <!--<ion-input type="password" [(ngModel)]="password" value="hiphop2008"></ion-input>-->
21
+    <ion-input type="password" [(ngModel)]="password"></ion-input>
22
+  </ion-item>
23
+  <ion-item>
24
+    <ion-label>Recordarme</ion-label>
25
+    <ion-checkbox [(ngModel)]="remember"></ion-checkbox>
20
   </ion-item>
26
   </ion-item>
21
 <div padding>
27
 <div padding>
22
   <button ion-button full (click)="login()">Ingresar</button>
28
   <button ion-button full (click)="login()">Ingresar</button>

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

1
 import { Component } from '@angular/core';
1
 import { Component } from '@angular/core';
2
 import { NavController } from 'ionic-angular';
2
 import { NavController } from 'ionic-angular';
3
+import { Storage } from '@ionic/storage';
3
 import { Main } from '../main/main'
4
 import { Main } from '../main/main'
4
 import { AlertController } from 'ionic-angular';
5
 import { AlertController } from 'ionic-angular';
5
 import { VespotServiceProvider } from '../../providers/vespot-service/vespot-service';
6
 import { VespotServiceProvider } from '../../providers/vespot-service/vespot-service';
13
 
14
 
14
   user:any;
15
   user:any;
15
   password:any;
16
   password:any;
17
+  remember:any;
16
 
18
 
17
   constructor(public navCtrl: NavController,
19
   constructor(public navCtrl: NavController,
18
 		public alertCtrl: AlertController,
20
 		public alertCtrl: AlertController,
19
 		public vespotService: VespotServiceProvider,
21
 		public vespotService: VespotServiceProvider,
20
-    public shareService: ShareService) {
22
+    public shareService: ShareService,
23
+    private storage: Storage) {
24
+      this.storage.get('remember').then((val)=>{
25
+          if(val) {
26
+            this.storage.get('authentication').then((valAuth)=>{
27
+                this.authenticateUser(valAuth);
28
+            });
29
+          }
30
+      });
31
+  }
32
+
33
+  /*ionViewCanEnter() {
34
+  }*/
21
 
35
 
36
+  authenticateUser(auth) {
37
+    this.vespotService.getDevices(auth)
38
+  	.subscribe(
39
+        (data) => { // Success
40
+          this.shareService.setDevices(data);
41
+          this.shareService.setAuthToken(auth);
42
+          if(this.remember == true) {
43
+            this.storage.set('remember', true);
44
+            this.storage.set('authentication', auth);
45
+          }
46
+
47
+          this.navCtrl.setRoot(Main);
48
+        },
49
+        (error) =>{
50
+          let alert = this.alertCtrl.create({
51
+        title: 'Advertencia',
52
+        subTitle: 'Usuario y Contraseña Incorrectos',
53
+        buttons: ['OK']
54
+      });
55
+      alert.present();
56
+        }
57
+      );
22
   }
58
   }
23
 
59
 
24
   login() {
60
   login() {
25
-	let auth = this.user + ':' + this.password;
26
-
27
-  this.vespotService.getDevices(auth)
28
-	.subscribe(
29
-      (data) => { // Success
30
-        this.shareService.setDevices(data);
31
-        this.shareService.setAuthToken(auth);
32
-        this.navCtrl.setRoot(Main);
33
-      },
34
-      (error) =>{
35
-        let alert = this.alertCtrl.create({
36
-      title: 'Advertencia',
37
-      subTitle: 'Usuario y Contraseña Incorrectos',
38
-      buttons: ['OK']
39
-    });
40
-    alert.present();
41
-      }
42
-    );
43
-
61
+    let auth = btoa(this.user + ':' + this.password);
62
+    this.authenticateUser(auth);
44
   }
63
   }
45
 
64
 
46
 }
65
 }

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

2
 import { NavController } from 'ionic-angular';
2
 import { NavController } from 'ionic-angular';
3
 import { AlertController } from 'ionic-angular';
3
 import { AlertController } from 'ionic-angular';
4
 import { interval } from 'rxjs/observable/interval';
4
 import { interval } from 'rxjs/observable/interval';
5
+import { Storage } from '@ionic/storage';
5
 
6
 
6
 import { HomePage } from '../home/home'
7
 import { HomePage } from '../home/home'
7
 import { DevicesPage } from '../devices/devices'
8
 import { DevicesPage } from '../devices/devices'
9
 import { ShareService } from '../../services/share/share';
10
 import { ShareService } from '../../services/share/share';
10
 import { VespotServiceProvider } from '../../providers/vespot-service/vespot-service';
11
 import { VespotServiceProvider } from '../../providers/vespot-service/vespot-service';
11
 
12
 
12
-
13
-
14
 import {
13
 import {
15
   GoogleMaps,
14
   GoogleMaps,
16
   GoogleMap,
15
   GoogleMap,
17
   GoogleMapsEvent,
16
   GoogleMapsEvent,
18
-  GoogleMapOptions,
19
-  CameraPosition,
20
-  MarkerOptions,
21
-  Marker,
22
-  LatLng
17
+  GoogleMapOptions
23
 } from '@ionic-native/google-maps';
18
 } from '@ionic-native/google-maps';
24
 
19
 
25
 @Component({
20
 @Component({
43
   public shareService: ShareService,
38
   public shareService: ShareService,
44
   private googleMaps: GoogleMaps,
39
   private googleMaps: GoogleMaps,
45
   private vespotService: VespotServiceProvider,
40
   private vespotService: VespotServiceProvider,
46
-  public alertCtrl: AlertController) {
41
+  public alertCtrl: AlertController,
42
+  private storage: Storage) {
47
       this.devicesPage = DevicesPage;
43
       this.devicesPage = DevicesPage;
48
       this.configurationPage = ConfigurationPage;
44
       this.configurationPage = ConfigurationPage;
49
       this.devices = this.shareService.getDevices();
45
       this.devices = this.shareService.getDevices();
54
 
50
 
55
   ionViewWillEnter() {
51
   ionViewWillEnter() {
56
     if(typeof this.shareService.getRootDevice() == "undefined") {
52
     if(typeof this.shareService.getRootDevice() == "undefined") {
57
-      this.navCtrl.push(DevicesPage);
53
+      this.storage.get('rootDevice').then((valDevice)=>{
54
+        if(valDevice == null) {
55
+          this.navCtrl.push(DevicesPage);
56
+        } else {
57
+          let auth = this.shareService.getAuthToken();
58
+          this.vespotService.getDeviceById(auth, valDevice)
59
+        	.subscribe(
60
+              (data) => { // Success
61
+                this.rootDevice = data[0];
62
+              },
63
+              (error) =>{
64
+      			       console.log('ionViewWillEnter: ' + error);
65
+              }
66
+            );
67
+        }
68
+      });
69
+
58
     } else {
70
     } else {
59
       this.getRootDevicePosition();
71
       this.getRootDevicePosition();
60
     }
72
     }
88
     this.navCtrl.push(DevicesPage);
100
     this.navCtrl.push(DevicesPage);
89
   }
101
   }
90
 
102
 
91
-  openConfigurationPage() {}
103
+  openConfigurationPage() {
104
+    this.navCtrl.push(ConfigurationPage);
105
+  }
92
 
106
 
93
   closeSession() {
107
   closeSession() {
94
-	   this.navCtrl.setRoot(HomePage);
108
+    let alert = this.alertCtrl.create({
109
+      title: 'Confirmación',
110
+      message: 'Realmente desea cerrar Sesión?',
111
+      buttons: [{
112
+        text: 'Si',
113
+        handler: () => {
114
+          this.storage.set('authentication', '');
115
+          this.storage.set('remember', false);
116
+          this.storage.set('rootDevice', null);
117
+      	  this.navCtrl.setRoot(HomePage);
118
+        }
119
+      },{
120
+        text: 'No',
121
+        handler: () => {
122
+          alert.dismiss();
123
+          return false;
124
+        }
125
+      }]
126
+    });
127
+    alert.present();
95
   }
128
   }
96
 
129
 
97
   /**
130
   /**
147
       this.vespotService.getPositionByDeviceId(auth, this.shareService.getRootDevice().id)
180
       this.vespotService.getPositionByDeviceId(auth, this.shareService.getRootDevice().id)
148
     	.subscribe(
181
     	.subscribe(
149
           (data) => { // Success
182
           (data) => { // Success
150
-  			       this.rootPosition = data[0];
151
-               this.getPosition();
183
+            if(data[0].serverTime != this.rootPosition.serverTime) {
184
+            this.rootPosition = data[0];
185
+            this.getPosition();
186
+            }
152
           },
187
           },
153
           (error) =>{
188
           (error) =>{
154
   			       console.log('updateMarker: ' + error);
189
   			       console.log('updateMarker: ' + error);

+ 4 - 4
src/providers/vespot-service/vespot-service.ts Просмотреть файл

18
   }
18
   }
19
 
19
 
20
   getDevices(auth) {
20
   getDevices(auth) {
21
-    return this.http.get(this.URL + '/devices', {headers: new HttpHeaders().set('Authorization', 'Basic ' + btoa(auth))});
21
+    return this.http.get(this.URL + '/devices', {headers: new HttpHeaders().set('Authorization', 'Basic ' + auth)});
22
   }
22
   }
23
 
23
 
24
   getDeviceById(auth, deviceId) {
24
   getDeviceById(auth, deviceId) {
25
-    return this.http.get(this.URL + '/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 ' + auth)});
26
   }
26
   }
27
 
27
 
28
   getPositionById(auth, positionId) {
28
   getPositionById(auth, positionId) {
29
-    return this.http.get(this.URL + '/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 ' + auth)});
30
   }
30
   }
31
 
31
 
32
   getPositionByDeviceId(auth, deviceId) {
32
   getPositionByDeviceId(auth, deviceId) {
33
-    return this.http.get(this.URL + '/positions/lastdeviceposition?deviceId=' + deviceId, {headers: new HttpHeaders().set('Authorization', 'Basic ' + btoa(auth))});
33
+    return this.http.get(this.URL + '/positions/lastdeviceposition?deviceId=' + deviceId, {headers: new HttpHeaders().set('Authorization', 'Basic ' + auth)});
34
   }
34
   }
35
 }
35
 }