Deisy 8 سال پیش
والد
کامیت
f3d51f1bd3

+ 1 - 1
ionic.config.json

@@ -6,7 +6,7 @@
     "proxies": [
         {
             "path": "/",
-            "proxyUrl": "http://192.168.88.123:8069/"
+            "proxyUrl": "http://127.0.0.1:8069/"
         }
     ]
 }

+ 5 - 0
src/app/app.module.ts

@@ -29,6 +29,7 @@ import { MenuPipe } from "../pipes/menu";
 
 // Directives
 import { DoubleTap } from "../directives/double-tap";
+import { ListPageComponent } from '../components/list-page/list-page';
 
 @NgModule({
     declarations: [
@@ -45,6 +46,8 @@ import { DoubleTap } from "../directives/double-tap";
         OMasterHeader,
         OMasterFooter,
         ODetailHeader,
+        ListPageComponent,
+
          // Pipes
         MenuPipe,
         // Directives
@@ -60,6 +63,7 @@ import { DoubleTap } from "../directives/double-tap";
         LoginPage,
         HomePage,
         CustomersPage,
+      
         ProductsPage,
         OrdersPage,
         ToolsPage,
@@ -69,6 +73,7 @@ import { DoubleTap } from "../directives/double-tap";
         OdooRPCService,
         AuthService,
         OdooService,
+    
         PouchService,
         SyncService,
         {

+ 71 - 0
src/components/list-page/base-view.ts

@@ -0,0 +1,71 @@
+import { ReflectiveInjector } from "@angular/core";
+
+import { getMetadataStorage } from '../../odoo/utils/metadata-storage';
+
+
+
+export class BaseView<T> {
+
+    type: T = {} as T;
+    model: any = {};
+    injector: any = {};
+    title: string;
+
+    constructor(c: { new (): T; }, ...injectables: any[]) {
+        this.type = new c();
+        this.model = getMetadataStorage().models.filterByTarget(this.type.constructor).items.shift();
+        this.injector = ReflectiveInjector.resolveAndCreate(injectables);
+        this.title = "Sin título";
+    }
+
+    /**
+     * 
+     * @param injectable 
+     */
+    getInjectable(injectable: any): any {
+        return this.injector.get(injectable);
+    }
+
+    /**
+     * 
+     */
+    getTitle(): string {
+        return this.title;
+    }
+
+    /**
+     * 
+     * @param title 
+     */
+    setTitle(title: string): void {
+        this.title = title;
+    }
+
+    /**
+     * 
+     */
+    getType(): T {
+        return this.type;
+    }
+
+    /**
+     * 
+     */
+    getModel(): any {
+        return this.model;
+    }
+
+    /**
+     * 
+     */
+    getModelName(): string {
+        return this.getModel().name;
+    }
+
+    /**
+     * 
+     */
+    getInjector(): any {
+        return this.injector;
+    }
+}

+ 30 - 0
src/components/list-page/list-page.html

@@ -0,0 +1,30 @@
+<ion-header>
+
+	<ion-navbar>
+		<button ion-button menuToggle>
+            <ion-icon name="menu"></ion-icon>
+        </button>
+		
+    	<ion-title>Clientesdddddd</ion-title>
+  	</ion-navbar>
+
+</ion-header>
+
+
+<ion-content padding>
+
+ <ion-card *ngFor="let p of lista">
+        <ion-item>
+            <h2>{{ p.name }}</h2>
+
+            <p>
+                <strong>Movil:</strong>
+                {{ p.mobile }}
+            </p>     
+
+        </ion-item>
+       
+    </ion-card>
+
+
+</ion-content>

+ 3 - 0
src/components/list-page/list-page.scss

@@ -0,0 +1,3 @@
+list-page {
+
+}

+ 169 - 0
src/components/list-page/list-page.ts

@@ -0,0 +1,169 @@
+import { PouchService } from '../../services/pouch-service';
+import { ba}
+
+
+
+export abstract class BaseListView<T> extends BaseView<T>{
+
+    items: T[];
+    selectedIndex: number;
+    filters: Array<[string, string, any]>;
+
+    constructor(c: { new (): T; }, ...filters: Array<[string, string, any]>) {
+        super(c, PouchService);
+
+        this.items = [];
+        this.selectedIndex = -1;
+        this.filters = filters;
+
+        // this.initialize();
+    }
+
+    /**
+     * 
+     */
+    protected initialize() {
+        super.getInjectable(PouchService).getAll(this.getModelName()).subscribe(result => { 
+            let obj = result.docs.shift();
+
+            if (!obj) {
+                return;
+            }
+
+            this.applyFilter(obj.records);
+        }, error => { 
+            console.log(error);
+        });
+    }
+
+    /**
+     * 
+     */
+    applyFilter(records: T[]): void {
+        if (records.length == 0) {
+            return;
+        }
+        
+        if (this.getFilters().length == 0) {
+            this.items = records;
+
+            return;
+        }
+
+        this.items = records.filter(record => {
+            let expressions = this.getFilters().map(filter => {
+                let operator = "===";
+                let leftOperand = "record." + filter[0];
+                let rightOperand = typeof(filter[2]) === "string" ? "'" + filter[2] + "'" : filter[2];
+
+                if (filter[1] === "!=") {
+                    operator = "!==";
+                }
+
+                if (filter[1] === ">") {
+                    operator = ">";
+                }
+
+                if (filter[1] === "<") {
+                    operator = "<";
+                }
+
+                if (filter[1] === ">=") {
+                    operator = "<=";
+                }
+
+                if (filter[1] === "<=") {
+                    operator = "<=";
+                }
+
+                return leftOperand + operator + rightOperand;
+            });
+
+            return eval(expressions.join("&&"));
+        });
+    }
+
+    /**
+     * 
+     */
+    getItems(): T[] {
+        return this.items;
+    }
+    
+    /**
+     * 
+     * @param items 
+     */
+    setItems(items: T[]): void {
+        this.items = items;
+
+        this.applyFilter(this.getItems());
+    }
+
+    /**
+     * 
+     */
+    getSelectedIndex(): number {
+        return this.selectedIndex;
+    }
+
+    /**
+     * 
+     * @param index 
+     */
+    setSelectedIndex(selectedIndex: number): void {
+        this.selectedIndex = selectedIndex;
+    }
+
+    /**
+     * 
+     * @param item 
+     */
+    indexOf(item: T): number {
+        return this.getItems().indexOf(item);
+    }
+
+    /**
+     * 
+     */
+    getSelectedItem(): T {
+        if (this.getSelectedIndex() === -1) {
+            return null;
+        }
+
+        return this.getItems()[this.getSelectedIndex()];
+    }
+
+    /**
+     * 
+     * @param item 
+     */
+    setSelectedItem(item: T): void {
+        let index = this.indexOf(item);
+        this.setSelectedIndex(index);
+    }
+
+    /**
+     * 
+     */
+    deselectItem(): void {
+        this.setSelectedIndex(-1);
+    }
+
+    /**
+     * 
+     */
+    getFilters(): Array<[string, string, any]> {
+        return this.filters;
+    }
+
+    /**
+     * 
+     * @param filters 
+     */
+    setFilters(filters: Array<[string, string, any]>): void {
+        this.filters = filters;
+
+        this.applyFilter(this.getItems());
+    }
+} 

+ 1 - 1
src/components/omaster-header/omaster-header.html

@@ -1,5 +1,5 @@
 <ion-header>
-    <ion-navbar color="primary">
+    <ion-navbar>
         <button ion-button menuToggle>
             <ion-icon name="menu"></ion-icon>
         </button>

+ 11 - 0
src/components/page-options/page-options.html

@@ -0,0 +1,11 @@
+<ion-list no-lines>
+    <button ion-item icon-left (click)="click('open')">
+        <ion-icon name="open"></ion-icon>
+        Abrir
+    </button>
+
+    <button ion-item icon-left (click)="click('delete')">
+        <ion-icon name="close"></ion-icon>
+        Eliminar
+    </button>
+</ion-list>

+ 22 - 0
src/components/page-options/page-options.ts

@@ -0,0 +1,22 @@
+import { Component } from '@angular/core';
+import { NavParams, ViewController } from 'ionic-angular';
+
+@Component({
+    templateUrl: 'page-options.html'
+})
+export class PageOptions {
+
+    constructor(
+        public nav: NavParams,
+        public viewCtrl: ViewController
+    ) { }
+
+    /**
+     *
+     */
+    click(role: string): void {
+        this.viewCtrl.dismiss({
+            role: role
+        });
+    }
+}

+ 8 - 0
src/odoo/interfaces/interface.ts

@@ -0,0 +1,8 @@
+export interface Interfaces{
+
+   
+    getModelName(): string;
+    initialize();
+
+       
+}

+ 2 - 0
src/odoo/models/customer.ts

@@ -5,6 +5,8 @@ import { FieldTypes } from "../types/field";
 @OdooModel("res.partner", [['customer', '=', true], ['active', '=', true]])
 export class Customer {
 
+   
+
     @OdooField(FieldTypes.CHAR)
     name: string;
 

+ 33 - 7
src/pages/customers/customers.html

@@ -1,16 +1,42 @@
 <ion-header>
 
-	<ion-navbar>
-		<button ion-button menuToggle>
+    <ion-navbar>
+
+        <button ion-button menuToggle>
             <ion-icon name="menu"></ion-icon>
         </button>
-		
-    	<ion-title>Clientes</ion-title>
-  	</ion-navbar>
+
+        <ion-title>Clientes</ion-title>
+        
+
+  </ion-navbar>
 
 </ion-header>
 
+<ion-content>
+
+    <ion-card *ngFor="let p of lista">
+        <ion-item>
+            <h2>{{ p.name }}</h2>
+
+            <p>
+                <strong>Movil:</strong>
+                {{ p.mobile }}
+            </p>     
+
+        </ion-item>
+       
+    </ion-card>
+
+
+
+  
 
-<ion-content padding>
+     
+     <!--
+    <ion-infinite-scroll (ionInfinite)="seek($event)">
+        <ion-infinite-scroll-content></ion-infinite-scroll-content>
+    </ion-infinite-scroll> 
+    -->
 
-</ion-content>
+</ion-content>

+ 13 - 15
src/pages/customers/customers.ts

@@ -1,32 +1,30 @@
 import { Component } from "@angular/core";
-import { NavController, NavParams } from "ionic-angular";
+import { NavController, NavParams, ActionSheetController } from "ionic-angular";
 
-import { PouchService } from "../../services/pouch-service";
+import { BaseListView } from "../../base/base-list-view";
+
+import { Customer } from '../../odoo/models/customer';
+import { ListPageComponent } from '../../components/list-page/list-page';
 
 @Component({
     selector: 'page-customers',
     templateUrl: 'customers.html'
 })
-export class CustomersPage {
+export class CustomersPage extends ListPageComponent<Customer> {
 
     constructor(
         public navCtrl: NavController,
         public navParams: NavParams,
-        public pouch: PouchService
-    ) { }
+        public actionSheetCtrl: ActionSheetController
+    ) {
+        super(Customer, ["customer", "=", true]);
+     }
 
     ionViewDidLoad() {
         console.log('ionViewDidLoad CustomersPage');
-
-        this.loadCustomers();
     }
 
-    /**
-     * 
-     */
-    loadCustomers(): void {
-        this.pouch.getAll('res.partner').subscribe(results => { 
-            console.log(results.docs.shift().records);
-        });
+    ionViewDidEnter() {
+        super.initialize();
     }
-}
+}

+ 1 - 1
src/pages/login/login.ts

@@ -30,7 +30,7 @@ export class LoginPage {
 	) { 
 		this.loginForm = this.formBuilder.group({
 			host: ['http://localhost:8100', Validators.required],
-			database: ['odoo', Validators.required],
+			database: ['odoo_mobile', Validators.required],
 			username: ['admin', Validators.required],
 			password: ['admin', Validators.required],
 		});

+ 14 - 3
src/pages/products/products.html

@@ -1,15 +1,26 @@
 <ion-header>
 
     <ion-navbar>
+
         <button ion-button menuToggle>
             <ion-icon name="menu"></ion-icon>
         </button>
 
         <ion-title>Productos</ion-title>
-    </ion-navbar>
+        
+
+  </ion-navbar>
 
 </ion-header>
 
-<ion-content padding>
+<ion-content>
+
+    <ion-card *ngFor="let p of lista">
+        <ion-item>
+            <h2>{{ p.name }}</h2>
+
+                 
 
-</ion-content>
+        </ion-item>
+       
+    </ion-card>

+ 6 - 12
src/pages/products/products.ts

@@ -1,22 +1,16 @@
 import { Component } from '@angular/core';
 import { NavController, NavParams } from 'ionic-angular';
+import { ListPageComponent } from '../../components/list-page/list-page';
+import { Product } from '../../odoo/models/product';
+
 
 @Component({
     selector: 'page-products',
     templateUrl: 'products.html'
 })
-export class ProductsPage {
-
-    constructor(
-        public navCtrl: NavController,
-        public navParams: NavParams
-    ) { }
-
-    /**
-     *
-     */
+export class ProductsPage{
+  
     ionViewDidLoad() {
-        console.log('ionViewDidLoad ProductsPage');
+  
     }
-
 }