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

motor de base datos orientado a documentos PouchDB agregado

robert2206 8 лет назад
Родитель
Сommit
7f53588390

+ 2 - 2
.editorconfig

@@ -5,7 +5,7 @@ root = true
 
 [*]
 indent_style = space
-indent_size = 2
+indent_size = 4
 
 # We recommend you to keep these unchanged
 end_of_line = lf
@@ -14,4 +14,4 @@ trim_trailing_whitespace = true
 insert_final_newline = true
 
 [*.md]
-trim_trailing_whitespace = false
+trim_trailing_whitespace = false

+ 36 - 36
config.xml

@@ -1,39 +1,39 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <widget id="com.eiru.odoo" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
-  <name>Odoo by Eiru</name>
-  <description>An awesome Ionic/Cordova app.</description>
-  <author email="robert.gauto@gmail.com" href="http://ionicframework.com/">Robert Alexis GAuto</author>
-  <content src="index.html"/>
-  <access origin="*"/>
-  <allow-intent href="http://*/*"/>
-  <allow-intent href="https://*/*"/>
-  <allow-intent href="tel:*"/>
-  <allow-intent href="sms:*"/>
-  <allow-intent href="mailto:*"/>
-  <allow-intent href="geo:*"/>
-  <platform name="android">
-    <allow-intent href="market:*"/>
-  </platform>
-  <platform name="ios">
-    <allow-intent href="itms:*"/>
-    <allow-intent href="itms-apps:*"/>
-  </platform>
-  <preference name="webviewbounce" value="false"/>
-  <preference name="UIWebViewBounce" value="false"/>
-  <preference name="DisallowOverscroll" value="true"/>
-  <preference name="android-minSdkVersion" value="16"/>
-  <preference name="BackupWebStorage" value="none"/>
-  <preference name="SplashScreenDelay" value="0"/>
-  <preference name="FadeSplashScreen" value="false"/>
-  <preference name="FadeSplashScreenDuration" value="0"/>
-  <preference name="SplashScreenBackgroundColor" value="0xFFFFFFFF"/>
-  <feature name="StatusBar">
-    <param name="ios-package" onload="true" value="CDVStatusBar"/>
-  </feature>
-  <plugin name="cordova-plugin-device" spec="~1.1.3"/>
-  <plugin name="cordova-plugin-console" spec="~1.0.4"/>
-  <plugin name="cordova-plugin-whitelist" spec="~1.3.0"/>
-  <plugin name="cordova-plugin-splashscreen" spec="~4.0.0"/>
-  <plugin name="cordova-plugin-statusbar" spec="~2.2.0"/>
-  <plugin name="ionic-plugin-keyboard" spec="~2.2.1"/>
+    <name>Odoo by Eiru</name>
+    <description>An awesome Ionic/Cordova app.</description>
+    <author email="robert.gauto@gmail.com" href="http://ionicframework.com/">Robert Alexis GAuto</author>
+    <content src="index.html"/>
+    <access origin="*"/>
+    <allow-intent href="http://*/*"/>
+    <allow-intent href="https://*/*"/>
+    <allow-intent href="tel:*"/>
+    <allow-intent href="sms:*"/>
+    <allow-intent href="mailto:*"/>
+    <allow-intent href="geo:*"/>
+    <platform name="android">
+        <allow-intent href="market:*"/>
+    </platform>
+    <platform name="ios">
+        <allow-intent href="itms:*"/>
+        <allow-intent href="itms-apps:*"/>
+    </platform>
+    <preference name="webviewbounce" value="false"/>
+    <preference name="UIWebViewBounce" value="false"/>
+    <preference name="DisallowOverscroll" value="true"/>
+    <preference name="android-minSdkVersion" value="16"/>
+    <preference name="BackupWebStorage" value="none"/>
+    <preference name="SplashScreenDelay" value="0"/>
+    <preference name="FadeSplashScreen" value="false"/>
+    <preference name="FadeSplashScreenDuration" value="0"/>
+    <preference name="SplashScreenBackgroundColor" value="0xFFFFFFFF"/>
+    <feature name="StatusBar">
+        <param name="ios-package" onload="true" value="CDVStatusBar"/>
+    </feature>
+    <plugin name="cordova-plugin-device" spec="~1.1.3"/>
+    <plugin name="cordova-plugin-console" spec="~1.0.4"/>
+    <plugin name="cordova-plugin-whitelist" spec="~1.3.0"/>
+    <plugin name="cordova-plugin-splashscreen" spec="~4.0.0"/>
+    <plugin name="cordova-plugin-statusbar" spec="~2.2.0"/>
+    <plugin name="ionic-plugin-keyboard" spec="~2.2.1"/>
 </widget>

+ 4 - 4
ionic.config.json

@@ -1,6 +1,6 @@
 {
-  "name": "Odoo by Eiru",
-  "app_id": "",
-  "v2": true,
-  "typescript": true
+    "name": "Odoo by Eiru",
+    "app_id": "",
+    "v2": true,
+    "typescript": true
 }

+ 6 - 1
package.json

@@ -16,7 +16,12 @@
     "@ionic/storage": "^1.0.3",
     "ionic-angular": "^2.0.0-rc.0",
     "ionic-native": "^2.0.3",
-    "ionicons": "^3.0.0"
+    "ionicons": "^3.0.0",
+    "pouchdb": "^6.0.6",
+    "pouchdb-node": "^6.0.6",
+    "relational-pouch": "^1.4.4",
+    "rollup-plugin-node-builtins": "^2.0.0",
+    "rollup-plugin-node-globals": "^1.0.9"
   },
   "devDependencies": {
     "@ionic/app-scripts": "^0.0.23",

+ 1 - 0
src/app/app.component.ts

@@ -10,6 +10,7 @@ import { LeadListPage } from '../pages/lead-list/lead-list';
 import { OpportunityListPage } from '../pages/opportunity-list/opportunity-list';
 import { CallListPage } from '../pages/call-list/call-list';
 
+
 import { ProjectListPage } from '../pages/project-list/project-list';
 import { TaskListPage } from '../pages/task-list/task-list';
 

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

@@ -7,6 +7,7 @@ import { HomePage } from '../pages/home/home'
 
 import { CustomerListPage } from '../pages/customer-list/customer-list';
 import { ProductListPage } from '../pages/product-list/product-list';
+import { ProductDetailsPage } from '../pages/product-details/product-details';
 import { LeadListPage } from '../pages/lead-list/lead-list';
 import { OpportunityListPage } from '../pages/opportunity-list/opportunity-list';
 import { CallListPage } from '../pages/call-list/call-list';
@@ -24,6 +25,7 @@ import { AboutPage } from '../pages/about/about'
         HomePage,
         CustomerListPage,
         ProductListPage,
+        ProductDetailsPage,
         LeadListPage,
         OpportunityListPage,
         CallListPage,
@@ -42,6 +44,7 @@ import { AboutPage } from '../pages/about/about'
         HomePage,
         CustomerListPage,
         ProductListPage,
+        ProductDetailsPage,
         LeadListPage,
         OpportunityListPage,
         CallListPage,

BIN
src/assets/images/product.png


+ 12 - 12
src/assets/manifest.json

@@ -1,13 +1,13 @@
 {
-  "name": "Ionic",
-  "short_name": "Ionic",
-  "start_url": "index.html",
-  "display": "standalone",
-  "icons": [{
-    "src": "assets/imgs/logo.png",
-    "sizes": "512x512",
-    "type": "image/png"
-  }],
-  "background_color": "#4e8ef7",
-  "theme_color": "#4e8ef7"
-}
+    "name": "Ionic",
+    "short_name": "Ionic",
+    "start_url": "index.html",
+    "display": "standalone",
+    "icons": [{
+        "src": "assets/imgs/logo.png",
+        "sizes": "512x512",
+        "type": "image/png"
+    }],
+    "background_color": "#4e8ef7",
+    "theme_color": "#4e8ef7"
+}

+ 1 - 0
src/declarations.d.ts

@@ -0,0 +1 @@
+declare module '*';

+ 21 - 5
src/defaults/default-listable.ts

@@ -3,7 +3,7 @@ import { IListable } from '../interfaces/listable-interface';
 export abstract class DefaultListable<T> implements IListable<T> {
 
     private isSearch: boolean;
-    private elements: Array<T>;
+    private _elements: Array<T>;
 
     constructor(
     ) {
@@ -11,11 +11,27 @@ export abstract class DefaultListable<T> implements IListable<T> {
         this.elements = [];
     }
 
+    /**
+     *
+     */
+    set elements(_elements: Array<T>) {
+        this._elements = _elements; 
+    }
+
+    /**
+     *
+     */
+    get elements() {
+        return this._elements;
+    }
+
+    
+
     /**
      *
      */
     add(T: any): void {
-        this.elements.push(T);
+        this._elements.push(T);
     }
 
     /**
@@ -23,7 +39,7 @@ export abstract class DefaultListable<T> implements IListable<T> {
      */
     remove(T: any): void {
         let index = this.elements.indexOf(T);
-        this.elements.slice(index, 1);
+        this._elements.slice(index, 1);
     }
 
     /**
@@ -31,14 +47,14 @@ export abstract class DefaultListable<T> implements IListable<T> {
      */
     get(T: any): T {
         let index = this.elements.indexOf(T);
-        return this.elements[index];
+        return this._elements[index];
     }
 
     /**
      *
      */
     list(): Array<T> {
-        return this.elements;
+        return this._elements;
     }
 
     /**

+ 0 - 11
src/defaults/default-navigable.ts

@@ -1,11 +0,0 @@
-import { INavigable } from '../interfaces/navigable-interface';
-import { NavController } from 'ionic-angular'
-
-export abstract class DefaultNavigable implements INavigable {
-
-    constructor(public navCtrl: NavController) {}
-
-    goToPage(page: any): void {
-        this.navCtrl.push(page.component);
-    }
-}

+ 10 - 0
src/defaults/default-persistible.ts

@@ -0,0 +1,10 @@
+import { IPersistible } from '../interfaces/persistible-interface';
+
+export abstract class DefaultPersistible<T> implements IPersistible<T> {
+
+    constructor() {}
+
+    save(T: any): void {
+
+    }
+}

+ 3 - 0
src/interfaces/persistible-interface.ts

@@ -0,0 +1,3 @@
+export interface IPersistible<T> {
+    save(T: any): void;
+}

+ 1 - 0
src/models/product.ts

@@ -1,3 +1,4 @@
+
 export class Product {
 
     constructor(

+ 31 - 0
src/pages/product-details/product-details.html

@@ -0,0 +1,31 @@
+<ion-header>
+    <ion-navbar color="primary">
+        <ion-title>Producto</ion-title>
+    </ion-navbar>
+
+</ion-header>
+
+<ion-content>
+    <ion-card>
+        <img src="./assets/images/no_product.png" />
+
+        <ion-fab right top>
+            <button ion-fab color="yellow">
+                <ion-icon name="camera" color="light"></ion-icon>
+            </button>
+        </ion-fab>
+    </ion-card>
+
+    <ion-list>
+        <ion-item>
+            <ion-label floating>Nombre</ion-label>
+            <ion-input type="text"></ion-input>
+        </ion-item>
+
+        <ion-item>
+            <ion-label floating>Precio</ion-label>
+            <ion-input type="number"></ion-input>
+        </ion-item>
+    </ion-list>
+
+</ion-content>

+ 12 - 0
src/pages/product-details/product-details.scss

@@ -0,0 +1,12 @@
+page-product-details {
+    ion-card img {
+        margin: 10px auto;
+        display: block;
+        width: 200px;
+        height: 200px;
+    }
+
+    ion-fab button {
+        margin-top: 200px;
+    }
+}

+ 21 - 0
src/pages/product-details/product-details.ts

@@ -0,0 +1,21 @@
+import { Component } from '@angular/core';
+import { NavController } from 'ionic-angular';
+import { Product } from '../../models/product'
+import { DataProvider } from '../../providers/data-provider'
+
+@Component({
+    selector: 'page-product-details',
+    providers: [DataProvider],
+    templateUrl: 'product-details.html'
+})
+export class ProductDetailsPage {
+
+    constructor(public navCtrl: NavController, public data: DataProvider) {}
+
+    ionViewDidLoad() {
+        this.data.save('product', {
+            name: 'product',
+            price: 1000
+        });
+    }
+}

+ 1 - 1
src/pages/product-list/product-list.html

@@ -49,7 +49,7 @@
     </ion-card>
 
     <ion-fab right bottom>
-        <button ion-fab color="yellow">
+        <button ion-fab color="yellow" (click)="goToPage(null)">
             <ion-icon name="add" color="light"></ion-icon>
         </button>
     </ion-fab>

+ 19 - 10
src/pages/product-list/product-list.ts

@@ -1,28 +1,37 @@
 import { Component } from '@angular/core';
 import { NavController } from 'ionic-angular';
 import { DefaultListable } from '../../defaults/default-listable';
+import { INavigable } from '../../interfaces/navigable-interface';
 import { Product } from '../../models/product';
+import { ProductDetailsPage } from '../product-details/product-details';
+import { DataProvider } from '../../providers/data-provider'
 
 @Component({
     selector: 'page-product-list',
+    providers: [DataProvider],
     templateUrl: 'product-list.html'
 })
-export class ProductListPage extends DefaultListable<Product> {
+export class ProductListPage extends DefaultListable<Product> implements INavigable {
 
-    constructor(public navCtrl: NavController) {
+    constructor(public navCtrl: NavController, public data: DataProvider) {
         super();
 
-        this.init();
+        this.initialize();
     }
 
-    init(): void {
-
-        for (let i = 0; i < 100; i++) {
-            this.add(new Product(i + 1, 'Product' + (i + 1), '', i * 200));
-        }
+    /**
+     * Initialize data list
+     */
+    initialize(): void {
+        this.data.getAll('product').then(r => { 
+            this.elements = r.products;
+        });
     }
 
-    ionViewDidLoad() {
-        console.log('Hello ProductList Page');
+    /**
+     * Goto page
+     */
+    goToPage(page: any) {
+        this.navCtrl.push(ProductDetailsPage);
     }
 }

+ 94 - 0
src/providers/data-provider.ts

@@ -0,0 +1,94 @@
+import { Injectable } from '@angular/core';
+import PouchDB from 'pouchdb';
+import * as Relational from 'relational-pouch';
+
+PouchDB.plugin(Relational);
+
+@Injectable()
+export class DataProvider {
+
+    data: any;
+
+    constructor() {
+        this.initialize();
+    }
+
+    /**
+     *
+     */
+    private initialize(): void {
+        this.data = new PouchDB('odoo');
+
+        this.data.setSchema([
+            {
+                singular: 'partner',
+                plural: 'partners'
+            },
+            {
+                singular: 'user',
+                plural: 'users',
+                relations: {
+                    partner: {
+                        belongsTo: 'partner'
+                    }
+                }
+            },
+            {
+                singular: 'currency',
+                plural: 'currencies'
+            },
+            {
+                singular: 'company',
+                plural: 'companies',
+                relations: {
+                    currency: {
+                        belongsTo: 'currency'
+                    }
+                }
+            },
+            {
+                singular: 'product',
+                plural: 'products',
+                relations: {
+                    company: {
+                        belongsTo: 'product'
+                    }
+                }
+            },
+            {
+                singular: 'warehouse',
+                plural: 'warehouses',
+            },
+            {
+                singular: 'stock',
+                plural: 'stocks'
+            },
+            {
+                singular: 'lead',
+                plural: 'leads',
+                relations: {
+                    partner: {
+                        belongsTo: 'partner'
+                    }
+                }
+            }
+        ]);
+    }
+
+    /**
+     *
+     */
+    save(type: string, data: any): void {
+        this.data.rel.save(type, data);
+    }
+
+    /**
+     *
+     */
+    getAll(type: string): Promise<string> {
+        return new Promise<string>((resolve, reject) => {
+            resolve(this.data.rel.find(type));
+        });
+        
+    }
+}

+ 18 - 21
tsconfig.json

@@ -1,22 +1,19 @@
 {
-  "compilerOptions": {
-    "allowSyntheticDefaultImports": true,
-    "declaration": true,
-    "emitDecoratorMetadata": true,
-    "experimentalDecorators": true,
-    "lib": [
-      "dom",
-      "es2015"
-    ],
-    "module": "es2015",
-    "moduleResolution": "node",
-    "target": "es5"
-  },
-  "exclude": [
-    "node_modules"
-  ],
-  "compileOnSave": false,
-  "atom": {
-    "rewriteTsconfig": false
-  }
-}
+    "compilerOptions": {
+        "allowSyntheticDefaultImports": true,
+        "declaration": true,
+        "emitDecoratorMetadata": true,
+        "experimentalDecorators": true,
+        "lib": [
+            "dom",
+            "es2015"
+        ],
+        "module": "es2015",
+        "moduleResolution": "node",
+        "target": "es5"
+    },
+    "compileOnSave": false,
+    "atom": {
+        "rewriteTsconfig": false
+    }
+}

+ 8 - 8
tslint.json

@@ -1,11 +1,11 @@
 {
-  "rules": {
-    "no-duplicate-variable": true,
-    "no-unused-variable": [
-      true
+    "rules": {
+        "no-duplicate-variable": true,
+        "no-unused-variable": [
+            true
+        ]
+    },
+    "rulesDirectory": [
+        "node_modules/tslint-eslint-rules/dist/rules"
     ]
-  },
-  "rulesDirectory": [
-    "node_modules/tslint-eslint-rules/dist/rules"
-  ]
 }

+ 6 - 0
typings.json

@@ -0,0 +1,6 @@
+{
+    "globalDependencies": {
+        "pouchdb": "registry:dt/pouchdb#5.4.4+20160724064500",
+        "pouchdb-adapter-websql": "registry:dt/pouchdb-adapter-websql#5.4.4+20160724064500"
+    }
+}

+ 31 - 0
typings/globals/pouchdb-adapter-websql/index.d.ts

@@ -0,0 +1,31 @@
+// Generated by typings
+// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/a396c170ba4b6a7f45b20fccbdba0d2b81cc8833/pouchdb-adapter-websql/pouchdb-adapter-websql.d.ts
+declare namespace PouchDB {
+    namespace Core {
+        interface DatabaseInfo {
+            sqlite_plugin?: boolean;
+            websql_encoding?: 'UTF-8' | 'UTF-16';
+        }
+    }
+
+    namespace AdapterWebSql {
+        interface Configuration
+                extends Configuration.LocalDatabaseConfiguration {
+            /**
+             * Amount in MB to request for storage.
+             */
+            size?: number;
+            adapter: 'websql';
+        }
+    }
+
+    interface Static {
+        new<Content extends Core.Encodable>(name: string | void,
+            options: AdapterWebSql.Configuration): Database<Content>;
+    }
+}
+
+declare module 'pouchdb-adapter-websql' {
+    const plugin: PouchDB.Plugin;
+    export = plugin;
+}

+ 8 - 0
typings/globals/pouchdb-adapter-websql/typings.json

@@ -0,0 +1,8 @@
+{
+  "resolution": "main",
+  "tree": {
+    "src": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/a396c170ba4b6a7f45b20fccbdba0d2b81cc8833/pouchdb-adapter-websql/pouchdb-adapter-websql.d.ts",
+    "raw": "registry:dt/pouchdb-adapter-websql#5.4.4+20160724064500",
+    "typings": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/a396c170ba4b6a7f45b20fccbdba0d2b81cc8833/pouchdb-adapter-websql/pouchdb-adapter-websql.d.ts"
+  }
+}

+ 6 - 0
typings/globals/pouchdb/index.d.ts

@@ -0,0 +1,6 @@
+// Generated by typings
+// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/a396c170ba4b6a7f45b20fccbdba0d2b81cc8833/pouchdb/pouchdb.d.ts
+declare module 'pouchdb' {
+    const plugin: PouchDB.Static;
+    export = plugin;
+}

+ 8 - 0
typings/globals/pouchdb/typings.json

@@ -0,0 +1,8 @@
+{
+  "resolution": "main",
+  "tree": {
+    "src": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/a396c170ba4b6a7f45b20fccbdba0d2b81cc8833/pouchdb/pouchdb.d.ts",
+    "raw": "registry:dt/pouchdb#5.4.4+20160724064500",
+    "typings": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/a396c170ba4b6a7f45b20fccbdba0d2b81cc8833/pouchdb/pouchdb.d.ts"
+  }
+}

+ 2 - 0
typings/index.d.ts

@@ -0,0 +1,2 @@
+/// <reference path="globals/pouchdb-adapter-websql/index.d.ts" />
+/// <reference path="globals/pouchdb/index.d.ts" />