rails_db_admin 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/GPL-3-LICENSE +674 -0
  2. data/README.md +5 -0
  3. data/Rakefile +30 -0
  4. data/app/assets/javascripts/rails_db_admin/application.js +9 -0
  5. data/app/assets/stylesheets/rails_db_admin/application.css +7 -0
  6. data/app/controllers/rails_db_admin/erp_app/desktop/base_controller.rb +182 -0
  7. data/app/controllers/rails_db_admin/erp_app/desktop/queries_controller.rb +173 -0
  8. data/app/helpers/rails_db_admin/application_helper.rb +4 -0
  9. data/app/views/layouts/application.html.erb +14 -0
  10. data/app/views/layouts/rails_db_admin/application.html.erb +14 -0
  11. data/config/initializers/rails_db_admin.rb +4 -0
  12. data/config/routes.rb +4 -0
  13. data/db/data_migrations/20110816005525_rails_db_admin_application.rb +31 -0
  14. data/lib/rails_db_admin.rb +15 -0
  15. data/lib/rails_db_admin/config.rb +27 -0
  16. data/lib/rails_db_admin/connection_handler.rb +17 -0
  17. data/lib/rails_db_admin/engine.rb +11 -0
  18. data/lib/rails_db_admin/extjs.rb +2 -0
  19. data/lib/rails_db_admin/extjs/json_column_builder.rb +139 -0
  20. data/lib/rails_db_admin/extjs/json_data_builder.rb +82 -0
  21. data/lib/rails_db_admin/query_support.rb +72 -0
  22. data/lib/rails_db_admin/table_support.rb +147 -0
  23. data/lib/rails_db_admin/version.rb +3 -0
  24. data/lib/tasks/rails_db_admin_tasks.rake +4 -0
  25. data/public/images/icons/rails_db_admin/rails_db_admin_16x16.png +0 -0
  26. data/public/images/icons/rails_db_admin/rails_db_admin_24x24.png +0 -0
  27. data/public/images/icons/rails_db_admin/rails_db_admin_32x32.png +0 -0
  28. data/public/images/icons/rails_db_admin/rails_db_admin_48x48.png +0 -0
  29. data/public/javascripts/erp_app/desktop/applications/rails_db_admin/database_combo.js +52 -0
  30. data/public/javascripts/erp_app/desktop/applications/rails_db_admin/module.js +429 -0
  31. data/public/javascripts/erp_app/desktop/applications/rails_db_admin/queries_tree_menu.js +86 -0
  32. data/public/javascripts/erp_app/desktop/applications/rails_db_admin/query_panel.js +206 -0
  33. data/public/javascripts/erp_app/desktop/applications/rails_db_admin/readonly_table_data_grid.js +27 -0
  34. data/public/javascripts/erp_app/desktop/applications/rails_db_admin/tables_tree_menu.js +87 -0
  35. data/public/stylesheets/erp_app/desktop/applications/rails_db_admin/rails_db_admin.css +10 -0
  36. data/spec/controllers/rails_db_admin/base_controller_spec.rb +481 -0
  37. data/spec/controllers/rails_db_admin/queries_controller_spec.rb +134 -0
  38. data/spec/dummy/Rakefile +7 -0
  39. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  40. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  41. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  42. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  43. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  44. data/spec/dummy/config.ru +4 -0
  45. data/spec/dummy/config/application.rb +45 -0
  46. data/spec/dummy/config/boot.rb +10 -0
  47. data/spec/dummy/config/database.yml +14 -0
  48. data/spec/dummy/config/environment.rb +5 -0
  49. data/spec/dummy/config/environments/cucumber.rb +3 -0
  50. data/spec/dummy/config/environments/spec.rb +27 -0
  51. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  52. data/spec/dummy/config/initializers/inflections.rb +10 -0
  53. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  54. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  55. data/spec/dummy/config/initializers/session_store.rb +8 -0
  56. data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
  57. data/spec/dummy/config/locales/en.yml +5 -0
  58. data/spec/dummy/config/routes.rb +5 -0
  59. data/spec/dummy/public/404.html +26 -0
  60. data/spec/dummy/public/422.html +26 -0
  61. data/spec/dummy/public/500.html +26 -0
  62. data/spec/dummy/public/favicon.ico +0 -0
  63. data/spec/dummy/script/rails +6 -0
  64. data/spec/lib/rails_db_admin/extjs/json_column_builder_spec.rb +206 -0
  65. data/spec/lib/rails_db_admin/extjs/json_data_builder_spec.rb +201 -0
  66. data/spec/lib/rails_db_admin/query_support_spec.rb +40 -0
  67. data/spec/lib/rails_db_admin/table_support_spec.rb +349 -0
  68. data/spec/spec_helper.rb +60 -0
  69. metadata +183 -0
@@ -0,0 +1,3 @@
1
+ module RailsDbAdmin
2
+ VERSION = "2.0.0"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :rails_db_admin do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,52 @@
1
+ Ext.define("Compass.ErpApp.Desktop.Applications.RailsDbAdmin.DatabaseComboBox",{
2
+ extend:"Ext.form.field.ComboBox",
3
+ alias:'widget.railsdbadmin_databasecombo',
4
+ initComponent: function() {
5
+
6
+ var databaseJsonStore = new Ext.data.Store({
7
+ autoLoad:true,
8
+ timeout:60000,
9
+ proxy: {
10
+ type: 'ajax',
11
+ url :'/rails_db_admin/erp_app/desktop/base/databases',
12
+ reader: {
13
+ type: 'json',
14
+ root: 'databases'
15
+ }
16
+ },
17
+ fields: [{
18
+ name:'value'
19
+ },{
20
+ name:'display'
21
+ }]
22
+ });
23
+
24
+ var me = this;
25
+ databaseJsonStore.on('load', function(store) {
26
+ me.setValue(store.first().get('value'));
27
+ });
28
+
29
+ this.store = databaseJsonStore;
30
+ this.callParent(arguments);
31
+ },
32
+
33
+ constructor : function(config) {
34
+ config = Ext.apply({
35
+ id:'databaseCombo',
36
+ valueField:'value',
37
+ displayField:'display',
38
+ triggerAction:'all',
39
+ editable:false,
40
+ forceSelection:true,
41
+ mode:'local',
42
+ //value:'development',
43
+ listeners:{
44
+ 'select':function(combo, record, index){
45
+ // switch databases
46
+ combo.initialConfig.module.connectToDatatbase();
47
+ }
48
+ }
49
+ }, config);
50
+ this.callParent([config]);
51
+ }
52
+ });
@@ -0,0 +1,429 @@
1
+ Ext.define("Compass.ErpApp.Desktop.Applications.RailsDbAdmin",{
2
+ extend:"Ext.ux.desktop.Module",
3
+ id:'rails_db_admin-win',
4
+
5
+ queriesTreePanel : function(){
6
+ return this.accordion.query('.railsdbadmin_queriestreemenu')[0];
7
+ },
8
+
9
+ setWindowStatus : function(status){
10
+ this.window.setStatus(status);
11
+ },
12
+
13
+ clearWindowStatus : function(){
14
+ this.window.clearStatus();
15
+ },
16
+
17
+ getTableData : function(table){
18
+ var database = this.getDatabase();
19
+
20
+ var grid = new Compass.ErpApp.Shared.DynamicEditableGridLoaderPanel({
21
+ title:table,
22
+ setupUrl:'/rails_db_admin/erp_app/desktop/base/setup_table_grid/' + table,
23
+ dataUrl:'/rails_db_admin/erp_app/desktop/base/table_data/' + table,
24
+ editable:true,
25
+ page:true,
26
+ pageSize:25,
27
+ displayMsg:'Displaying {0} - {1} of {2}',
28
+ emptyMsg:'Empty',
29
+ loadErrorMessage:'Tables Without Ids Can Not Be Edited',
30
+ closable:true,
31
+ params:{
32
+ database:database
33
+ },
34
+ grid_listeners:{
35
+ validateedit:{
36
+ fn:function(editor,e) {
37
+ this.store.proxy.setOldModel(e.record);
38
+ }
39
+ }
40
+ },
41
+ proxy:{
42
+ type: 'rest',
43
+ url:'/rails_db_admin/erp_app/desktop/base/table_data/' + table,
44
+ //private var to store the previous model in an
45
+ //update operation
46
+ oldModel: null,
47
+ setOldModel: function(old_model) {
48
+ this.oldModel = old_model.copy();
49
+ },
50
+ update: function(operation, callback, scope){
51
+ operation.records.push(this.oldModel);
52
+ //[CB:2011-Oct] this.callParent wasn't working, so did the old (explicit) way
53
+ Ext.data.proxy.Rest.superclass.update.call(this, operation,callback,scope);
54
+ },
55
+ reader: {
56
+ type: 'json',
57
+ successProperty: 'success',
58
+ root: 'data',
59
+ messageProperty: 'message'
60
+ },
61
+ writer: {
62
+ type: 'json',
63
+ writeAllFields:true,
64
+ root: 'data'
65
+ },
66
+ listeners: {
67
+ exception: function(proxy, response, operation){
68
+ var msg;
69
+ if (operation.getError() === undefined) {
70
+ responseObject = Ext.JSON.decode(response.responseText);
71
+ msg = responseObject.exception;
72
+ } else {
73
+ msg = operation.getError();
74
+ }
75
+ Ext.MessageBox.show({
76
+ title: 'REMOTE EXCEPTION',
77
+ msg: msg,
78
+ icon: Ext.MessageBox.ERROR,
79
+ buttons: Ext.Msg.OK
80
+ });
81
+ }
82
+ }
83
+ }
84
+ });
85
+
86
+ this.container.add(grid);
87
+ this.container.setActiveTab(this.container.items.length - 1);
88
+ },
89
+
90
+ selectTopFifty : function(table){
91
+ this.setWindowStatus('Selecting Top 50 from '+ table +'...');
92
+ var database = this.getDatabase();
93
+ var self = this;
94
+
95
+ var conn = new Ext.data.Connection();
96
+ conn.request({
97
+ url: '/rails_db_admin/erp_app/desktop/queries/select_top_fifty/' + table,
98
+ timeout:60000,
99
+ params:{
100
+ database:database
101
+ },
102
+ success: function(responseObject) {
103
+ self.clearWindowStatus();
104
+ var response = Ext.decode(responseObject.responseText);
105
+ var sql = response.sql;
106
+ var columns = response.columns;
107
+ var fields = response.fields;
108
+ var data = response.data;
109
+
110
+ var readOnlyDataGrid = new Compass.ErpApp.Desktop.Applications.RailsDbAdmin.ReadOnlyTableDataGrid({
111
+ columns:columns,
112
+ fields:fields,
113
+ data:data
114
+ });
115
+
116
+ var queryPanel = new Compass.ErpApp.Desktop.Applications.RailsDbAdmin.QueryPanel({
117
+ module:self,
118
+ sqlQuery:sql
119
+ });
120
+
121
+ self.container.add(queryPanel);
122
+ self.container.setActiveTab(queryPanel.id);
123
+
124
+ queryPanel.gridContainer.add(readOnlyDataGrid);
125
+ queryPanel.gridContainer.getLayout().setActiveItem(0);
126
+ },
127
+ failure: function() {
128
+ self.clearWindowStatus();
129
+ Ext.Msg.alert('Status', 'Error loading grid');
130
+ }
131
+ });
132
+ },
133
+
134
+ addNewQueryTab : function(){
135
+ this.container.add({
136
+ xtype:'railsdbadmin_querypanel',
137
+ module:this
138
+ });
139
+ this.container.setActiveTab(this.container.items.length - 1);
140
+ },
141
+
142
+ connectToDatatbase : function(){
143
+ var database = Ext.getCmp('databaseCombo').getValue();
144
+ var tablestreePanelStore = this.accordion.query('.railsdbadmin_tablestreemenu')[0].store;
145
+ var queriesTreePanelStore = this.accordion.query('.railsdbadmin_queriestreemenu')[0].store;
146
+
147
+ tablestreePanelStore.setProxy({
148
+ type: 'ajax',
149
+ url: '/rails_db_admin/erp_app/desktop/base/tables',
150
+ extraParams:{
151
+ database:database
152
+ }
153
+ });
154
+ tablestreePanelStore.load();
155
+
156
+ queriesTreePanelStore.setProxy({
157
+ type: 'ajax',
158
+ url: '/rails_db_admin/erp_app/desktop/queries/saved_queries_tree',
159
+ extraParams:{
160
+ database:database
161
+ }
162
+ });
163
+ queriesTreePanelStore.load();
164
+ },
165
+
166
+ getDatabase : function(){
167
+ var database = Ext.get('databaseCombo').getValue();
168
+ return database;
169
+ },
170
+
171
+ deleteQuery : function(queryName){
172
+ var self = this;
173
+ Ext.MessageBox.confirm('Confirm', 'Are you sure you want to delete this query?', function(btn){
174
+ if(btn == 'no'){
175
+ return false;
176
+ }
177
+ else
178
+ if(btn == 'yes')
179
+ {
180
+ self.setWindowStatus('Deleting '+ queryName +'...');
181
+ var database = self.getDatabase();
182
+ var conn = new Ext.data.Connection();
183
+ conn.request({
184
+ url: '/rails_db_admin/erp_app/desktop/queries/delete_query/',
185
+ params:{
186
+ database:database,
187
+ query_name:queryName
188
+ },
189
+ success: function(responseObject){
190
+ self.clearWindowStatus();
191
+ var response = Ext.decode(responseObject.responseText);
192
+ if(response.success)
193
+ {
194
+ Ext.Msg.alert('Error', 'Query deleted');
195
+ var queriesTreePanelStore = self.accordion.query('.railsdbadmin_queriestreemenu')[0].store;
196
+ queriesTreePanelStore.setProxy({
197
+ type: 'ajax',
198
+ url: '/rails_db_admin/erp_app/desktop/queries/saved_queries_tree',
199
+ extraParams:{
200
+ database:database
201
+ }
202
+ });
203
+ queriesTreePanelStore.load();
204
+ }
205
+ else
206
+ {
207
+ Ext.Msg.alert('Error', response.exception);
208
+ }
209
+
210
+ },
211
+ failure: function() {
212
+ self.clearWindowStatus();
213
+ Ext.Msg.alert('Status', 'Error deleting query');
214
+ }
215
+ });
216
+ }
217
+ });
218
+ },
219
+
220
+ displayAndExecuteQuery : function(queryName){
221
+ this.setWindowStatus('Executing '+ queryName +'...');
222
+ var self = this;
223
+ var database = this.getDatabase();
224
+ var conn = new Ext.data.Connection();
225
+ conn.request({
226
+ url: '/rails_db_admin/erp_app/desktop/queries/open_and_execute_query/',
227
+ params:{
228
+ database:database,
229
+ query_name:queryName
230
+ },
231
+ success: function(responseObject) {
232
+ var response = Ext.decode(responseObject.responseText);
233
+ var query = response.query;
234
+
235
+ var queryPanel = null;
236
+
237
+ if(response.success)
238
+ {
239
+ self.clearWindowStatus();
240
+ var columns = response.columns;
241
+ var fields = response.fields;
242
+ var data = response.data;
243
+
244
+ var readOnlyDataGrid = new Compass.ErpApp.Desktop.Applications.RailsDbAdmin.ReadOnlyTableDataGrid({
245
+ columns:columns,
246
+ fields:fields,
247
+ data:data
248
+ });
249
+
250
+ queryPanel = new Compass.ErpApp.Desktop.Applications.RailsDbAdmin.QueryPanel({
251
+ module:self,
252
+ sqlQuery:query
253
+ });
254
+
255
+ self.container.add(queryPanel);
256
+ self.container.setActiveTab(self.container.items.length - 1);
257
+
258
+ queryPanel.gridContainer.add(readOnlyDataGrid);
259
+ queryPanel.gridContainer.getLayout().setActiveItem(0);
260
+ }
261
+ else
262
+ {
263
+ Ext.Msg.alert('Error', response.exception);
264
+ queryPanel = new Compass.ErpApp.Desktop.Applications.RailsDbAdmin.QueryPanel({
265
+ module:self,
266
+ sqlQuery:query
267
+ });
268
+
269
+ self.container.add(queryPanel);
270
+ self.container.setActiveTab(self.container.items.length - 1);
271
+ }
272
+
273
+ },
274
+ failure: function() {
275
+ self.clearWindowStatus();
276
+ Ext.Msg.alert('Status', 'Error loading query');
277
+ }
278
+ });
279
+ },
280
+
281
+ init : function(){
282
+ this.launcher = {
283
+ text: 'RailsDbAdmin',
284
+ iconCls:'icon-rails_db_admin',
285
+ handler : this.createWindow,
286
+ scope: this
287
+ }
288
+ },
289
+
290
+ displayQuery : function(queryName){
291
+ this.setWindowStatus('Retrieving '+ queryName +'...');
292
+ var self = this;
293
+ var database = this.getDatabase();
294
+ var conn = new Ext.data.Connection();
295
+ conn.request({
296
+ url: '/rails_db_admin/erp_app/desktop/queries/open_query/',
297
+ params:{
298
+ database:database,
299
+ query_name:queryName
300
+ },
301
+ success: function(responseObject) {
302
+ var response = Ext.decode(responseObject.responseText);
303
+ var query = response.query;
304
+
305
+ var queryPanel = null;
306
+
307
+ if(response.success)
308
+ {
309
+ self.clearWindowStatus();
310
+
311
+ queryPanel = new Compass.ErpApp.Desktop.Applications.RailsDbAdmin.QueryPanel({
312
+ module:self,
313
+ sqlQuery:query
314
+ });
315
+
316
+ self.container.add(queryPanel);
317
+ self.container.setActiveTab(self.container.items.length - 1);
318
+ }
319
+ else
320
+ {
321
+ Ext.Msg.alert('Error', response.exception);
322
+ queryPanel = new Compass.ErpApp.Desktop.Applications.RailsDbAdmin.QueryPanel({
323
+ module:self,
324
+ sqlQuery:query
325
+ });
326
+
327
+ self.container.add(queryPanel);
328
+ self.container.setActiveTab(self.container.items.length - 1);
329
+ }
330
+
331
+ },
332
+ failure: function() {
333
+ self.clearWindowStatus();
334
+ Ext.Msg.alert('Status', 'Error loading query');
335
+ }
336
+ });
337
+ },
338
+
339
+ createWindow : function(){
340
+ var self = this;
341
+ var desktop = this.app.getDesktop();
342
+ var win = desktop.getWindow('rails_db_admin');
343
+ if(!win){
344
+ this.container = new Ext.TabPanel({
345
+ region : 'center',
346
+ margins : '0 0 0 0',
347
+ minsize : 300
348
+ });
349
+
350
+ this.accordion = new Ext.Panel({
351
+ region : 'west',
352
+ margins : '0 0 0 0',
353
+ cmargins : '0 0 0 0',
354
+ width : 300,
355
+ collapsible: true,
356
+ layout: 'accordion',
357
+ items:[
358
+ {
359
+ xtype:'railsdbadmin_tablestreemenu',
360
+ module:this
361
+ },
362
+
363
+ {
364
+ xtype:'railsdbadmin_queriestreemenu',
365
+ module:this
366
+ }
367
+ ]
368
+ });
369
+
370
+ win = desktop.createWindow({
371
+ id: 'rails_db_admin',
372
+ title:'RailsDBAdmin',
373
+ autoDestroy:true,
374
+ width:1200,
375
+ height:550,
376
+ iconCls: 'icon-rails_db_admin',
377
+ shim:false,
378
+ animCollapse:false,
379
+ constrainHeader:true,
380
+ layout: 'border',
381
+ tbar:{
382
+ items:[
383
+ {
384
+ text:'Database:'
385
+ },
386
+ {
387
+ xtype:'railsdbadmin_databasecombo',
388
+ module: self
389
+ }
390
+ ]
391
+ },
392
+ items:[this.accordion, this.container]
393
+ });
394
+
395
+ this.window = win;
396
+ }
397
+ win.show();
398
+ }
399
+ });
400
+
401
+ Ext.define("Compass.ErpApp.Desktop.Applications.RailsDbAdmin.BooleanEditor",{
402
+ extend:"Ext.form.ComboBox",
403
+ alias:'widget.booleancolumneditor',
404
+ initComponent: function() {
405
+ var trueFalseStore = new Ext.data.ArrayStore({
406
+ fields: ['display', 'value'],
407
+ data: [['False', '0'],['True', '1']]
408
+ });
409
+
410
+ this.store = trueFalseStore;
411
+
412
+ this.callParent(arguments);
413
+ },
414
+ constructor : function(config) {
415
+ config = Ext.apply({
416
+ valueField:'value',
417
+ displayField:'display',
418
+ triggerAction:'all',
419
+ forceSelection:true,
420
+ mode:'local'
421
+ }, config);
422
+
423
+ this.callParent([config])
424
+ }
425
+ });
426
+
427
+ Compass.ErpApp.Desktop.Applications.RailsDbAdmin.renderBooleanColumn = function(v){
428
+ return (v == 1) ? "True" : "False";
429
+ }