smartkiosk-server 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (254) hide show
  1. data/.gitignore +32 -0
  2. data/.rspec +1 -0
  3. data/Capfile +4 -0
  4. data/Gemfile +71 -0
  5. data/Gemfile.lock +439 -0
  6. data/Guardfile +25 -0
  7. data/LICENSE +287 -0
  8. data/README.md +13 -0
  9. data/Rakefile +5 -0
  10. data/app/acquirers/cards_mkb_acquirer.rb +87 -0
  11. data/app/acquirers/cash_acquirer.rb +22 -0
  12. data/app/admin/agents.rb +108 -0
  13. data/app/admin/collections.rb +62 -0
  14. data/app/admin/commissions.rb +87 -0
  15. data/app/admin/gateways.rb +183 -0
  16. data/app/admin/limits.rb +82 -0
  17. data/app/admin/payments.rb +246 -0
  18. data/app/admin/provider_groups.rb +60 -0
  19. data/app/admin/provider_profiles.rb +11 -0
  20. data/app/admin/provider_receipt_templates.rb +82 -0
  21. data/app/admin/providers.rb +201 -0
  22. data/app/admin/rebates.rb +83 -0
  23. data/app/admin/report_results.rb +66 -0
  24. data/app/admin/report_templates.rb +209 -0
  25. data/app/admin/reports.rb +158 -0
  26. data/app/admin/revisions.rb +120 -0
  27. data/app/admin/system_receipt_templates.rb +76 -0
  28. data/app/admin/terminal_builds.rb +39 -0
  29. data/app/admin/terminal_profiles.rb +123 -0
  30. data/app/admin/terminals.rb +388 -0
  31. data/app/admin/users.rb +117 -0
  32. data/app/admin/versions.rb +131 -0
  33. data/app/admin/welcome.rb +64 -0
  34. data/app/assets/fonts/PT_Sans-Web-Bold.eot +0 -0
  35. data/app/assets/fonts/PT_Sans-Web-Bold.svg +6386 -0
  36. data/app/assets/fonts/PT_Sans-Web-Bold.ttf +0 -0
  37. data/app/assets/fonts/PT_Sans-Web-Bold.woff +0 -0
  38. data/app/assets/fonts/PT_Sans-Web-Regular.eot +0 -0
  39. data/app/assets/fonts/PT_Sans-Web-Regular.svg +5650 -0
  40. data/app/assets/fonts/PT_Sans-Web-Regular.ttf +0 -0
  41. data/app/assets/fonts/PT_Sans-Web-Regular.woff +0 -0
  42. data/app/assets/images/chosen-sprite.png +0 -0
  43. data/app/assets/javascripts/active_admin/chosen.js.erb.coffee +12 -0
  44. data/app/assets/javascripts/active_admin/qtip.js.coffee +22 -0
  45. data/app/assets/javascripts/active_admin/sortable_forms.js.coffee +14 -0
  46. data/app/assets/javascripts/active_admin.js.coffee +9 -0
  47. data/app/assets/javascripts/application.js +15 -0
  48. data/app/assets/javascripts/report_templates.js.coffee +10 -0
  49. data/app/assets/javascripts/terminals.js.coffee +12 -0
  50. data/app/assets/stylesheets/active_admin/PIE.css.scss +18 -0
  51. data/app/assets/stylesheets/active_admin/filter_numeric_range.css.scss +14 -0
  52. data/app/assets/stylesheets/active_admin/selectable_check_boxes.css.scss +12 -0
  53. data/app/assets/stylesheets/active_admin/sortable_forms.css.scss +11 -0
  54. data/app/assets/stylesheets/active_admin.css.scss +705 -0
  55. data/app/assets/stylesheets/fonts.css.scss +14 -0
  56. data/app/assets/stylesheets/provider_groups.css.scss +12 -0
  57. data/app/assets/stylesheets/provider_receipt_templates.css.scss +12 -0
  58. data/app/assets/stylesheets/terminals.css.scss +9 -0
  59. data/app/controllers/application_controller.rb +12 -0
  60. data/app/controllers/collections_controller.rb +10 -0
  61. data/app/controllers/payments_controller.rb +73 -0
  62. data/app/controllers/system_receipt_templates_controller.rb +10 -0
  63. data/app/controllers/terminal_builds_controller.rb +5 -0
  64. data/app/controllers/terminal_orders_controller.rb +25 -0
  65. data/app/controllers/terminal_pings_controller.rb +45 -0
  66. data/app/controllers/welcome_controller.rb +5 -0
  67. data/app/helpers/active_admin/report_templates_helper.rb +56 -0
  68. data/app/helpers/active_admin/views_helper.rb +20 -0
  69. data/app/helpers/application_helper.rb +2 -0
  70. data/app/mailers/.gitkeep +0 -0
  71. data/app/models/.gitkeep +0 -0
  72. data/app/models/ability.rb +30 -0
  73. data/app/models/agent.rb +24 -0
  74. data/app/models/collection.rb +65 -0
  75. data/app/models/commission.rb +77 -0
  76. data/app/models/commission_section.rb +75 -0
  77. data/app/models/gateway.rb +99 -0
  78. data/app/models/gateway_attachment.rb +9 -0
  79. data/app/models/gateway_setting.rb +7 -0
  80. data/app/models/gateway_switch.rb +7 -0
  81. data/app/models/limit.rb +77 -0
  82. data/app/models/limit_section.rb +58 -0
  83. data/app/models/payment.rb +322 -0
  84. data/app/models/provider.rb +59 -0
  85. data/app/models/provider_field.rb +7 -0
  86. data/app/models/provider_gateway.rb +47 -0
  87. data/app/models/provider_group.rb +45 -0
  88. data/app/models/provider_profile.rb +9 -0
  89. data/app/models/provider_rebate.rb +69 -0
  90. data/app/models/provider_receipt_template.rb +85 -0
  91. data/app/models/rebate.rb +84 -0
  92. data/app/models/report.rb +71 -0
  93. data/app/models/report_result.rb +11 -0
  94. data/app/models/report_template.rb +56 -0
  95. data/app/models/revision.rb +104 -0
  96. data/app/models/role.rb +48 -0
  97. data/app/models/system_receipt_template.rb +13 -0
  98. data/app/models/terminal.rb +126 -0
  99. data/app/models/terminal_build.rb +62 -0
  100. data/app/models/terminal_order.rb +42 -0
  101. data/app/models/terminal_ping.rb +120 -0
  102. data/app/models/terminal_profile.rb +51 -0
  103. data/app/models/terminal_profile_promotion.rb +18 -0
  104. data/app/models/terminal_profile_provider.rb +11 -0
  105. data/app/models/terminal_profile_provider_group.rb +19 -0
  106. data/app/models/user.rb +38 -0
  107. data/app/models/user_role.rb +45 -0
  108. data/app/reports/agents_report.rb +81 -0
  109. data/app/reports/collections_report.rb +151 -0
  110. data/app/reports/payments_report.rb +189 -0
  111. data/app/reports/terminals_report.rb +123 -0
  112. data/app/uploaders/file_uploader.rb +53 -0
  113. data/app/uploaders/icon_uploader.rb +15 -0
  114. data/app/uploaders/zip_uploader.rb +53 -0
  115. data/app/views/admin/gateways/providers.html.arb +10 -0
  116. data/app/views/admin/revisions/payments.html.arb +28 -0
  117. data/app/views/admin/terminal_profiles/_tree.html.haml +35 -0
  118. data/app/views/admin/terminal_profiles/sort.html.haml +21 -0
  119. data/app/views/admin/terminals/pings.html.arb +55 -0
  120. data/app/views/admin/terminals/upgrade_build.html.arb +30 -0
  121. data/app/views/layouts/application.html.erb +1 -0
  122. data/app/views/welcome/index.html.erb +25 -0
  123. data/app/workers/pay_worker.rb +11 -0
  124. data/app/workers/report_worker.rb +7 -0
  125. data/app/workers/revise_worker.rb +7 -0
  126. data/config/acquiring.yml +13 -0
  127. data/config/application.rb +75 -0
  128. data/config/boot.rb +6 -0
  129. data/config/database.yml +17 -0
  130. data/config/deploy/roundlake-passenger.rb +3 -0
  131. data/config/deploy/roundlake-trinidad.rb +3 -0
  132. data/config/deploy.rb +37 -0
  133. data/config/environment.rb +5 -0
  134. data/config/environments/development.rb +39 -0
  135. data/config/environments/production.rb +67 -0
  136. data/config/environments/test.rb +37 -0
  137. data/config/initializers/active_admin.rb +31 -0
  138. data/config/initializers/backtrace_silencers.rb +7 -0
  139. data/config/initializers/devise.rb +232 -0
  140. data/config/initializers/inflections.rb +15 -0
  141. data/config/initializers/mime_types.rb +5 -0
  142. data/config/initializers/money.rb +6 -0
  143. data/config/initializers/redis.rb +4 -0
  144. data/config/initializers/secret_token.rb +7 -0
  145. data/config/initializers/session_store.rb +8 -0
  146. data/config/initializers/setup_rack.rb +1 -0
  147. data/config/initializers/wrap_parameters.rb +14 -0
  148. data/config/locales/active_admin.ru.yml +71 -0
  149. data/config/locales/activerecord.ru.yml +645 -0
  150. data/config/locales/devise.ru.yml +57 -0
  151. data/config/locales/ru.yml +33 -0
  152. data/config/locales/smartkiosk.gateways.ru.yml +241 -0
  153. data/config/locales/smartkiosk.hardware.ru.yml +38 -0
  154. data/config/locales/smartkiosk.reports.ru.yml +56 -0
  155. data/config/locales/smartkiosk.ru.yml +163 -0
  156. data/config/nginx.conf +9 -0
  157. data/config/redis.yml +9 -0
  158. data/config/routes.rb +48 -0
  159. data/config/schedule.rb +13 -0
  160. data/config/sidekiq.yml +5 -0
  161. data/config/trinidad.yml +6 -0
  162. data/config.ru +4 -0
  163. data/db/migrate/20120825083035_create_terminals.rb +47 -0
  164. data/db/migrate/20120825083305_create_payments.rb +51 -0
  165. data/db/migrate/20120827062618_devise_create_users.rb +50 -0
  166. data/db/migrate/20120827132621_create_admin_notes.rb +17 -0
  167. data/db/migrate/20120827132622_move_admin_notes_to_comments.rb +25 -0
  168. data/db/migrate/20120903193346_create_providers.rb +24 -0
  169. data/db/migrate/20120922075345_create_collections.rb +26 -0
  170. data/db/migrate/20120922080440_create_agents.rb +29 -0
  171. data/db/migrate/20120922081104_create_commissions.rb +10 -0
  172. data/db/migrate/20120927035841_create_gateways.rb +13 -0
  173. data/db/migrate/20120927040626_create_provider_gateways.rb +13 -0
  174. data/db/migrate/20120927091849_create_limits.rb +10 -0
  175. data/db/migrate/20120927164647_create_roles.rb +14 -0
  176. data/db/migrate/20121003131522_create_report_templates.rb +18 -0
  177. data/db/migrate/20121007135652_create_reports.rb +13 -0
  178. data/db/migrate/20121008073905_create_report_results.rb +10 -0
  179. data/db/migrate/20121017114538_create_gateway_settings.rb +12 -0
  180. data/db/migrate/20121017114556_create_gateway_attachments.rb +10 -0
  181. data/db/migrate/20121019132606_create_revisions.rb +19 -0
  182. data/db/migrate/20121023073501_create_gateway_switches.rb +10 -0
  183. data/db/migrate/20121112142743_create_terminal_orders.rb +13 -0
  184. data/db/migrate/20121118191553_create_versions.rb +19 -0
  185. data/db/migrate/20121125093414_create_system_receipt_templates.rb +9 -0
  186. data/db/migrate/20121127192257_create_terminal_builds.rb +10 -0
  187. data/db/migrate/20121212053441_create_rebates.rb +15 -0
  188. data/db/migrate/20121216143855_create_provider_receipt_templates.rb +9 -0
  189. data/db/migrate/20130101091100_create_terminal_profiles.rb +13 -0
  190. data/db/migrate/20130101091734_create_provider_rebates.rb +21 -0
  191. data/db/migrate/20130102164447_create_limit_sections.rb +14 -0
  192. data/db/migrate/20130102164503_create_commission_sections.rb +17 -0
  193. data/db/migrate/20130102171743_create_provider_profiles.rb +10 -0
  194. data/db/migrate/20130103152507_create_provider_fields.rb +17 -0
  195. data/db/migrate/20130103154526_create_provider_groups.rb +10 -0
  196. data/db/migrate/20130104063628_create_terminal_profile_providers.rb +11 -0
  197. data/db/migrate/20130104090957_create_terminal_profile_provider_groups.rb +11 -0
  198. data/db/migrate/20130108091644_create_terminal_profile_promotions.rb +10 -0
  199. data/db/schema.rb +489 -0
  200. data/db/seeds/receipt_templates/payment.txt +19 -0
  201. data/db/seeds/receipt_templates/system/balance.txt +13 -0
  202. data/db/seeds/receipt_templates/system/collection.txt +17 -0
  203. data/db/seeds/receipt_templates/system/touchtest.txt +15 -0
  204. data/db/seeds.rb +18 -0
  205. data/doc/README_FOR_APP +2 -0
  206. data/init.rb +1 -0
  207. data/lib/active_admin/cancan_integration.rb +81 -0
  208. data/lib/active_admin/form_builder_fix.rb +76 -0
  209. data/lib/active_admin/inputs/filter_date_range_input_fix.rb +24 -0
  210. data/lib/active_admin/inputs/filter_multiple_select_input.rb +18 -0
  211. data/lib/active_admin/inputs/filter_numeric_range_input.rb +31 -0
  212. data/lib/active_admin/resource_controller_fix.rb +23 -0
  213. data/lib/active_admin/views/pages/base_fix.rb +13 -0
  214. data/lib/assets/.gitkeep +0 -0
  215. data/lib/blueprints.rb +79 -0
  216. data/lib/date_expander.rb +38 -0
  217. data/lib/dav4rack/build_resource.rb +59 -0
  218. data/lib/formtastic/inputs/selectable_check_boxes.rb +39 -0
  219. data/lib/paper_trail/version_fix.rb +3 -0
  220. data/lib/report_builder.rb +88 -0
  221. data/lib/seeder.rb +103 -0
  222. data/lib/smartkiosk/server/version.rb +5 -0
  223. data/lib/smartkiosk/server.rb +35 -0
  224. data/lib/string_file.rb +12 -0
  225. data/lib/tasks/.gitkeep +0 -0
  226. data/lib/tasks/db.rake +27 -0
  227. data/lib/tasks/dump.rake +53 -0
  228. data/lib/tasks/matrioshka.rake +16 -0
  229. data/log/.gitkeep +0 -0
  230. data/log/gateways/.gitkeep +0 -0
  231. data/public/404.html +26 -0
  232. data/public/422.html +26 -0
  233. data/public/500.html +25 -0
  234. data/public/robots.txt +5 -0
  235. data/script/rails +6 -0
  236. data/smartkiosk-server.gemspec +23 -0
  237. data/spec/controllers/collections_controller_spec.rb +32 -0
  238. data/spec/controllers/payments_controller_spec.rb +123 -0
  239. data/spec/controllers/system_receipt_templates_controller_spec.rb +5 -0
  240. data/spec/controllers/terminal_builds_controller_spec.rb +5 -0
  241. data/spec/controllers/terminal_orders_controller_spec.rb +32 -0
  242. data/spec/controllers/terminal_pings_controller_spec.rb +31 -0
  243. data/spec/spec_helper.rb +66 -0
  244. data/vendor/assets/javascripts/.gitkeep +0 -0
  245. data/vendor/assets/javascripts/chosen.jquery.js +1026 -0
  246. data/vendor/assets/javascripts/datepicker-ru.jquery.js +21 -0
  247. data/vendor/assets/javascripts/nestedSortable.jquery.js +429 -0
  248. data/vendor/assets/javascripts/qtip.jquery.js +3403 -0
  249. data/vendor/assets/stylesheets/.gitkeep +0 -0
  250. data/vendor/assets/stylesheets/chosen.jquery.css +397 -0
  251. data/vendor/assets/stylesheets/modules/PIE.htc +96 -0
  252. data/vendor/assets/stylesheets/qtip.jquery.css.scss +604 -0
  253. data/vendor/plugins/.gitkeep +0 -0
  254. metadata +333 -0
@@ -0,0 +1,388 @@
1
+ ActiveAdmin.register Terminal do
2
+
3
+ SIMPLE_ORDERS = Terminal::ORDERS.select{|x| x != 'upgrade'} unless defined?(SIMPLE_ORDERS)
4
+
5
+ menu :parent => I18n.t('activerecord.models.terminal.other'),
6
+ :label => I18n.t('smartkiosk.admin.menu.manage'),
7
+ :priority => 1,
8
+ :if => proc { can? :index, Terminal }
9
+
10
+ controller do
11
+ def scoped_collection
12
+ Terminal.includes(:agent)
13
+ end
14
+ end
15
+
16
+ member_action(:pings,
17
+ :method => :get,
18
+ :title => I18n.t('smartkiosk.admin.panels.terminals.all_pings')
19
+ ) do
20
+ @pings = Terminal.find(params[:id]).pings.to_a
21
+
22
+ if params[:format] == 'xls'
23
+ package = Axlsx::Package.new do |p|
24
+ p.workbook.add_worksheet(:name => "Pings") do |ws|
25
+ bold = ws.styles.add_style :b => true, :alignment=> {:horizontal => :center}
26
+ fields = %w(
27
+ created_at condition state version ip queues banknotes
28
+ cash_sum cash_count cash_acceptor_error cash_acceptor_version
29
+ printer_error printer_version modem_balance modem_signal_level
30
+ modem_version
31
+ )
32
+ ws.add_row fields.map{|x| TerminalPing.human_attribute_name(x)}, :style => bold
33
+
34
+ @pings.each do |p|
35
+ values = Hash[*fields.map{|x| [x, p.send(x)]}.flatten]
36
+
37
+ values['created_at'] = p.created_at.strftime("%d.%m.%Y %H:%M:%S")
38
+ values['state'] = I18n.t("smartkiosk.terminal_states.#{p.state}")
39
+ values['condition'] = I18n.t("smartkiosk.terminal_conditions.#{p.condition}")
40
+
41
+ ws.add_row values.values
42
+ end
43
+ end
44
+ end
45
+
46
+ package.use_shared_strings = true
47
+ send_data package.to_stream.read, :filename => 'report.xlsx',
48
+ :type => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
49
+ end
50
+ end
51
+
52
+ member_action(:upgrade_build,
53
+ :method => :get,
54
+ :title => I18n.t('smartkiosk.admin.panels.terminals.upgrade')
55
+ ) do
56
+ raise CanCan::AccessDenied unless current_user.priveleged?(:terminals, :upgrade)
57
+
58
+ @terminals = Terminal.where(:id => params[:id].split(','))
59
+ @ids = @terminals.map(&:id).join(',')
60
+ end
61
+
62
+ member_action :upgrade, :method => :post do
63
+ build = TerminalBuild.find(params[:build_id])
64
+
65
+ Terminal.where(:id => params[:id].split(',')).each do |t|
66
+ t.order! :upgrade, build.id, build.version, build.path, build.url
67
+ end
68
+
69
+ redirect_to :action => :index
70
+ end
71
+
72
+ SIMPLE_ORDERS.each do |order|
73
+ member_action order, :method => :post do
74
+ Terminal.find(params[:id]).order!(order)
75
+ redirect_to :action => :show
76
+ end
77
+ end
78
+
79
+ #
80
+ # INDEX
81
+ #
82
+ batch_action(
83
+ I18n.t('smartkiosk.admin.actions.terminals.upgrade'),
84
+ :if => proc{current_user.priveleged?(:terminals, :upgrade)}
85
+ ) do |selection|
86
+ redirect_to upgrade_build_admin_terminal_path(Terminal.find(selection).map(&:id).join(','))
87
+ end
88
+
89
+ SIMPLE_ORDERS.each do |order|
90
+ batch_action(
91
+ I18n.t("smartkiosk.admin.actions.terminals.#{order}"),
92
+ :if => proc{current_user.priveleged?(:terminals, order)}
93
+ ) do |selection|
94
+ Terminal.find(selection).each do |x|
95
+ x.order!(order)
96
+ end
97
+ redirect_to :back
98
+ end
99
+ end
100
+
101
+ scope I18n.t('active_admin.all'), :all
102
+ scope I18n.t('activerecord.scopes.terminal.ok'), :ok
103
+ scope I18n.t('activerecord.scopes.terminal.warning'), :warning
104
+ scope I18n.t('activerecord.scopes.terminal.error'), :error
105
+
106
+ filter :agent, :as => 'multiple_select', :input_html => { :class => 'chosen' },
107
+ :collection => proc { Agent.rmap }
108
+ filter :state, :as => 'multiple_select',
109
+ :collection => proc { I18n.t('smartkiosk.terminal_states').invert },
110
+ :input_html => { :class => 'chosen' }
111
+ filter :keyword
112
+ filter :address
113
+ filter :ip
114
+ filter :issues_started_at
115
+ filter :collected_at
116
+ filter :notified_at
117
+ Terminal::HARDWARE.each do |device|
118
+ filter :"#{device}_error", :as => 'multiple_select',
119
+ :collection => proc { I18n.t("smartkiosk.hardware.#{device}.errors").invert },
120
+ :input_html => { :class => 'chosen' }
121
+ end
122
+
123
+ index do
124
+ selectable_column
125
+ column :keyword, :sortable => :keyword do |x|
126
+ div :class => "important #{'error' unless x.issues_started_at.blank?}" do
127
+ link_to x.keyword, [:admin, x]
128
+ end
129
+
130
+ unless x.issues_started_at.blank?
131
+ div :title => I18n.l(x.issues_started_at, :format => :long) do
132
+ status_tag distance_of_time_in_words_to_now(x.issues_started_at), :error
133
+ end
134
+ end
135
+ end
136
+ column :address
137
+ column :agent
138
+ column :condition do |x|
139
+ div :class => 'nowrap centered' do
140
+ Terminal::HARDWARE.each do |device|
141
+ error = x.send "#{device}_error"
142
+ state = error.blank? ? :ok : (error >= 1000 ? :warning : :error)
143
+ title = I18n.t("smartkiosk.hardware.#{device}.title")
144
+
145
+ unless error.blank?
146
+ title += ": "+(
147
+ I18n.t("smartkiosk.hardware.#{device}.errors")[error] ||
148
+ I18n.t('smartkiosk.unlocalized')
149
+ )
150
+ title += " (#{error})"
151
+ end
152
+
153
+ status_tag I18n.t("smartkiosk.hardware.#{device}.abbr"), state, :title => title
154
+ end
155
+ end
156
+ div :class => 'nowrap centered' do
157
+ status_tag I18n.t("smartkiosk.terminal_states.#{x.state}"), :raw
158
+ end
159
+ end
160
+ column :collected_at, :sortable => :collected_at do |x|
161
+ unless x.collected_at.blank?
162
+ status_tag I18n.l(x.collected_at, :format => :long), :raw
163
+ end
164
+ end
165
+ column :notified_at, :sortable => :notified_at do |x|
166
+ unless x.notified_at.blank?
167
+ state = :raw
168
+ state = :warning if Time.now - x.notified_at > 5*60
169
+ state = :error if Time.now - x.notified_at > 15*60
170
+
171
+ div :title => I18n.l(x.notified_at, :format => :long) do
172
+ status_tag distance_of_time_in_words_to_now(x.notified_at), state
173
+ end
174
+ end
175
+ end
176
+ column :terminal_orders do |x|
177
+ if x.incomplete_orders_count > 0
178
+ x.terminal_orders.incomplete.map do |order|
179
+ title = I18n.t("smartkiosk.terminal_orders.#{order.keyword}")
180
+ title += " (#{order.percent}%)" unless order.percent.blank?
181
+
182
+ status = nil
183
+ status = :error if order.error?
184
+ status = :warning if order.sent?
185
+ div status_tag(title, status), :style => 'white-space: nowrap'
186
+ end
187
+ end
188
+ end
189
+ end
190
+
191
+ #
192
+ # SHOW
193
+ #
194
+ action_item :only => [:pings] do
195
+ link_to I18n.t('smartkiosk.admin.actions.terminals.pings_excel'),
196
+ pings_admin_terminal_path(:format => 'xls')
197
+ end
198
+
199
+ action_item :only => [:show], :if => proc{current_user.priveleged?(:terminals, :upgrade)} do
200
+ link_to I18n.t('smartkiosk.admin.actions.terminals.upgrade'),
201
+ upgrade_build_admin_terminal_path(terminal), :method => :get
202
+ end
203
+
204
+ SIMPLE_ORDERS.each do |order|
205
+ action_item :only => [:show], :if => proc{current_user.priveleged?(:terminals, order)} do
206
+ link_to I18n.t("smartkiosk.admin.actions.terminals.#{order}"),
207
+ send("#{order}_admin_terminal_path", terminal), :method => :post
208
+ end
209
+ end
210
+
211
+ show do |terminal|
212
+ attributes_table do
213
+ row :agent
214
+ row :keyword
215
+ row :description
216
+ row :has_adv_monitor do |x|
217
+ status_boolean(self, x.has_adv_monitor)
218
+ end
219
+ if terminal.incomplete_orders_count > 0
220
+ row :terminal_orders do
221
+ terminal.terminal_orders.incomplete.map do |order|
222
+ title = I18n.t("smartkiosk.terminal_orders.#{order.keyword}")
223
+ title += " (#{order.percent}%)" unless order.percent.blank?
224
+
225
+ status = nil
226
+ status = :error if order.error?
227
+ status = :warning if order.sent?
228
+ status_tag(title, status)
229
+ end
230
+ end
231
+ end
232
+ row :state do |t|
233
+ unless t.state.blank?
234
+ I18n.t "smartkiosk.terminal_states.#{t.state}"
235
+ end
236
+ end
237
+ row :condition do |t|
238
+ unless t.condition.blank?
239
+ status_tag (I18n.t "smartkiosk.terminal_conditions.#{t.condition}"), t.condition.to_sym
240
+ end
241
+ end
242
+ row :notified_at do |x|
243
+ unless x.notified_at.blank?
244
+ state = :raw
245
+ state = :warning if Time.now - x.notified_at > 5*60
246
+ state = :error if Time.now - x.notified_at > 15*60
247
+
248
+ div :title => I18n.l(x.notified_at, :format => :long) do
249
+ status_tag distance_of_time_in_words_to_now(x.notified_at), state
250
+ end
251
+ end
252
+ end
253
+ row :issues_started_at
254
+ Terminal::HARDWARE.each do |device|
255
+ row :"#{device}_error" do |x|
256
+ unless x.send("#{device}_error").blank?
257
+ I18n.t("smartkiosk.hardware.#{device}.errors")[x.send("#{device}_error")] ||
258
+ I18n.t('smartkiosk.unlocalized') + " (#{x.send("#{device}_error")})"
259
+ else
260
+ span(I18n.t('active_admin.empty'), :class => 'empty')
261
+ end
262
+ end
263
+ end
264
+ end
265
+
266
+ unless terminal.pings.last.blank?
267
+ panel I18n.t('smartkiosk.admin.panels.terminals.hardware') do
268
+ attributes_table_for terminal.pings.last do
269
+ row :cash_acceptor_model
270
+ row :cash_acceptor_version
271
+ row :modem_model
272
+ row :modem_version
273
+ row :printer_model
274
+ row :printer_version
275
+ end
276
+ end
277
+ end
278
+
279
+ panel I18n.t('smartkiosk.admin.panels.terminals.juridical') do
280
+ attributes_table_for terminal do
281
+ row :terminal_profile
282
+ row :sector
283
+ row :contact_name
284
+ row :contact_phone
285
+ row :contact_email
286
+ row :schedule
287
+ row :juristic_name
288
+ row :contract_number
289
+ row :manager
290
+ row :rent
291
+ row :rent_finish_date
292
+ row :collection_zone
293
+ row :check_phone_number
294
+ row :address do |t|
295
+ div t.address
296
+ unless t.address.blank?
297
+ div(:class => 'terminal_map', :id => 'map')
298
+ script(:type => 'text/javascript') do
299
+ raw "$(function(){ showAddress('map', '#{t.address}') })"
300
+ end
301
+ end
302
+ end
303
+ end
304
+ end
305
+
306
+ panel I18n.t('activerecord.models.terminal_order.other') do
307
+ table_for(terminal.terminal_orders.limit(20), :i18n => TerminalOrder) do |t|
308
+ t.column :keyword do |x|
309
+ I18n.t "smartkiosk.terminal_orders.#{x.keyword}"
310
+ end
311
+ t.column :args do |x|
312
+ x.args.join(', ') unless x.args.blank?
313
+ end
314
+ t.column :state do |x|
315
+ status = nil
316
+ status = :error if x.error?
317
+ status = :warning if x.sent?
318
+ status_tag I18n.t("smartkiosk.terminal_order_states.#{x.state}"), status
319
+ end
320
+ t.column :created_at
321
+ end
322
+ end
323
+
324
+ panel I18n.t('smartkiosk.admin.panels.terminals.pings') do
325
+ table_for(terminal.pings[0..20], :i18n => TerminalPing) do |t|
326
+ t.column :condition do |x|
327
+ status_tag I18n.t("smartkiosk.terminal_conditions.#{x.condition}"), x.condition.to_sym
328
+ end
329
+ t.column :state do |x|
330
+ I18n.t "smartkiosk.terminal_states.#{x.state}"
331
+ end
332
+ t.column :version
333
+ t.column :cash_sum
334
+ t.column :cash_count
335
+ t.column :modem_balance
336
+ t.column :modem_signal_level
337
+ end
338
+ button(
339
+ link_to I18n.t('smartkiosk.admin.panels.terminals.all_pings'),
340
+ pings_admin_terminal_path(terminal.id)
341
+ )
342
+ end
343
+
344
+ panel I18n.t('activerecord.models.collection.other') do
345
+ table_for(terminal.collections.limit(20), :i18n => Collection) do |t|
346
+ t.column :cash_sum
347
+ t.column :payments_sum
348
+ t.column :approved_payments_sum
349
+ t.column :collected_at
350
+ end
351
+ button(
352
+ link_to I18n.t('smartkiosk.full_list'),
353
+ admin_collections_path(:q => {:terminal_id_eq => terminal.id})
354
+ )
355
+ end
356
+
357
+ active_admin_comments
358
+ end
359
+
360
+ #
361
+ # FORM
362
+ #
363
+ form do |f|
364
+ f.inputs do
365
+ f.input :agent, :input_html => { :class => 'chosen' }
366
+ f.input :keyword
367
+ f.input :description
368
+ f.input :terminal_profile, :input_html => { :class => 'chosen' }
369
+ f.input :has_adv_monitor, :as => :select, :input_html => { :class => 'chosen' }
370
+ end
371
+ f.inputs do
372
+ f.input :sector
373
+ f.input :contact_name
374
+ f.input :contact_phone
375
+ f.input :contact_email
376
+ f.input :schedule
377
+ f.input :juristic_name
378
+ f.input :contract_number
379
+ f.input :manager
380
+ f.input :rent
381
+ f.input :rent_finish_date
382
+ f.input :collection_zone
383
+ f.input :check_phone_number
384
+ f.input :address
385
+ end
386
+ f.actions
387
+ end
388
+ end
@@ -0,0 +1,117 @@
1
+ ActiveAdmin.register User do
2
+
3
+ menu :parent => I18n.t('activerecord.models.user.other'),
4
+ :label => I18n.t('smartkiosk.admin.menu.manage'),
5
+ :priority => 1,
6
+ :if => proc { can? :index, User }
7
+
8
+ controller do
9
+ before_filter(:only => [:update]) do
10
+ if params[:user][:password].blank?
11
+ params[:user].delete(:password)
12
+ params[:user].delete(:password_confirmation)
13
+ end
14
+ end
15
+ end
16
+
17
+ #
18
+ # INDEX
19
+ #
20
+ filter :id
21
+ filter :roles_id, :as => 'multiple_select', :collection => proc{ Role.all }, :input_html => {
22
+ :class => "chosen"
23
+ }
24
+ filter :email
25
+ filter :current_sign_in_at
26
+ filter :current_sign_in_ip
27
+ filter :last_sign_in_at
28
+ filter :last_sign_in_ip
29
+ filter :created_at
30
+ filter :updated_at
31
+
32
+ index do
33
+ selectable_column
34
+ column :id, :sortable => :id do |x|
35
+ link_to x.id, [:admin, x]
36
+ end
37
+ column :email
38
+ column :root do |x|
39
+ status_boolean(self, x.root?)
40
+ end
41
+ column :roles do |x|
42
+ x.roles.map{|x| x.title}.join(', ')
43
+ end
44
+ column :last_sign_in_at
45
+ column :updated_at
46
+ default_actions
47
+ end
48
+
49
+ #
50
+ # SHOW
51
+ #
52
+ show do |user|
53
+ attributes_table do
54
+ row :id
55
+ row :email
56
+ row :root do |x|
57
+ status_boolean(self, x.root?)
58
+ end
59
+ row :roles do |x|
60
+ x.roles.map{|x| x.title}.join(', ')
61
+ end
62
+ row :current_sign_in_at
63
+ row :current_sign_in_ip
64
+ row :last_sign_in_at
65
+ row :last_sign_in_ip
66
+ row :created_at
67
+ row :updated_at
68
+ end
69
+ end
70
+
71
+ #
72
+ # FORM
73
+ #
74
+ form do |f|
75
+ f.inputs do
76
+ f.input :full_name
77
+ f.input :email
78
+ f.input :password
79
+ f.input :password_confirmation
80
+ f.input :root, :as => :select, :input_html => { :class => 'chosen' }
81
+ end
82
+ f.inputs do
83
+ roles = Role.all
84
+ actions = Role.entries_actions
85
+
86
+ f.has_many :user_roles do |ur|
87
+ ur.input :role, :input_html => {
88
+ :class => 'chosen',
89
+ :onchange => <<-JS
90
+ select = $(this);
91
+ group = select.parent().parent();
92
+ visible = group.find('.privelege_'+select.val());
93
+
94
+ group.find('.privelege').hide();
95
+ visible.show();
96
+ chosenify(visible.find('select'));
97
+ JS
98
+ }
99
+ roles.each do |role|
100
+ actions[role.keyword].each do |action, label|
101
+ ur.input "can_#{role.keyword}_#{action}", :as => :select, :label => label,
102
+ :input_html => { :class => ("chosen" if ur.object.role == role) },
103
+ :wrapper_html => {
104
+ :class => "privelege privelege_#{role.id}",
105
+ :style => ("display: none" unless ur.object.role == role)
106
+ }
107
+ end
108
+ end
109
+ unless ur.object.new_record?
110
+ ur.input :_destroy, :as => :boolean, :label => I18n.t('active_admin.delete')
111
+ end
112
+ ur.form_buffers.last
113
+ end
114
+ end
115
+ f.buttons
116
+ end
117
+ end
@@ -0,0 +1,131 @@
1
+ ActiveAdmin.register Version do
2
+ config.batch_actions = false
3
+ actions :index, :show
4
+
5
+ menu :parent => I18n.t('activerecord.models.user.other'),
6
+ :if => proc { can? :index, Version }
7
+
8
+ #
9
+ # INDEX
10
+ #
11
+ filter :user, :as => 'multiple_select', :input_html => { :class => 'chosen' }
12
+ filter :item_type, :as => 'multiple_select', :input_html => { :class => 'chosen' },
13
+ :collection => proc {
14
+ [
15
+ 'User', 'Agent', 'Collection', 'Commission', 'Gateway', 'Limit', 'Payment',
16
+ 'Provider', 'TerminalCondition', 'TerminalType', 'Terminal'
17
+ ].map {|x| [I18n.t("activerecord.models.#{x.underscore}", :count => 1), x]}
18
+ }
19
+ filter :item_id, :as => 'numeric'
20
+
21
+ index do
22
+ column :id do |x|
23
+ link_to x.id, [:admin, x]
24
+ end
25
+ column :created_at
26
+ column :user
27
+ column :item_type do |x|
28
+ I18n.t "activerecord.models.#{x.item_type.underscore}", :count => 1
29
+ end
30
+ column :item_id, :order => :item_id do |x|
31
+ link_to x.item_id, :q => {:item_type_in => x.item_type, :item_id_eq => x.item_id}
32
+ end
33
+ column :item do |x|
34
+ item = x.item || x.reify
35
+ title = item.respond_to?(:title) ? item.title : "---"
36
+
37
+ if x.item.blank?
38
+ span(title)
39
+ else
40
+ span(link_to title, [:admin, x.item]) rescue span(title)
41
+ end
42
+ end
43
+ column :event do |x|
44
+ type = :ok
45
+ type = :warning if x.event == 'update'
46
+ type = :error if x.event == 'destroy'
47
+
48
+ status_tag I18n.t("smartkiosk.version_actions.#{x.event}"), type
49
+ end
50
+ end
51
+
52
+ #
53
+ # SHOW
54
+ #
55
+ show do |version|
56
+ attributes_table do
57
+ row :id
58
+ row :created_at
59
+ row :user
60
+ row :item_type do |x|
61
+ I18n.t "activerecord.models.#{x.item_type.underscore}", :count => 1
62
+ end
63
+ row :item_id do |x|
64
+ x.item_id
65
+ end
66
+ row :item do |x|
67
+ item = x.item || x.reify
68
+ title = item.respond_to?(:title) ? item.title : "---"
69
+
70
+ if x.item.blank?
71
+ span(title)
72
+ else
73
+ span(link_to title, [:admin, x.item]) rescue span(title)
74
+ end
75
+ end
76
+ row :event do |x|
77
+ type = :ok
78
+ type = :warning if x.event == 'update'
79
+ type = :error if x.event == 'destroy'
80
+
81
+ status_tag I18n.t("smartkiosk.version_actions.#{x.event}"), type
82
+ end
83
+
84
+ # FIELDS
85
+ type = version.item_type.constantize
86
+ item = version.reify || version.item
87
+
88
+ row :changeset do |x|
89
+ unless x.changeset.blank?
90
+ ul do
91
+ x.changeset.each do |k, v|
92
+ li do
93
+ strong "#{type.human_attribute_name k}:"
94
+ span v[0]
95
+ span "&rarr;".html_safe
96
+ span v[1]
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
102
+ row :fields do |x|
103
+ ul do
104
+ item.attributes.each do |k, v|
105
+ li do
106
+ strong "#{type.human_attribute_name k}:"
107
+ span v
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
113
+
114
+ panel I18n.t('activerecord.models.version.other') do
115
+ table_for(version.item.versions, :i18n => Version) do |t|
116
+ column :id do |x|
117
+ link_to x.id, [:admin, x]
118
+ end
119
+ column :created_at
120
+ column :user
121
+ column :event do |x|
122
+ type = :ok
123
+ type = :warning if x.event == 'update'
124
+ type = :error if x.event == 'destroy'
125
+
126
+ status_tag I18n.t("smartkiosk.version_actions.#{x.event}"), type
127
+ end
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,64 @@
1
+ ActiveAdmin.register_page "Dashboard" do
2
+ menu :label => I18n.t('active_admin.dashboard')
3
+
4
+ content do
5
+ h3 I18n.t("smartkiosk.welcome.header", :user => current_user.full_name),
6
+ :style => 'margin-bottom: 30px'
7
+
8
+ table do
9
+ tr do
10
+ td :style => 'width: 60%' do
11
+ panel I18n.t("smartkiosk.welcome.roles") do
12
+ table do
13
+ unless current_user.root
14
+ current_user.user_roles.in_groups_of(3, false).each do |group|
15
+ tr do
16
+ group.each do |ur|
17
+ td :style => 'width: 33%;' do
18
+ div :style => 'padding: 5px; border: 1px solid gray; background-color: white;' do
19
+ h4 ur.role.title, :style => 'margin-bottom: 8px; font-weight: bold'
20
+ ur.role.actions.select{|k,v| ur.priveleged?(k)}.values.each do |v|
21
+ div v
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ else
29
+ Role.entries_actions.to_a.in_groups_of(3, false).each do |group|
30
+ tr do
31
+ group.each do |role, actions|
32
+ td :style => 'width: 33%;' do
33
+ div :style => 'padding: 5px; border: 1px solid gray; background-color: white;' do
34
+ h4 I18n.t("activerecord.models.#{role.singularize}.other"), :style => 'margin-bottom: 8px; font-weight: bold'
35
+ actions.values.each do |label|
36
+ div label
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ td do
48
+ panel I18n.t("smartkiosk.welcome.properties") do
49
+ attributes_table_for current_user do
50
+ row :id
51
+ row :email
52
+ row :current_sign_in_at
53
+ row :current_sign_in_ip
54
+ row :last_sign_in_at
55
+ row :last_sign_in_ip
56
+ row :created_at
57
+ row :updated_at
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end