Browse Source

sincronizacion de nuevos productos hecho y modulo de preconfiguracion y comprobacion de datos hecho

robert2206 8 years ago
parent
commit
ce9468ea65

+ 1 - 1
src/pages/hall/hall.html

@@ -1,3 +1,3 @@
 <ion-content padding>
-   <div class="drip"></div>
+   
 </ion-content>

+ 0 - 137
src/pages/hall/hall.scss

@@ -2,141 +2,4 @@ page-hall {
     ion-content {
         background: #3f50b4 !important;
     }
-// Animation properties
-$anim-width:    200px;
-$anim-height:   250px;
-$anim-duration: 4s;
-
-// Splash properties
-$splash-width:  $anim-width;
-$splash-height: $anim-width / 2;
-$splash-origin: $splash-height / 2;
-$water-level:   $splash-origin;
-
-// Drip properties
-$drip-size:     15px;
-$drip-pos:      ($splash-width / 2) - ($drip-size / 2);
-$drip-rebound:  40px;
-$drip-re-size:  5px;
-$drip-re-pos:   ($splash-width / 2) - ($drip-re-size / 2);
-
-// Colours
-$c-drip:        #FFF;
-$c-splash:      #FFF;
-$c-bg:          #43A2CE;
-
-
-.drip {
-  width: $anim-width;
-  height: $anim-height;
-  display: flex;
-  flex-wrap: wrap;
-  justify-content: center;
-  margin: auto;
-  position: relative;
-
-  &:before {
-    position: absolute;
-    left: $drip-pos;
-    top: 0;
-    content: '';
-    width: $drip-size;
-    height: $drip-size;
-    background-color: $c-drip;
-    border-radius: 50%;
-    opacity: 0;
-    animation: drip $anim-duration ease infinite;
-  }
-
-  &:after {
-    box-sizing: border-box;
-    position: absolute;
-    bottom: 0;
-    left: 0;
-    content: '';
-    width: 0px;
-    height: 0px;
-    border: solid 4px $c-drip;
-    border-radius: 50%;
-    opacity: 0;
-    animation: splash $anim-duration ease infinite;
-  }
-}
-
-@keyframes drip {
-  10% {
-    top: 0;
-    opacity: 1;
-    animation-timing-function: cubic-bezier(.24,0,.76,.14);
-  }
-  25% {
-    opacity: 1;
-    top: $anim-height - $water-level;
-    animation-timing-function: ease-out;
-    width: $drip-size;
-    height: $drip-size;
-    left: $drip-pos;
-  }
-  30% {
-    opacity: 1;
-    top: $anim-height - ($water-level + $drip-rebound);
-    width: $drip-re-size;
-    height: $drip-re-size;
-    animation-timing-function: ease-in;
-    left: $drip-re-pos;
-  }
-  33% {
-    top: $anim-height - $water-level;
-    opacity: 0;
-    animation-timing-function: ease-out;
-    left: $drip-re-pos;
-  }
-  33.001% {
-    opacity: 0;
-  }
-  100% {
-    opacity: 0;
-  }
-}
-
-@keyframes splash {
-  0% {
-    opacity: 0;
-  }
-  25% {
-    bottom: $splash-height / 2;
-    left: $splash-width / 2;
-    opacity: 0;
-    width: 0px;
-    height: 0px;
-  }
-  25.001% {
-    opacity: 1;
-  }
-  33% {
-    bottom: 0;
-    left: 0;
-    opacity: 0;
-    width: $splash-width;
-    height: $splash-height;
-  }
-  33.001% {
-    bottom: $splash-height / 2;
-    left: $splash-width / 2;
-    opacity: 1;
-    width: 0px;
-    height: 0px;
-  }
-  43% {
-    bottom: 0;
-    left: 0;
-    opacity: 0;
-    width: $splash-width;
-    height: $splash-height;
-  }
-  43.001% {
-    opacity: 0;
-  }
-}
-
 }

+ 48 - 4
src/pages/hall/hall.ts

@@ -1,5 +1,8 @@
 import { Component } from '@angular/core';
-import { NavController } from 'ionic-angular';
+import { NavController, Loading, LoadingController, MenuController } from 'ionic-angular';
+import { ToolsProvider } from '../../providers/tools-provider';
+import { LoginPage } from '../../pages/login/login';
+import { HomePage } from '../../pages/home/home';
 
 @Component({
     selector: 'page-hall',
@@ -7,9 +10,50 @@ import { NavController } from 'ionic-angular';
 })
 export class HallPage {
 
-    constructor(public navCtrl: NavController) {}
+    loader: Loading;
 
+    constructor(
+        public navCtrl: NavController,
+        public menuCtrl: MenuController,
+        public loaderCtrl: LoadingController,
+        public toolsProvider: ToolsProvider
+    ) { }
+
+    /**
+     *
+     */
     ionViewDidLoad() {
-      console.log('Hello Hall Page');
-   }
+        console.log('Hello Hall Page');
+        
+        this.loader = this.loaderCtrl.create({
+            content: "Configurando aplicación, espere..."
+        });
+        
+        this.loader.present();
+
+        this.toolsProvider.initializeDatabase().then(r => { 
+            this.loader.dismiss();
+            this.goToHome();
+        }).catch(e => {
+            console.log(e);
+            this.loader.dismiss();
+            
+            this.goToLogin();
+        });
+    }
+
+    /**
+     * Go to login
+     */
+    private goToLogin(): void {
+        this.navCtrl.setRoot(LoginPage);
+    }
+
+    /**
+     * Go to home
+     */
+    private goToHome(): void {
+        this.navCtrl.setRoot(HomePage);
+        this.menuCtrl.enable(true);
+    }
 }

+ 2 - 17
src/pages/login/login.ts

@@ -2,7 +2,6 @@ import { Component } from '@angular/core';
 import { NavController, MenuController, LoadingController, ToastController } from 'ionic-angular';
 import { TokenService } from '../../providers/token-service';
 import { HallPage } from '../hall/hall';
-import { HomePage } from '../home/home';
 
 @Component({
     selector: 'page-login',
@@ -39,18 +38,10 @@ export class LoginPage {
         loader.present();
 
         this.tokenService.getToken().then(r => {
+
             loader.dismiss();
             this.goToHall();
-            // this.goToHome();
-
-            // this.toolsProvider.initializeDatabase().then(r => { 
-            //     loader.dismiss();
-            //     this.goToHome();
-            // }).catch(e => { 
-            //     console.log(e);
-                
-            // });
-            
+ 
         }).catch(e => {
             console.log(e);
             loader.dismiss();
@@ -68,10 +59,4 @@ export class LoginPage {
     private goToHall(): void {
         this.navCtrl.setRoot(HallPage);
     }
-
-    // Go to home
-    private goToHome(): void {
-        this.navCtrl.setRoot(HomePage);
-        this.menuCtrl.enable(true);
-    }
 }

+ 2 - 2
src/pages/product-details/product-details.html

@@ -14,8 +14,8 @@
 <ion-content>
     <ion-card>
         <div style="position: relative">
-            <img src="./assets/images/product.png" *ngIf="!product.image"/>
-            <img src="data:image/jpeg;base64,{{ product.image }}" *ngIf="product.image"/>
+            <img src="./assets/images/product.png" *ngIf="!product.image_medium"/>
+            <img src="data:image/jpeg;base64,{{ product.image_medium }}" *ngIf="product.image_medium"/>
 
             <ion-fab left bottom>
                 <button ion-fab color="yellow" class="fab-picture" (click)="showPhotoOptions()">

+ 8 - 3
src/pages/product-details/product-details.ts

@@ -3,6 +3,7 @@ import { NavController, NavParams, ActionSheetController } from 'ionic-angular';
 import { Product } from '../../models/product'
 import { DataProvider } from '../../providers/data-provider'
 import { CameraProvider } from '../../providers/camera-provider';
+import { PreferencesProvider } from '../../providers/preferences-provider';
 
 @Component({
     selector: 'page-product-details',
@@ -12,7 +13,7 @@ import { CameraProvider } from '../../providers/camera-provider';
 export class ProductDetailsPage {
 
     product = {
-        company_id: false,
+        company_id: 0,
         default_code: false,
         description: false,
         ean13: false,
@@ -35,7 +36,8 @@ export class ProductDetailsPage {
         public params: NavParams,
         public data: DataProvider,
         public actionSheetCtrl: ActionSheetController,
-        private cameraProvider: CameraProvider
+        private cameraProvider: CameraProvider,
+        private preferencesPreferences: PreferencesProvider
     ) { 
         this.initialize();
     }
@@ -110,14 +112,17 @@ export class ProductDetailsPage {
             return;
         }
 
+        this.product.company_id = this.preferencesPreferences.getCompany();
+    
         this.data.save('product', this.product).then(result => {
             if (this.params.data instanceof Array) {
                 this.params.data.push(result.products[0]);
-            } 
+            }
             
             this.navCtrl.pop(this);
         }).catch(e => {
             console.log(e);
         });
+  
     }
 }

+ 1 - 3
src/providers/data-provider.ts

@@ -78,9 +78,7 @@ export class DataProvider {
     /**
      *
      */
-    save(type: string, data: any): any {
-        console.log(data);
-        
+    save(type: string, data: any): Promise<any> {
         return new Promise((resolve, reject) => {
             resolve(this.data.rel.save(type, data));
         });

+ 3 - 19
src/providers/odoo-provider.ts

@@ -61,7 +61,7 @@ export class OdooProvider {
     private encodeData(data: any) {
         let body = [];
         for (let field in data) {
-            if (['doc_state', "remote_id", "rev"].indexOf(field) == -1) {
+            if (['doc_state', "remote_id", "rev"].indexOf(field) != -1) {
                 continue;
             }
 
@@ -85,9 +85,9 @@ export class OdooProvider {
 
         return new Promise((resolve, reject) => {
             this.http.get(this.url, options).toPromise().then(r => { 
-                resolve(r);
+                resolve(r.json());
             }).catch(e => { 
-                reject(e);
+                reject(e.json());
             });
         });
     }
@@ -105,20 +105,4 @@ export class OdooProvider {
     delete(resource: string, data: Array<any>) {
 
     }
-
-    /**
-     *
-     */
-    private extractData(response: Response): any {
-        return response.json() || [];
-    }
-
-    /**
-     *
-     */
-    private handleError(error: any) {
-         let msg = error._body;
-
-        return Observable.throw(msg);
-    }
 }

+ 30 - 0
src/providers/preferences-provider.ts

@@ -5,6 +5,8 @@ export class PreferencesProvider {
 
     tokenPrefix: string = "odix_token";
     hostPrefix: string = "odix_host";
+    companyPrefix: string = "odix_company";
+    partnerPrefix: string = "odix_partner";
     startPagePrefix: string = "odix_start_page";
     syncPrefix: string = "odix_sync";
     syncFrecuencyPrefix: string = "odix_sync_frecuency";
@@ -39,6 +41,34 @@ export class PreferencesProvider {
         return localStorage.getItem(this.hostPrefix);
     }
 
+    /**
+     *
+     */
+    setCompany(company: number): void {
+        localStorage.setItem(this.companyPrefix, company.toString());
+    }
+
+    /**
+     *
+     */
+    getCompany(): number {
+        return +localStorage.getItem(this.companyPrefix);
+    }
+
+    /**
+     *
+     */
+    setPartner(partner: number): void {
+        localStorage.setItem(this.partnerPrefix, partner.toString());
+    }
+
+    /**
+     *
+     */
+    getPartner(): number {
+        return +localStorage.getItem(this.partnerPrefix);
+    }
+
     /**
      *
      */

+ 6 - 2
src/providers/sync-provider.ts

@@ -16,8 +16,12 @@ export class SyncProvider {
      */
     doSync(): Promise<any> {
         return new Promise((resolve, reject) => {
-            this.getCreatedProducts().then(p => {
-                this.odooProvider.post("products", p).then(r => { 
+            this.getCreatedProducts().then(products => {
+                if (products.length == 0) {
+                    resolve();
+                }
+                
+                this.odooProvider.post("products", products).then(r => { 
                     resolve(r);
                 }).catch(e => {
                     reject(e);

+ 3 - 3
src/providers/token-service.ts

@@ -11,9 +11,9 @@ import 'rxjs/add/observable/throw'
 @Injectable()
 export class TokenService {
 
-    private username: string = 'admin';
-    private password: string = 'admin';
-    private url: string = '192.168.88.123:8069';
+    username: string = 'admin';
+    password: string = 'admin';
+    url: string = '192.168.88.123:8069';
 
     constructor(
         private http: Http,

+ 43 - 4
src/providers/tools-provider.ts

@@ -1,14 +1,15 @@
 import { Injectable } from '@angular/core';
 import { OdooProvider } from './odoo-provider';
-// import { DataProvider } from './data-provider';
-
+import { DataProvider } from './data-provider';
+import { PreferencesProvider } from './preferences-provider';
 
 @Injectable()
 export class ToolsProvider {
 
     constructor(
         public odooProvider: OdooProvider,
-        // public dataProvider: DataProvider
+        public dataProvider: DataProvider,
+        public preferencesProvider: PreferencesProvider
     ) { }
     
     /**
@@ -16,7 +17,45 @@ export class ToolsProvider {
      */
     initializeDatabase(): Promise<any> {
         return new Promise((resolve, reject) => {
-            resolve("ok");
+
+            this.dataProvider.getAll("users").then(r => {
+
+                if (r.users.length == 0) {
+                    this.odooProvider.get("users").then(users => {
+                
+                    let user = users.filter(item => {
+                        return item.jwt_token === this.preferencesProvider.getToken();
+                    });
+
+                    this.dataProvider.save("user", user[0]).then(r => {
+                        this.preferencesProvider.setCompany(r.users[0].company_id);
+                        this.preferencesProvider.setPartner(r.users[0].partner_id);
+                        
+                        resolve();
+                    }).catch(e => { 
+                        reject(e);
+                    });
+                        
+                }).catch(e => { 
+                    console.log(e);
+                    reject(e);
+                });
+                   
+                } else {
+                    resolve(); 
+                }
+            });
+        });
+    }
+
+    getCompany(): Promise<any> {
+        return new Promise((reject, resolve) => { 
+            this.dataProvider.getAll("user").then(data => {
+                resolve(data.users[0].company_id);
+            }).catch(e => {
+                reject(e);
+            });
         });
+       
     }
 }