smartkiosk-server 0.11.6 → 0.11.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,7 +13,7 @@ ActiveAdmin.register ReportResult do
13
13
  package = Axlsx::Package.new do |p|
14
14
  p.workbook.add_worksheet(:name => "Report") do |ws|
15
15
  bold = ws.styles.add_style :b => true, :alignment=> {:horizontal => :center}
16
- ws.add_row fields.map{|x| view_context.localize_report_fields(x)[0]}, :style => bold
16
+ ws.add_row fields.map{|x| report_result.human_column_name(x)}, :style => bold
17
17
 
18
18
  result.each do |r|
19
19
  row = []
@@ -50,7 +50,7 @@ ActiveAdmin.register ReportResult do
50
50
  table do
51
51
  tr do
52
52
  fields.each do |field|
53
- th localize_report_fields(field)[0]
53
+ th report_result.human_column_name(field)
54
54
  end
55
55
  end
56
56
  result.each do |row|
@@ -63,17 +63,17 @@ ActiveAdmin.register ReportTemplate do
63
63
  status_boolean(self, x.open?)
64
64
  end
65
65
  row :groupping do
66
- localize_report_fields(report_template.groupping)[0] unless report_template.groupping.blank?
66
+ report_template.human_groupping_name
67
67
  end
68
68
  row :fields do
69
69
  unless report_template.fields.blank?
70
70
  report_template.fields.select{|x| !x.blank?}.map do |x|
71
- localize_report_fields(x)[0]
71
+ report_template.human_field_name x
72
72
  end.join ', '
73
73
  end
74
74
  end
75
75
  row :sorting do
76
- localize_report_fields(report_template.sorting)[0] unless report_template.sorting.blank?
76
+ report_template.human_sorting_name
77
77
  end
78
78
  row :sort_desc do |x|
79
79
  status_boolean(self, x.sort_desc?)
@@ -90,14 +90,10 @@ ActiveAdmin.register ReportTemplate do
90
90
  report_template.report_builder.conditions.each do |condition, values|
91
91
  tr do
92
92
  th do
93
- localize_report_condition_title(report_template.report_builder, condition)
93
+ report_template.human_condition_name condition
94
94
  end
95
95
  td do
96
- unless report_template.conditions[condition].blank?
97
- localize_report_condition_value(report_template.report_builder, condition, report_template.conditions[condition])
98
- else
99
- span(I18n.t('active_admin.empty'), :class => 'empty')
100
- end
96
+ report_template.human_condition_values(condition) || span(I18n.t('active_admin.empty'), :class => 'empty')
101
97
  end
102
98
  end
103
99
  end
@@ -140,7 +136,7 @@ ActiveAdmin.register ReportTemplate do
140
136
  if f.object.report_builder
141
137
  f.inputs I18n.t('smartkiosk.admin.panels.report_templates.form.select') do
142
138
  f.input :groupping, :as => :select,
143
- :collection => localize_report_fields(f.object.report_builder.groupping),
139
+ :collection => f.object.report_builder.human_groupping_names,
144
140
  :input_html => {
145
141
  :class => 'chosen',
146
142
  :onchange => "reportChangeGroupping($(this).val())"
@@ -148,7 +144,7 @@ ActiveAdmin.register ReportTemplate do
148
144
 
149
145
  ([''] + f.object.report_builder.groupping).each do |g|
150
146
  f.input :fields, :as => :selectable_check_boxes,
151
- :collection => localize_report_fields(f.object.report_builder.fields[g]),
147
+ :collection => f.object.report_builder.human_groupping_field_names(g),
152
148
  :wrapper_html => {
153
149
  :class => "groupping groupping-#{g.gsub '.', '-'}",
154
150
  :style => ('display: none' unless f.object.groupping == g)
@@ -156,11 +152,11 @@ ActiveAdmin.register ReportTemplate do
156
152
  end
157
153
 
158
154
  f.input :calculations, :as => :selectable_check_boxes,
159
- :collection => localize_report_calculations(f.object.report_builder)
155
+ :collection => f.object.report_builder.human_calculation_names
160
156
 
161
157
  ([''] + f.object.report_builder.groupping).each do |g|
162
158
  f.input :sorting, :as => :select,
163
- :collection => localize_report_fields(f.object.report_builder.fields[g]),
159
+ :collection => f.object.report_builder.human_groupping_field_names(g),
164
160
  :input_html => {
165
161
  :id => "report_template_sorting_#{g.gsub '.', '-'}",
166
162
  :style => 'min-width: 50%',
@@ -181,8 +177,8 @@ ActiveAdmin.register ReportTemplate do
181
177
  f.inputs I18n.t('smartkiosk.admin.panels.report_templates.form.conditions') do
182
178
  f.object.report_builder.conditions.each do |condition, values|
183
179
  f.input "condition_#{condition}", :as => :select,
184
- :label => localize_report_condition_title(f.object.report_builder, condition),
185
- :collection => localize_report_conditions(f.object.report_builder, condition),
180
+ :label => f.object.report_builder.human_condition_name(condition),
181
+ :collection => f.object.report_builder.human_condition_values(condition).invert,
186
182
  :input_html => {
187
183
  :class => 'chosen',
188
184
  :multiple => true,
@@ -109,24 +109,15 @@ ActiveAdmin.register Report do
109
109
  result = report.report_results.first
110
110
 
111
111
  panel "#{I18n.t 'smartkiosk.admin.panels.reports.last_result'} (#{result.rows})" do
112
- result = result.data
113
- unless result.blank?
114
- fields = result.first.keys
112
+ unless result.data.blank?
113
+ fields = result.data.first.keys
115
114
  table do
116
115
  tr do
117
116
  fields.each do |field|
118
- data = field.split('.')
119
-
120
- if data.first == 'calculations'
121
- field = I18n.t "smartkiosk.reports.data.#{report.report_template.kind}.calculations.#{data.last}"
122
- else
123
- field = localize_report_fields(field)[0]
124
- end
125
-
126
- th field
117
+ th result.human_column_name(field)
127
118
  end
128
119
  end
129
- result.each do |row|
120
+ result.data.each do |row|
130
121
  tr do
131
122
  fields.each do |field|
132
123
  td row[field]
@@ -68,4 +68,9 @@ class Report < ActiveRecord::Base
68
68
  return :error
69
69
  end
70
70
  end
71
+
72
+ def decode_field(field)
73
+ raise "Incorrect field '#{field}' given" unless field.starts_with?('_')
74
+ report_template.fields[field[1..-1].to_i]
75
+ end
71
76
  end
@@ -3,9 +3,18 @@ class ReportResult < ActiveRecord::Base
3
3
  # RELATIONS
4
4
  #
5
5
  belongs_to :report
6
+ has_one :report_template, :through => :report
6
7
 
7
8
  #
8
9
  # MODIFICATIONS
9
10
  #
10
11
  serialize :data
12
+
13
+ def human_column_name(field)
14
+ if field.starts_with?('_')
15
+ report_template.human_field_name report.decode_field(field)
16
+ else
17
+ report_template.human_calculation_name field
18
+ end
19
+ end
11
20
  end
@@ -18,11 +18,14 @@ class ReportTemplate < ActiveRecord::Base
18
18
  #
19
19
  # MODIFCIATIONS
20
20
  #
21
- serialize :groupping
22
21
  serialize :fields
23
22
  serialize :calculations
24
23
  serialize :conditions
25
24
 
25
+ before_save do
26
+ fields.select!{|x| !x.blank?}
27
+ end
28
+
26
29
  #
27
30
  # METHODS
28
31
  #
@@ -53,4 +56,36 @@ class ReportTemplate < ActiveRecord::Base
53
56
  self.conditions[name]
54
57
  end
55
58
  end
59
+
60
+ def human_field_name(field)
61
+ report_builder.human_field_name field
62
+ end
63
+
64
+ def human_calculation_name(field)
65
+ report_builder.human_calculation_name field
66
+ end
67
+
68
+ def human_condition_name(field)
69
+ report_builder.human_condition_name field
70
+ end
71
+
72
+ def human_groupping_name
73
+ return nil if groupping.blank?
74
+ human_field_name groupping
75
+ end
76
+
77
+ def human_sorting_name
78
+ return nil if sorting.blank?
79
+ human_field_name sorting
80
+ end
81
+
82
+ def human_condition_values(condition)
83
+ return nil if conditions[condition].blank?
84
+
85
+ values = conditions[condition].map do |v|
86
+ report_builder.human_condition_values(condition)[v]
87
+ end
88
+
89
+ values.join(', ')
90
+ end
56
91
  end
@@ -69,7 +69,7 @@ class AgentsReport < ReportBuilder::Base
69
69
 
70
70
  def calculations
71
71
  {
72
- :quantity => lambda{|q, t| t.groupping.blank? ? q : q.project('COUNT(*) AS "calculations.quantity"').where(tables[:agent][:agent_id].not_eq nil) }
72
+ :quantity => lambda{|q, t| t.groupping.blank? ? q : q.project('COUNT(*) AS "quantity"').where(tables[:agent][:agent_id].not_eq nil) }
73
73
  }.with_indifferent_access
74
74
  end
75
75
 
@@ -138,9 +138,9 @@ class CollectionsReport < ReportBuilder::Base
138
138
 
139
139
  def calculations
140
140
  {
141
- :cash_sum => lambda{|q, t| t.groupping.blank? ? q : q.project('SUM(collections.cash_sum) AS "calculations.cash_sum"') },
142
- :approved_payments_sum => lambda{|q, t| t.groupping.blank? ? q : q.project('SUM(collections.approved_payments_sum) AS "calculations.approved_payments_sum"') },
143
- :payments_sum => lambda{|q, t| t.groupping.blank? ? q : q.project('SUM(collections.payments_sum) AS "calculations.payments_sum"') }
141
+ :cash_sum => lambda{|q, t| t.groupping.blank? ? q : q.project('SUM(collections.cash_sum) AS "cash_sum"') },
142
+ :approved_payments_sum => lambda{|q, t| t.groupping.blank? ? q : q.project('SUM(collections.approved_payments_sum) AS "approved_payments_sum"') },
143
+ :payments_sum => lambda{|q, t| t.groupping.blank? ? q : q.project('SUM(collections.payments_sum) AS "payments_sum"') }
144
144
  }.with_indifferent_access
145
145
  end
146
146
 
@@ -172,10 +172,10 @@ class PaymentsReport < ReportBuilder::Base
172
172
 
173
173
  def calculations
174
174
  {
175
- :quantity => lambda{|q, t| t.groupping.blank? ? q : q.project('COUNT(*) AS "calculations.quantity"') },
176
- :enrolled => lambda{|q, t| t.groupping.blank? ? q : q.project('SUM(enrolled_amount) AS "calculations.enrolled"') },
177
- :paid => lambda{|q, t| t.groupping.blank? ? q : q.project('SUM(paid_amount) AS "calculations.paid"') },
178
- :commission => lambda{|q, t| t.groupping.blank? ? q : q.project('SUM(commission_amount) AS "calculations.commission"') }
175
+ :quantity => lambda{|q, t| t.groupping.blank? ? q : q.project('COUNT(*) AS "quantity"') },
176
+ :enrolled => lambda{|q, t| t.groupping.blank? ? q : q.project('SUM(enrolled_amount) AS "enrolled"') },
177
+ :paid => lambda{|q, t| t.groupping.blank? ? q : q.project('SUM(paid_amount) AS "paid"') },
178
+ :commission => lambda{|q, t| t.groupping.blank? ? q : q.project('SUM(commission_amount) AS "commission"') }
179
179
  }.with_indifferent_access
180
180
  end
181
181
 
@@ -111,7 +111,7 @@ class TerminalsReport < ReportBuilder::Base
111
111
 
112
112
  def calculations
113
113
  {
114
- :quantity => lambda{|q, t| t.groupping.blank? ? q : q.project('COUNT(*) AS "calculations.quantity"') }
114
+ :quantity => lambda{|q, t| t.groupping.blank? ? q : q.project('COUNT(*) AS "quantity"') }
115
115
  }.with_indifferent_access
116
116
  end
117
117
 
@@ -7,8 +7,7 @@ ru:
7
7
  quantity: Количество
8
8
  conditions:
9
9
  agent:
10
- agent_id:
11
- title: Агент
10
+ agent_id: Агент
12
11
  collections:
13
12
  calculations:
14
13
  approved_payments_sum: Сумма проведенных платежей
@@ -22,19 +21,15 @@ ru:
22
21
  quantity: Количество
23
22
  conditions:
24
23
  payment:
25
- state:
26
- title: Состояние
27
- payment_type:
28
- title: Тип
29
- provider_id:
30
- title: Получатели
24
+ state: Состояние
25
+ payment_type: Тип
26
+ provider_id: Получатели
31
27
  terminals:
32
28
  calculations:
33
29
  quantity: Количество
34
30
  conditions:
35
31
  terminal:
36
- condition:
37
- title: Состояние
32
+ condition: Состояние
38
33
  kinds:
39
34
  # preprocessing: Предпроцессинг
40
35
  agents: Агенты
@@ -46,7 +46,7 @@ module ReportBuilder
46
46
  'postgresql' => 'MIN'
47
47
  }[ActiveRecord::Base.configurations[Rails.env]['adapter']]
48
48
 
49
- fields = template.fields.select{|x| !x.blank?}.each do |field|
49
+ fields = template.fields.each_with_index do |field, i|
50
50
  projection = arelize(field)
51
51
 
52
52
  if !aggregate.blank? && !template.groupping.blank?
@@ -55,7 +55,7 @@ module ReportBuilder
55
55
  )
56
56
  end
57
57
 
58
- projection = projection.as("\"#{field}\"")
58
+ projection = projection.as("\"_#{i}\"")
59
59
  query = query.project(projection)
60
60
  end
61
61
 
@@ -84,5 +84,39 @@ module ReportBuilder
84
84
 
85
85
  query.to_sql
86
86
  end
87
+
88
+ def human_field_name(field)
89
+ model, name = field.split '.'
90
+ title = []
91
+
92
+ title << I18n.t("activerecord.models.#{model}", :count => 1)
93
+ title << I18n.t("activerecord.attributes.#{model}.#{name}")
94
+
95
+ title.join(': ')
96
+ end
97
+
98
+ def human_calculation_name(field)
99
+ I18n.t "smartkiosk.reports.data.#{keyword}.calculations.#{field}"
100
+ end
101
+
102
+ def human_condition_name(field)
103
+ I18n.t "smartkiosk.reports.data.#{keyword}.conditions.#{field}"
104
+ end
105
+
106
+ def human_groupping_names
107
+ groupping.map{|x| [human_field_name(x), x]}
108
+ end
109
+
110
+ def human_groupping_field_names(groupping)
111
+ fields[groupping].map{|x| [human_field_name(x), x]}
112
+ end
113
+
114
+ def human_calculation_names
115
+ calculations.keys.map{|x| [human_calculation_name(x), x]}
116
+ end
117
+
118
+ def human_condition_values(condition)
119
+ conditions[condition].call().with_indifferent_access
120
+ end
87
121
  end
88
122
  end
@@ -1,5 +1,5 @@
1
1
  module Smartkiosk
2
2
  module Server
3
- VERSION = '0.11.6'
3
+ VERSION = '0.11.7'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartkiosk-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.6
4
+ version: 0.11.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-03-25 00:00:00.000000000 Z
13
+ date: 2013-04-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -123,7 +123,6 @@ files:
123
123
  - app/controllers/terminal_orders_controller.rb
124
124
  - app/controllers/terminal_pings_controller.rb
125
125
  - app/controllers/welcome_controller.rb
126
- - app/helpers/active_admin/report_templates_helper.rb
127
126
  - app/helpers/active_admin/views_helper.rb
128
127
  - app/helpers/application_helper.rb
129
128
  - app/mailers/.gitkeep
@@ -334,7 +333,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
334
333
  version: '0'
335
334
  segments:
336
335
  - 0
337
- hash: 4539088124566055437
336
+ hash: -3103762174964566922
338
337
  required_rubygems_version: !ruby/object:Gem::Requirement
339
338
  none: false
340
339
  requirements:
@@ -1,56 +0,0 @@
1
- module ActiveAdmin::ReportTemplatesHelper
2
- def localize_report_fields(data)
3
- if data.is_a? Array
4
- data.map do |x|
5
- localize_report_entry x
6
- end
7
- else
8
- localize_report_entry data
9
- end
10
- end
11
-
12
- def localize_report_entry(entry)
13
- model, name = entry.split '.'
14
-
15
- title = I18n.t("activerecord.models.#{model}", :count => 1)
16
- title += ' / '
17
- title += I18n.t("activerecord.attributes.#{model}.#{name}")
18
-
19
- [title, entry]
20
- end
21
-
22
- def localize_report_calculations(builder)
23
- builder.calculations.keys.map do |x|
24
- title = I18n.t "smartkiosk.reports.data.#{builder.keyword}.calculations.#{x}"
25
- [title, x]
26
- end
27
- end
28
-
29
- def localize_report_condition_title(builder, field)
30
- I18n.t "smartkiosk.reports.data.#{builder.keyword}.conditions.#{field}.title"
31
- end
32
-
33
- def localize_report_condition_value(builder, field, value)
34
- condition = builder.conditions[field]
35
- collection = if condition.is_a?(Array)
36
- I18n.t "smartkiosk.reports.data.#{builder.keyword}.conditions.#{field}.values"
37
- else
38
- condition.call().with_indifferent_access
39
- end
40
-
41
- return value.is_a?(Array) ? value.map{|x| collection[x]}.join(', ') : collection[value]
42
- end
43
-
44
- def localize_report_conditions(builder, field)
45
- condition = builder.conditions[field]
46
-
47
- if condition.is_a?(Array)
48
- return condition.map do |x|
49
- title = I18n.t "smartkiosk.reports.data.#{builder.keyword}.conditions.#{field}.values.#{x}"
50
- [title, x]
51
- end
52
- elsif condition.is_a?(Proc)
53
- return condition.call().invert
54
- end
55
- end
56
- end