X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=dbgenerate.js;h=e81c5ae4de769ab95e4585a7ee78ab10a6939f06;hb=d9708917f2d4813c040b5fdeb88e2a41705f99f6;hp=a192a2f7ea23aeccd0d657a72d79a0cfa46402a8;hpb=08e6d53df5ae5d56c1a2bba3c4121df6892751bc;p=app.Builder.js diff --git a/dbgenerate.js b/dbgenerate.js index a192a2f7e..e81c5ae4d 100644 --- a/dbgenerate.js +++ b/dbgenerate.js @@ -13,7 +13,25 @@ * * write readers.. * - * usage: seed generate.js + * usage: seed generate.js + * + * + * + * + *Hack needed to latest GLib-2.0.gir + * + * + + + + + + * + * + * remove introspectable =0 from g_key_file_get_groups + * and add transfer-owneership = none to return value + * remove introspectable =0 from g_key_file_get_keys + * and add transfer-owneership = none to return value* * */ Gda = imports.gi.Gda; @@ -25,7 +43,7 @@ console = imports.console; File = imports.File.File; Options = imports.Options.Options; -Gda.init(); +//Gda.init(); var prov = Gda.Config.list_providers (); //print(prov.dump_as_string()); @@ -96,13 +114,16 @@ Gda.DataSelect.prototype.fetchAll = function() var map = { 'date' : 'date', - 'datetime' : 'string', + 'datetime' : 'date', + 'time' : 'string', //bogus 'int' : 'int', 'bigint' : 'int', - 'char' : 'int', + 'double' : 'float', 'tinyint' : 'int', + 'smallint' : 'int', 'decimal' : 'float', 'float' : 'float', + 'char' : 'string', 'varchar' : 'string', 'text' : 'string', 'longtext' : 'string', @@ -118,6 +139,7 @@ var ini = { } function readIni(fn) { + print('Read INI : ' + fn); var key_file = new GLib.KeyFile.c_new(); if (!key_file.load_from_file (fn , GLib.KeyFileFlags.NONE )) { return; @@ -126,9 +148,10 @@ function readIni(fn) var groups = key_file.get_groups(); groups.forEach(function(g) { ini[g] = {} - + print("KEY:"+g); var keys = key_file.get_keys(g); - keys.forEach(function(k) { + if (!keys) { return; } + keys.forEach(function(k) { ini[g][k] = key_file.get_value(g,k); }) }) @@ -142,6 +165,7 @@ if (File.isFile(cfg.INI)) { } } + if (File.isDirectory(cfg.INI)) { @@ -190,7 +214,7 @@ if (File.isDirectory(cfg.INI)) { } -print(JSON.stringify(ini, null,4)); +//print(JSON.stringify(ini, null,4)); //console.dump(ini); @@ -215,7 +239,7 @@ tables.forEach(function(table) { var firstTxtCol = ''; - print(JSON.stringify(schema, null,4)); + //print(JSON.stringify(schema, null,4)); schema.forEach(function(e) { var type = e.Type.match(/([^(]+)\(([^\)]+)\)/); @@ -277,9 +301,9 @@ tables.forEach(function(table) { if (e.Type == 'text') { xtype = 'TextArea'; } - if (e.name == 'id') { + if (row.name == 'id') { xtype = 'Hidden'; - } + } // what about booleans.. -> checkboxes.. @@ -294,7 +318,10 @@ tables.forEach(function(table) { if (xtype == 'TextArea') { form[row.name].height = 100; } - + if (xtype == 'Hidden') { + delete form[row.name].fieldLabel; + delete form[row.name].width; + } }); @@ -417,6 +444,7 @@ readers.forEach(function(reader) { continue; } if (typeof(reader.form[col]) == 'undefined') { + print (JSON.stringify(reader.form, null,4)); print("missing linked column " + col); continue; } @@ -452,6 +480,7 @@ readers.forEach(function(reader) { var dir = GLib.get_home_dir() + '/.Builder/Roo.data.JsonReader'; if (!File.isDirectory(dir)) { + print("mkdir " + dir); File.mkdir(dir); } @@ -466,6 +495,7 @@ readers.forEach(function(reader) { root : "data", '*prop' : "reader", id : 'id', // maybe no.. + '|fields' : JSON.stringify(reader.reader, null,4).replace(/"/g,"'") }; @@ -478,6 +508,7 @@ readers.forEach(function(reader) { // GRIDS dir = GLib.get_home_dir() + '/.Builder/Roo.GridPanel'; if (!File.isDirectory(dir)) { + print("mkdir " + dir); File.mkdir(dir); } @@ -496,6 +527,7 @@ readers.forEach(function(reader) { "fitContainer": true, "tableName": reader.table, "background": true, + "region" : 'center', "listeners": { "|activate": "function() {\n _this.panel = this;\n if (_this.grid) {\n _this.grid.footer.onClick('first');\n }\n}" }, @@ -508,12 +540,19 @@ readers.forEach(function(reader) { "listeners": { "|render": "function() \n" + "{\n" + - " _this.grid = this; \n" + + " _this.grid = this; \n" + " //_this.dialog = Pman.Dialog.FILL_IN\n" + " if (_this.panel.active) {\n" + " this.footer.onClick('first');\n" + " }\n" + - "}" + "}", + "|rowdblclick": "function (_self, rowIndex, e)\n" + + "{\n" + + " if (!_this.dialog) return;\n" + + " _this.dialog.show( this.getDataSource().getAt(rowIndex), function() {\n" + + " _this.grid.footer.onClick('first');\n" + + " }); \n" + + "}\n" }, "|xns": "Roo.grid", @@ -521,7 +560,8 @@ readers.forEach(function(reader) { { "*prop": "dataSource", "xtype": "Store", - + remoteSort : true, + '|sortInfo' : "{ field : '" + reader.firstTxtCol + "', direction: 'ASC' }", "|xns": "Roo.data", "items": [ @@ -557,9 +597,10 @@ readers.forEach(function(reader) { "listeners": { "|click": "function()\n"+ "{\n"+ - " //yourdialog.show( { id : 0 } , function() {\n"+ - " // _this.grid.footer.onClick('first');\n"+ - " //}); \n"+ + " if (!_this.dialog) return;\n" + + " _this.dialog.show( { id : 0 } , function() {\n"+ + " _this.grid.footer.onClick('first');\n"+ + " }); \n"+ "}\n" }, "|xns": "Roo.Toolbar" @@ -577,10 +618,10 @@ readers.forEach(function(reader) { " Roo.MessageBox.alert(\"Error\", s.length ? \"Select only one Row\" : \"Select a Row\");\n"+ " return;\n"+ " }\n"+ - " \n"+ - " //_this.dialog.show(s[0].data, function() {\n"+ - " // _this.grid.footer.onClick('first');\n"+ - " // }); \n"+ + " if (!_this.dialog) return;\n" + + " _this.dialog.show(s[0].data, function() {\n"+ + " _this.grid.footer.onClick('first');\n"+ + " }); \n"+ " \n"+ "}\n" @@ -595,7 +636,7 @@ readers.forEach(function(reader) { "listeners": { "|click": "function()\n"+ "{\n"+ - " //Pman.genericDelete(_this, _this.grid.tableName); \n"+ + " Pman.genericDelete(_this, '" + reader.table + "'); \n"+ "}\n"+ " " }, @@ -615,61 +656,71 @@ readers.forEach(function(reader) { dir = GLib.get_home_dir() + '/.Builder/Roo.form.Form'; if (!File.isDirectory(dir)) { + print("mkdir " + dir); File.mkdir(dir); } var formElements = []; + var formHeight = 50; for (var k in reader.form) { if (k == 'id') { // should really do primary key testing.. continue; } + formHeight += reader.form[k].xtype == 'TextArea' ? 100 : 30; + formElements.push(reader.form[k]); } - formElements.push(reader.form['id']); + if (reader.form['id']) { + formElements.push(reader.form['id']); + } + print("WRITE: " + dir + '/' + cfg.DBNAME + '_' + reader.table + '.json'); + var frmCfg = + { + '|xns' : 'Roo.form', + xtype : "Form", + listeners : { + "|actioncomplete" : "function(_self,action)\n"+ + "{\n"+ + " if (action.type == 'setdata') {\n"+ + " //_this.dialog.el.mask(\"Loading\");\n"+ + " //this.load({ method: 'GET', params: { '_id' : _this.data.id }});\n"+ + " return;\n"+ + " }\n"+ + " if (action.type == 'load') {\n"+ + " _this.dialog.el.unmask();\n"+ + " return;\n"+ + " }\n"+ + " if (action.type =='submit') {\n"+ + " \n"+ + " _this.dialog.el.unmask();\n"+ + " _this.dialog.hide();\n"+ + " \n"+ + " if (_this.callback) {\n"+ + " _this.callback.call(_this, _this.form.getValues());\n"+ + " }\n"+ + " _this.form.reset();\n"+ + " return;\n"+ + " }\n"+ + "}\n", + + "|rendered" : "function (form)\n"+ + "{\n"+ + " _this.form= form;\n"+ + "}\n" + }, + method : "POST", + style : "margin:10px;", + "|url" : "baseURL + '/Roo/" + reader.table + ".php'", + items : formElements + }; + File.write( dir + '/' + cfg.DBNAME + '_' + reader.table + '.json', - JSON.stringify({ - '|xns' : 'Roo.form', - xtype : "Form", - listeners : { - "|actioncomplete" : "function(_self,action)\n"+ - "{\n"+ - " if (action.type == 'setdata') {\n"+ - " //_this.dialog.el.mask(\"Loading\");\n"+ - " //this.load({ method: 'GET', params: { '_id' : _this.data.id }});\n"+ - " return;\n"+ - " }\n"+ - " if (action.type == 'load') {\n"+ - " _this.dialog.el.unmask();\n"+ - " return;\n"+ - " }\n"+ - " if (action.type =='submit') {\n"+ - " \n"+ - " _this.dialog.el.unmask();\n"+ - " _this.dialog.hide();\n"+ - " \n"+ - " if (_this.callback) {\n"+ - " _this.callback.call(_this, _this.form.getValues());\n"+ - " }\n"+ - " _this.form.reset();\n"+ - " return;\n"+ - " }\n"+ - "}\n", - - "|rendered" : "function (form)\n"+ - "{\n"+ - " _this.form= form;\n"+ - "}\n" - }, - method : "POST", - style : "margin:10px;", - "|url" : "baseURL + '/Roo/" + reader.table + ".php'", - items : formElements - }, null, 4) + JSON.stringify( frmCfg, null, 4) ); @@ -680,6 +731,7 @@ readers.forEach(function(reader) { dir = GLib.get_home_dir() + '/.Builder/Roo.form.ComboBox'; if (!File.isDirectory(dir)) { + print("mkdir " + dir); File.mkdir(dir); } @@ -697,12 +749,78 @@ readers.forEach(function(reader) { + // DIALOG. + + dir = GLib.get_home_dir() + '/.Builder/Roo.LayoutDialog'; + if (!File.isDirectory(dir)) { + print("mkdir " + dir); + File.mkdir(dir); + } + var formElements = []; + for (var k in reader.form) { + if (k == 'id') { // should really do primary key testing.. + continue; + } + formElements.push(reader.form[k]); + } + formElements.push(reader.form['id']); + + print("WRITE: " + dir + '/' + cfg.DBNAME + '_' + reader.table + '.json'); + + File.write( + dir + '/' + cfg.DBNAME + '_' + reader.table + '.json', + + + JSON.stringify({ + + "closable": false, + "collapsible": false, + "height": formHeight, + "resizable": false, + "title": "Edit / Create " + reader.table, + "width": 400, + "xtype": "LayoutDialog", + "|xns": "Roo", + "items": [ + { + "|xns": "Roo", + "xtype": "LayoutRegion", + "*prop": "center" + }, + { + "region": "center", + "xtype": "ContentPanel", + "|xns": "Roo", + "items": [ + frmCfg + ] + }, + + { + "listeners": { + "click": "function (_self, e)\n{\n _this.dialog.hide();\n}" + }, + "*prop": "buttons[]", + "text": "Cancel", + "xtype": "Button", + "|xns": "Roo" + }, + { + "listeners": { + "click": "function (_self, e)\n{\n // do some checks?\n \n \n _this.dialog.el.mask(\"Saving\");\n _this.form.doAction(\"submit\");\n\n}" + }, + "*prop": "buttons[]", + "text": "Save", + "xtype": "Button", + "|xns": "Roo" + } + ] + }, null,4) + ); -}); - - +});