Commit f8418da0749fba1daf5d354c30e73e4a3f030099
1 parent
31a10546
Exists in
master
and in
2 other branches
VLibras Rapid implementation
Showing
23 changed files
with
266 additions
and
63 deletions
Show diff stats
Gemfile
@@ -12,7 +12,7 @@ gem 'sass-rails', '~> 4.0.3' | @@ -12,7 +12,7 @@ gem 'sass-rails', '~> 4.0.3' | ||
12 | gem 'twitter-bootstrap-rails' | 12 | gem 'twitter-bootstrap-rails' |
13 | gem 'less-rails' | 13 | gem 'less-rails' |
14 | 14 | ||
15 | -gem 'httparty' | 15 | +gem 'httmultiparty' |
16 | 16 | ||
17 | gem 'uglifier', '>= 1.3.0' | 17 | gem 'uglifier', '>= 1.3.0' |
18 | gem 'coffee-rails', '~> 4.0.0' | 18 | gem 'coffee-rails', '~> 4.0.0' |
@@ -29,7 +29,9 @@ gem 'simple_form' | @@ -29,7 +29,9 @@ gem 'simple_form' | ||
29 | gem 'inherited_resources' | 29 | gem 'inherited_resources' |
30 | 30 | ||
31 | gem 'delayed_job_active_record' | 31 | gem 'delayed_job_active_record' |
32 | +gem 'delayed_job_web' | ||
32 | gem 'foreman' | 33 | gem 'foreman' |
34 | +gem 'carrierwave' | ||
33 | 35 | ||
34 | group :development do | 36 | group :development do |
35 | gem 'better_errors' | 37 | gem 'better_errors' |
Gemfile.lock
@@ -69,6 +69,11 @@ GEM | @@ -69,6 +69,11 @@ GEM | ||
69 | rack (>= 1.0.0) | 69 | rack (>= 1.0.0) |
70 | rack-test (>= 0.5.4) | 70 | rack-test (>= 0.5.4) |
71 | xpath (~> 2.0) | 71 | xpath (~> 2.0) |
72 | + carrierwave (0.10.0) | ||
73 | + activemodel (>= 3.2.0) | ||
74 | + activesupport (>= 3.2.0) | ||
75 | + json (>= 1.7) | ||
76 | + mime-types (>= 1.16) | ||
72 | celluloid (0.15.2) | 77 | celluloid (0.15.2) |
73 | timers (~> 1.1.0) | 78 | timers (~> 1.1.0) |
74 | celluloid-io (0.15.0) | 79 | celluloid-io (0.15.0) |
@@ -100,6 +105,10 @@ GEM | @@ -100,6 +105,10 @@ GEM | ||
100 | delayed_job_active_record (4.0.1) | 105 | delayed_job_active_record (4.0.1) |
101 | activerecord (>= 3.0, < 4.2) | 106 | activerecord (>= 3.0, < 4.2) |
102 | delayed_job (>= 3.0, < 4.1) | 107 | delayed_job (>= 3.0, < 4.1) |
108 | + delayed_job_web (1.2.9) | ||
109 | + activerecord (> 3.0.0) | ||
110 | + delayed_job (> 2.0.3) | ||
111 | + sinatra (>= 1.4.4) | ||
103 | devise (3.2.4) | 112 | devise (3.2.4) |
104 | bcrypt (~> 3.0) | 113 | bcrypt (~> 3.0) |
105 | orm_adapter (~> 0.1) | 114 | orm_adapter (~> 0.1) |
@@ -163,6 +172,10 @@ GEM | @@ -163,6 +172,10 @@ GEM | ||
163 | haml (>= 4.0.0.rc.1) | 172 | haml (>= 4.0.0.rc.1) |
164 | hpricot (~> 0.8.6) | 173 | hpricot (~> 0.8.6) |
165 | ruby_parser (~> 3.1.1) | 174 | ruby_parser (~> 3.1.1) |
175 | + httmultiparty (0.3.14) | ||
176 | + httparty (>= 0.7.3) | ||
177 | + mimemagic | ||
178 | + multipart-post | ||
166 | http_parser.rb (0.6.0) | 179 | http_parser.rb (0.6.0) |
167 | httparty (0.13.1) | 180 | httparty (0.13.1) |
168 | json (~> 1.8) | 181 | json (~> 1.8) |
@@ -200,10 +213,12 @@ GEM | @@ -200,10 +213,12 @@ GEM | ||
200 | treetop (~> 1.4.8) | 213 | treetop (~> 1.4.8) |
201 | method_source (0.8.2) | 214 | method_source (0.8.2) |
202 | mime-types (1.25.1) | 215 | mime-types (1.25.1) |
216 | + mimemagic (0.2.1) | ||
203 | mini_portile (0.5.3) | 217 | mini_portile (0.5.3) |
204 | minitest (5.3.3) | 218 | minitest (5.3.3) |
205 | multi_json (1.10.0) | 219 | multi_json (1.10.0) |
206 | multi_xml (0.5.5) | 220 | multi_xml (0.5.5) |
221 | + multipart-post (2.0.0) | ||
207 | mysql2 (0.3.15) | 222 | mysql2 (0.3.15) |
208 | nio4r (1.0.0) | 223 | nio4r (1.0.0) |
209 | nokogiri (1.6.2) | 224 | nokogiri (1.6.2) |
@@ -229,6 +244,8 @@ GEM | @@ -229,6 +244,8 @@ GEM | ||
229 | rack (1.5.2) | 244 | rack (1.5.2) |
230 | rack-livereload (0.3.15) | 245 | rack-livereload (0.3.15) |
231 | rack | 246 | rack |
247 | + rack-protection (1.5.3) | ||
248 | + rack | ||
232 | rack-test (0.6.2) | 249 | rack-test (0.6.2) |
233 | rack (>= 1.0) | 250 | rack (>= 1.0) |
234 | rails (4.1.1) | 251 | rails (4.1.1) |
@@ -304,6 +321,10 @@ GEM | @@ -304,6 +321,10 @@ GEM | ||
304 | simple_form (3.0.2) | 321 | simple_form (3.0.2) |
305 | actionpack (~> 4.0) | 322 | actionpack (~> 4.0) |
306 | activemodel (~> 4.0) | 323 | activemodel (~> 4.0) |
324 | + sinatra (1.4.5) | ||
325 | + rack (~> 1.4) | ||
326 | + rack-protection (~> 1.4) | ||
327 | + tilt (~> 1.3, >= 1.3.4) | ||
307 | slop (3.5.0) | 328 | slop (3.5.0) |
308 | spring (1.1.3) | 329 | spring (1.1.3) |
309 | sprockets (2.11.0) | 330 | sprockets (2.11.0) |
@@ -356,9 +377,11 @@ DEPENDENCIES | @@ -356,9 +377,11 @@ DEPENDENCIES | ||
356 | binding_of_caller | 377 | binding_of_caller |
357 | cancan | 378 | cancan |
358 | capybara | 379 | capybara |
380 | + carrierwave | ||
359 | coffee-rails (~> 4.0.0) | 381 | coffee-rails (~> 4.0.0) |
360 | database_cleaner | 382 | database_cleaner |
361 | delayed_job_active_record | 383 | delayed_job_active_record |
384 | + delayed_job_web | ||
362 | devise | 385 | devise |
363 | factory_girl_rails | 386 | factory_girl_rails |
364 | faker | 387 | faker |
@@ -369,7 +392,7 @@ DEPENDENCIES | @@ -369,7 +392,7 @@ DEPENDENCIES | ||
369 | guard-rspec | 392 | guard-rspec |
370 | haml-rails | 393 | haml-rails |
371 | html2haml | 394 | html2haml |
372 | - httparty | 395 | + httmultiparty |
373 | inherited_resources | 396 | inherited_resources |
374 | jquery-rails | 397 | jquery-rails |
375 | launchy | 398 | launchy |
app/admin/user.rb
@@ -0,0 +1,18 @@ | @@ -0,0 +1,18 @@ | ||
1 | +ActiveAdmin.register VLibras::Request do | ||
2 | + menu :priority => 10 | ||
3 | + | ||
4 | + | ||
5 | + # See permitted parameters documentation: | ||
6 | + # https://github.com/gregbell/active_admin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters | ||
7 | + # | ||
8 | + # permit_params :list, :of, :attributes, :on, :model | ||
9 | + # | ||
10 | + # or | ||
11 | + # | ||
12 | + # permit_params do | ||
13 | + # permitted = [:permitted, :attributes] | ||
14 | + # permitted << :other if resource.something? | ||
15 | + # permitted | ||
16 | + # end | ||
17 | + | ||
18 | +end |
@@ -0,0 +1,17 @@ | @@ -0,0 +1,17 @@ | ||
1 | +ActiveAdmin.register VLibras::Video do | ||
2 | + menu :priority => 15 | ||
3 | + | ||
4 | + # See permitted parameters documentation: | ||
5 | + # https://github.com/gregbell/active_admin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters | ||
6 | + # | ||
7 | + # permit_params :list, :of, :attributes, :on, :model | ||
8 | + # | ||
9 | + # or | ||
10 | + # | ||
11 | + # permit_params do | ||
12 | + # permitted = [:permitted, :attributes] | ||
13 | + # permitted << :other if resource.something? | ||
14 | + # permitted | ||
15 | + # end | ||
16 | + | ||
17 | +end |
app/assets/stylesheets/application.css.scss
@@ -11,6 +11,7 @@ | @@ -11,6 +11,7 @@ | ||
11 | * file per style scope. | 11 | * file per style scope. |
12 | * | 12 | * |
13 | *= require 'bootstrap' | 13 | *= require 'bootstrap' |
14 | + *= require 'bootstrap_overrides' | ||
14 | *= require 'v_libras/videos' | 15 | *= require 'v_libras/videos' |
15 | *= require_self | 16 | *= require_self |
16 | */ | 17 | */ |
@@ -0,0 +1,46 @@ | @@ -0,0 +1,46 @@ | ||
1 | +.breadcrumb { | ||
2 | + padding: 7px 14px; | ||
3 | + margin: 0 0 18px; | ||
4 | + background-color: #fbfbfb; | ||
5 | + background-image: -moz-linear-gradient(top, #ffffff, #f5f5f5); | ||
6 | + background-image: -ms-linear-gradient(top, #ffffff, #f5f5f5); | ||
7 | + background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), to(#f5f5f5)); | ||
8 | + background-image: -webkit-linear-gradient(top, #ffffff, #f5f5f5); | ||
9 | + background-image: -o-linear-gradient(top, #ffffff, #f5f5f5); | ||
10 | + background-image: linear-gradient(top, #ffffff, #f5f5f5); | ||
11 | + background-repeat: repeat-x; | ||
12 | + filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#f5f5f5', GradientType=0); | ||
13 | + background-color: #fbfbfb; | ||
14 | + background-image: -moz-linear-gradient(top, #ffffff, #f5f5f5); | ||
15 | + background-image: -ms-linear-gradient(top, #ffffff, #f5f5f5); | ||
16 | + background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), to(#f5f5f5)); | ||
17 | + background-image: -webkit-linear-gradient(top, #ffffff, #f5f5f5); | ||
18 | + background-image: -o-linear-gradient(top, #ffffff, #f5f5f5); | ||
19 | + background-image: linear-gradient(top, #ffffff, #f5f5f5); | ||
20 | + background-repeat: repeat-x; | ||
21 | + filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#f5f5f5', GradientType=0); | ||
22 | + border: 1px solid #ddd; | ||
23 | + -webkit-border-radius: 3px; | ||
24 | + -moz-border-radius: 3px; | ||
25 | + border-radius: 3px; | ||
26 | + -webkit-border-radius: 3px; | ||
27 | + -moz-border-radius: 3px; | ||
28 | + border-radius: 3px; | ||
29 | + -webkit-box-shadow: inset 0 1px 0 #ffffff; | ||
30 | + -moz-box-shadow: inset 0 1px 0 #ffffff; | ||
31 | + box-shadow: inset 0 1px 0 #ffffff; | ||
32 | + -webkit-box-shadow: inset 0 1px 0 #ffffff; | ||
33 | + -moz-box-shadow: inset 0 1px 0 #ffffff; | ||
34 | + box-shadow: inset 0 1px 0 #ffffff; | ||
35 | +} | ||
36 | +.breadcrumb li { | ||
37 | + display: inline-block; | ||
38 | + text-shadow: 0 1px 0 #ffffff; | ||
39 | +} | ||
40 | +.breadcrumb .divider { | ||
41 | + padding: 0 5px; | ||
42 | + color: #999999; | ||
43 | +} | ||
44 | +.breadcrumb .active a { | ||
45 | + color: #333333; | ||
46 | +} | ||
0 | \ No newline at end of file | 47 | \ No newline at end of file |
app/controllers/application_controller.rb
@@ -3,11 +3,10 @@ class ApplicationController < ActionController::Base | @@ -3,11 +3,10 @@ class ApplicationController < ActionController::Base | ||
3 | # For APIs, you may want to use :null_session instead. | 3 | # For APIs, you may want to use :null_session instead. |
4 | protect_from_forgery with: :exception | 4 | protect_from_forgery with: :exception |
5 | 5 | ||
6 | - | ||
7 | protected | 6 | protected |
8 | def check_vlibras_api_status | 7 | def check_vlibras_api_status |
9 | unless ApiClient.check_status | 8 | unless ApiClient.check_status |
10 | - flash[:error] = 'SEAaaS API is down :(' | 9 | + flash[:error] = t('error.api.offline') |
11 | redirect_to home_path | 10 | redirect_to home_path |
12 | end | 11 | end |
13 | end | 12 | end |
app/controllers/v_libras/requests_controller.rb
1 | class VLibras::RequestsController < ApplicationController | 1 | class VLibras::RequestsController < ApplicationController |
2 | - before_filter :check_vlibras_api_status | 2 | + protect_from_forgery with: :null_session, :only => [ :callback ] |
3 | + before_filter :check_vlibras_api_status, :only => [ :rapid, :create ] | ||
3 | 4 | ||
4 | def rapid | 5 | def rapid |
5 | @request = VLibras::Request.new | 6 | @request = VLibras::Request.new |
@@ -8,16 +9,29 @@ class VLibras::RequestsController < ApplicationController | @@ -8,16 +9,29 @@ class VLibras::RequestsController < ApplicationController | ||
8 | def create | 9 | def create |
9 | @request = VLibras::Request.build_from_params(params, current_user) | 10 | @request = VLibras::Request.build_from_params(params, current_user) |
10 | 11 | ||
12 | + video = FileUploader.new | ||
13 | + video.cache!(params[:video]) | ||
14 | + | ||
15 | + subtitle = FileUploader.new | ||
16 | + subtitle.cache!(params[:subtitle]) | ||
17 | + | ||
18 | + files = { :video => video, :subtitle => subtitle } | ||
19 | + | ||
20 | + | ||
11 | if @request.save | 21 | if @request.save |
12 | - @request.perform_request | 22 | + @request.perform_request(files) |
13 | 23 | ||
14 | flash[:success] = 'Sua requisição foi submetida com sucesso!' | 24 | flash[:success] = 'Sua requisição foi submetida com sucesso!' |
15 | - redirect_to :action => :rapid | 25 | + redirect_to v_libras_videos_path |
16 | else | 26 | else |
17 | flash[:error] = 'Algo deu errado com a sua requisição.' | 27 | flash[:error] = 'Algo deu errado com a sua requisição.' |
18 | render :action => :rapid | 28 | render :action => :rapid |
19 | end | 29 | end |
30 | + end | ||
20 | 31 | ||
32 | + def callback | ||
33 | + ApiClient::CallbackProcessor.process(params) | ||
21 | 34 | ||
35 | + render :text => "OK!" | ||
22 | end | 36 | end |
23 | end | 37 | end |
app/controllers/v_libras/videos_controller.rb
1 | class VLibras::VideosController < ApplicationController | 1 | class VLibras::VideosController < ApplicationController |
2 | - before_filter :check_vlibras_api_status | 2 | + before_filter :check_vlibras_api_status, :only => [ :index ] |
3 | 3 | ||
4 | def index | 4 | def index |
5 | @videos = current_user.videos | 5 | @videos = current_user.videos |
app/models/v_libras/request.rb
@@ -2,18 +2,20 @@ | @@ -2,18 +2,20 @@ | ||
2 | # | 2 | # |
3 | # Table name: v_libras_requests | 3 | # Table name: v_libras_requests |
4 | # | 4 | # |
5 | -# id :integer not null, primary key | ||
6 | -# status :string(255) | ||
7 | -# service_type :string(255) | ||
8 | -# owner_id :integer | ||
9 | -# params :text | ||
10 | -# response :text | ||
11 | -# created_at :datetime | ||
12 | -# updated_at :datetime | 5 | +# id :integer not null, primary key |
6 | +# status :string(255) | ||
7 | +# service_type :string(255) | ||
8 | +# owner_id :integer | ||
9 | +# params :text | ||
10 | +# response :text | ||
11 | +# created_at :datetime | ||
12 | +# updated_at :datetime | ||
13 | +# video_filename :string(255) | ||
13 | # | 14 | # |
14 | 15 | ||
15 | class VLibras::Request < ActiveRecord::Base | 16 | class VLibras::Request < ActiveRecord::Base |
16 | serialize :params | 17 | serialize :params |
18 | + attr_accessor :video | ||
17 | 19 | ||
18 | belongs_to :owner, :class => User | 20 | belongs_to :owner, :class => User |
19 | 21 | ||
@@ -21,13 +23,13 @@ class VLibras::Request < ActiveRecord::Base | @@ -21,13 +23,13 @@ class VLibras::Request < ActiveRecord::Base | ||
21 | 23 | ||
22 | validates :service_type, | 24 | validates :service_type, |
23 | presence: true, | 25 | presence: true, |
24 | - inclusion: { in: %w(video-subtitle video), message: "%{value} is not a valid service type" } | 26 | + inclusion: { in: %w(video-legenda video), message: "%{value} is not a valid service type" } |
25 | 27 | ||
26 | validates :status, | 28 | validates :status, |
27 | presence: true, | 29 | presence: true, |
28 | - inclusion: { in: %w(created processing error success), message: "%{value} is not a valid service type" } | 30 | + inclusion: { in: %w(created processing error success), message: "%{value} is not a valid status" } |
29 | 31 | ||
30 | - before_save :default_values | 32 | + before_validation :default_values |
31 | 33 | ||
32 | default_scope { order('created_at DESC') } | 34 | default_scope { order('created_at DESC') } |
33 | 35 | ||
@@ -35,6 +37,7 @@ class VLibras::Request < ActiveRecord::Base | @@ -35,6 +37,7 @@ class VLibras::Request < ActiveRecord::Base | ||
35 | request = self.new | 37 | request = self.new |
36 | 38 | ||
37 | request.service_type = params[:service] | 39 | request.service_type = params[:service] |
40 | + request.video_filename = params[:video].original_filename | ||
38 | request.owner = user | 41 | request.owner = user |
39 | 42 | ||
40 | request.params = params[:params] | 43 | request.params = params[:params] |
@@ -42,10 +45,11 @@ class VLibras::Request < ActiveRecord::Base | @@ -42,10 +45,11 @@ class VLibras::Request < ActiveRecord::Base | ||
42 | request | 45 | request |
43 | end | 46 | end |
44 | 47 | ||
45 | - def perform_request | 48 | + def perform_request(files) |
46 | logger.debug '[VLibras::Request] Starting request' | 49 | logger.debug '[VLibras::Request] Starting request' |
50 | + self.update!(status: 'processing') | ||
47 | 51 | ||
48 | - ApiClient::Client.submit(self) | 52 | + ApiClient::Client.submit(self, files) |
49 | 53 | ||
50 | logger.debug '[VLibras::Request] Request done' | 54 | logger.debug '[VLibras::Request] Request done' |
51 | end | 55 | end |
@@ -0,0 +1,42 @@ | @@ -0,0 +1,42 @@ | ||
1 | +# encoding: utf-8 | ||
2 | + | ||
3 | +class FileUploader < CarrierWave::Uploader::Base | ||
4 | + storage :file | ||
5 | + | ||
6 | + def store_dir | ||
7 | + "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" | ||
8 | + end | ||
9 | + | ||
10 | + # Provide a default URL as a default if there hasn't been a file uploaded: | ||
11 | + # def default_url | ||
12 | + # # For Rails 3.1+ asset pipeline compatibility: | ||
13 | + # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) | ||
14 | + # | ||
15 | + # "/images/fallback/" + [version_name, "default.png"].compact.join('_') | ||
16 | + # end | ||
17 | + | ||
18 | + # Process files as they are uploaded: | ||
19 | + # process :scale => [200, 300] | ||
20 | + # | ||
21 | + # def scale(width, height) | ||
22 | + # # do something | ||
23 | + # end | ||
24 | + | ||
25 | + # Create different versions of your uploaded files: | ||
26 | + # version :thumb do | ||
27 | + # process :resize_to_fit => [50, 50] | ||
28 | + # end | ||
29 | + | ||
30 | + # Add a white list of extensions which are allowed to be uploaded. | ||
31 | + # For images you might use something like this: | ||
32 | + # def extension_white_list | ||
33 | + # %w(jpg jpeg gif png) | ||
34 | + # end | ||
35 | + | ||
36 | + # Override the filename of the uploaded files: | ||
37 | + # Avoid using model.id or version_name here, see uploader/store.rb for details. | ||
38 | + # def filename | ||
39 | + # "something.jpg" if original_filename | ||
40 | + # end | ||
41 | + | ||
42 | +end |
app/views/layouts/application.html.erb
@@ -72,15 +72,13 @@ | @@ -72,15 +72,13 @@ | ||
72 | </div> | 72 | </div> |
73 | 73 | ||
74 | <div class="container"> | 74 | <div class="container"> |
75 | - <div class="body"></div> | ||
76 | - | ||
77 | <% if content_for?(:menu) %> | 75 | <% if content_for?(:menu) %> |
78 | <div class="breadcrumb"> | 76 | <div class="breadcrumb"> |
79 | <%= yield :menu %> | 77 | <%= yield :menu %> |
80 | </div> | 78 | </div> |
81 | <% end %> | 79 | <% end %> |
82 | 80 | ||
83 | - <div class="container-fluid"> | 81 | + |
84 | <% flash.each do |type, message| %> | 82 | <% flash.each do |type, message| %> |
85 | <div class="alert <%= bootstrap_class_for(type) %> fade in"> | 83 | <div class="alert <%= bootstrap_class_for(type) %> fade in"> |
86 | <button class="close" data-dismiss="alert">×</button> | 84 | <button class="close" data-dismiss="alert">×</button> |
@@ -89,7 +87,7 @@ | @@ -89,7 +87,7 @@ | ||
89 | <% end %> | 87 | <% end %> |
90 | 88 | ||
91 | <%= yield %> | 89 | <%= yield %> |
92 | - </div> | 90 | + |
93 | <footer> | 91 | <footer> |
94 | <p>GTAaaS - <%= t('shared.project') %> <a href="http://gtaaas.lavid.ufpb.br" target="_blank">LAVID</a> | © <%= Time.now.year %>. <%= t('shared.copyright') %>.</p> | 92 | <p>GTAaaS - <%= t('shared.project') %> <a href="http://gtaaas.lavid.ufpb.br" target="_blank">LAVID</a> | © <%= Time.now.year %>. <%= t('shared.copyright') %>.</p> |
95 | </footer> | 93 | </footer> |
app/views/v_libras/requests/rapid.haml
@@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
4 | %h2 | 4 | %h2 |
5 | = t('videos.new') | 5 | = t('videos.new') |
6 | 6 | ||
7 | - = form_tag v_libras_requests_path, method: :post do |f| | 7 | + = form_tag v_libras_requests_path, method: :post, :multipart => true do |f| |
8 | - if @request.errors.any? | 8 | - if @request.errors.any? |
9 | #error_explanation | 9 | #error_explanation |
10 | %p/ | 10 | %p/ |
@@ -22,28 +22,27 @@ | @@ -22,28 +22,27 @@ | ||
22 | = radio_button_tag :service, 'video', false, :id => 'service-video' | 22 | = radio_button_tag :service, 'video', false, :id => 'service-video' |
23 | Voz | 23 | Voz |
24 | %label.radio | 24 | %label.radio |
25 | - = radio_button_tag :service, 'video-subtitle', false, :id => 'service-video-subtitle' | 25 | + = radio_button_tag :service, 'video-legenda', false, :id => 'service-video-subtitle' |
26 | Legenda (.SRT) | 26 | Legenda (.SRT) |
27 | 27 | ||
28 | #url.hide | 28 | #url.hide |
29 | - = label_tag :url, t('videos.url'), :class => "bold" | ||
30 | - = file_field_tag :url, :onchange => "return check_video(this)" | 29 | + = label_tag :video, t('videos.url'), :class => "bold" |
30 | + = file_field_tag :video, :onchange => "return check_video(this)" | ||
31 | #legend.hide | 31 | #legend.hide |
32 | - = label_tag :legend, t('videos.subtitle'), :class => "bold" | ||
33 | - = file_field_tag :legend, :prompt => "LEGENDA", :onchange => "return check_subtitle(this)" | 32 | + = label_tag :subtitle, t('videos.subtitle'), :class => "bold" |
33 | + = file_field_tag :subtitle, :prompt => "LEGENDA", :onchange => "return check_subtitle(this)" | ||
34 | .field | 34 | .field |
35 | - = label_tag 'params[:window_size]', t('videos.window_size'), :class => "bold" | ||
36 | - = select_tag 'params[:window_size]', options_for_select([['Pequena', 'pequeno'], ['Média', 'medio'], ['Grande', 'grande']]) | 35 | + = label_tag 'params[tamanho]', t('videos.window_size'), :class => "bold" |
36 | + = select_tag 'params[tamanho]', options_for_select([['Pequena', 'pequeno'], ['Média', 'medio'], ['Grande', 'grande']]) | ||
37 | .field | 37 | .field |
38 | %p | 38 | %p |
39 | %b | 39 | %b |
40 | - = label_tag 'params[:window_position]', t('videos.window_position'), :class => "bold" | ||
41 | - = select_tag 'params[:window_position]', options_for_select([[t('videos.top_left'), | 40 | + = label_tag 'params[posicao]', t('videos.window_position'), :class => "bold" |
41 | + = select_tag 'params[posicao]', options_for_select([[t('videos.top_left'), | ||
42 | 'superior-esquerdo'], [t('videos.top_right'), 'superior-direito'], | 42 | 'superior-esquerdo'], [t('videos.top_right'), 'superior-direito'], |
43 | [t('videos.bottom_right'),'inferior-direito'], [t('videos.bottom_left'), 'inferior-esquerdo']]) | 43 | [t('videos.bottom_right'),'inferior-direito'], [t('videos.bottom_left'), 'inferior-esquerdo']]) |
44 | .field | 44 | .field |
45 | - = label_tag 'params[:transparency]', t('videos.transparency'), :class => "bold" | ||
46 | - = select_tag 'params[:transparency]', options_for_select([['Opaco', 'opaco'], ['Transparente', 'transparente']]) | ||
47 | - = hidden_field_tag :user_id, :value => current_user.id | 45 | + = label_tag 'params[transparencia]', t('videos.transparency'), :class => "bold" |
46 | + = select_tag 'params[transparencia]', options_for_select([['Opaco', 'opaco'], ['Transparente', 'transparente']]) | ||
48 | = submit_tag "Confirmar", :class => "btn btn-primary actions" | 47 | = submit_tag "Confirmar", :class => "btn btn-primary actions" |
49 | 48 |
app/views/v_libras/videos/index.haml
1 | .breadcrumb | 1 | .breadcrumb |
2 | %h3= t('videos.list') | 2 | %h3= t('videos.list') |
3 | 3 | ||
4 | -.row | 4 | +.row.text-center |
5 | - @videos.each do |video| | 5 | - @videos.each do |video| |
6 | - .span3 | ||
7 | - = link_to image_tag("avatar.png"), video_path(video) | 6 | + .span4 |
7 | + = link_to image_tag("avatar.png"), video.url | ||
8 | %p | 8 | %p |
9 | = link_to t('videos.show'), video_path(video), class: "btn btn-success" | 9 | = link_to t('videos.show'), video_path(video), class: "btn btn-success" |
10 | = link_to t('videos.delete'), video_path(video), confirm: t('shared.confirm_delete'), method: :delete, class: "btn btn-danger" | 10 | = link_to t('videos.delete'), video_path(video), confirm: t('shared.confirm_delete'), method: :delete, class: "btn btn-danger" |
11 | 11 | ||
12 | - | ||
13 | .breadcrumb.requests | 12 | .breadcrumb.requests |
14 | %h4= t('requests.list') | 13 | %h4= t('requests.list') |
15 | 14 | ||
16 | -.row | ||
17 | - %table.table.table-hover.table-striped.table-requests.span6.offset3 | 15 | +.row-fluid |
16 | + %table.table.table-hover.table-striped.table-requests.span8.offset2 | ||
18 | %thead | 17 | %thead |
19 | %tr | 18 | %tr |
20 | %th Situação | 19 | %th Situação |
@@ -23,9 +22,9 @@ | @@ -23,9 +22,9 @@ | ||
23 | 22 | ||
24 | - @requests.each do |request| | 23 | - @requests.each do |request| |
25 | %tr | 24 | %tr |
26 | - %td.span1= request_status_label(request.status) | ||
27 | - %td.span2 Vídeo | ||
28 | - %td.span3= time_ago_in_words(request.created_at) | 25 | + %td.span2= request_status_label(request.status) |
26 | + %td.span5= request.video_filename | ||
27 | + %td.span5= time_ago_in_words(request.created_at) | ||
29 | 28 | ||
30 | 29 | ||
31 | 30 |
config/initializers/active_admin.rb
@@ -195,11 +195,11 @@ ActiveAdmin.setup do |config| | @@ -195,11 +195,11 @@ ActiveAdmin.setup do |config| | ||
195 | # | 195 | # |
196 | # If you wanted to add a static menu item to the default menu provided: | 196 | # If you wanted to add a static menu item to the default menu provided: |
197 | # | 197 | # |
198 | - # config.namespace :admin do |admin| | ||
199 | - # admin.build_menu :default do |menu| | ||
200 | - # menu.add label: "My Great Website", url: "http://www.mygreatwebsite.com", html_options: { target: :blank } | ||
201 | - # end | ||
202 | - # end | 198 | + config.namespace :admin do |admin| |
199 | + admin.build_menu :default do |menu| | ||
200 | + menu.add label: 'Background Jobs Admin', url: 'delayed_job' | ||
201 | + end | ||
202 | + end | ||
203 | 203 | ||
204 | 204 | ||
205 | # == Download Links | 205 | # == Download Links |
@@ -0,0 +1,7 @@ | @@ -0,0 +1,7 @@ | ||
1 | +class CanAccessDelayedJobWeb | ||
2 | + def self.matches?(request) | ||
3 | + current_user = request.env['warden'].user | ||
4 | + return false if current_user.blank? | ||
5 | + Ability.new(current_user).can? :manage, DelayedJobWeb | ||
6 | + end | ||
7 | +end | ||
0 | \ No newline at end of file | 8 | \ No newline at end of file |
config/locales/pt-BR.yml
@@ -9,6 +9,10 @@ pt-BR: | @@ -9,6 +9,10 @@ pt-BR: | ||
9 | error: 'Erro' | 9 | error: 'Erro' |
10 | success: 'Sucesso' | 10 | success: 'Sucesso' |
11 | 11 | ||
12 | + error: | ||
13 | + api: | ||
14 | + offline: 'O serviço de tradução de LIBRAS está fora do ar. Iremos notificar o administrador. Desculpe-nos o inconveniente.' | ||
15 | + | ||
12 | shared: | 16 | shared: |
13 | main: "MENU" | 17 | main: "MENU" |
14 | about: "SOBRE O PROJETO" | 18 | about: "SOBRE O PROJETO" |
config/routes.rb
1 | Rails.application.routes.draw do | 1 | Rails.application.routes.draw do |
2 | devise_for :users, ActiveAdmin::Devise.config | 2 | devise_for :users, ActiveAdmin::Devise.config |
3 | 3 | ||
4 | + constraints CanAccessDelayedJobWeb do | ||
5 | + namespace :admin do | ||
6 | + match "/delayed_job" => DelayedJobWeb, :anchor => false, via: [:get, :post] | ||
7 | + end | ||
8 | + end | ||
9 | + | ||
4 | ActiveAdmin.routes(self) | 10 | ActiveAdmin.routes(self) |
5 | 11 | ||
6 | root 'static#home', as: :home | 12 | root 'static#home', as: :home |
@@ -8,9 +14,12 @@ Rails.application.routes.draw do | @@ -8,9 +14,12 @@ Rails.application.routes.draw do | ||
8 | namespace :v_libras do | 14 | namespace :v_libras do |
9 | resources :requests, :only => [ :new, :create ] do | 15 | resources :requests, :only => [ :new, :create ] do |
10 | get 'rapid', on: :collection | 16 | get 'rapid', on: :collection |
17 | + post 'callback', on: :collection | ||
11 | end | 18 | end |
12 | 19 | ||
13 | resources :videos, :only => [ :index ] | 20 | resources :videos, :only => [ :index ] |
21 | + | ||
22 | + | ||
14 | end | 23 | end |
15 | 24 | ||
16 | end | 25 | end |
db/migrate/20140523175644_add_video_filename_to_request.rb
0 → 100644
db/schema.rb
@@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
11 | # | 11 | # |
12 | # It's strongly recommended that you check this file into your version control system. | 12 | # It's strongly recommended that you check this file into your version control system. |
13 | 13 | ||
14 | -ActiveRecord::Schema.define(version: 20140522160613) do | 14 | +ActiveRecord::Schema.define(version: 20140523175644) do |
15 | 15 | ||
16 | create_table "delayed_jobs", force: true do |t| | 16 | create_table "delayed_jobs", force: true do |t| |
17 | t.integer "priority", default: 0, null: false | 17 | t.integer "priority", default: 0, null: false |
@@ -74,6 +74,7 @@ ActiveRecord::Schema.define(version: 20140522160613) do | @@ -74,6 +74,7 @@ ActiveRecord::Schema.define(version: 20140522160613) do | ||
74 | t.text "response" | 74 | t.text "response" |
75 | t.datetime "created_at" | 75 | t.datetime "created_at" |
76 | t.datetime "updated_at" | 76 | t.datetime "updated_at" |
77 | + t.string "video_filename" | ||
77 | end | 78 | end |
78 | 79 | ||
79 | create_table "v_libras_videos", force: true do |t| | 80 | create_table "v_libras_videos", force: true do |t| |
@@ -0,0 +1,7 @@ | @@ -0,0 +1,7 @@ | ||
1 | +class ApiClient::CallbackProcessor | ||
2 | + def self.process(params) | ||
3 | + request = VLibras::Request.find(params[:request_id]) | ||
4 | + request.update(:status => 'success') | ||
5 | + request.create_video(:url => params['response']) | ||
6 | + end | ||
7 | +end | ||
0 | \ No newline at end of file | 8 | \ No newline at end of file |
lib/api_client/client.rb
1 | require 'httparty' | 1 | require 'httparty' |
2 | 2 | ||
3 | module ApiClient::Client | 3 | module ApiClient::Client |
4 | - include HTTParty | 4 | + include HTTMultiParty |
5 | default_timeout 10 * 60 | 5 | default_timeout 10 * 60 |
6 | 6 | ||
7 | - def self.submit(request) | ||
8 | - request.update(status: 'processing') | 7 | + def self.submit(request, files) |
8 | + o = { query: request.params.clone } | ||
9 | + o[:query].merge!({ :servico => request.service_type }) | ||
10 | + o[:query].merge!({ :callback => "http://150.165.205.192:3000/v_libras/requests/callback?request_id=#{request.id}" }) | ||
9 | 11 | ||
10 | - options = { query: request.params } | 12 | + o[:query].merge!({ :video => files[:video].file.to_file }) |
11 | 13 | ||
12 | - Delayed::Worker.logger.debug "[VLibras::Request] Options: #{options}" | 14 | + unless files[:subtitle].file.nil? |
15 | + o[:query].merge!({ :legenda => files[:subtitle].file.to_file }) | ||
16 | + o[:query].merge!({ :linguagem => 'portugues' }) | ||
17 | + end | ||
13 | 18 | ||
14 | - binding.pry | 19 | + Delayed::Worker.logger.debug "[VLibras::Request] Options: #{o}" |
15 | 20 | ||
16 | - response = self.post(url_with_service('texto'), { query: { texto: 'bola', transparencia: 'opaco' } }) | 21 | + response = self.post(ApiClient::API_URL, o) |
17 | 22 | ||
18 | Delayed::Worker.logger.debug "[VLibras::Request] Status #{response.response.code}" | 23 | Delayed::Worker.logger.debug "[VLibras::Request] Status #{response.response.code}" |
19 | 24 | ||
20 | if response.response.code == '200' | 25 | if response.response.code == '200' |
21 | - request.create_video(:url => response.parsed_response['response']) | ||
22 | - request.update(:status => 'success') | 26 | + |
23 | else | 27 | else |
24 | - request.update(:response => response.body, :status => 'error') | 28 | + request.update!(:response => response.body, :status => 'error') |
25 | end | 29 | end |
30 | + rescue | ||
31 | + | ||
26 | end | 32 | end |
27 | 33 | ||
28 | private | 34 | private |