smartkiosk-server 0.12.1 → 0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/.ruby-version +1 -1
  2. data/Gemfile +9 -6
  3. data/Gemfile.lock +36 -9
  4. data/app/assets/images/sort-asc.png +0 -0
  5. data/app/assets/images/sort-desc.png +0 -0
  6. data/app/assets/javascripts/application.js +1 -1
  7. data/app/assets/javascripts/monitoring.js.coffee +25 -0
  8. data/app/assets/javascripts/monitoring/helpers/application.js.coffee +12 -0
  9. data/app/assets/javascripts/monitoring/layouts/application.js.coffee +2 -0
  10. data/app/assets/javascripts/monitoring/pages/application.js.coffee +1 -0
  11. data/app/assets/javascripts/monitoring/pages/welcome/index.js.coffee +229 -0
  12. data/app/assets/javascripts/monitoring/resources/.gitkeep +0 -0
  13. data/app/assets/javascripts/monitoring/routes.js.coffee +8 -0
  14. data/app/assets/javascripts/monitoring/templates/layouts/.gitkeep +0 -0
  15. data/app/assets/javascripts/monitoring/templates/layouts/application.jst.hamlc +1 -0
  16. data/app/assets/javascripts/monitoring/templates/pages/welcome/_row.jst.hamlc +28 -0
  17. data/app/assets/javascripts/monitoring/templates/pages/welcome/_tbody.jst.hamlc +3 -0
  18. data/app/assets/javascripts/monitoring/templates/pages/welcome/index.jst.hamlc +37 -0
  19. data/app/assets/javascripts/monitoring/templates/widgets/.gitkeep +0 -0
  20. data/app/assets/javascripts/monitoring/widgets/.gitkeep +0 -0
  21. data/app/assets/javascripts/monitoring_preloader.js.coffee.erb +17 -0
  22. data/app/assets/stylesheets/active_admin.css.scss +4 -4
  23. data/app/assets/stylesheets/{fonts.css.scss → active_admin/fonts.css.scss} +0 -0
  24. data/app/assets/stylesheets/active_admin/provider_groups.css.scss +12 -0
  25. data/app/assets/stylesheets/{provider_receipt_templates.css.scss → active_admin/provider_receipt_templates.css.scss} +0 -0
  26. data/app/assets/stylesheets/{terminals.css.scss → active_admin/terminals.css.scss} +0 -0
  27. data/app/assets/stylesheets/monitoring.css.scss +4 -0
  28. data/app/assets/stylesheets/monitoring/bootstrap.css +9 -0
  29. data/app/assets/stylesheets/monitoring/theme.css.scss +35 -0
  30. data/app/controllers/monitoring_controller.rb +31 -0
  31. data/app/controllers/payments_controller.rb +1 -1
  32. data/app/controllers/terminal_builds_controller.rb +2 -0
  33. data/app/controllers/welcome_controller.rb +5 -2
  34. data/app/models/ability.rb +6 -4
  35. data/app/models/agent.rb +6 -0
  36. data/app/models/collection.rb +2 -2
  37. data/app/models/payment.rb +3 -3
  38. data/app/models/provider_gateway.rb +1 -1
  39. data/app/models/report_result.rb +1 -1
  40. data/app/models/report_template.rb +3 -3
  41. data/app/models/role.rb +51 -10
  42. data/app/models/terminal.rb +25 -1
  43. data/app/models/terminal_build.rb +1 -1
  44. data/app/models/terminal_order.rb +1 -1
  45. data/app/models/terminal_ping.rb +3 -0
  46. data/app/models/terminal_profile.rb +6 -0
  47. data/app/models/user_role.rb +1 -1
  48. data/app/views/monitoring/index.html.erb +28 -0
  49. data/config.ru +7 -0
  50. data/config/deploy.rb +1 -1
  51. data/config/environments/development.rb +2 -0
  52. data/config/environments/production.rb +1 -1
  53. data/config/initializers/monitoring.rb +3 -0
  54. data/config/initializers/redis.rb +1 -1
  55. data/config/locales/activerecord.ru.yml +14 -0
  56. data/config/locales/smartkiosk.ru.yml +38 -0
  57. data/config/routes.rb +1 -1
  58. data/db/migrate/20130419125334_add_ping_to_terminals.rb +22 -0
  59. data/db/schema.rb +25 -7
  60. data/lib/blueprints.rb +2 -0
  61. data/lib/monitorer.rb +41 -0
  62. data/lib/seeder.rb +1 -1
  63. data/lib/smartkiosk/server/version.rb +1 -1
  64. data/vendor/assets/javascripts/chosen.jquery.js +1 -1
  65. data/vendor/assets/javascripts/cookie.jquery.js +95 -0
  66. data/vendor/assets/javascripts/copypaste.js +148 -0
  67. data/vendor/assets/javascripts/event-drag.jquery.js +402 -0
  68. data/vendor/assets/javascripts/sheetclip.js +87 -0
  69. data/vendor/assets/javascripts/slick.cellrangedecorator.js +64 -0
  70. data/vendor/assets/javascripts/slick.cellrangeselector.js +111 -0
  71. data/vendor/assets/javascripts/slick.cellselectionmodel.js +152 -0
  72. data/vendor/assets/javascripts/slick.core.js +458 -0
  73. data/vendor/assets/javascripts/slick.grid.js +3287 -0
  74. data/vendor/assets/stylesheets/slick.grid.css +167 -0
  75. metadata +42 -9
  76. data/app/assets/stylesheets/provider_groups.css.scss +0 -12
  77. data/app/views/layouts/application.html.erb +0 -1
  78. data/app/views/welcome/index.html.erb +0 -25
@@ -1,3 +1,4 @@
1
+ require 'monitorer'
1
2
  require_dependency 'terminal_ping'
2
3
 
3
4
  class Terminal < ActiveRecord::Base
@@ -9,9 +10,15 @@ class Terminal < ActiveRecord::Base
9
10
  has_rmap({:id => lambda{|x| x.to_s}}, :keyword)
10
11
  has_paper_trail :ignore => [:incomplete_orders_count]
11
12
 
13
+ after_save do
14
+ Monitorer.notify Hash[*changed.map{|x| [x, send(x)]}.flatten].merge(:id => id)
15
+ end
16
+
12
17
  #
13
18
  # RELATIONS
14
19
  #
20
+ serialize :banknotes, JSON
21
+
15
22
  belongs_to :terminal_profile
16
23
  belongs_to :agent
17
24
  has_many :collections, :order => 'id DESC'
@@ -25,6 +32,8 @@ class Terminal < ActiveRecord::Base
25
32
  scope :warning, where(:condition => 'warning')
26
33
  scope :error, where(:condition => 'error')
27
34
 
35
+ delegate :title, :to => :agent, :prefix => true
36
+
28
37
  #
29
38
  # VALIDATIONS
30
39
  #
@@ -36,6 +45,12 @@ class Terminal < ActiveRecord::Base
36
45
  #
37
46
  # METHODS
38
47
  #
48
+ def self.as_hash(fields)
49
+ connection.select_all(select(fields).arel).each do |attrs|
50
+ yield(attrs) if block_given?
51
+ end
52
+ end
53
+
39
54
  def title
40
55
  keyword
41
56
  end
@@ -48,13 +63,22 @@ class Terminal < ActiveRecord::Base
48
63
  :state => data.state,
49
64
  :condition => data.condition,
50
65
  :notified_at => data.created_at,
51
- :version => data.version
66
+ :version => data.version,
67
+ :banknotes => data.banknotes,
68
+ :cash => data.cash,
69
+ :cashless => data.cashless,
70
+ :ip => data.ip,
52
71
  }
53
72
 
54
73
  HARDWARE.each do |device|
55
74
  update["#{device}_error"] = data.error(device)
75
+ update["#{device}_model"] = data.value('model', device)
76
+ update["#{device}_version"] = data.value('version', device)
56
77
  end
57
78
 
79
+ update["modem_signal_level"] = data.value('signal_level', 'modem')
80
+ update["modem_balance"] = data.value('balance', 'modem')
81
+
58
82
  if data.ok?
59
83
  update[:issues_started_at] = nil
60
84
  else
@@ -9,7 +9,7 @@ class TerminalBuild < ActiveRecord::Base
9
9
  mount_uploader :source, ZipUploader
10
10
 
11
11
  validates :source, :presence => true
12
- serialize :hashes
12
+ serialize :hashes, JSON
13
13
 
14
14
  validate do
15
15
  errors[:base] << I18n.t('activerecord.errors.models.terminal_build.no_version') if version.blank?
@@ -9,7 +9,7 @@ class TerminalOrder < ActiveRecord::Base
9
9
 
10
10
  validates :terminal, :presence => true
11
11
 
12
- serialize :args
12
+ serialize :args, JSON
13
13
 
14
14
  after_save do
15
15
  terminal.update_attribute :incomplete_orders_count,
@@ -13,6 +13,9 @@ class TerminalPing
13
13
  attribute :version
14
14
  attribute :ip, :type => String
15
15
 
16
+ attribute :cash, :type => Float
17
+ attribute :cashless, :type => Float
18
+
16
19
  # '100' => 1, '1000' => 5
17
20
  attribute :banknotes, :default => {}
18
21
 
@@ -21,6 +21,12 @@ class TerminalProfile < ActiveRecord::Base
21
21
 
22
22
  validates :title, :presence => true, :uniqueness => true
23
23
 
24
+ def self.as_hash(fields)
25
+ connection.select_all(select(fields).arel).each do |attrs|
26
+ yield(attrs) if block_given?
27
+ end
28
+ end
29
+
24
30
  def actualize_links!
25
31
  ProviderGroup.where(ProviderGroup.arel_table[:id].not_in TerminalProfileProviderGroup.arel_table.project(:provider_group_id)).each do |pg|
26
32
  terminal_profile_provider_groups << TerminalProfileProviderGroup.new(:provider_group_id => pg.id, :terminal_profile_id => id)
@@ -2,7 +2,7 @@ class UserRole < ActiveRecord::Base
2
2
  belongs_to :user
3
3
  belongs_to :role
4
4
 
5
- serialize :priveleges
5
+ serialize :priveleges, JSON
6
6
 
7
7
  validates :role, :presence => true
8
8
 
@@ -0,0 +1,28 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>monitoring</title>
5
+
6
+ <script type="text/javascript">
7
+ window.joosy = {
8
+ libraries: <%= extract_sources_and_sizes_from_include_tag('monitoring') %>,
9
+ environment: '<%= Rails.env.to_s %>',
10
+ locale: '<%= I18n.locale %>'
11
+ };
12
+
13
+ window.terminals = <%= raw @terminals %>;
14
+ </script>
15
+
16
+ <%= stylesheet_link_tag 'monitoring' %>
17
+ <%= csrf_meta_tags %>
18
+ </head>
19
+
20
+ <body>
21
+ <%= javascript_include_tag 'monitoring_preloader' %>
22
+ <div id="application">
23
+ <div id="preloader" class="container-fluid">
24
+ Loading...
25
+ </div>
26
+ </div>
27
+ </body>
28
+ </html>
data/config.ru CHANGED
@@ -1,4 +1,11 @@
1
1
  # This file is used by Rack-based servers to start the application.
2
2
 
3
+ require ::File.expand_path('../lib/monitorer', __FILE__)
3
4
  require ::File.expand_path('../config/environment', __FILE__)
4
5
  run Rails.application.class
6
+
7
+ Thread.new {
8
+ EM.run do
9
+ puts "=> EventMachine started"
10
+ end
11
+ } unless defined?(Thin)
@@ -28,7 +28,7 @@ namespace :deploy do
28
28
  end
29
29
 
30
30
  task :install do
31
- run "cd #{release_path}; bundle exec rake db:install RAILS_ENV=#{rails_env} SEED_TEST=true"
31
+ run "cd #{current_path}; bundle exec rake db:install RAILS_ENV=#{rails_env} SEED_TEST=true"
32
32
  end
33
33
 
34
34
  task :restart do
@@ -36,4 +36,6 @@ Rails.application.class.configure do
36
36
 
37
37
  # Expands the lines which load the assets
38
38
  config.assets.debug = true
39
+
40
+ config.middleware.delete Rack::Lock
39
41
  end
@@ -46,7 +46,7 @@ Rails.application.class.configure do
46
46
  # config.action_controller.asset_host = "http://assets.example.com"
47
47
 
48
48
  # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
49
- config.assets.precompile += %w( modules/PIE.htc )
49
+ config.assets.precompile += %w( modules/PIE.htc monitoring.css monitoring.js monitoring_preloader.js )
50
50
 
51
51
  # Disable delivery errors, bad email addresses will be ignored
52
52
  # config.action_mailer.raise_delivery_errors = false
@@ -0,0 +1,3 @@
1
+ EM.next_tick do
2
+ Monitorer.setup!(:host => "0.0.0.0", :port => 3001)
3
+ end
@@ -1,4 +1,4 @@
1
1
  if File.exist?(config = Rails.root.join('config/redis.yml'))
2
2
  config = YAML::load File.read(config)
3
- Redis.current = Redis.new(config[Rails.env])
3
+ Redis.current = Redis.new(config[Rails.env].merge(:driver => :ruby))
4
4
  end
@@ -44,6 +44,8 @@ ru:
44
44
  min:
45
45
  too_large: должно быть меньше До
46
46
  models:
47
+ monitoring:
48
+ other: Мониторинг
47
49
  terminal_ping:
48
50
  few: Пинга
49
51
  many: Пингов
@@ -583,6 +585,7 @@ ru:
583
585
  keyword: Ключ
584
586
  title: Название
585
587
  manager: Менеджер
588
+ error: Ошибка
586
589
  modem_error: Ошибка модема
587
590
  notified_at: Время связи
588
591
  printer_error: Ошибка принтера
@@ -604,6 +607,17 @@ ru:
604
607
  watchdog_error: Ошибка сторожевика
605
608
  watchdog_model: Модель сторожевика
606
609
  watchdog_version: Версия сторожевика
610
+ printer_model: Модель принтера
611
+ printer_version: Версия принтера
612
+ cash_acceptor_version: Версия купюроприемника
613
+ cash_acceptor_model: Модель купюроприемника
614
+ modem_signal_level: Уровень связи
615
+ modem_balance: Баланс сим-карты
616
+ banknotes: Купюры
617
+ cash: Нал
618
+ cashless: Безнал
619
+ upstream: Входящий трафик
620
+ downstream: Исходящий трафик
607
621
  terminal_ping:
608
622
  terminal: Терминал
609
623
  condition: Состояние
@@ -1,5 +1,9 @@
1
1
  ru:
2
2
  smartkiosk:
3
+ monitoring:
4
+ title: Мониторинг
5
+ manage: Управление терминалами
6
+ filter: Фильтровать
3
7
  welcome:
4
8
  header: Вы авторизованы как %{user}
5
9
  roles: Доступные роли
@@ -84,6 +88,8 @@ ru:
84
88
  gems_ready: Готова к деплою
85
89
  gems_not_ready: Подготавливается
86
90
  gems_not_ready_error: Сборка еще подготавливается
91
+ roles:
92
+ monitoring: Мониторинг
87
93
  role_priveleges:
88
94
  basic:
89
95
  create: Создание
@@ -96,6 +102,38 @@ ru:
96
102
  enable: Разблокировка
97
103
  disable: Блокировка
98
104
  upgrade: Обновление
105
+ monitoring:
106
+ keyword: Ключ
107
+ address: Адрес
108
+ printer-error: Ошибка принтера
109
+ printer-model: Модель принтера
110
+ printer-version: Версия принтера
111
+ cash-acceptor-error: Ошибка купюроприемника
112
+ cash-acceptor-version: Версия купюроприемника
113
+ cash-acceptor-model: Модель купюроприемника
114
+ modem-error: Ошибка модема
115
+ modem-signal-level: Уровень сигнала
116
+ modem-balance: Баланс сим-карты
117
+ card-reader-error: Ошибка картоприемника
118
+ card-reader-version: Версия картоприемника
119
+ card-reader-model: Модель картоприемника
120
+ watchdog-error: Ошибка сторожевика
121
+ collected-at: Инкассация
122
+ notified-at: Время связи
123
+ issues-started-at: Время ошибки
124
+ agent-id: Агент
125
+ terminal-profile-id: Профиль
126
+ version: Версия
127
+ banknotes: Банкноты
128
+ cash: Сумма наличных платежей
129
+ cashless: Сумма безналичных платежей
130
+ upstream: Исходящий трафик
131
+ downstream: Входящий трафик
132
+ ip: IP
133
+ juristic-name: Юридическое имя
134
+ contract-number: Номер договора
135
+ rent: Аренда
136
+ rent-finish-date: Срок окончания аренды
99
137
  debug_levels:
100
138
  '0': 'DEBUG'
101
139
  '1': 'INFO'
@@ -3,7 +3,7 @@ require 'sidekiq/web'
3
3
  Rails.application.class.routes.draw do
4
4
  ActiveAdmin.routes(self)
5
5
 
6
- root :to => 'welcome#index'
6
+ root :to => 'monitoring#index'
7
7
 
8
8
  devise_for :users, ActiveAdmin::Devise.config
9
9
 
@@ -0,0 +1,22 @@
1
+ class AddPingToTerminals < ActiveRecord::Migration
2
+ def change
3
+ add_column :terminals, :banknotes, :string
4
+ add_column :terminals, :cash, :decimal, :precision => 38, :scale => 2
5
+ add_column :terminals, :cashless, :decimal, :precision => 38, :scale => 2
6
+ add_column :terminals, :ip, :string
7
+ add_column :terminals, :cash_acceptor_version, :string
8
+ add_column :terminals, :cash_acceptor_model, :string
9
+ add_column :terminals, :modem_version, :string
10
+ add_column :terminals, :modem_model, :string
11
+ add_column :terminals, :modem_signal_level, :string
12
+ add_column :terminals, :modem_balance, :string
13
+ add_column :terminals, :printer_version, :string
14
+ add_column :terminals, :printer_model, :string
15
+ add_column :terminals, :card_reader_version, :string
16
+ add_column :terminals, :card_reader_model, :string
17
+ add_column :terminals, :watchdog_version, :string
18
+ add_column :terminals, :watchdog_model, :string
19
+ add_column :terminals, :upstream, :integer
20
+ add_column :terminals, :downstream, :integer
21
+ end
22
+ end
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended to check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(:version => 20130410142059) do
14
+ ActiveRecord::Schema.define(:version => 20130419125334) do
15
15
 
16
16
  create_table "active_admin_comments", :force => true do |t|
17
17
  t.string "resource_id", :null => false
@@ -434,7 +434,7 @@ ActiveRecord::Schema.define(:version => 20130410142059) do
434
434
  t.string "address"
435
435
  t.string "keyword"
436
436
  t.string "description"
437
- t.string "state", :default => "unknown"
437
+ t.string "state", :default => "unknown"
438
438
  t.string "condition"
439
439
  t.datetime "notified_at"
440
440
  t.datetime "collected_at"
@@ -456,14 +456,32 @@ ActiveRecord::Schema.define(:version => 20130410142059) do
456
456
  t.integer "cash_acceptor_error"
457
457
  t.integer "modem_error"
458
458
  t.string "version"
459
- t.boolean "has_adv_monitor", :default => true, :null => false
460
- t.integer "incomplete_orders_count", :default => 0, :null => false
461
- t.datetime "created_at", :null => false
462
- t.datetime "updated_at", :null => false
459
+ t.boolean "has_adv_monitor", :default => true, :null => false
460
+ t.integer "incomplete_orders_count", :default => 0, :null => false
461
+ t.datetime "created_at", :null => false
462
+ t.datetime "updated_at", :null => false
463
463
  t.integer "card_reader_error"
464
464
  t.integer "watchdog_error"
465
- t.integer "last_session_started_at", :default => 0, :null => false
465
+ t.integer "last_session_started_at", :default => 0, :null => false
466
466
  t.text "address_details"
467
+ t.string "banknotes"
468
+ t.decimal "cash", :precision => 38, :scale => 2
469
+ t.decimal "cashless", :precision => 38, :scale => 2
470
+ t.string "ip"
471
+ t.string "cash_acceptor_version"
472
+ t.string "cash_acceptor_model"
473
+ t.string "modem_version"
474
+ t.string "modem_model"
475
+ t.string "modem_signal_level"
476
+ t.string "modem_balance"
477
+ t.string "printer_version"
478
+ t.string "printer_model"
479
+ t.string "card_reader_version"
480
+ t.string "card_reader_model"
481
+ t.string "watchdog_version"
482
+ t.string "watchdog_model"
483
+ t.integer "upstream"
484
+ t.integer "downstream"
467
485
  end
468
486
 
469
487
  add_index "terminals", ["agent_id"], :name => "index_terminals_on_agent_id"
@@ -62,6 +62,8 @@ TerminalPing.blueprint do
62
62
  printer { {'error' => nil, 'version' => '1.0'} }
63
63
  modem { {'error' => nil, 'version' => '1.0', 'signal_level' => 4, 'balance' => 44.5} }
64
64
  queues { {'payments' => 4, 'orders' => 0} }
65
+ cash { 1000 }
66
+ cashless { 1000 }
65
67
  end
66
68
 
67
69
  Provider.blueprint do
@@ -0,0 +1,41 @@
1
+ class MonitorConnection < EventMachine::WebSocket::Connection
2
+ def initialize(service)
3
+ @service = service
4
+ end
5
+
6
+ def trigger_on_open(handshake)
7
+ @id = @service.channel.subscribe &method(:post_event)
8
+ end
9
+
10
+ def trigger_on_close(event = {})
11
+ @service.channel.unsubscribe @id
12
+ end
13
+
14
+ private
15
+
16
+ def post_event(event)
17
+ send event
18
+ end
19
+ end
20
+
21
+ class Monitorer
22
+ cattr_reader :current
23
+ attr_reader :channel
24
+
25
+ def self.setup!(opts)
26
+ @@current = Monitorer.new(opts)
27
+ end
28
+
29
+ def self.notify(event)
30
+ current.notify(event) if current
31
+ end
32
+
33
+ def initialize(opts={})
34
+ @channel = EventMachine::Channel.new
35
+ EventMachine.start_server opts[:host], opts[:port], MonitorConnection, self
36
+ end
37
+
38
+ def notify(event)
39
+ @channel.push JSON.dump(event)
40
+ end
41
+ end
@@ -51,7 +51,7 @@ class Seeder
51
51
  end
52
52
 
53
53
  def seed_test_terminals
54
- 100.times do |i|
54
+ 3000.times do |i|
55
55
  @terminals << Terminal.make!(:agent => @agent)
56
56
  end
57
57
  end
@@ -1,5 +1,5 @@
1
1
  module Smartkiosk
2
2
  module Server
3
- VERSION = '0.12.1'
3
+ VERSION = '0.13'
4
4
  end
5
5
  end