smartkiosk-server 0.12.1 → 0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/.ruby-version +1 -1
- data/Gemfile +9 -6
- data/Gemfile.lock +36 -9
- data/app/assets/images/sort-asc.png +0 -0
- data/app/assets/images/sort-desc.png +0 -0
- data/app/assets/javascripts/application.js +1 -1
- data/app/assets/javascripts/monitoring.js.coffee +25 -0
- data/app/assets/javascripts/monitoring/helpers/application.js.coffee +12 -0
- data/app/assets/javascripts/monitoring/layouts/application.js.coffee +2 -0
- data/app/assets/javascripts/monitoring/pages/application.js.coffee +1 -0
- data/app/assets/javascripts/monitoring/pages/welcome/index.js.coffee +229 -0
- data/app/assets/javascripts/monitoring/resources/.gitkeep +0 -0
- data/app/assets/javascripts/monitoring/routes.js.coffee +8 -0
- data/app/assets/javascripts/monitoring/templates/layouts/.gitkeep +0 -0
- data/app/assets/javascripts/monitoring/templates/layouts/application.jst.hamlc +1 -0
- data/app/assets/javascripts/monitoring/templates/pages/welcome/_row.jst.hamlc +28 -0
- data/app/assets/javascripts/monitoring/templates/pages/welcome/_tbody.jst.hamlc +3 -0
- data/app/assets/javascripts/monitoring/templates/pages/welcome/index.jst.hamlc +37 -0
- data/app/assets/javascripts/monitoring/templates/widgets/.gitkeep +0 -0
- data/app/assets/javascripts/monitoring/widgets/.gitkeep +0 -0
- data/app/assets/javascripts/monitoring_preloader.js.coffee.erb +17 -0
- data/app/assets/stylesheets/active_admin.css.scss +4 -4
- data/app/assets/stylesheets/{fonts.css.scss → active_admin/fonts.css.scss} +0 -0
- data/app/assets/stylesheets/active_admin/provider_groups.css.scss +12 -0
- data/app/assets/stylesheets/{provider_receipt_templates.css.scss → active_admin/provider_receipt_templates.css.scss} +0 -0
- data/app/assets/stylesheets/{terminals.css.scss → active_admin/terminals.css.scss} +0 -0
- data/app/assets/stylesheets/monitoring.css.scss +4 -0
- data/app/assets/stylesheets/monitoring/bootstrap.css +9 -0
- data/app/assets/stylesheets/monitoring/theme.css.scss +35 -0
- data/app/controllers/monitoring_controller.rb +31 -0
- data/app/controllers/payments_controller.rb +1 -1
- data/app/controllers/terminal_builds_controller.rb +2 -0
- data/app/controllers/welcome_controller.rb +5 -2
- data/app/models/ability.rb +6 -4
- data/app/models/agent.rb +6 -0
- data/app/models/collection.rb +2 -2
- data/app/models/payment.rb +3 -3
- data/app/models/provider_gateway.rb +1 -1
- data/app/models/report_result.rb +1 -1
- data/app/models/report_template.rb +3 -3
- data/app/models/role.rb +51 -10
- data/app/models/terminal.rb +25 -1
- data/app/models/terminal_build.rb +1 -1
- data/app/models/terminal_order.rb +1 -1
- data/app/models/terminal_ping.rb +3 -0
- data/app/models/terminal_profile.rb +6 -0
- data/app/models/user_role.rb +1 -1
- data/app/views/monitoring/index.html.erb +28 -0
- data/config.ru +7 -0
- data/config/deploy.rb +1 -1
- data/config/environments/development.rb +2 -0
- data/config/environments/production.rb +1 -1
- data/config/initializers/monitoring.rb +3 -0
- data/config/initializers/redis.rb +1 -1
- data/config/locales/activerecord.ru.yml +14 -0
- data/config/locales/smartkiosk.ru.yml +38 -0
- data/config/routes.rb +1 -1
- data/db/migrate/20130419125334_add_ping_to_terminals.rb +22 -0
- data/db/schema.rb +25 -7
- data/lib/blueprints.rb +2 -0
- data/lib/monitorer.rb +41 -0
- data/lib/seeder.rb +1 -1
- data/lib/smartkiosk/server/version.rb +1 -1
- data/vendor/assets/javascripts/chosen.jquery.js +1 -1
- data/vendor/assets/javascripts/cookie.jquery.js +95 -0
- data/vendor/assets/javascripts/copypaste.js +148 -0
- data/vendor/assets/javascripts/event-drag.jquery.js +402 -0
- data/vendor/assets/javascripts/sheetclip.js +87 -0
- data/vendor/assets/javascripts/slick.cellrangedecorator.js +64 -0
- data/vendor/assets/javascripts/slick.cellrangeselector.js +111 -0
- data/vendor/assets/javascripts/slick.cellselectionmodel.js +152 -0
- data/vendor/assets/javascripts/slick.core.js +458 -0
- data/vendor/assets/javascripts/slick.grid.js +3287 -0
- data/vendor/assets/stylesheets/slick.grid.css +167 -0
- metadata +42 -9
- data/app/assets/stylesheets/provider_groups.css.scss +0 -12
- data/app/views/layouts/application.html.erb +0 -1
- data/app/views/welcome/index.html.erb +0 -25
data/app/models/terminal.rb
CHANGED
@@ -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?
|
data/app/models/terminal_ping.rb
CHANGED
@@ -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)
|
data/app/models/user_role.rb
CHANGED
@@ -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)
|
data/config/deploy.rb
CHANGED
@@ -28,7 +28,7 @@ namespace :deploy do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
task :install do
|
31
|
-
run "cd #{
|
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
|
@@ -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
|
@@ -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'
|
data/config/routes.rb
CHANGED
@@ -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
|
data/db/schema.rb
CHANGED
@@ -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 =>
|
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",
|
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",
|
460
|
-
t.integer "incomplete_orders_count",
|
461
|
-
t.datetime "created_at",
|
462
|
-
t.datetime "updated_at",
|
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",
|
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"
|
data/lib/blueprints.rb
CHANGED
@@ -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
|
data/lib/monitorer.rb
ADDED
@@ -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
|
data/lib/seeder.rb
CHANGED