ソースを参照

Adds storage features

Jorge Baquero 7 年 前
コミット
86559ecac3
共有10 個のファイルを変更した126 個の追加44 個の削除を含む
  1. 1 0
      config.xml
  2. 13 0
      package-lock.json
  3. 4 2
      package.json
  4. 3 1
      src/app/app.module.ts
  5. 1 1
      src/pages/devices/devices.html
  6. 5 1
      src/pages/devices/devices.ts
  7. 8 2
      src/pages/home/home.html
  8. 39 20
      src/pages/home/home.ts
  9. 48 13
      src/pages/main/main.ts
  10. 4 4
      src/providers/vespot-service/vespot-service.ts

+ 1 - 0
config.xml ファイルの表示

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

+ 13 - 0
package-lock.json ファイルの表示

@@ -1344,6 +1344,19 @@
1344 1344
       "resolved": "https://registry.npmjs.org/cordova-plugin-whitelist/-/cordova-plugin-whitelist-1.3.3.tgz",
1345 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 1360
     "core-util-is": {
1348 1361
       "version": "1.0.2",
1349 1362
       "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",

+ 4 - 2
package.json ファイルの表示

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

+ 3 - 1
src/app/app.module.ts ファイルの表示

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

+ 1 - 1
src/pages/devices/devices.html ファイルの表示

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

+ 5 - 1
src/pages/devices/devices.ts ファイルの表示

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

+ 8 - 2
src/pages/home/home.html ファイルの表示

@@ -11,12 +11,18 @@
11 11
 
12 12
   <ion-item>
13 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 16
   </ion-item>
16 17
 
17 18
   <ion-item>
18 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 26
   </ion-item>
21 27
 <div padding>
22 28
   <button ion-button full (click)="login()">Ingresar</button>

+ 39 - 20
src/pages/home/home.ts ファイルの表示

@@ -1,5 +1,6 @@
1 1
 import { Component } from '@angular/core';
2 2
 import { NavController } from 'ionic-angular';
3
+import { Storage } from '@ionic/storage';
3 4
 import { Main } from '../main/main'
4 5
 import { AlertController } from 'ionic-angular';
5 6
 import { VespotServiceProvider } from '../../providers/vespot-service/vespot-service';
@@ -13,34 +14,52 @@ export class HomePage {
13 14
 
14 15
   user:any;
15 16
   password:any;
17
+  remember:any;
16 18
 
17 19
   constructor(public navCtrl: NavController,
18 20
 		public alertCtrl: AlertController,
19 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 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,6 +2,7 @@ import { Component } from '@angular/core';
2 2
 import { NavController } from 'ionic-angular';
3 3
 import { AlertController } from 'ionic-angular';
4 4
 import { interval } from 'rxjs/observable/interval';
5
+import { Storage } from '@ionic/storage';
5 6
 
6 7
 import { HomePage } from '../home/home'
7 8
 import { DevicesPage } from '../devices/devices'
@@ -9,17 +10,11 @@ import { ConfigurationPage } from '../configuration/configuration'
9 10
 import { ShareService } from '../../services/share/share';
10 11
 import { VespotServiceProvider } from '../../providers/vespot-service/vespot-service';
11 12
 
12
-
13
-
14 13
 import {
15 14
   GoogleMaps,
16 15
   GoogleMap,
17 16
   GoogleMapsEvent,
18
-  GoogleMapOptions,
19
-  CameraPosition,
20
-  MarkerOptions,
21
-  Marker,
22
-  LatLng
17
+  GoogleMapOptions
23 18
 } from '@ionic-native/google-maps';
24 19
 
25 20
 @Component({
@@ -43,7 +38,8 @@ export class Main {
43 38
   public shareService: ShareService,
44 39
   private googleMaps: GoogleMaps,
45 40
   private vespotService: VespotServiceProvider,
46
-  public alertCtrl: AlertController) {
41
+  public alertCtrl: AlertController,
42
+  private storage: Storage) {
47 43
       this.devicesPage = DevicesPage;
48 44
       this.configurationPage = ConfigurationPage;
49 45
       this.devices = this.shareService.getDevices();
@@ -54,7 +50,23 @@ export class Main {
54 50
 
55 51
   ionViewWillEnter() {
56 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 70
     } else {
59 71
       this.getRootDevicePosition();
60 72
     }
@@ -88,10 +100,31 @@ export class Main {
88 100
     this.navCtrl.push(DevicesPage);
89 101
   }
90 102
 
91
-  openConfigurationPage() {}
103
+  openConfigurationPage() {
104
+    this.navCtrl.push(ConfigurationPage);
105
+  }
92 106
 
93 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,8 +180,10 @@ export class Main {
147 180
       this.vespotService.getPositionByDeviceId(auth, this.shareService.getRootDevice().id)
148 181
     	.subscribe(
149 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 188
           (error) =>{
154 189
   			       console.log('updateMarker: ' + error);

+ 4 - 4
src/providers/vespot-service/vespot-service.ts ファイルの表示

@@ -18,18 +18,18 @@ export class VespotServiceProvider {
18 18
   }
19 19
 
20 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 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 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 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
 }