Builder/Provider/Database/generate.js
[app.Builder.js] / Builder / Provider / Database / generate.js
index def9a45..c95ecc1 100644 (file)
@@ -57,21 +57,26 @@ Gda.DataSelect.prototype.fetchAll = function()
     for (var i =0;i < this.get_n_columns(); i++) {
         cols.push(this.get_column_name(i));
     }
-    //console.dump(cols);
+    //print(JSON.stringify(cols, null,4));
     var iter = this.create_iter();
     var res = [];
-    while (iter.move_next()) {
+    //print(this.get_n_rows());
+    var _this = this;
+    for (var r = 0; r < this.get_n_rows(); r++) {
+        
+        // single clo..
+        //print("GOT ROW");
         if (cols.length == 1) {
-            res.push(iter.get_value_at(0).get_string());
+            res.push(this.get_value_at(0,r).get_string());
             continue;
         }
         var add = { };
         
         cols.forEach(function(n,i) {
-           var val = iter.get_value_at(i);
-           var type = GObject.type_name(val.g_type) ;
-           var vs = type == 'GdaBlob' ? val.value.to_string(1024) : val.value;
-         //  print(n + " : TYPE: " + GObject.type_name(val.g_type) + " : " + vs);
+            var val = _this.get_value_at(i,r);
+            var type = GObject.type_name(val.g_type) ;
+            var vs = ['GdaBinary', 'GdaBlob' ].indexOf(type) > -1 ? val.value.to_string(1024) : val.value;
+            //print(n + " : TYPE: " + GObject.type_name(val.g_type) + " : " + vs);
             //print (n + '=' + iter.get_value_at(i).value);
             add[n] = vs;
         });
@@ -97,7 +102,8 @@ var map = {
     'longtext' : 'string',
     'mediumtext' : 'string',
     'enum' : 'string',
-    
+    'timestamp' : 'number',
+    'blob' => 'text'
     
 }
 
@@ -134,16 +140,21 @@ if (File.isDirectory(cfg.INI)) {
 
     //--- load ini files..
     // this is very specific.
-    var dirs = File.list( GLib.get_home_dir() + '/gitlive').filter( 
-        function(e) { return e.match(/^Pman/); }
+    
+    var dirs = File.list( cfg.INI + '/Pman').filter( 
+        function(e) { 
+            if (!File.isDirectory(cfg.INI + '/Pman/' + e + '/DataObjects')) {
+                return false;
+            }
+            return true;
+        }
     );
     
+     
     dirs.forEach(function(d) {
         // this currently misses the web.*/Pman/XXXX/DataObjects..
-        var path = GLib.get_home_dir() + '/gitlive/' + d + '/DataObjects';
-        if (!File.isDirectory(path)) {
-            path = GLib.get_home_dir() + '/gitlive/' + d + '/Pman/DataObjects';
-        }
+        var path = cfg.INI + '/Pman/' + d + '/DataObjects';
+         
         if (!File.isDirectory(path)) {
             return; //skip
         }
@@ -158,10 +169,19 @@ if (File.isDirectory(cfg.INI)) {
             readIni(path + '/' + i); 
             
         })
-
-        
-        
     });
+    // look at web.XXXX/Pman/XXX/DataObjects/*.ini
+    var inis = File.list(cfg.INI).filter(
+        function(e) { return e.match(/\.links\.ini$/); }
+    )
+    
+     inis.forEach(function(i) {
+        readIni(path + '/' + i); 
+        
+    })
+    
+    
 }
 print(JSON.stringify(ini, null,4));
  //console.dump(ini);
@@ -188,7 +208,7 @@ tables.forEach(function(table) {
        
     var firstTxtCol = '';
     
-    
+    print(JSON.stringify(schema, null,4));
     
     schema.forEach(function(e)  {
         var type = e.Type.match(/([^(]+)\(([^\)]+)\)/);
@@ -284,7 +304,7 @@ tables.forEach(function(table) {
         pageSize : 20,
         qtip: 'Select ' + table,
         selectOnFocus: true,
-        tirggerAction : 'all',
+        triggerAction : 'all',
         typeAhead: true,
         
         width: 300,
@@ -372,9 +392,6 @@ readers.forEach(function(reader) {
         // merge in data (eg. project_id => project_id_*****
      
         add.oreader.forEach(function(or) {
-           
-            
-            
             reader.reader.push({
                 name : col + '_' + or.name,
                 type : or.type
@@ -383,6 +400,14 @@ readers.forEach(function(reader) {
         
         // col is mapped to something..
         var combofields = add.combofields;
+        if (add.combofields.length < 2) {
+            continue;
+        }
+        if (typeof(reader.form[col]) == 'undefined') {
+            print("missing linked column " + col);
+            continue;
+        }
+        
         var combofields_name = add.combofields[1].name;
         var old =   reader.form[col];
         reader.form[col] = JSON.parse(JSON.stringify(add.combo)); // clone
@@ -579,7 +604,7 @@ readers.forEach(function(reader) {
     if (!File.isDirectory(dir)) {
         File.mkdir(dir);
     }
-    formElements = [];
+    var formElements = [];
     for (var k in reader.form) {
         if (k == 'id') { // should really do primary key testing..
             continue;
@@ -635,7 +660,34 @@ readers.forEach(function(reader) {
     );
             
             
-                   
+   
+   
+   
+     /// COMBO..
+    
+    dir = GLib.get_home_dir() + '/.Builder/Roo.form.ComboBox'; 
+    if (!File.isDirectory(dir)) {
+        File.mkdir(dir);
+    }
+   
+    print("WRITE: " +  dir + '/' + cfg.DB_NAME + '_' + reader.table + '.json');
+    
+    File.write(
+        dir + '/' + cfg.DB_NAME + '_' + reader.table + '.json',
+            
+       
+        JSON.stringify(reader.combo, null, 4)
+    );
+            
+   
+   
+   
+   
+   
+   
+   
+   
+   
 });