rails_db_admin 2.0.3 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -179,7 +179,8 @@ module RailsDbAdmin
179
179
 
180
180
  database_name
181
181
  end
182
- end
183
- end
184
- end
185
- end
182
+
183
+ end #BaseController
184
+ end #Desktop
185
+ end #ErpApp
186
+ end #RailsDbAdmin
@@ -1,7 +1,8 @@
1
1
  module RailsDbAdmin
2
2
  module ErpApp
3
3
  module Desktop
4
- class QueriesController < RailsDbAdmin::ErpApp::Desktop::BaseController
4
+ class QueriesController < BaseController
5
+
5
6
  def save_query
6
7
  query = params[:query]
7
8
  query_name = params[:query_name]
@@ -167,7 +168,8 @@ module RailsDbAdmin
167
168
  end
168
169
  render :json => result
169
170
  end
170
- end
171
- end
172
- end
173
- end
171
+
172
+ end #QueriesController
173
+ end #Desktop
174
+ end #ErpApp
175
+ end #RailsDbAdmin
@@ -0,0 +1,78 @@
1
+ module RailsDbAdmin
2
+ module ErpApp
3
+ module Desktop
4
+ class ReportsController < QueriesController
5
+
6
+ def index
7
+ reports = Report.all.collect{ |report|{:text => report.name, :id => report.id,
8
+ :uniqueName => report.internal_identifier,
9
+ :iconCls => 'icon-document', :leaf => true} }
10
+
11
+ render :json => reports
12
+ end
13
+
14
+ def create
15
+ name = params[:name]
16
+ internal_identifier = params[:internal_identifier]
17
+
18
+ report = Report.new(:name => name, :internal_identifier => internal_identifier)
19
+ if report.save
20
+ render :json => {:success => true}
21
+ else
22
+ render :json => {:success => false, :msg => 'Error creating report'}
23
+ end
24
+ end
25
+
26
+ def edit
27
+ id = params[:id]
28
+
29
+ report = Report.find(id)
30
+
31
+ if report
32
+ render :json => {:success => true, :report =>
33
+ {:title => report.name, :id => report.id, :query => report.query,
34
+ :internalIdentifier => report.internal_identifier, :template => report.template}
35
+ }
36
+ else
37
+ render :json => {:success => false}
38
+ end
39
+ end
40
+
41
+ def save
42
+ id = params[:id]
43
+ query = params[:query]
44
+ template = params[:template]
45
+
46
+ report = Report.find(id)
47
+
48
+ report.query = query
49
+ report.template = template
50
+
51
+ if report.save
52
+ render :json => {:success => true}
53
+ else
54
+ render :json => {:success => false}
55
+ end
56
+ end
57
+
58
+ def delete
59
+ id = params[:id]
60
+
61
+ if Report.find(id).destroy
62
+ render :json => {:success => true}
63
+ else
64
+ render :json => {:success => false}
65
+ end
66
+ end
67
+
68
+ def open_query
69
+ query_name = params[:query_name]
70
+ query = @query_support.get_query(query_name)
71
+
72
+ render :json => {:success => true, :query => query}
73
+ end
74
+
75
+ end #QueriesController
76
+ end #Desktop
77
+ end #ErpApp
78
+ end #RailsDbAdmin
@@ -0,0 +1,38 @@
1
+ module RailsDbAdmin
2
+ module Reports
3
+
4
+ class BaseController < ::ErpApp::Desktop::BaseController
5
+
6
+ def index
7
+ report_iid = params[:iid]
8
+
9
+ @report = Report.find_by_internal_identifier(report_iid)
10
+
11
+ if @report.nil?
12
+ render :no_report, :layout => false
13
+ else
14
+ respond_to do |format|
15
+ format.html {
16
+ render :show_report, :layout => false
17
+ }
18
+
19
+ format.csv {
20
+ data = RailsDbAdmin::ReportSupport.new.render_report(report_iid, :csv)
21
+
22
+ send_data(data, :filename => "#{@report.name}.csv", :type => "application/csv")
23
+ }
24
+
25
+ format.pdf {
26
+ data = RailsDbAdmin::ReportSupport.new.render_report(report_iid, :pdf)
27
+
28
+ send_data(data, :filename => "#{@report.name}.pdf", :type => "application/pdf")
29
+ }
30
+ end
31
+ end
32
+
33
+
34
+ end
35
+
36
+ end #BaseController
37
+ end #Reports
38
+ end #RailsDbAdmin
@@ -0,0 +1,28 @@
1
+ class Report < ActiveRecord::Base
2
+ validates :name, :internal_identifier, :uniqueness => true
3
+
4
+ before_create :set_default_template
5
+
6
+ def set_default_template
7
+ self.template =
8
+ "<h3><%= title %></h3>
9
+
10
+ <table>
11
+ <tr>
12
+ <% columns.each do |column| %>
13
+ <th><%= column %></th>
14
+ <% end %>
15
+ </tr>
16
+ <% rows.each do |row| %>
17
+ <tr>
18
+ <% row.values.each do |value| %>
19
+ <td><%= value %></td>
20
+ <% end %>
21
+ </tr>
22
+ <% end %>
23
+ </table>
24
+
25
+ <%= report_download_link(unique_name, :csv, 'Download CSV') %> |
26
+ <%= report_download_link(unique_name, :pdf, 'Download PDF') %>"
27
+ end
28
+ end
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>No Report</title>
5
+ <%= yield :head %>
6
+ </head>
7
+ <body>
8
+ <h3>No Report Found</h3>
9
+ </body>
10
+ </html>
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= @report.name %></title>
5
+ </head>
6
+ <body>
7
+
8
+ <%= render_report(@report.internal_identifier) %>
9
+
10
+ </body>
11
+ </html>
@@ -1,4 +1,9 @@
1
+ Rails.application.routes.draw do
2
+ match '/reports/display/:iid(.:format)' => "rails_db_admin/reports/base#index"
3
+ end
4
+
1
5
  RailsDbAdmin::Engine.routes.draw do
2
6
  match '/erp_app/desktop/base(/:action(/:table(/:id)))' => "erp_app/desktop/base"
3
7
  match '/erp_app/desktop/queries(/:action(/:table(/:id)))' => "erp_app/desktop/queries"
8
+ match '/erp_app/desktop/reports(/:action(/:table(/:id)))' => "erp_app/desktop/reports"
4
9
  end
@@ -0,0 +1,20 @@
1
+ class AddReports < ActiveRecord::Migration
2
+ def up
3
+ unless table_exists? :reports
4
+ create_table :reports do |t|
5
+ t.string :name
6
+ t.string :internal_identifier
7
+ t.text :template
8
+ t.text :query
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
14
+
15
+ def down
16
+ if table.exists? :reports
17
+ drop_table :reports
18
+ end
19
+ end
20
+ end
@@ -2,12 +2,14 @@
2
2
  require 'erp_app'
3
3
  require 'erp_forms'
4
4
 
5
+ require "rails_db_admin/extensions/railties/action_view/base"
5
6
  require "rails_db_admin/version"
6
7
  require 'rails_db_admin/config'
7
8
  require 'rails_db_admin/extjs'
8
9
  require 'rails_db_admin/connection_handler'
9
10
  require 'rails_db_admin/query_support'
10
11
  require 'rails_db_admin/table_support'
12
+ require 'rails_db_admin/report_support'
11
13
  require "rails_db_admin/engine"
12
14
 
13
15
  module RailsDbAdmin
@@ -5,7 +5,8 @@ module RailsDbAdmin
5
5
 
6
6
  def init!
7
7
  @defaults = {
8
- :@query_location => File.join('lib', 'rails_db_admin', 'queries')
8
+ :@query_location => File.join('lib', 'rails_db_admin', 'queries'),
9
+ :@reports_location => File.join('lib', 'rails_db_admin', 'reports')
9
10
  }
10
11
  end
11
12
 
@@ -8,11 +8,8 @@ module RailsDbAdmin
8
8
  app.middleware.insert_before Rack::Lock, ::ActionDispatch::Static, "#{root}/public"
9
9
  end
10
10
 
11
- engine = self
12
- config.to_prepare do
13
- ErpBaseErpSvcs.register_compass_ae_engine(engine)
14
- ::ErpApp::Widgets::Loader.load_compass_ae_widgets(engine)
15
- end
11
+ ErpBaseErpSvcs.register_as_compass_ae_engine(config, self)
12
+ ::ErpApp::Widgets::Loader.load_compass_ae_widgets(config, self)
16
13
 
17
14
  end
18
15
  end
@@ -0,0 +1,8 @@
1
+ #require all ActionView helper files
2
+ Dir.entries(File.join(File.dirname(__FILE__),"helpers")).delete_if{|name| name =~ /^\./}.each do |file|
3
+ require "rails_db_admin/extensions/railties/action_view/helpers/#{file}"
4
+ end
5
+
6
+ ActionView::Base.class_eval do
7
+ include RailsDbAdmin::Extensions::Railties::ActionView::Helpers::ReportHelper
8
+ end
@@ -0,0 +1,30 @@
1
+ module RailsDbAdmin
2
+ module Extensions
3
+ module Railties
4
+ module ActionView
5
+ module Helpers
6
+ module ReportHelper
7
+
8
+ def render_report(report_iid)
9
+ RailsDbAdmin::ReportSupport.new.render_report(report_iid)
10
+ end
11
+
12
+ def get_report_data(report_iid)
13
+ RailsDbAdmin::ReportSupport.new.get_report_data(report_iid)
14
+ end
15
+
16
+ def report_download_url(report_iid, format)
17
+ raw "/reports/display/#{report_iid}.#{format}"
18
+ end
19
+
20
+ def report_download_link(report_iid, format, display=nil)
21
+ display = display || "Download #{format.to_s.humanize}"
22
+ raw "<a target='_blank' href='#{report_download_url(report_iid, format)}'>#{display}</a>"
23
+ end
24
+
25
+ end #ReportHelper
26
+ end #Helpers
27
+ end #ActionView
28
+ end #Railties
29
+ end #Extensions
30
+ end #RailsDbAdmin
@@ -0,0 +1,52 @@
1
+ require 'fileutils'
2
+ require 'csv'
3
+
4
+ module RailsDbAdmin
5
+ class ReportSupport < QuerySupport
6
+
7
+ def initialize()
8
+ @connection = RailsDbAdmin::ConnectionHandler.create_connection_class(Rails.env).connection
9
+ end
10
+
11
+ def render_report(iid, format=:html)
12
+ report = Report.find_by_internal_identifier(iid.to_s)
13
+
14
+ if report.nil? or report.query.nil?
15
+ "Invalid Report, make sure report exists and query is valid"
16
+ else
17
+ data = get_report_data(iid)
18
+
19
+ case format
20
+ when :html
21
+ ActionView::Base.new().render(:inline => report.template, :locals =>
22
+ {:unique_name => iid, :title => report.name, :columns => data[:columns], :rows => data[:rows]}
23
+ )
24
+ when :pdf
25
+ html = ActionView::Base.new().render(:inline => report.template, :locals =>
26
+ {:unique_name => iid, :title => report.name, :columns => data[:columns], :rows => data[:rows]}
27
+ )
28
+
29
+ kit = PDFKit.new(html, :page_size => 'Letter')
30
+ kit.to_pdf
31
+ when :csv
32
+ CSV.generate do |csv|
33
+ csv << data[:columns]
34
+ data[:rows].each do |row|
35
+ csv << row.values
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ end
42
+
43
+ def get_report_data(iid)
44
+ report = Report.find_by_internal_identifier(iid.to_s)
45
+ columns, values = self.execute_sql(report.query)
46
+
47
+ return {:columns => columns, :rows => values}
48
+ end
49
+
50
+
51
+ end #ReportSupport
52
+ end #RailsDbAdmin
@@ -2,7 +2,7 @@ module RailsDbAdmin
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 2
4
4
  MINOR = 0
5
- TINY = 3
5
+ TINY = 4
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].compact.join('.')
8
8
  end
@@ -113,6 +113,7 @@ Ext.define("Compass.ErpApp.Desktop.Applications.RailsDbAdmin", {
113
113
 
114
114
  var queryPanel = Ext.create('Compass.ErpApp.Desktop.Applications.RailsDbAdmin.QueryPanel', {
115
115
  module:self,
116
+ closable:true,
116
117
  sqlQuery:sql,
117
118
  southRegion:readOnlyDataGrid
118
119
  });
@@ -243,7 +244,8 @@ Ext.define("Compass.ErpApp.Desktop.Applications.RailsDbAdmin", {
243
244
  var queryPanel = Ext.create('Compass.ErpApp.Desktop.Applications.RailsDbAdmin.QueryPanel', {
244
245
  module:self,
245
246
  sqlQuery:query,
246
- southRegion:readOnlyDataGrid
247
+ southRegion:readOnlyDataGrid,
248
+ closable:true
247
249
  });
248
250
 
249
251
  self.container.add(queryPanel);
@@ -253,6 +255,7 @@ Ext.define("Compass.ErpApp.Desktop.Applications.RailsDbAdmin", {
253
255
  Ext.Msg.alert('Error', response.exception);
254
256
  queryPanel = Ext.create('Compass.ErpApp.Desktop.Applications.RailsDbAdmin.QueryPanel', {
255
257
  module:self,
258
+ closable:true,
256
259
  sqlQuery:query
257
260
  });
258
261
 
@@ -268,6 +271,26 @@ Ext.define("Compass.ErpApp.Desktop.Applications.RailsDbAdmin", {
268
271
  });
269
272
  },
270
273
 
274
+ //************ Reporting ************************************************
275
+
276
+ editReport : function(reportObj){
277
+ var me = this;
278
+
279
+ me.container.add({
280
+ title:reportObj.title,
281
+ xtype:'railsdbadmin_reportpanel',
282
+ module:me,
283
+ query:reportObj.query,
284
+ reportId:reportObj.id,
285
+ template:reportObj.template,
286
+ internalIdentifier:reportObj.internalIdentifier,
287
+ closable:true
288
+ });
289
+ me.container.setActiveTab(me.container.items.length - 1);
290
+ },
291
+
292
+ //***********************************************************************
293
+
271
294
  init:function () {
272
295
  this.launcher = {
273
296
  text:'RailsDbAdmin',
@@ -298,6 +321,7 @@ Ext.define("Compass.ErpApp.Desktop.Applications.RailsDbAdmin", {
298
321
 
299
322
  queryPanel = Ext.create('Compass.ErpApp.Desktop.Applications.RailsDbAdmin.QueryPanel', {
300
323
  module:self,
324
+ closable:true,
301
325
  sqlQuery:query
302
326
  });
303
327
 
@@ -308,6 +332,7 @@ Ext.define("Compass.ErpApp.Desktop.Applications.RailsDbAdmin", {
308
332
  Ext.Msg.alert('Error', response.exception);
309
333
  queryPanel = Ext.create('Compass.ErpApp.Desktop.Applications.RailsDbAdmin.QueryPanel', {
310
334
  module:self,
335
+ closable:true,
311
336
  sqlQuery:query
312
337
  });
313
338
 
@@ -346,11 +371,12 @@ Ext.define("Compass.ErpApp.Desktop.Applications.RailsDbAdmin", {
346
371
  {
347
372
  xtype:'railsdbadmin_tablestreemenu',
348
373
  module:this
349
- },
350
-
351
- {
374
+ }, {
352
375
  xtype:'railsdbadmin_queriestreemenu',
353
376
  module:this
377
+ }, {
378
+ xtype:'railsdbadmin_reportstreepanel',
379
+ module:this
354
380
  }
355
381
  ]
356
382
  });
@@ -1,6 +1,11 @@
1
1
  Ext.define("Compass.ErpApp.Desktop.Applications.RailsDbAdmin.QueryPanel", {
2
2
  extend:"Ext.panel.Panel",
3
3
  alias:'widget.railsdbadmin_querypanel',
4
+
5
+ getSql: function(){
6
+ return this.down('codemirror').getValue();
7
+ },
8
+
4
9
  initComponent:function () {
5
10
  var self = this;
6
11
  var messageBox = null;
@@ -24,167 +29,172 @@ Ext.define("Compass.ErpApp.Desktop.Applications.RailsDbAdmin.QueryPanel", {
24
29
  ]
25
30
  });
26
31
 
27
- var codeMirrorPanel = {
28
- height:250,
29
- region:'north',
30
- xtype:'codemirror',
31
- parser:'sql',
32
- tbarItems:[
33
- {
34
- text:'Execute',
35
- iconCls:'icon-settings',
36
- handler:function (button) {
37
- var textarea = self.query('.codemirror')[0];
38
- var sql = textarea.getValue();
39
- var selected_sql = textarea.getSelection();
40
- var cursor_pos = textarea.getCursor().line;
41
- var database = self.module.getDatabase();
42
-
43
- messageBox = Ext.Msg.wait('Status', 'Executing..');
44
-
45
- Ext.Ajax.request({
46
- url:'/rails_db_admin/erp_app/desktop/queries/execute_query',
47
- params:{
48
- sql:sql,
49
- database:database,
50
- cursor_pos:cursor_pos,
51
- selected_sql:selected_sql
52
- },
53
- method:'post',
54
- success:function (responseObject) {
55
- messageBox.hide();
56
- var response = Ext.decode(responseObject.responseText);
57
-
58
- if (response.success) {
59
- var columns = response.columns;
60
- var fields = response.fields;
61
- var data = response.data;
62
-
63
- if(!Ext.isEmpty(self.down('railsdbadmin_readonlytabledatagrid'))){
64
- var jsonStore = new Ext.data.JsonStore({
65
- fields:fields,
66
- data:data
67
- });
32
+ var tbarItems = [
33
+ {
34
+ text:'Execute',
35
+ iconCls:'icon-settings',
36
+ handler:function (button) {
37
+ var textarea = self.query('.codemirror')[0];
38
+ var sql = textarea.getValue();
39
+ var selected_sql = textarea.getSelection();
40
+ var cursor_pos = textarea.getCursor().line;
41
+ var database = self.module.getDatabase();
68
42
 
69
- self.down('railsdbadmin_readonlytabledatagrid').reconfigure(jsonStore, columns);
70
- }
71
- else{
72
- var readOnlyDataGrid = Ext.create('Compass.ErpApp.Desktop.Applications.RailsDbAdmin.ReadOnlyTableDataGrid',{
73
- layout:'fit',
74
- columns:columns,
75
- fields:fields,
76
- data:data
77
- });
43
+ messageBox = Ext.Msg.wait('Status', 'Executing..');
78
44
 
79
- var cardPanel = self.down('#resultCardPanel');
80
- cardPanel.removeAll(true);
81
- cardPanel.add(readOnlyDataGrid);
82
- cardPanel.getLayout().setActiveItem(readOnlyDataGrid);
83
- }
45
+ Ext.Ajax.request({
46
+ url:'/rails_db_admin/erp_app/desktop/queries/execute_query',
47
+ params:{
48
+ sql:sql,
49
+ database:database,
50
+ cursor_pos:cursor_pos,
51
+ selected_sql:selected_sql
52
+ },
53
+ method:'post',
54
+ success:function (responseObject) {
55
+ messageBox.hide();
56
+ var response = Ext.decode(responseObject.responseText);
57
+
58
+ if (response.success) {
59
+ var columns = response.columns;
60
+ var fields = response.fields;
61
+ var data = response.data;
62
+
63
+ if (!Ext.isEmpty(self.down('railsdbadmin_readonlytabledatagrid'))) {
64
+ var jsonStore = new Ext.data.JsonStore({
65
+ fields:fields,
66
+ data:data
67
+ });
68
+
69
+ self.down('railsdbadmin_readonlytabledatagrid').reconfigure(jsonStore, columns);
84
70
  }
85
71
  else {
86
- Ext.Msg.alert("Error", response.exception);
87
- }
72
+ var readOnlyDataGrid = Ext.create('Compass.ErpApp.Desktop.Applications.RailsDbAdmin.ReadOnlyTableDataGrid', {
73
+ layout:'fit',
74
+ columns:columns,
75
+ fields:fields,
76
+ data:data
77
+ });
88
78
 
89
- },
90
- failure:function () {
91
- messageBox.hide();
92
- Ext.Msg.alert('Status', 'Error loading grid');
79
+ var cardPanel = self.down('#resultCardPanel');
80
+ cardPanel.removeAll(true);
81
+ cardPanel.add(readOnlyDataGrid);
82
+ cardPanel.getLayout().setActiveItem(readOnlyDataGrid);
83
+ }
93
84
  }
94
- });
95
- }
96
- },
97
- {
98
- text:'Save',
99
- iconCls:'icon-save',
100
- handler:function () {
101
- var textarea = self.down('.codemirror');
102
- var save_window = new Ext.Window({
103
- layout:'fit',
104
- width:375,
105
- title:'Save Query',
106
- height:125,
107
- buttonAlign:'center',
108
- closeAction:'hide',
109
- plain:true,
110
- items:new Ext.FormPanel({
111
- frame:false,
112
- bodyStyle:'padding:5px 5px 0',
113
- width:500,
114
- items:[
115
- {
116
- xtype:'combo',
117
- fieldLabel:'Query Name',
118
- name:'query_name',
119
- allowBlank:false,
120
- store:savedQueriesJsonStore,
121
- valueField:'value',
122
- displayField:'display',
123
- triggerAction:'all',
124
- forceSelection:false,
125
- mode:'remote'
126
- },
127
- {
128
- xtype:'hidden',
129
- value:textarea.getValue(),
130
- name:'query'
131
- },
132
- {
133
- xtype:'hidden',
134
- value:self.module.getDatabase(),
135
- name:'database'
136
- }
137
- ]
138
- }),
139
- buttons:[
85
+ else {
86
+ Ext.Msg.alert("Error", response.exception);
87
+ }
88
+
89
+ },
90
+ failure:function () {
91
+ messageBox.hide();
92
+ Ext.Msg.alert('Status', 'Error loading grid');
93
+ }
94
+ });
95
+ }
96
+ }
97
+ ];
98
+
99
+ if (!this.initialConfig['hideSave']) {
100
+ tbarItems.push({
101
+ text:'Save',
102
+ iconCls:'icon-save',
103
+ handler:function () {
104
+ var textarea = self.down('.codemirror');
105
+ var save_window = new Ext.Window({
106
+ layout:'fit',
107
+ width:375,
108
+ title:'Save Query',
109
+ height:125,
110
+ buttonAlign:'center',
111
+ closeAction:'hide',
112
+ plain:true,
113
+ items:new Ext.FormPanel({
114
+ frame:false,
115
+ bodyStyle:'padding:5px 5px 0',
116
+ width:500,
117
+ items:[
140
118
  {
141
- text:'Save',
142
- handler:function () {
143
- var fp = this.up('window').down('.form');
144
- if (fp.getForm().isValid()) {
145
- fp.getForm().submit({
146
- url:'/rails_db_admin/erp_app/desktop/queries/save_query',
147
- waitMsg:'Saving Query...',
148
- success:function (fp, o) {
149
- Ext.Msg.alert('Success', 'Saved Query');
150
- var database = self.module.getDatabase();
151
- self.module.queriesTreePanel().store.setProxy({
152
- type:'ajax',
153
- url:'/rails_db_admin/erp_app/desktop/queries/saved_queries_tree',
154
- extraParams:{
155
- database:database
156
- }
157
- });
158
- self.module.queriesTreePanel().store.load();
159
- save_window.hide();
160
- }
161
- });
162
- }
163
- }
119
+ xtype:'combo',
120
+ fieldLabel:'Query Name',
121
+ name:'query_name',
122
+ allowBlank:false,
123
+ store:savedQueriesJsonStore,
124
+ valueField:'value',
125
+ displayField:'display',
126
+ triggerAction:'all',
127
+ forceSelection:false,
128
+ mode:'remote'
164
129
  },
165
130
  {
166
- text:'Cancel',
167
- handler:function () {
168
- save_window.hide();
169
- }
131
+ xtype:'hidden',
132
+ value:textarea.getValue(),
133
+ name:'query'
134
+ },
135
+ {
136
+ xtype:'hidden',
137
+ value:self.module.getDatabase(),
138
+ name:'database'
170
139
  }
171
140
  ]
141
+ }),
142
+ buttons:[
143
+ {
144
+ text:'Save',
145
+ handler:function () {
146
+ var fp = this.up('window').down('.form');
147
+ if (fp.getForm().isValid()) {
148
+ fp.getForm().submit({
149
+ url:'/rails_db_admin/erp_app/desktop/queries/save_query',
150
+ waitMsg:'Saving Query...',
151
+ success:function (fp, o) {
152
+ Ext.Msg.alert('Success', 'Saved Query');
153
+ var database = self.module.getDatabase();
154
+ self.module.queriesTreePanel().store.setProxy({
155
+ type:'ajax',
156
+ url:'/rails_db_admin/erp_app/desktop/queries/saved_queries_tree',
157
+ extraParams:{
158
+ database:database
159
+ }
160
+ });
161
+ self.module.queriesTreePanel().store.load();
162
+ save_window.hide();
163
+ }
164
+ });
165
+ }
166
+ }
167
+ },
168
+ {
169
+ text:'Cancel',
170
+ handler:function () {
171
+ save_window.hide();
172
+ }
173
+ }
174
+ ]
172
175
 
173
- });
174
- save_window.show();
175
- }
176
+ });
177
+ save_window.show();
176
178
  }
177
- ],
179
+ });
180
+ }
181
+
182
+ var codeMirrorPanel = {
183
+ height:250,
184
+ region:'north',
185
+ xtype:'codemirror',
186
+ parser:'sql',
187
+ tbarItems:tbarItems,
178
188
  sourceCode:this.initialConfig['sqlQuery'],
179
189
  disableSave:true
180
190
  };
181
191
 
182
192
  this.items = [codeMirrorPanel];
183
193
 
184
- if(!Ext.isEmpty(this.initialConfig['southRegion'])){
194
+ if (!Ext.isEmpty(this.initialConfig['southRegion'])) {
185
195
  this.items.push(this.initialConfig['southRegion']);
186
196
  }
187
- else{
197
+ else {
188
198
  this.items.push({
189
199
  layout:'card',
190
200
  region:'center',
@@ -199,10 +209,9 @@ Ext.define("Compass.ErpApp.Desktop.Applications.RailsDbAdmin.QueryPanel", {
199
209
  },
200
210
 
201
211
  constructor:function (config) {
202
- config = Ext.apply({
212
+ config = Ext.applyIf({
203
213
  title:'Query',
204
214
  layout:'border',
205
- closable:true,
206
215
  border:false
207
216
  }, config);
208
217
  this.callParent([config]);
@@ -0,0 +1,78 @@
1
+ Ext.define("Compass.ErpApp.Desktop.Applications.RailsDbAdmin.ReportPanel", {
2
+ extend:"Ext.tab.Panel",
3
+ alias:'widget.railsdbadmin_reportpanel',
4
+
5
+ initComponent:function () {
6
+ var me = this;
7
+
8
+ var codeMirror = Ext.create("widget.codemirror", {
9
+ title:'Template',
10
+ disableSave:true,
11
+ parser:'rb',
12
+ sourceCode:me.initialConfig.template
13
+ });
14
+
15
+ var queryPanel = Ext.create('widget.railsdbadmin_querypanel',{
16
+ title:'Query',
17
+ hideSave:true,
18
+ closable:false,
19
+ module:me.initialConfig.module,
20
+ sqlQuery:me.initialConfig.query
21
+ });
22
+
23
+ this.items = [queryPanel, codeMirror];
24
+
25
+ this.tbar = {
26
+ items:[
27
+ {
28
+ text:'Save Report',
29
+ iconCls:'icon-save',
30
+ handler:function(btn){
31
+ var template, query = null;
32
+
33
+ //need to show all tabs to make sure codemirror fully rendered.
34
+ var tabPanel = btn.up('railsdbadmin_reportpanel');
35
+ activeTab = tabPanel.getActiveTab();
36
+ tabPanel.setActiveTab(1);
37
+ tabPanel.setActiveTab(0);
38
+ tabPanel.setActiveTab(activeTab);
39
+
40
+ template = codeMirror.getValue();
41
+ query = queryPanel.getSql();
42
+
43
+ var waitMsg = Ext.Msg.wait("Saving Report...", "Status");
44
+ Ext.Ajax.request({
45
+ url:'/rails_db_admin/erp_app/desktop/reports/save',
46
+ params:{
47
+ id:me.initialConfig.reportId,
48
+ template:template,
49
+ query:query
50
+ },
51
+ success:function (responseObject) {
52
+ waitMsg.close();
53
+ var obj = Ext.decode(responseObject.responseText);
54
+ if (!obj.success) {
55
+ Ext.Msg.alert('Status', 'Error saving report');
56
+ }
57
+ },
58
+ failure:function () {
59
+ waitMsg.close();
60
+ Ext.Msg.alert('Status', 'Error saving report');
61
+ }
62
+ });
63
+ }
64
+ },
65
+ {
66
+ text:'Execute Report',
67
+ iconCls:'icon-settings',
68
+ handler:function(btn){
69
+ var webNavigator = window.compassDesktop.getModule('web-navigator-win');
70
+ webNavigator.createWindow('/reports/display/'+me.initialConfig.internalIdentifier);
71
+ }
72
+ }
73
+ ]
74
+ };
75
+
76
+ this.callParent(arguments);
77
+ }
78
+ });
@@ -0,0 +1,237 @@
1
+ Ext.define("Compass.ErpApp.Desktop.Applications.RailsDbAdmin.ReportsTreePanel", {
2
+ extend:"Ext.tree.TreePanel",
3
+ alias:'widget.railsdbadmin_reportstreepanel',
4
+
5
+ newReport:function () {
6
+ var me = this;
7
+
8
+ Ext.create("Ext.window.Window", {
9
+ title:'New Report',
10
+ plain:true,
11
+ buttonAlign:'center',
12
+ items:Ext.create('Ext.FormPanel', {
13
+ labelWidth:110,
14
+ frame:false,
15
+ bodyStyle:'padding:5px 5px 0',
16
+ url:'/rails_db_admin/erp_app/desktop/reports/create',
17
+ defaults:{
18
+ width:225
19
+ },
20
+ items:[
21
+ {
22
+ xtype:'textfield',
23
+ fieldLabel:'Title',
24
+ allowBlank:false,
25
+ name:'name'
26
+ },
27
+ {
28
+ xtype:'textfield',
29
+ fieldLabel:'Unique Name',
30
+ allowBlank:false,
31
+ name:'internal_identifier'
32
+ }
33
+ ]
34
+ }),
35
+ buttons:[
36
+ {
37
+ text:'Submit',
38
+ listeners:{
39
+ 'click':function (button) {
40
+ var window = button.up('window');
41
+ var formPanel = window.down('form');
42
+ formPanel.getForm().submit({
43
+ waitMsg:'Creating Report...',
44
+ success:function (form, action) {
45
+ var obj = Ext.decode(action.response.responseText);
46
+ if (obj.success) {
47
+ button.up('window').close();
48
+ me.getStore().load();
49
+ }
50
+ else {
51
+ Ext.Msg.alert("Error", obj.msg);
52
+ }
53
+ },
54
+ failure:function (form, action) {
55
+ var obj = Ext.decode(action.response.responseText);
56
+ if (obj.msg) {
57
+ Ext.Msg.alert("Error", obj.msg);
58
+ }
59
+ else {
60
+ Ext.Msg.alert("Error", "Error creating report.");
61
+ }
62
+ }
63
+ });
64
+ }
65
+ }
66
+ },
67
+ {
68
+ text:'Close',
69
+ handler:function (btn) {
70
+ btn.up('window').close();
71
+ }
72
+ }
73
+ ]
74
+ }).show();
75
+ },
76
+
77
+ deleteReport:function (id) {
78
+ var me = this;
79
+
80
+ Ext.MessageBox.confirm('Confirm', 'Are you sure you want to delete this report?', function (btn) {
81
+ if (btn === 'no') {
82
+ return false;
83
+ }
84
+ else if (btn === 'yes') {
85
+ Ext.Ajax.request({
86
+ url:'/rails_db_admin/erp_app/desktop/reports/delete',
87
+ params:{
88
+ id:id
89
+ },
90
+ success:function (responseObject) {
91
+ var obj = Ext.decode(responseObject.responseText);
92
+ if (obj.success) {
93
+ me.getStore().load();
94
+ }
95
+ else {
96
+ Ext.Msg.alert('Status', 'Error deleting report');
97
+ }
98
+ },
99
+ failure:function () {
100
+ Ext.Msg.alert('Status', 'Error deleting report');
101
+ }
102
+ });
103
+ }
104
+ });
105
+ },
106
+
107
+ editReport:function (id) {
108
+ var me = this;
109
+
110
+ var waitMsg = Ext.Msg.wait("Loading report...", "Status");
111
+ Ext.Ajax.request({
112
+ url:'/rails_db_admin/erp_app/desktop/reports/edit',
113
+ params:{
114
+ id:id
115
+ },
116
+ success:function (responseObject) {
117
+ waitMsg.close();
118
+ var obj = Ext.decode(responseObject.responseText);
119
+ if (obj.success) {
120
+ me.initialConfig.module.editReport(obj.report);
121
+ }
122
+ else {
123
+ Ext.Msg.alert('Status', 'Error deleting report');
124
+ }
125
+ },
126
+ failure:function () {
127
+ waitMsg.close();
128
+ Ext.Msg.alert('Status', 'Error deleting report');
129
+ }
130
+ });
131
+ },
132
+
133
+ constructor:function (config) {
134
+ var me = this;
135
+
136
+ config = Ext.apply({
137
+ title:'Reports',
138
+ autoScroll:true,
139
+ store:Ext.create('Ext.data.TreeStore', {
140
+ proxy:{
141
+ type:'ajax',
142
+ url:'/rails_db_admin/erp_app/desktop/reports'
143
+ },
144
+ root:{
145
+ text:'Reports',
146
+ expanded:true,
147
+ draggable:false,
148
+ iconCls:'icon-content'
149
+ },
150
+ fields:[
151
+ {
152
+ name:'text'
153
+ }, {
154
+ name:'iconCls'
155
+ }, {
156
+ name:'leaf'
157
+ }, {
158
+ name:'id'
159
+ }, {
160
+ name:'uniqueName'
161
+ }
162
+
163
+ ]
164
+ }),
165
+ animate:false,
166
+ listeners:{
167
+ 'itemclick':function (view, record, item, index, e) {
168
+ e.stopEvent();
169
+ if (record.data.leaf) {
170
+ me.editReport(record.data.id);
171
+ }
172
+ },
173
+ 'itemcontextmenu':function (view, record, item, index, e) {
174
+ e.stopEvent();
175
+ var contextMenu = null;
176
+ if (record.data.leaf) {
177
+ contextMenu = Ext.create('Ext.menu.Menu',{
178
+ items:[
179
+ {
180
+ text:"Edit Report",
181
+ iconCls:'icon-settings',
182
+ listeners:{
183
+ scope:record,
184
+ 'click':function () {
185
+ me.editReport(record.data.id);
186
+ }
187
+ }
188
+ },
189
+ {
190
+ text:"Delete",
191
+ iconCls:'icon-delete',
192
+ listeners:{
193
+ scope:record,
194
+ 'click':function () {
195
+ me.deleteReport(record.data.id);
196
+ }
197
+ }
198
+ },
199
+ {
200
+ text:"Info",
201
+ iconCls:'icon-info',
202
+ listeners:{
203
+ scope:record,
204
+ 'click':function () {
205
+ Ext.Msg.alert('Details', 'Title: '+record.data.text +
206
+ '<br /> Unique Name: '+record.data.uniqueName
207
+ );
208
+ }
209
+ }
210
+ }
211
+ ]
212
+ });
213
+ }
214
+ else {
215
+ contextMenu = Ext.create('Ext.menu.Menu',{
216
+ items:[
217
+ {
218
+ text:"New Report",
219
+ iconCls:'icon-new',
220
+ listeners:{
221
+ 'click':function () {
222
+ me.newReport();
223
+ }
224
+ }
225
+ }
226
+ ]
227
+ });
228
+ }
229
+ contextMenu.showAt(e.xy);
230
+ }
231
+ }
232
+ }, config);
233
+
234
+ this.callParent([config]);
235
+ }
236
+ });
237
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_db_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-24 00:00:00.000000000 Z
12
+ date: 2013-01-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: erp_forms
16
- requirement: &70191058725800 !ruby/object:Gem::Requirement
16
+ requirement: &70219717203920 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70191058725800
24
+ version_requirements: *70219717203920
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: erp_dev_svcs
27
- requirement: &70191058725280 !ruby/object:Gem::Requirement
27
+ requirement: &70219717203200 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '3.0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70191058725280
35
+ version_requirements: *70219717203200
36
36
  description: RailsDB Admin is similar in functionality to PHPMyAdmin and other database
37
37
  browsing and data editing tools. It uses the CompassAE database connection information
38
38
  to discover the schema for an installation, and generates Extjs UIs for creating
@@ -52,24 +52,33 @@ files:
52
52
  - public/javascripts/erp_app/desktop/applications/rails_db_admin/queries_tree_menu.js
53
53
  - public/javascripts/erp_app/desktop/applications/rails_db_admin/query_panel.js
54
54
  - public/javascripts/erp_app/desktop/applications/rails_db_admin/readonly_table_data_grid.js
55
+ - public/javascripts/erp_app/desktop/applications/rails_db_admin/report_panel.js
56
+ - public/javascripts/erp_app/desktop/applications/rails_db_admin/reports_tree_panel.js
55
57
  - public/javascripts/erp_app/desktop/applications/rails_db_admin/tables_tree_menu.js
56
58
  - public/stylesheets/erp_app/desktop/applications/rails_db_admin/rails_db_admin.css
57
59
  - app/assets/javascripts/rails_db_admin/application.js
58
60
  - app/assets/stylesheets/rails_db_admin/application.css
59
61
  - app/controllers/rails_db_admin/erp_app/desktop/base_controller.rb
60
62
  - app/controllers/rails_db_admin/erp_app/desktop/queries_controller.rb
63
+ - app/controllers/rails_db_admin/erp_app/desktop/reports_controller.rb
64
+ - app/controllers/rails_db_admin/reports/base_controller.rb
61
65
  - app/helpers/rails_db_admin/application_helper.rb
62
- - app/views/layouts/application.html.erb
63
- - app/views/layouts/rails_db_admin/application.html.erb
66
+ - app/models/report.rb
67
+ - app/views/rails_db_admin/reports/base/no_report.erb
68
+ - app/views/rails_db_admin/reports/base/show_report.erb
64
69
  - config/routes.rb
65
70
  - db/data_migrations/20110816005525_rails_db_admin_application.rb
71
+ - db/migrate/20121210160131_add_reports.rb
66
72
  - lib/rails_db_admin/config.rb
67
73
  - lib/rails_db_admin/connection_handler.rb
68
74
  - lib/rails_db_admin/engine.rb
75
+ - lib/rails_db_admin/extensions/railties/action_view/base.rb
76
+ - lib/rails_db_admin/extensions/railties/action_view/helpers/report_helper.rb
69
77
  - lib/rails_db_admin/extjs/json_column_builder.rb
70
78
  - lib/rails_db_admin/extjs/json_data_builder.rb
71
79
  - lib/rails_db_admin/extjs.rb
72
80
  - lib/rails_db_admin/query_support.rb
81
+ - lib/rails_db_admin/report_support.rb
73
82
  - lib/rails_db_admin/table_support.rb
74
83
  - lib/rails_db_admin/version.rb
75
84
  - lib/rails_db_admin.rb
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>RailsDbAdmin</title>
5
- <%= stylesheet_link_tag "rails_db_admin/application" %>
6
- <%= javascript_include_tag "rails_db_admin/application" %>
7
- <%= csrf_meta_tags %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>RailsDbAdmin</title>
5
- <%= stylesheet_link_tag "rails_db_admin/application" %>
6
- <%= javascript_include_tag "rails_db_admin/application" %>
7
- <%= csrf_meta_tags %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>