rails_db_admin 3.0.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/{public → app/assets}/images/icons/rails_db_admin/rails_db_admin_16x16.png +0 -0
  3. data/{public → app/assets}/images/icons/rails_db_admin/rails_db_admin_24x24.png +0 -0
  4. data/{public → app/assets}/images/icons/rails_db_admin/rails_db_admin_32x32.png +0 -0
  5. data/{public → app/assets}/images/icons/rails_db_admin/rails_db_admin_64x64.png +0 -0
  6. data/{public → app/assets}/images/icons/rails_db_admin/rails_db_admin_light_16x16.png +0 -0
  7. data/app/assets/images/splash/db_admin_splash.png +0 -0
  8. data/{public → app/assets}/images/splash/images/console-icon.png +0 -0
  9. data/{public → app/assets}/images/splash/images/data-model-icon.png +0 -0
  10. data/app/assets/javascripts/erp_app/desktop/applications/rails_db_admin/app.js +20 -0
  11. data/{public → app/assets}/javascripts/erp_app/desktop/applications/rails_db_admin/database_combo.js +1 -1
  12. data/{public → app/assets}/javascripts/erp_app/desktop/applications/rails_db_admin/module.js +227 -135
  13. data/{public → app/assets}/javascripts/erp_app/desktop/applications/rails_db_admin/queries_tree_menu.js +6 -6
  14. data/app/assets/javascripts/erp_app/desktop/applications/rails_db_admin/query_panel.js +383 -0
  15. data/{public → app/assets}/javascripts/erp_app/desktop/applications/rails_db_admin/readonly_table_data_grid.js +0 -0
  16. data/app/assets/javascripts/erp_app/desktop/applications/rails_db_admin/reports/ParamWindow.js +426 -0
  17. data/app/assets/javascripts/erp_app/desktop/applications/rails_db_admin/reports/ParamsManager.js +177 -0
  18. data/app/assets/javascripts/erp_app/desktop/applications/rails_db_admin/reports/RolesPanel.js +95 -0
  19. data/app/assets/javascripts/erp_app/desktop/applications/rails_db_admin/reports/SetDefaultWindow.js +244 -0
  20. data/app/assets/javascripts/erp_app/desktop/applications/rails_db_admin/reports/Settings.js +155 -0
  21. data/app/assets/javascripts/erp_app/desktop/applications/rails_db_admin/reports/TreePanel.js +391 -0
  22. data/app/assets/javascripts/erp_app/desktop/applications/rails_db_admin/splash_screen.js +163 -0
  23. data/{public → app/assets}/javascripts/erp_app/desktop/applications/rails_db_admin/tables_tree_menu.js +5 -3
  24. data/app/assets/javascripts/erp_app/shared/MultiOption.js +151 -0
  25. data/app/assets/javascripts/erp_app/shared/ReportsParams.js +289 -0
  26. data/app/assets/javascripts/erp_app/shared/rails_db_admin_shared.js +13 -0
  27. data/{public/stylesheets/erp_app/desktop/applications/rails_db_admin/rails_db_admin.css → app/assets/stylesheets/erp_app/shared/rails_db_admin_shared.css} +5 -10
  28. data/app/controllers/rails_db_admin/erp_app/desktop/base_controller.rb +7 -6
  29. data/app/controllers/rails_db_admin/erp_app/desktop/queries_controller.rb +88 -74
  30. data/app/controllers/rails_db_admin/erp_app/desktop/reports_controller.rb +361 -30
  31. data/app/controllers/rails_db_admin/reports/base_controller.rb +105 -22
  32. data/app/mailers/report_mailer.rb +15 -0
  33. data/app/models/report.rb +227 -14
  34. data/app/views/rails_db_admin/reports/base/error_report.erb +27 -0
  35. data/app/views/report_mailer/email_report.html.erb +255 -0
  36. data/config/routes.rb +2 -1
  37. data/db/data_migrations/20110816005525_rails_db_admin_application.rb +6 -14
  38. data/db/data_migrations/20151015093724_add_report_role_type.rb +15 -0
  39. data/db/migrate/20121210160131_add_reports.rb +2 -0
  40. data/db/migrate/20150926061259_add_meta_data_to_reports.rb +9 -0
  41. data/lib/rails_db_admin.rb +4 -2
  42. data/lib/rails_db_admin/engine.rb +12 -4
  43. data/lib/rails_db_admin/erp_string_parser.rb +26 -0
  44. data/lib/rails_db_admin/extensions/railties/action_view/helpers/report_helper.rb +167 -10
  45. data/lib/rails_db_admin/extjs/json_data_builder.rb +36 -20
  46. data/lib/rails_db_admin/query_params.rb +14 -0
  47. data/lib/rails_db_admin/query_support.rb +56 -46
  48. data/lib/rails_db_admin/services/report_helper.rb +241 -0
  49. data/lib/rails_db_admin/version.rb +1 -1
  50. metadata +41 -30
  51. data/app/assets/javascripts/rails_db_admin/application.js +0 -9
  52. data/app/assets/stylesheets/rails_db_admin/application.css +0 -7
  53. data/app/views/rails_db_admin/reports/base/show_report.erb +0 -11
  54. data/db/migrate/20131112013053_add_rails_db_admin_missing_indexes.rb +0 -17
  55. data/lib/rails_db_admin/report_support.rb +0 -52
  56. data/public/images/splash/splash.png +0 -0
  57. data/public/javascripts/erp_app/desktop/applications/rails_db_admin/query_panel.js +0 -223
  58. data/public/javascripts/erp_app/desktop/applications/rails_db_admin/report_panel.js +0 -78
  59. data/public/javascripts/erp_app/desktop/applications/rails_db_admin/reports_tree_panel.js +0 -237
  60. data/public/javascripts/erp_app/desktop/applications/rails_db_admin/splash_screen.js +0 -136
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require_tree .
@@ -1,14 +1,9 @@
1
1
  .icon-rails_db_admin {
2
- background-image:url( /images/icons/rails_db_admin/rails_db_admin_16x16.png ) !important;
3
- filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/icons/rails_db_admin/rails_db_admin_16x16.png', sizingMethod='crop');
2
+ background-image:url( /assets/icons/rails_db_admin/rails_db_admin_16x16.png ) !important;
3
+ filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/assets/icons/rails_db_admin/rails_db_admin_16x16.png', sizingMethod='crop');
4
4
  }
5
5
 
6
6
  .icon-rails_db_admin-light {
7
- background-image:url( /images/icons/rails_db_admin/rails_db_admin_light_16x16.png ) !important;
8
- filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/icons/rails_db_admin/rails_db_admin_16x16.png', sizingMethod='crop');
9
- }
10
-
11
-
12
-
13
-
14
-
7
+ background-image:url( /assets/icons/rails_db_admin/rails_db_admin_light_16x16.png ) !important;
8
+ filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/assets/icons/rails_db_admin/rails_db_admin_16x16.png', sizingMethod='crop');
9
+ }
@@ -93,6 +93,7 @@ module RailsDbAdmin
93
93
  start = params[:start] || 0
94
94
  limit = params[:limit] || 30
95
95
  table = params[:table]
96
+ query_filter = params[:query_filter] || ''
96
97
 
97
98
  order = nil
98
99
 
@@ -102,7 +103,7 @@ module RailsDbAdmin
102
103
  order = 'created_at desc'
103
104
  end
104
105
 
105
- @json_data_builder.build_json_data(:table => table, :limit => limit, :offset => start, :order => order)
106
+ @json_data_builder.build_json_data(:table => table, :limit => limit, :offset => start, :order => order, :query_filter => query_filter)
106
107
  end
107
108
 
108
109
  def create_table_row
@@ -129,15 +130,15 @@ module RailsDbAdmin
129
130
 
130
131
  if @table_support.primary_key?(table)
131
132
  id = @table_support.primary_key(table)
132
- id[1] = params[:data][0][id[0]]
133
- params[:data][0].delete(id[0])
133
+ id[1] = params[:data]['id']
134
+ params[:data].delete('id')
134
135
 
135
- @table_support.update_table(table, id, params[:data][0])
136
+ @table_support.update_table(table, id, params[:data])
136
137
  record = @json_data_builder.get_row_data(table, id)
137
138
  else
138
- fake_id = params[:data][0]['fake_id']
139
+ fake_id = params[:data]['fake_id']
139
140
  @table_support.update_table_without_id(table, params[:data])
140
- record = @json_data_builder.get_row_data_no_id(table, params[:data][0])
141
+ record = @json_data_builder.get_row_data_no_id(table, params[:data])
141
142
  record['fake_id'] = fake_id
142
143
  end
143
144
 
@@ -5,7 +5,7 @@ module RailsDbAdmin
5
5
 
6
6
  def save_query
7
7
  query = params[:query]
8
- query_name = params[:query_name]
8
+ query_name = params[:query_name]
9
9
 
10
10
  @query_support.save_query(query, query_name)
11
11
 
@@ -25,7 +25,7 @@ module RailsDbAdmin
25
25
  end
26
26
 
27
27
  def delete_query
28
- query_name = params[:query_name]
28
+ query_name = params[:query_name]
29
29
  @query_support.delete_query(query_name)
30
30
 
31
31
  render :json => {:success => true}
@@ -51,16 +51,12 @@ module RailsDbAdmin
51
51
  end
52
52
 
53
53
  def open_and_execute_query
54
- result = {}
55
54
  query_name = params[:query_name]
56
55
 
57
56
  query = @query_support.get_query(query_name)
58
57
  columns, values, exception = @query_support.execute_sql(query)
59
58
 
60
- if columns.blank? || values.blank?
61
- result = {:success => false, :query => query,
62
- :exception => "Empty result set"}
63
- elsif exception.nil?
59
+ if exception.nil?
64
60
 
65
61
  columns_array = columns.collect do |column|
66
62
  RailsDbAdmin::Extjs::JsonColumnBuilder.build_readonly_column(column)
@@ -71,11 +67,11 @@ module RailsDbAdmin
71
67
  end
72
68
 
73
69
  result = {:success => true, :query => query,
74
- :columns => columns_array,
75
- :fields => fields_array, :data => values}
70
+ :columns => columns_array,
71
+ :fields => fields_array, :data => values}
76
72
  else
77
73
  result = {:success => false, :query => query,
78
- :exception => exception.gsub("\n", " ")}
74
+ :exception => exception.gsub("\n", " ")}
79
75
  end
80
76
 
81
77
  render :json => result
@@ -88,85 +84,103 @@ module RailsDbAdmin
88
84
  columns = @database_connection_class.connection.columns(table)
89
85
 
90
86
  render :json => {:success => true,
91
- :sql => sql,
92
- :columns => RailsDbAdmin::Extjs::JsonColumnBuilder.build_grid_columns(columns),
93
- :fields => RailsDbAdmin::Extjs::JsonColumnBuilder.build_store_fields(columns),
94
- :data => results}
87
+ :sql => sql,
88
+ :columns => RailsDbAdmin::Extjs::JsonColumnBuilder.build_grid_columns(columns),
89
+ :fields => RailsDbAdmin::Extjs::JsonColumnBuilder.build_store_fields(columns),
90
+ :data => results}
95
91
  end
96
92
 
97
93
  def execute_query
98
- sql = params[:sql]
99
- selection = params[:selected_sql]
100
- sql = sql.rstrip
101
- cursor_pos = params[:cursor_pos].to_i
102
-
103
- #append a semicolon as the last character if the
104
- #user forgot
105
- if !sql.end_with?(";")
106
- sql << ";"
107
- end
94
+ begin
108
95
 
109
- sql_arr = sql.split("\n")
110
- sql_stmt_arry = []
111
- sql_str = ""
112
-
113
- #search for the query to run based on cursor position if there
114
- #was nothing selected by the user
115
- if (selection == nil || selection == "")
116
- last_stmt_end = 0
117
- sql_arr.each_with_index do |val,idx|
118
- if val.match(';')
119
- sql_stmt_arry << {:begin => (sql_stmt_arry.length > 0) ? last_stmt_end +1 : 0, :end => idx}
120
- last_stmt_end = idx
121
- end
96
+ sql = params[:sql]
97
+ selection = params[:selected_sql]
98
+ sql = sql.rstrip
99
+ cursor_pos = params[:cursor_pos].to_i
100
+
101
+ # if we have report params process them
102
+ if params[:report_params]
103
+ # add current_user to locals
104
+ params[:report_params][:current_user] = current_user
105
+
106
+ sql = RailsDbAdmin::ErbStringParser.render(sql, locals: params[:report_params])
122
107
  end
123
108
 
124
- last_sql_stmt = sql_stmt_arry.length-1
125
- #run the first complete query if we're in whitespace
126
- #at the beginning of the text area
127
- if cursor_pos <= sql_stmt_arry[0].fetch(:begin)
128
- sql_str = sql_arr.values_at(sql_stmt_arry[0].fetch(:begin)..
129
- sql_stmt_arry[0].fetch(:end)).join(" ")
130
- #run the last query if we're in whitespace at the end of the
131
- #textarea
132
- elsif cursor_pos > sql_stmt_arry[last_sql_stmt].fetch(:begin)
133
- sql_str = sql_arr.values_at(
134
- sql_stmt_arry[last_sql_stmt].fetch(:begin)..
135
- sql_stmt_arry[last_sql_stmt].fetch(:end)).join(" ")
136
- #run query based on cursor position
137
- else
138
- sql_stmt_arry.each do |sql_stmt|
139
- if cursor_pos >= sql_stmt.fetch(:begin) &&
140
- cursor_pos <= sql_stmt.fetch(:end)
141
- sql_str = sql_arr.values_at(sql_stmt.fetch(:begin)..
142
- sql_stmt.fetch(:end)).join(" ")
109
+ # append a semicolon as the last character if the
110
+ # user forgot
111
+ if !sql.end_with?(";")
112
+ sql << ";"
113
+ end
114
+
115
+ sql_arr = sql.split("\n")
116
+ sql_stmt_arry = []
117
+ sql_str = ""
118
+
119
+ #search for the query to run based on cursor position if there
120
+ #was nothing selected by the user
121
+ if (selection == nil || selection == "")
122
+ last_stmt_end = 0
123
+ sql_arr.each_with_index do |val, idx|
124
+ if val.match(';')
125
+ sql_stmt_arry << {:begin => (sql_stmt_arry.length > 0) ? last_stmt_end +1 : 0, :end => idx}
126
+ last_stmt_end = idx
143
127
  end
144
128
  end
129
+
130
+ last_sql_stmt = sql_stmt_arry.length-1
131
+ #run the first complete query if we're in whitespace
132
+ #at the beginning of the text area
133
+ if cursor_pos <= sql_stmt_arry[0].fetch(:begin)
134
+ sql_str = sql_arr.values_at(sql_stmt_arry[0].fetch(:begin)..
135
+ sql_stmt_arry[0].fetch(:end)).join(" ")
136
+ #run the last query if we're in whitespace at the end of the
137
+ #textarea
138
+ elsif cursor_pos > sql_stmt_arry[last_sql_stmt].fetch(:begin)
139
+ sql_str = sql_arr.values_at(
140
+ sql_stmt_arry[last_sql_stmt].fetch(:begin)..
141
+ sql_stmt_arry[last_sql_stmt].fetch(:end)).join(" ")
142
+ #run query based on cursor position
143
+ else
144
+ sql_stmt_arry.each do |sql_stmt|
145
+ if cursor_pos >= sql_stmt.fetch(:begin) &&
146
+ cursor_pos <= sql_stmt.fetch(:end)
147
+ sql_str = sql_arr.values_at(sql_stmt.fetch(:begin)..
148
+ sql_stmt.fetch(:end)).join(" ")
149
+ end
150
+ end
151
+ end
152
+ else
153
+ sql_str = selection
145
154
  end
146
- else
147
- sql_str = selection
148
- end
149
155
 
150
- columns, values, exception = @query_support.execute_sql(sql_str)
156
+ columns, values, exception = @query_support.execute_sql(sql_str)
151
157
 
152
- if !exception.nil?
153
- result = {:success => false, :exception => exception.gsub("\n"," ")}
154
- elsif columns.empty? || values.empty?
155
- result = {:success => false, :exception => "Empty result set"}
156
- else exception.nil?
157
- columns_array = columns.collect do |column|
158
- RailsDbAdmin::Extjs::JsonColumnBuilder.build_readonly_column(column)
159
- end
158
+ if !exception.nil?
159
+ result = {:success => false, :message => exception.gsub("\n", " ")}
160
+ else
161
+ exception.nil?
162
+ columns_array = columns.collect do |column|
163
+ RailsDbAdmin::Extjs::JsonColumnBuilder.build_readonly_column(column)
164
+ end
160
165
 
161
- fields_array = columns.collect do |column|
162
- {:name => column}
166
+ fields_array = columns.collect do |column|
167
+ {:name => column}
168
+ end
169
+
170
+ result = {:success => true, :sql => sql,
171
+ :columns => columns_array,
172
+ :fields => fields_array, :data => values}
163
173
  end
174
+ render :json => result
175
+ rescue StandardError => ex
176
+ Rails.logger.error ex.message
177
+ Rails.logger.error ex.backtrace.join("\n")
178
+
179
+ # email notification
180
+ ExceptionNotifier.notify_exception(ex) if defined? ExceptionNotifier
164
181
 
165
- result = {:success => true, :sql => sql,
166
- :columns => columns_array,
167
- :fields => fields_array, :data => values}
182
+ render :json => {success: false, message: ex.message}
168
183
  end
169
- render :json => result
170
184
  end
171
185
 
172
186
  end #QueriesController
@@ -3,43 +3,121 @@ module RailsDbAdmin
3
3
  module Desktop
4
4
  class ReportsController < QueriesController
5
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} }
6
+ before_filter :set_file_support
10
7
 
11
- render :json => reports
8
+ def index
9
+ if params[:node] == 'root_node'
10
+ setup_tree
11
+ else
12
+ node = File.join(@file_support.root, params[:node])
13
+ report = get_report(params[:node])
14
+ unless report.nil?
15
+ render :json => @file_support.build_tree(node, :file_asset_holder => report, :preload => true)
16
+ else
17
+ render :json => {:success => false, :message => 'Could not find report'}
18
+ end
19
+ end
12
20
  end
13
21
 
14
22
  def create
15
- name = params[:name]
16
- internal_identifier = params[:internal_identifier]
23
+ begin
24
+ ActiveRecord::Base.transaction do
25
+
26
+ if params[:report_data].present?
27
+ Report.import(params[:report_data])
28
+ render :inline => {:success => true}.to_json
29
+ else
30
+ name = params[:name]
31
+ internal_identifier = params[:internal_identifier]
32
+ report = Report.new(:name => name, :internal_identifier => internal_identifier)
33
+
34
+ report.save!
35
+
36
+ render :json => {:success => true}
37
+ end
38
+
39
+ end
40
+ rescue ActiveRecord::RecordInvalid => invalid
41
+ Rails.logger.error invalid.record.errors.full_messages
42
+
43
+ render json: {success: false, message: invalid.record.errors.full_messages.join('</br>')}
44
+
45
+ rescue StandardError => ex
46
+ Rails.logger.error ex.message
47
+ Rails.logger.error ex.backtrace.join("\n")
48
+
49
+ ExceptionNotifier.notify_exception(ex) if defined? ExceptionNotifier
50
+
51
+ render json: {success: false, message: 'Error creating report'}
17
52
 
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
53
  end
24
54
  end
25
55
 
26
- def edit
27
- id = params[:id]
56
+ def query
57
+ render :json => {success: true, query: Report.find(params[:id]).query}
58
+ end
28
59
 
29
- report = Report.find(id)
60
+ def update
61
+ begin
62
+ ActiveRecord::Base.transaction do
63
+ report = Report.find(params[:id])
64
+
65
+ report.meta_data['print_page_size'] = params[:print_page_size].strip if params[:print_page_size]
66
+ report.meta_data['print_margin_top'] = params[:print_margin_top].strip if params[:print_margin_top]
67
+ report.meta_data['print_margin_right'] = params[:print_margin_right].strip if params[:print_margin_right]
68
+ report.meta_data['print_margin_bottom'] = params[:print_margin_bottom].strip if params[:print_margin_bottom]
69
+ report.meta_data['print_margin_left'] = params[:print_margin_left].strip if params[:print_margin_left]
70
+ report.meta_data['print_orientation'] = params[:print_orientation].strip if params[:print_orientation]
71
+ report.meta_data['auto_execute'] = params['auto_execute'] == 'on'
72
+
73
+ unless params[:report_name].blank?
74
+ report.name = params[:report_name].squish
75
+ end
76
+
77
+ unless params[:report_iid].blank?
78
+ report.internal_identifier = params[:report_iid].squish
79
+ end
80
+
81
+ if params.key?(:report_params)
82
+ report.meta_data['params'] = params[:report_params].nil? ? [] : params[:report_params]
83
+ end
84
+
85
+ report_roles = params[:report_roles]
86
+ if report_roles
87
+ available_role_types = report.role_types.pluck(:internal_identifier)
88
+ # delete all roles associated with the report
89
+ report.entity_party_roles.destroy_all
90
+
91
+ # assign report roles
92
+ report_roles.split(',').each do |role_type|
93
+ report.add_party_with_role(
94
+ current_user.party,
95
+ RoleType.iid(role_type)
96
+ ) unless available_role_types.include?(role_type.to_sym)
97
+ end
98
+ end
99
+
100
+ render json: {success: report.save!}
101
+
102
+ end
103
+ rescue ActiveRecord::RecordInvalid => invalid
104
+ Rails.logger.error invalid.record.errors.full_messages
105
+
106
+ render json: {success: false, message: invalid.record.errors.full_messages.join('</br>')}
107
+
108
+ rescue StandardError => ex
109
+ Rails.logger.error ex.message
110
+ Rails.logger.error ex.backtrace.join("\n")
111
+
112
+ ExceptionNotifier.notify_exception(ex) if defined? ExceptionNotifier
113
+
114
+ render json: {success: false, message: 'Could not save report'}
30
115
 
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
116
  end
39
117
  end
40
118
 
41
119
  def save
42
- id = params[:id]
120
+ id = params[:id]
43
121
  query = params[:query]
44
122
  template = params[:template]
45
123
 
@@ -55,16 +133,199 @@ module RailsDbAdmin
55
133
  end
56
134
  end
57
135
 
58
- def delete
59
- id = params[:id]
136
+ def save_query
137
+ id = params[:id]
138
+ query = params[:query]
139
+
140
+ report = Report.find(id)
141
+
142
+ report.query = query
143
+
144
+ if report.save
145
+ render :json => {:success => true}
146
+ else
147
+ render :json => {:success => false}
148
+ end
149
+ end
60
150
 
61
- if Report.find(id).destroy
151
+ def delete
152
+ report = Report.find(params[:id])
153
+ if report.destroy
62
154
  render :json => {:success => true}
63
155
  else
64
156
  render :json => {:success => false}
65
157
  end
66
158
  end
67
159
 
160
+ def export
161
+ report = Report.find(params[:id])
162
+ zip_path = report.export
163
+ send_file(zip_path.to_s, :stream => false) rescue raise "Error sending #{zip_path} file"
164
+ end
165
+
166
+ def create_file
167
+ begin
168
+ path = File.join(@file_support.root, params[:path])
169
+ name = params[:name]
170
+
171
+ report = get_report(path)
172
+ report.add_file('#Empty File', File.join(path, name))
173
+
174
+ render :json => {:success => true, :node => @file_support.find_node(File.join(path, name), {:file_asset_holder => report})}
175
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability => ex
176
+ render :json => {:success => false, :message => ex.message}
177
+ end
178
+ end
179
+
180
+ def create_folder
181
+ begin
182
+ path = File.join(@file_support.root, params[:path])
183
+ name = params[:name]
184
+ @file_support.create_folder(path, name)
185
+ render :json => {:success => true, :node => @file_support.find_node(File.join(path, name), {keep_full_path: false})}
186
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability => ex
187
+ render :json => {:success => false, :message => ex.message}
188
+ end
189
+ end
190
+
191
+ def update_file
192
+ begin
193
+ path = File.join(@file_support.root, params[:node])
194
+ content = params[:content]
195
+ @file_support.update_file(path, content)
196
+ nodes = params[:node].split('/')
197
+ if nodes.last == 'base.html.erb'
198
+ report = Report.iid(nodes[nodes.index("compass_ae_reports") + 1])
199
+ report.template = content
200
+ report.save
201
+ end
202
+ render :json => {:success => true}
203
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability => ex
204
+ render :json => {:success => false, :message => ex.message}
205
+ end
206
+ end
207
+
208
+ def save_move
209
+ result = {}
210
+ nodes_to_move = (params[:selected_nodes] ? JSON(params[:selected_nodes]) : [params[:node]])
211
+ begin
212
+ nodes_to_move.each do |node|
213
+ path = File.join(@file_support.root, node)
214
+ new_parent_path = File.join(@file_support.root, params[:parent_node])
215
+
216
+ unless @file_support.exists? path
217
+ result = {:success => false, :msg => 'File does not exist.'}
218
+ else
219
+ report_file = get_report_file(path)
220
+ report_file.move(params[:parent_node])
221
+ result = {:success => true, :msg => "#{File.basename(path)} was moved to #{new_parent_path} successfully"}
222
+ end
223
+ end
224
+ render :json => result
225
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability => ex
226
+ render :json => {:success => false, :message => ex.message}
227
+ end
228
+ end
229
+
230
+ def get_contents
231
+ path = File.join(@file_support.root, params[:node])
232
+ contents, message = @file_support.get_contents(path)
233
+
234
+ if contents.nil?
235
+ render :text => message
236
+ else
237
+ render :text => contents
238
+ end
239
+ end
240
+
241
+ def download_file
242
+ begin
243
+ path = File.join(@file_support.root, params[:path])
244
+ contents, message = @file_support.get_contents(path)
245
+
246
+ send_data contents, :filename => File.basename(path)
247
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability => ex
248
+ render :json => {:success => false, :message => ex.message}
249
+ end
250
+ end
251
+
252
+ def upload_file
253
+ begin
254
+ result = {}
255
+ upload_path = params[:directory]
256
+ name = params[:name]
257
+ data = request.raw_post
258
+
259
+ report = get_report(upload_path)
260
+ name = File.join(@file_support.root, upload_path, name)
261
+
262
+ begin
263
+ report.add_file(data, name)
264
+ result = {:success => true, :node => @file_support.find_node(name, {:file_asset_holder => report})}
265
+ rescue => ex
266
+ logger.error ex.message
267
+ logger.error ex.backtrace.join("\n")
268
+ result = {:success => false, :error => "Error uploading #{name}"}
269
+ end
270
+
271
+ render :inline => result.to_json
272
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability => ex
273
+ render :json => {:success => false, :message => ex.message}
274
+ end
275
+ end
276
+
277
+ def delete_file
278
+ messages = []
279
+ nodes_to_delete = (params[:selected_nodes] ? JSON(params[:selected_nodes]) : [params[:node]])
280
+ begin
281
+ result = false
282
+ nodes_to_delete.each do |path|
283
+ begin
284
+ name = File.basename(path)
285
+ result, message, is_folder = @file_support.delete_file(File.join(@file_support.root, path), {force: true})
286
+ if result && !is_folder
287
+ report_file = get_report_file(path)
288
+ report_file.destroy
289
+ end
290
+ messages << message
291
+ rescue StandardError => ex
292
+ Rails.logger.error ex.message
293
+ Rails.logger.error ex.backtrace.join("\n")
294
+
295
+ ExceptionNotifier.notify_exception(ex) if defined? ExceptionNotifier
296
+
297
+ render :json => {:success => false, :error => "Error deleting #{name}"} and return
298
+ end
299
+ end # end nodes_to_delete.each
300
+ if result
301
+ render :json => {:success => true, :message => messages.join(',')}
302
+ else
303
+ render :json => {:success => false, :error => messages.join(',')}
304
+ end
305
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability => ex
306
+ render :json => {:success => false, :message => ex.message}
307
+ end
308
+ end
309
+
310
+ def rename_file
311
+ begin
312
+ result = {:success => true, :data => {:success => true}}
313
+ path = params[:node]
314
+ name = params[:file_name]
315
+
316
+ result, message = @file_support.rename_file(File.join(@file_support.root, path), name)
317
+ if result
318
+ report_file = get_report_file(path)
319
+ report_file.name = name
320
+ report_file.save
321
+ end
322
+
323
+ render :json => {:success => true, :message => message}
324
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability => ex
325
+ render :json => {:success => false, :message => ex.message}
326
+ end
327
+ end
328
+
68
329
  def open_query
69
330
  query_name = params[:query_name]
70
331
  query = @query_support.get_query(query_name)
@@ -72,7 +333,77 @@ module RailsDbAdmin
72
333
  render :json => {:success => true, :query => query}
73
334
  end
74
335
 
75
- end #QueriesController
76
- end #Desktop
77
- end #ErpApp
78
- end #RailsDbAdmin
336
+ def setup_tree
337
+ tree = []
338
+ Report.all.collect do |report|
339
+ report_data = build_report_data(report)
340
+
341
+ ['stylesheets', 'images', 'templates', 'javascripts', 'query'].each do |resource_folder|
342
+ report_data[:children] << {
343
+ :reportId => report.id,
344
+ :reportName => report.name,
345
+ :reportIid => report.internal_identifier,
346
+ :text => resource_folder.titleize,
347
+ :iconCls => case resource_folder
348
+ when 'query'
349
+ 'icon-query'
350
+ else
351
+ 'icon-content'
352
+ end,
353
+ :id => "#{report.url}/#{resource_folder}",
354
+ :leaf => (resource_folder == 'query'),
355
+ :handleContextMenu => (resource_folder == 'query') || (resource_folder == 'preview_report')
356
+ }
357
+ end
358
+
359
+ tree << report_data
360
+ end
361
+
362
+ render :json => tree
363
+ end
364
+
365
+ def get_report(path)
366
+ reports_index = path.index('reports')
367
+ path = path[reports_index..path.length]
368
+ report_name = path.split('/')[1]
369
+ @report = Report.iid(report_name)
370
+
371
+ @report
372
+ end
373
+
374
+ def get_report_file(path)
375
+ report = get_report(path)
376
+ file_dir = ::File.dirname(path).gsub(Regexp.new(Rails.root.to_s), '')
377
+ report.files.where('name = ? and directory = ?', ::File.basename(path), file_dir).first
378
+ end
379
+
380
+ def set_file_support
381
+ @file_support = ErpTechSvcs::FileSupport::Base.new(:storage => ErpTechSvcs::Config.file_storage)
382
+ end
383
+
384
+ private
385
+
386
+ def build_report_data(report)
387
+ meta_data = report.meta_data || {}
388
+ meta_data.merge!({
389
+ params: report.meta_data['params'] || [],
390
+ roles: report.role_types.pluck(:internal_identifier).join(','),
391
+ })
392
+
393
+ {
394
+ text: report.name,
395
+ reportName: report.name,
396
+ reportId: report.id,
397
+ internalIdentifier: report.internal_identifier,
398
+ iconCls: 'icon-content',
399
+ isReport: true,
400
+ handleContextMenu: true,
401
+ children: [],
402
+ reportMetaData: meta_data
403
+ }
404
+ end
405
+
406
+ end # ReportsController
407
+ end # Desktop
408
+ end # ErpApp
409
+ end # RailsDbAdmin