Revert "File.js"
[app.Builder.js] / dbgenerate.js
index e105408..0ea16fd 100644 (file)
@@ -55,7 +55,7 @@ var o = new Options({
         { arg_long : 'DBTYPE' , arg_short : 't', description : 'Database Type (eg. MySQL or PostgreSQL ' },
         { arg_long : 'DBNAME' , arg_short : 'd', description : 'Database Name' },
         { arg_long : 'USERNAME' , arg_short : 'u', description : 'Username'},
-        { arg_long : 'PASSWORD' , arg_short : 'p', description : '' , arg_default :'' },
+        { arg_long : 'PASSWORD' , arg_short : 'p', description : 'Password' , arg_default :'' },
         { arg_long : 'INI' , arg_short : 'I', description :
                     'Either base directory which has Pman/***/DataObjects/***.links.ini or location of ini file.' },
     ]
@@ -119,6 +119,7 @@ var map = {
     'date' : 'date',
     'datetime' : 'date',
     'timestamp with time zone' : 'date',
+    'timestamp without time zone' : 'date',
     'time' : 'string', //bogus
     'int' : 'int',
     'integer' : 'int',
@@ -128,7 +129,10 @@ var map = {
     'smallint' : 'int',
     'decimal' : 'float',
     'float' : 'float',
+    'numeric' : 'float',
     'char' : 'string',
+    'character' : 'string',
+    'character varying' : 'string',
     'varchar' : 'string',
     'text' : 'string',
     'longtext' : 'string',
@@ -136,7 +140,10 @@ var map = {
     'mediumtext' : 'string',
     'enum' : 'string',
     'timestamp' : 'number',
-    'blob' : 'text'
+    'blob' : 'text',
+    'bytea' : 'text',
+    'boolean' : 'int',
+    'text[]' : 'string',
     
 }
 
@@ -152,16 +159,22 @@ function readIni(fn)
    
     var groups = key_file.get_groups();
     groups.forEach(function(g) {
+        //print("KEY:"+g);
         ini[g] = {}
-           print("KEY:"+g);
+        
         var keys = key_file.get_keys(g);
         if (!keys) { return; }
-         keys.forEach(function(k) {
-            ini[g][k] = key_file.get_value(g,k);
-        })
-    })
-    
+        
+        keys.forEach(function(k) {
+                print("GET val: " + k);
+                ini[g][k] = key_file.get_value(g,k);
+                print(ini[g][k] );
+        });
+        //print("DONE KEY:"+g);
+    });
+    //print("DONE KEYS");
 }
 if (File.isFile(cfg.INI)) {
     if (cfg.INI.match(/links\.ini$/)) {
         readIni(cfg.INI);
@@ -221,7 +234,7 @@ if (File.isDirectory(cfg.INI)) {
 }
 //print(JSON.stringify(ini, null,4));
  //console.dump(ini);
-
+print("DONE INI");
 
  //Seed.quit();
 
@@ -265,6 +278,12 @@ switch(cfg.DBTYPE) {
                 
                 
         break;
+    default:
+        throw {
+             name: "ArgumentError", 
+             message: "Invalid data base type " + cfg.DBTYPE + " should be MySQL or PostgreSQL"
+         };
+            
 /*
            "Field": "province",
         "Type": "varchar(255)",
@@ -278,13 +297,13 @@ switch(cfg.DBTYPE) {
 
  
 
-var tables = Gda.execute_select_command(cnc, query_tables).fetchAll();
+var tables = cnc.execute_select_command( query_tables).fetchAll();
 print(JSON.stringify(tables));
 
 var readers = [];
 tables.forEach(function(table) {
     //print(table);
-    var schema = Gda.execute_select_command(cnc,
+    var schema = cnc.execute_select_command(
             query_describe_table.replace(/%s/, table).replace(/%n/,'public')
             ).fetchAll();
     
@@ -300,11 +319,9 @@ tables.forEach(function(table) {
     //print(JSON.stringify(schema, null,4));    Seed.quit();
     
     schema.forEach(function(e)  {
-        
-        if (!e.Type) {
-            print(JSON.stringify(e, null,4));    Seed.quit();
-        }
-        
+        e.Type = e.Type || e.type;
+        e.Field = e.Field || e.field;
+         
         var type = e.Type.match(/([^(]+)\(([^\)]+)\)/);
         var row  = { }; 
         if (type) {
@@ -380,6 +397,11 @@ tables.forEach(function(table) {
             '|xns' : 'Roo.form',
             xtype : xtype
         }
+         if (xtype == 'DateField') {
+            form[row.name].format = 'Y-m-d';
+            form[row.name].width = 100;
+        }
+        
         if (xtype == 'TextArea') {
             form[row.name].height = 100;
         }
@@ -393,8 +415,8 @@ tables.forEach(function(table) {
     var combo = {
         '|xns' : 'Roo.form',
         xtype: 'ComboBox',
-        allowBlank : 'false',
-        editable : 'false',
+        allowBlank : false,
+        editable : false,
         emptyText : 'Select ' + table,
         forceSelection : true,
         listWidth : 400,
@@ -614,7 +636,7 @@ readers.forEach(function(reader) {
                         "|rowdblclick": "function (_self, rowIndex, e)\n" + 
                             "{\n" + 
                             "    if (!_this.dialog) return;\n" + 
-                            "    _this.dialog.show( this.getDataSource().getAt(rowIndex), function() {\n" + 
+                            "    _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {\n" + 
                             "        _this.grid.footer.onClick('first');\n" + 
                             "    }); \n" + 
                             "}\n"
@@ -845,6 +867,7 @@ readers.forEach(function(reader) {
             "resizable": false,
             "title": "Edit / Create " + reader.table,
             "width": 400,
+            "modal" : true,
             "xtype": "LayoutDialog",
             "|xns": "Roo",
             "items": [