diff --git a/Gemfile b/Gemfile index 936139a..f5217d1 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,7 @@ gem 'sass-rails', '~> 4.0.3' gem 'twitter-bootstrap-rails' gem 'less-rails' -gem 'httparty' +gem 'httmultiparty' gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.0.0' @@ -29,7 +29,9 @@ gem 'simple_form' gem 'inherited_resources' gem 'delayed_job_active_record' +gem 'delayed_job_web' gem 'foreman' +gem 'carrierwave' group :development do gem 'better_errors' diff --git a/Gemfile.lock b/Gemfile.lock index 9cafaea..8711895 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -69,6 +69,11 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) + carrierwave (0.10.0) + activemodel (>= 3.2.0) + activesupport (>= 3.2.0) + json (>= 1.7) + mime-types (>= 1.16) celluloid (0.15.2) timers (~> 1.1.0) celluloid-io (0.15.0) @@ -100,6 +105,10 @@ GEM delayed_job_active_record (4.0.1) activerecord (>= 3.0, < 4.2) delayed_job (>= 3.0, < 4.1) + delayed_job_web (1.2.9) + activerecord (> 3.0.0) + delayed_job (> 2.0.3) + sinatra (>= 1.4.4) devise (3.2.4) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -163,6 +172,10 @@ GEM haml (>= 4.0.0.rc.1) hpricot (~> 0.8.6) ruby_parser (~> 3.1.1) + httmultiparty (0.3.14) + httparty (>= 0.7.3) + mimemagic + multipart-post http_parser.rb (0.6.0) httparty (0.13.1) json (~> 1.8) @@ -200,10 +213,12 @@ GEM treetop (~> 1.4.8) method_source (0.8.2) mime-types (1.25.1) + mimemagic (0.2.1) mini_portile (0.5.3) minitest (5.3.3) multi_json (1.10.0) multi_xml (0.5.5) + multipart-post (2.0.0) mysql2 (0.3.15) nio4r (1.0.0) nokogiri (1.6.2) @@ -229,6 +244,8 @@ GEM rack (1.5.2) rack-livereload (0.3.15) rack + rack-protection (1.5.3) + rack rack-test (0.6.2) rack (>= 1.0) rails (4.1.1) @@ -304,6 +321,10 @@ GEM simple_form (3.0.2) actionpack (~> 4.0) activemodel (~> 4.0) + sinatra (1.4.5) + rack (~> 1.4) + rack-protection (~> 1.4) + tilt (~> 1.3, >= 1.3.4) slop (3.5.0) spring (1.1.3) sprockets (2.11.0) @@ -356,9 +377,11 @@ DEPENDENCIES binding_of_caller cancan capybara + carrierwave coffee-rails (~> 4.0.0) database_cleaner delayed_job_active_record + delayed_job_web devise factory_girl_rails faker @@ -369,7 +392,7 @@ DEPENDENCIES guard-rspec haml-rails html2haml - httparty + httmultiparty inherited_resources jquery-rails launchy diff --git a/app/admin/user.rb b/app/admin/user.rb index c9b8ee7..2c80e45 100644 --- a/app/admin/user.rb +++ b/app/admin/user.rb @@ -1,4 +1,6 @@ ActiveAdmin.register User do + menu :priority => 80 + permit_params :email, :password, :password_confirmation index do diff --git a/app/admin/v_libras_request.rb b/app/admin/v_libras_request.rb new file mode 100644 index 0000000..b643abc --- /dev/null +++ b/app/admin/v_libras_request.rb @@ -0,0 +1,18 @@ +ActiveAdmin.register VLibras::Request do + menu :priority => 10 + + + # See permitted parameters documentation: + # https://github.com/gregbell/active_admin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters + # + # permit_params :list, :of, :attributes, :on, :model + # + # or + # + # permit_params do + # permitted = [:permitted, :attributes] + # permitted << :other if resource.something? + # permitted + # end + +end diff --git a/app/admin/v_libras_video.rb b/app/admin/v_libras_video.rb new file mode 100644 index 0000000..6648e3a --- /dev/null +++ b/app/admin/v_libras_video.rb @@ -0,0 +1,17 @@ +ActiveAdmin.register VLibras::Video do + menu :priority => 15 + + # See permitted parameters documentation: + # https://github.com/gregbell/active_admin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters + # + # permit_params :list, :of, :attributes, :on, :model + # + # or + # + # permit_params do + # permitted = [:permitted, :attributes] + # permitted << :other if resource.something? + # permitted + # end + +end diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index a089a6d..050ab95 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -11,6 +11,7 @@ * file per style scope. * *= require 'bootstrap' + *= require 'bootstrap_overrides' *= require 'v_libras/videos' *= require_self */ diff --git a/app/assets/stylesheets/bootstrap_overrides.css.scss b/app/assets/stylesheets/bootstrap_overrides.css.scss new file mode 100644 index 0000000..8aecd73 --- /dev/null +++ b/app/assets/stylesheets/bootstrap_overrides.css.scss @@ -0,0 +1,46 @@ +.breadcrumb { + padding: 7px 14px; + margin: 0 0 18px; + background-color: #fbfbfb; + background-image: -moz-linear-gradient(top, #ffffff, #f5f5f5); + background-image: -ms-linear-gradient(top, #ffffff, #f5f5f5); + background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), to(#f5f5f5)); + background-image: -webkit-linear-gradient(top, #ffffff, #f5f5f5); + background-image: -o-linear-gradient(top, #ffffff, #f5f5f5); + background-image: linear-gradient(top, #ffffff, #f5f5f5); + background-repeat: repeat-x; + filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#f5f5f5', GradientType=0); + background-color: #fbfbfb; + background-image: -moz-linear-gradient(top, #ffffff, #f5f5f5); + background-image: -ms-linear-gradient(top, #ffffff, #f5f5f5); + background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), to(#f5f5f5)); + background-image: -webkit-linear-gradient(top, #ffffff, #f5f5f5); + background-image: -o-linear-gradient(top, #ffffff, #f5f5f5); + background-image: linear-gradient(top, #ffffff, #f5f5f5); + background-repeat: repeat-x; + filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#f5f5f5', GradientType=0); + border: 1px solid #ddd; + -webkit-border-radius: 3px; + -moz-border-radius: 3px; + border-radius: 3px; + -webkit-border-radius: 3px; + -moz-border-radius: 3px; + border-radius: 3px; + -webkit-box-shadow: inset 0 1px 0 #ffffff; + -moz-box-shadow: inset 0 1px 0 #ffffff; + box-shadow: inset 0 1px 0 #ffffff; + -webkit-box-shadow: inset 0 1px 0 #ffffff; + -moz-box-shadow: inset 0 1px 0 #ffffff; + box-shadow: inset 0 1px 0 #ffffff; +} +.breadcrumb li { + display: inline-block; + text-shadow: 0 1px 0 #ffffff; +} +.breadcrumb .divider { + padding: 0 5px; + color: #999999; +} +.breadcrumb .active a { + color: #333333; +} \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b78efb7..839e8dc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,11 +3,10 @@ class ApplicationController < ActionController::Base # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception - protected def check_vlibras_api_status unless ApiClient.check_status - flash[:error] = 'SEAaaS API is down :(' + flash[:error] = t('error.api.offline') redirect_to home_path end end diff --git a/app/controllers/v_libras/requests_controller.rb b/app/controllers/v_libras/requests_controller.rb index 83d8773..01d7ae4 100644 --- a/app/controllers/v_libras/requests_controller.rb +++ b/app/controllers/v_libras/requests_controller.rb @@ -1,5 +1,6 @@ class VLibras::RequestsController < ApplicationController - before_filter :check_vlibras_api_status + protect_from_forgery with: :null_session, :only => [ :callback ] + before_filter :check_vlibras_api_status, :only => [ :rapid, :create ] def rapid @request = VLibras::Request.new @@ -8,16 +9,29 @@ class VLibras::RequestsController < ApplicationController def create @request = VLibras::Request.build_from_params(params, current_user) + video = FileUploader.new + video.cache!(params[:video]) + + subtitle = FileUploader.new + subtitle.cache!(params[:subtitle]) + + files = { :video => video, :subtitle => subtitle } + + if @request.save - @request.perform_request + @request.perform_request(files) flash[:success] = 'Sua requisição foi submetida com sucesso!' - redirect_to :action => :rapid + redirect_to v_libras_videos_path else flash[:error] = 'Algo deu errado com a sua requisição.' render :action => :rapid end + end + def callback + ApiClient::CallbackProcessor.process(params) + render :text => "OK!" end end diff --git a/app/controllers/v_libras/videos_controller.rb b/app/controllers/v_libras/videos_controller.rb index c491b8f..b446271 100644 --- a/app/controllers/v_libras/videos_controller.rb +++ b/app/controllers/v_libras/videos_controller.rb @@ -1,5 +1,5 @@ class VLibras::VideosController < ApplicationController - before_filter :check_vlibras_api_status + before_filter :check_vlibras_api_status, :only => [ :index ] def index @videos = current_user.videos diff --git a/app/models/v_libras/request.rb b/app/models/v_libras/request.rb index b337f98..76bccc2 100644 --- a/app/models/v_libras/request.rb +++ b/app/models/v_libras/request.rb @@ -2,18 +2,20 @@ # # Table name: v_libras_requests # -# id :integer not null, primary key -# status :string(255) -# service_type :string(255) -# owner_id :integer -# params :text -# response :text -# created_at :datetime -# updated_at :datetime +# id :integer not null, primary key +# status :string(255) +# service_type :string(255) +# owner_id :integer +# params :text +# response :text +# created_at :datetime +# updated_at :datetime +# video_filename :string(255) # class VLibras::Request < ActiveRecord::Base serialize :params + attr_accessor :video belongs_to :owner, :class => User @@ -21,13 +23,13 @@ class VLibras::Request < ActiveRecord::Base validates :service_type, presence: true, - inclusion: { in: %w(video-subtitle video), message: "%{value} is not a valid service type" } + inclusion: { in: %w(video-legenda video), message: "%{value} is not a valid service type" } validates :status, presence: true, - inclusion: { in: %w(created processing error success), message: "%{value} is not a valid service type" } + inclusion: { in: %w(created processing error success), message: "%{value} is not a valid status" } - before_save :default_values + before_validation :default_values default_scope { order('created_at DESC') } @@ -35,6 +37,7 @@ class VLibras::Request < ActiveRecord::Base request = self.new request.service_type = params[:service] + request.video_filename = params[:video].original_filename request.owner = user request.params = params[:params] @@ -42,10 +45,11 @@ class VLibras::Request < ActiveRecord::Base request end - def perform_request + def perform_request(files) logger.debug '[VLibras::Request] Starting request' + self.update!(status: 'processing') - ApiClient::Client.submit(self) + ApiClient::Client.submit(self, files) logger.debug '[VLibras::Request] Request done' end diff --git a/app/uploaders/file_uploader.rb b/app/uploaders/file_uploader.rb new file mode 100644 index 0000000..866e348 --- /dev/null +++ b/app/uploaders/file_uploader.rb @@ -0,0 +1,42 @@ +# encoding: utf-8 + +class FileUploader < CarrierWave::Uploader::Base + storage :file + + def store_dir + "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + end + + # Provide a default URL as a default if there hasn't been a file uploaded: + # def default_url + # # For Rails 3.1+ asset pipeline compatibility: + # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) + # + # "/images/fallback/" + [version_name, "default.png"].compact.join('_') + # end + + # Process files as they are uploaded: + # process :scale => [200, 300] + # + # def scale(width, height) + # # do something + # end + + # Create different versions of your uploaded files: + # version :thumb do + # process :resize_to_fit => [50, 50] + # end + + # Add a white list of extensions which are allowed to be uploaded. + # For images you might use something like this: + # def extension_white_list + # %w(jpg jpeg gif png) + # end + + # Override the filename of the uploaded files: + # Avoid using model.id or version_name here, see uploader/store.rb for details. + # def filename + # "something.jpg" if original_filename + # end + +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 5004f84..f7cdf9d 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -72,15 +72,13 @@