From 73abd85f6181e33fe0b2fe31a5c46f2fbc44eb8a Mon Sep 17 00:00:00 2001 From: Luc Donnet Date: Thu, 7 May 2015 14:40:37 +0200 Subject: Fix import --- app/assets/stylesheets/main/imports.css.scss | 1 + app/controllers/exports_controller.rb | 2 +- app/controllers/imports_controller.rb | 6 ++- app/models/import.rb | 46 +----------------- app/views/imports/_import.erb | 13 ++--- app/views/imports/_results_dashboard.html.erb | 70 --------------------------- app/views/imports/show.html.erb | 15 +++++- app/views/imports/show.js.coffee | 45 ----------------- 8 files changed, 26 insertions(+), 172 deletions(-) delete mode 100644 app/views/imports/_results_dashboard.html.erb delete mode 100644 app/views/imports/show.js.coffee diff --git a/app/assets/stylesheets/main/imports.css.scss b/app/assets/stylesheets/main/imports.css.scss index cd5ce6d27..9fc6d300c 100644 --- a/app/assets/stylesheets/main/imports.css.scss +++ b/app/assets/stylesheets/main/imports.css.scss @@ -4,6 +4,7 @@ #workspace.imports.show { @import "../partials/ie_report"; + @import "../modules/job_status_colors"; .links{ margin: 0 0 20px 0; diff --git a/app/controllers/exports_controller.rb b/app/controllers/exports_controller.rb index b41ce1ca0..68ee00568 100644 --- a/app/controllers/exports_controller.rb +++ b/app/controllers/exports_controller.rb @@ -5,7 +5,7 @@ class ExportsController < ChouetteController defaults :resource_class => Export respond_to :html, :only => [:show, :index, :destroy, :exported_file] - respond_to :js, :only => [:show, :index] + respond_to :js, :only => [:index] belongs_to :referential def index diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb index 752c08f5b..3b02c9026 100644 --- a/app/controllers/imports_controller.rb +++ b/app/controllers/imports_controller.rb @@ -6,7 +6,7 @@ class ImportsController < ChouetteController defaults :resource_class => Import respond_to :html, :only => [:show, :index, :destroy, :imported_file, :rule_parameter_set, :compliance_check] - respond_to :js, :only => [:show, :index, :compliance_check] + respond_to :js, :only => [:index, :compliance_check] belongs_to :referential def index @@ -44,6 +44,10 @@ class ImportsController < ChouetteController end def imported_file + # WARNING : files under 10kb in size get treated as StringIO by OpenUri + # http://stackoverflow.com/questions/10496874/why-does-openuri-treat-files-under-10kb-in-size-as-stringio + OpenURI::Buffer.send :remove_const, 'StringMax' if OpenURI::Buffer.const_defined?('StringMax') + OpenURI::Buffer.const_set 'StringMax', 0 begin send_file open(resource.file_path), { :type => "application/#{resource.filename_extension}", :disposition => "attachment", :filename => resource.filename } rescue Ievkit::Error => error diff --git a/app/models/import.rb b/app/models/import.rb index 903da32aa..54795361e 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -1,23 +1,7 @@ require 'open-uri' class Import - extend ActiveModel::Naming - extend ActiveModel::Translation - include ActiveModel::Model - - attr_reader :datas - - def initialize( response ) - @datas = response - end - - def links - {}.tap do |links| - datas.links.each do |link| - links[link["rel"]] = link["href"] - end - end - end + include JobConcern def compliance_check_validation_report report_path = links["validation_report"] @@ -82,40 +66,12 @@ class Import File.extname(filename).gsub(".", "") if filename end - def id - datas.id - end - - def status - datas.status.downcase - end - def format datas.type end - def referential_name - datas.referential - end - - def name - datas.action_parameters.name - end - - def user_name - datas.action_parameters.user_name - end - def no_save datas.action_parameters.no_save end - def created_at - Time.at(datas.created.to_i / 1000) if datas.created - end - - def updated_at - Time.at(datas.updated.to_i / 1000) if datas.updated - end - end diff --git a/app/views/imports/_import.erb b/app/views/imports/_import.erb index 6824b9bf7..11dae5638 100644 --- a/app/views/imports/_import.erb +++ b/app/views/imports/_import.erb @@ -8,24 +8,21 @@
<%= link_to image_tag("icons/file_#{import.filename_extension}.png") + t("imports.show.imported_file"), imported_file_referential_import_path(@referential, import.id) %>
- <% if import.rule_parameter_set %> +<%= link_to image_tag("icons/file_#{import.filename_extension}.png") + t("imports.show.imported_file"), imported_file_referential_import_path(@referential, import.id) if !import.aborted? %>
+ <% if import.rule_parameter_set && !import.aborted? %><%= link_to image_tag("icons/link_page.png") + t("imports.show.rule_parameter_set"), rule_parameter_set_referential_import_path(@referential, import.id) %>
<% end %> - <% if import.compliance_check %> + <% if import.compliance_check && !import.aborted? %><%= link_to image_tag("icons/link_page.png") + t("imports.show.compliance_check"), compliance_check_referential_import_path(@referential, import.id) %>
<% end %>