extface 0.0.1
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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +34 -0
- data/app/assets/javascripts/extface/application.js +13 -0
- data/app/assets/javascripts/extface/devices.js +2 -0
- data/app/assets/javascripts/extface/jobs.js +17 -0
- data/app/assets/stylesheets/extface/application.css +13 -0
- data/app/assets/stylesheets/extface/devices.css +4 -0
- data/app/assets/stylesheets/extface/jobs.css +4 -0
- data/app/assets/stylesheets/extface/sse.css +4 -0
- data/app/assets/stylesheets/scaffold.css +56 -0
- data/app/controllers/extface/application_controller.rb +21 -0
- data/app/controllers/extface/devices_controller.rb +69 -0
- data/app/controllers/extface/handler_controller.rb +66 -0
- data/app/controllers/extface/jobs_controller.rb +30 -0
- data/app/helpers/extface/application_helper.rb +40 -0
- data/app/helpers/extface/devices_helper.rb +21 -0
- data/app/helpers/extface/jobs_helper.rb +4 -0
- data/app/helpers/extface/sse_helper.rb +4 -0
- data/app/models/extface/device.rb +47 -0
- data/app/models/extface/driver/datecs_fp550.rb +6 -0
- data/app/models/extface/driver/fixed_width_serial_cdr.rb +6 -0
- data/app/models/extface/driver/generic_pos.rb +7 -0
- data/app/models/extface/driver/raw_serial.rb +27 -0
- data/app/models/extface/driver/star_scp700.rb +16 -0
- data/app/models/extface/driver/star_tsp200.rb +6 -0
- data/app/models/extface/driver_base.rb +67 -0
- data/app/models/extface/fiscal_print_driver.rb +8 -0
- data/app/models/extface/job.rb +54 -0
- data/app/models/extface/pbx_cdr_driver.rb +12 -0
- data/app/models/extface/pos_print_driver.rb +45 -0
- data/app/models/extface/raw_driver.rb +16 -0
- data/app/models/extface/serial_config.rb +10 -0
- data/app/views/extface/application/_object_errors.html.erb +10 -0
- data/app/views/extface/devices/form.html.erb +46 -0
- data/app/views/extface/devices/index.html.erb +36 -0
- data/app/views/extface/devices/show.html.erb +56 -0
- data/app/views/extface/driver/fixed_width_serial_cdr/_settings.html.erb +0 -0
- data/app/views/extface/driver/star_scp700/_settings.html.erb +1 -0
- data/app/views/extface/jobs/_form.html.erb +21 -0
- data/app/views/extface/jobs/edit.html.erb +6 -0
- data/app/views/extface/jobs/index.html.erb +27 -0
- data/app/views/extface/jobs/new.html.erb +5 -0
- data/app/views/extface/jobs/show.html.erb +9 -0
- data/app/views/extface/serial_configs/_settings.html.erb +37 -0
- data/app/views/layouts/extface/application.html.erb +14 -0
- data/config/routes.rb +12 -0
- data/db/migrate/20140215192111_create_extface_devices.rb +12 -0
- data/db/migrate/20140216110018_create_extface_pos_print_drivers.rb +9 -0
- data/db/migrate/20140216110608_create_extface_serial_configs.rb +14 -0
- data/db/migrate/20140216131245_create_extface_raw_drivers.rb +9 -0
- data/db/migrate/20140216131457_create_extface_fiscal_print_drivers.rb +9 -0
- data/db/migrate/20140216134748_create_extface_pbx_cdr_drivers.rb +9 -0
- data/db/migrate/20140219091811_create_extface_jobs.rb +9 -0
- data/db/migrate/20140219175006_add_job_info_to_extface_jobs.rb +9 -0
- data/lib/extface.rb +34 -0
- data/lib/extface/engine.rb +17 -0
- data/lib/extface/extfaceable.rb +17 -0
- data/lib/extface/mapping.rb +31 -0
- data/lib/extface/routes.rb +8 -0
- data/lib/extface/version.rb +3 -0
- data/lib/tasks/extface_tasks.rake +4 -0
- data/test/controllers/extface/devices_controller_test.rb +51 -0
- data/test/controllers/extface/jobs_controller_test.rb +14 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/shop.rb +3 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +24 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +29 -0
- data/test/dummy/config/environments/production.rb +80 -0
- data/test/dummy/config/environments/test.rb +36 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +12 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +7 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20140221203517_create_shops.rb +8 -0
- data/test/dummy/db/schema.rb +83 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +57 -0
- data/test/dummy/log/test.log +5908 -0
- data/test/dummy/public/404.html +58 -0
- data/test/dummy/public/422.html +58 -0
- data/test/dummy/public/500.html +57 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/0a8a23b1a73ebf217f4e2b765013ce7b +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/21fb58a50e25d1170f2c7d5bd5d29c54 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/263375f2d55c31687ed052f99ddead55 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/3f4ff460a79b2e29781690193a3960f6 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/4ef10b222fde3c042209a46daf3d3e36 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/544650645bc510ef8fbee0043c41fdcf +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/6dbf2b0443792e51055710be15c83197 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/717acb3e7c0df18696cf1bc56de6d3d5 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/9891cbb0808f38b2c42f42fd89e662a4 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/9b178820b9dc8c81c9784cf7ee3b7d35 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/a06a4a7f51754a6a2c0694eb39ff824b +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/a8cc2e73253025d2518d2449e16e5266 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/b56dfad0b14283f2cc10c62f37d71cc7 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/e1197e0129ade843b08de0b45c47fc40 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/ece3270b150db7c668579bb91ac7e2e5 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f018ab87f3490dbbcbc2e3c9f36aed3d +0 -0
- data/test/extface_test.rb +7 -0
- data/test/fixtures/extface/devices.yml +13 -0
- data/test/fixtures/extface/fiscal_print_drivers.yml +7 -0
- data/test/fixtures/extface/jobs.yml +7 -0
- data/test/fixtures/extface/pbx_cdr_drivers.yml +7 -0
- data/test/fixtures/extface/pos_print_drivers.yml +7 -0
- data/test/fixtures/extface/raw_drivers.yml +7 -0
- data/test/fixtures/extface/serial_configs.yml +17 -0
- data/test/fixtures/shops.yml +11 -0
- data/test/helpers/extface/devices_helper_test.rb +6 -0
- data/test/helpers/extface/jobs_helper_test.rb +6 -0
- data/test/helpers/extface/sse_helper_test.rb +6 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/models/extface/device_test.rb +9 -0
- data/test/models/extface/driver/star_tsp200_test.rb +9 -0
- data/test/models/extface/driver_test.rb +9 -0
- data/test/models/extface/fiscal_print_driver_test.rb +9 -0
- data/test/models/extface/job_test.rb +9 -0
- data/test/models/extface/pbx_cdr_driver_test.rb +9 -0
- data/test/models/extface/pos_print_driver_test.rb +9 -0
- data/test/models/extface/raw_driver_test.rb +9 -0
- data/test/models/extface/serial_config_test.rb +9 -0
- data/test/test_helper.rb +29 -0
- metadata +322 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 50fe0dde9ad7cd1749c2819c00e3291b7629c187
|
4
|
+
data.tar.gz: cafdda56e3f9a23b420adcc8841bce37a73bb345
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: db39c65a3bdf25944595fa9e43f45975a8facfd4cb62c0811b7d099536b1532b70a6c24497dd8d317ab39f04a47178d661c13fa8700c85c9cbbe90dafea2188f
|
7
|
+
data.tar.gz: f46898eceb756cbda18114e8a29116b287a72e311c0bedc9217e5e43b107b455f38f433ba2d33a9850f8f1ed82194e1a03b54146919a600d05a069d25f26489b
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Extface'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.libs << 'test'
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
30
|
+
t.verbose = false
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
task default: :test
|
@@ -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
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,17 @@
|
|
1
|
+
document.open_sse = function(url) {
|
2
|
+
if (!!window.EventSource) {
|
3
|
+
var source = new EventSource(url);
|
4
|
+
|
5
|
+
source.onmessage = function(e) {
|
6
|
+
console.log(e.data);
|
7
|
+
};
|
8
|
+
|
9
|
+
source.onopen = function(e) {
|
10
|
+
console.log('connection opened');
|
11
|
+
};
|
12
|
+
|
13
|
+
source.onerror = function(e) {
|
14
|
+
source.close();
|
15
|
+
};
|
16
|
+
}
|
17
|
+
};
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,56 @@
|
|
1
|
+
body { background-color: #fff; color: #333; }
|
2
|
+
|
3
|
+
body, p, ol, ul, td {
|
4
|
+
font-family: verdana, arial, helvetica, sans-serif;
|
5
|
+
font-size: 13px;
|
6
|
+
line-height: 18px;
|
7
|
+
}
|
8
|
+
|
9
|
+
pre {
|
10
|
+
background-color: #eee;
|
11
|
+
padding: 10px;
|
12
|
+
font-size: 11px;
|
13
|
+
}
|
14
|
+
|
15
|
+
a { color: #000; }
|
16
|
+
a:visited { color: #666; }
|
17
|
+
a:hover { color: #fff; background-color:#000; }
|
18
|
+
|
19
|
+
div.field, div.actions {
|
20
|
+
margin-bottom: 10px;
|
21
|
+
}
|
22
|
+
|
23
|
+
#notice {
|
24
|
+
color: green;
|
25
|
+
}
|
26
|
+
|
27
|
+
.field_with_errors {
|
28
|
+
padding: 2px;
|
29
|
+
background-color: red;
|
30
|
+
display: table;
|
31
|
+
}
|
32
|
+
|
33
|
+
#error_explanation {
|
34
|
+
width: 450px;
|
35
|
+
border: 2px solid red;
|
36
|
+
padding: 7px;
|
37
|
+
padding-bottom: 0;
|
38
|
+
margin-bottom: 20px;
|
39
|
+
background-color: #f0f0f0;
|
40
|
+
}
|
41
|
+
|
42
|
+
#error_explanation h2 {
|
43
|
+
text-align: left;
|
44
|
+
font-weight: bold;
|
45
|
+
padding: 5px 5px 5px 15px;
|
46
|
+
font-size: 12px;
|
47
|
+
margin: -7px;
|
48
|
+
margin-bottom: 0px;
|
49
|
+
background-color: #c00;
|
50
|
+
color: #fff;
|
51
|
+
}
|
52
|
+
|
53
|
+
#error_explanation ul li {
|
54
|
+
font-size: 12px;
|
55
|
+
list-style: square;
|
56
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Extface
|
2
|
+
class ApplicationController < ActionController::Base
|
3
|
+
prepend_before_filter :include_extra_module
|
4
|
+
|
5
|
+
def index
|
6
|
+
end
|
7
|
+
|
8
|
+
def extfaceable
|
9
|
+
@extfaceable ||= extface_mapping.i_klass.find_by(extface_mapping.i_find_key => params[extface_mapping.i_param])
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def extface_mapping
|
14
|
+
@extface_mapping ||= Extface::Mapping.find(request.fullpath)
|
15
|
+
end
|
16
|
+
|
17
|
+
def include_extra_module
|
18
|
+
self.class.send(:include, extface_mapping.i_extra_module) if extface_mapping.i_extra_module.present?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require_dependency "extface/application_controller"
|
2
|
+
|
3
|
+
module Extface
|
4
|
+
class DevicesController < ApplicationController
|
5
|
+
before_action :set_device, only: [:show, :edit, :update, :destroy]
|
6
|
+
|
7
|
+
# GET /devices
|
8
|
+
def index
|
9
|
+
@devices = extfaceable.extface_devices.load
|
10
|
+
end
|
11
|
+
|
12
|
+
# GET /devices/1
|
13
|
+
def show
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /devices/new
|
17
|
+
def new
|
18
|
+
@device = extfaceable.extface_devices.new
|
19
|
+
render action: :form
|
20
|
+
end
|
21
|
+
|
22
|
+
# GET /devices/1/edit
|
23
|
+
def edit
|
24
|
+
render action: :form
|
25
|
+
end
|
26
|
+
|
27
|
+
# POST /devices
|
28
|
+
def create
|
29
|
+
@device = extfaceable.extface_devices.new(device_params)
|
30
|
+
if @device.save
|
31
|
+
redirect_to @device, notice: 'Device was successfully created.'
|
32
|
+
else
|
33
|
+
render action: :form
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# PATCH/PUT /devices/1
|
38
|
+
def update
|
39
|
+
if @device.update(device_params)
|
40
|
+
redirect_to @device, notice: 'Device was successfully updated.'
|
41
|
+
else
|
42
|
+
render action: :form
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# DELETE /devices/1
|
47
|
+
def destroy
|
48
|
+
@device.destroy
|
49
|
+
redirect_to devices_url, notice: 'Device was successfully destroyed.'
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_page
|
53
|
+
set_device
|
54
|
+
job = @device.driveable.print_test_page
|
55
|
+
render text: job_path(job)
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
# Use callbacks to share common setup or constraints between actions.
|
60
|
+
def set_device
|
61
|
+
@device = extfaceable.extface_devices.find(params[:id])
|
62
|
+
end
|
63
|
+
|
64
|
+
# Only allow a trusted parameter "white list" through.
|
65
|
+
def device_params
|
66
|
+
params.require(:device).permit(:uuid, :name, :driver, :driveable_id, :driveable_type)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require_dependency "extface/application_controller"
|
2
|
+
# while RESULT=$(curl -u extface:extface -c extface -b extface -s localhost:3003/parking/demo/park_extface/d894db672bc916676d3d004394343031); do if [ -z "$RESULT" ]; then sleep 5; else echo -e "$RESULT"; sleep 1; fi done
|
3
|
+
# while true; do RESULT=$(curl -u extface:extface -c extface -b extface -s localhost:3003/parking/demo/park_extface/d894db672bc916676d3d004394343031); if [ -z "$RESULT" ]; then sleep 5; else echo -e "$RESULT"; sleep 1; fi done
|
4
|
+
require "timeout"
|
5
|
+
module Extface
|
6
|
+
class HandlerController < ApplicationController
|
7
|
+
include ActionController::Live
|
8
|
+
skip_before_filter :include_extra_module
|
9
|
+
#http_basic_authenticate_with name: "extface", password: "extface", except: :index
|
10
|
+
before_action :require_device
|
11
|
+
|
12
|
+
def pull
|
13
|
+
# request.body.read usable?
|
14
|
+
unless device.present?
|
15
|
+
render nothing: true, status: :not_found
|
16
|
+
else
|
17
|
+
response.headers['Content-Type'] = 'text/event-stream'
|
18
|
+
# find current job or get new one
|
19
|
+
redis = Redis.new
|
20
|
+
Timeout.timeout(2) do
|
21
|
+
if job = device.jobs.active.find_by(id: cookies[:extface]) || device.jobs.active.try(:first)
|
22
|
+
cookies.permanent[:extface] = job.id
|
23
|
+
p "Processing job #{job.id}"
|
24
|
+
list, data = redis.blpop(job.id, timeout: 1)
|
25
|
+
while data
|
26
|
+
response.stream.write data
|
27
|
+
redis.publish(job.id, "OK")
|
28
|
+
list, data = redis.blpop(job.id, timeout: 1)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end #timeout
|
32
|
+
end
|
33
|
+
rescue => e
|
34
|
+
p "will continue next time #{e.message}"
|
35
|
+
ensure
|
36
|
+
redis.quit
|
37
|
+
response.stream.close
|
38
|
+
end
|
39
|
+
|
40
|
+
def push
|
41
|
+
# get request.body.read
|
42
|
+
# if it is push message, process it
|
43
|
+
response.headers['Content-Type'] = 'text/event-stream'
|
44
|
+
p request.body.read
|
45
|
+
Extface.redis.subscribe(:alabala) do |on|
|
46
|
+
on.message do |event, data|
|
47
|
+
response.stream.write("event: #{event} data: #{data}\n\n")
|
48
|
+
Extface.redis.unsubscribe
|
49
|
+
end
|
50
|
+
end
|
51
|
+
response.stream.write "finish\n"
|
52
|
+
ensure
|
53
|
+
response.stream.write "failed\n"
|
54
|
+
response.stream.close
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
def device
|
59
|
+
@device ||= extfaceable.extface_devices.find_by(uuid: params[:device_uuid])
|
60
|
+
end
|
61
|
+
|
62
|
+
def require_device
|
63
|
+
render status: :not_found if device.nil?
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_dependency "extface/application_controller"
|
2
|
+
|
3
|
+
module Extface
|
4
|
+
class JobsController < ApplicationController
|
5
|
+
include ActionController::Live
|
6
|
+
|
7
|
+
def show
|
8
|
+
response.headers['Content-Type'] = 'text/event-stream'
|
9
|
+
@job = Job.find(params[:id])
|
10
|
+
if @job.completed?
|
11
|
+
response.stream.write("data: Job #{@job.id} completed!\n\n")
|
12
|
+
else
|
13
|
+
#redis = Redis.new
|
14
|
+
response.stream.write("data: Job #{@job.id} waiting for device connection...\n\n")
|
15
|
+
Extface.redis_block do |r|
|
16
|
+
r.subscribe(@job.id) do |on|
|
17
|
+
on.message do |event, data|
|
18
|
+
#p "data: #{data}\n\n"
|
19
|
+
response.stream.write("data: #{data}\n\n") unless data == 'OK'
|
20
|
+
r.unsubscribe if data == "Job #{@job.id} completed!" || data == "Job #{@job.id} failed!"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
ensure
|
26
|
+
response.stream.close
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Extface
|
2
|
+
module ApplicationHelper
|
3
|
+
|
4
|
+
def bootstrap_class_for flash_type
|
5
|
+
case flash_type
|
6
|
+
when :success
|
7
|
+
"alert-success"
|
8
|
+
when :error
|
9
|
+
"alert-danger"
|
10
|
+
when :alert
|
11
|
+
"alert-warning"
|
12
|
+
when :notice
|
13
|
+
"alert-info"
|
14
|
+
else
|
15
|
+
flash_type.to_s
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def form_group(f, field, control, options = {})
|
20
|
+
content_tag(:div, class: 'form-group') do
|
21
|
+
f.label(field, class: 'col-sm-2 control-label') +
|
22
|
+
content_tag(:div, class: 'col-sm-10 col-md-8') do
|
23
|
+
f.send(control, field, options.merge( class: "form-control #{options[:class]}"))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def driver_settings(form, driver)
|
29
|
+
content_tag(:div, class: 'panel panel-default') do
|
30
|
+
content_tag(:div, class: 'panel-heading') do
|
31
|
+
"#{driver.class::NAME} #{t('.settings')}".html_safe
|
32
|
+
end +
|
33
|
+
content_tag(:div, class: 'panel-body') do
|
34
|
+
render "extface/driver/#{driver.class.name.demodulize.underscore}/settings", form: form
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Extface
|
2
|
+
module DevicesHelper
|
3
|
+
|
4
|
+
def subdrivers(options, object)
|
5
|
+
object.subclasses.each do |s|
|
6
|
+
options << [s::NAME, s.name]
|
7
|
+
subdrivers(options, s) if s.subclasses.any?
|
8
|
+
end
|
9
|
+
return options
|
10
|
+
end
|
11
|
+
|
12
|
+
def options_for_drivers
|
13
|
+
Extface::Engine.eager_load!
|
14
|
+
{}.tap do |drivers|
|
15
|
+
Extface::DriverBase.subclasses.collect{ |type|
|
16
|
+
drivers[type::GROUP] = subdrivers(Array.new, type)
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|