aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Donnet2015-05-07 14:40:37 +0200
committerLuc Donnet2015-05-07 14:40:37 +0200
commit73abd85f6181e33fe0b2fe31a5c46f2fbc44eb8a (patch)
treef284e3994937c1e58a68625dc347a0ad7d557945
parent46c9cd634a1b2f36df872bd0acbca25884673810 (diff)
downloadchouette-core-73abd85f6181e33fe0b2fe31a5c46f2fbc44eb8a.tar.bz2
Fix import
-rw-r--r--app/assets/stylesheets/main/imports.css.scss1
-rw-r--r--app/controllers/exports_controller.rb2
-rw-r--r--app/controllers/imports_controller.rb6
-rw-r--r--app/models/import.rb46
-rw-r--r--app/views/imports/_import.erb13
-rw-r--r--app/views/imports/_results_dashboard.html.erb70
-rw-r--r--app/views/imports/show.html.erb15
-rw-r--r--app/views/imports/show.js.coffee45
8 files changed, 26 insertions, 172 deletions
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 @@
</span>
<h5>
<%= link_to( referential_import_path(@referential, import.id), :class => "preview", :title => "#{ImportTask.model_name.human.capitalize} #{import.name}") do %>
- <span class="name">
- <%= truncate(import.name, :length => 20) %>
- </span>
+ <%= job_status_title(import) %>
<% end %>
</h5>
</div>
</div>
<div class="panel-body">
- <p><%= link_to image_tag("icons/file_#{import.filename_extension}.png") + t("imports.show.imported_file"), imported_file_referential_import_path(@referential, import.id) %></p>
- <% if import.rule_parameter_set %>
+ <p><%= 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? %></p>
+ <% if import.rule_parameter_set && !import.aborted? %>
<p><%= link_to image_tag("icons/link_page.png") + t("imports.show.rule_parameter_set"), rule_parameter_set_referential_import_path(@referential, import.id) %></p>
<% end %>
- <% if import.compliance_check %>
+ <% if import.compliance_check && !import.aborted? %>
<p><%= link_to image_tag("icons/link_page.png") + t("imports.show.compliance_check"), compliance_check_referential_import_path(@referential, import.id) %></p>
<% end %>
</div>
- <div class="panel-footer">
- <%= progress_bar_tag(import) %>
+ <div class="panel-footer">
<div class="history">
<%= l(import.created_at, :format => "%d/%m/%Y %H:%M") if import.created_at %> | <%= import.user_name %>
</div>
diff --git a/app/views/imports/_results_dashboard.html.erb b/app/views/imports/_results_dashboard.html.erb
deleted file mode 100644
index 8fad7e9fb..000000000
--- a/app/views/imports/_results_dashboard.html.erb
+++ /dev/null
@@ -1,70 +0,0 @@
-<div class="resume row">
- <div class="col-md-4">
- <% file_title = (@import.filename_extension=="zip") ? t("imports.show.graph.files.title_zip") : t("imports.show.graph.files.title_default", :extension => @import.filename_extension)%>
- <div class="caption"><%= file_title %></div>
- <div id="files_statistics"></div>
- </div>
- <div class="col-md-8">
- <div class="caption"><%= t "imports.show.graph.lines.title" %></div>
- <div id="objects_statistics"></div>
- </div>
-</div>
-
-<div class="report">
- <div class="files files_error">
- <% @import.report.error_files.each_with_index do |file, index| %>
- <div class="col-md-6">
- <%= image_tag "icons/file_xml_md.png" %><span class="file_name" title='<%= file.name %>'><%= truncate(file.name, :length => 40) %></span>
- </div>
- <% end %>
- </div>
- <div class="files files_ignored">
- <% @import.report.ignored_files.each_with_index do |file, index| %>
- <div class="col-md-6">
- <%= image_tag "icons/file_xml_md.png" %><span class="file_name" title='<%= file.name %>'><%= truncate(file.name, :length => 40) %></span>
- </div>
- <% end %>
- </div>
- <div class="files files_ok">
- <% @import.report.ok_files.each_with_index do |file, index| %>
- <div class="col-md-6">
- <%= image_tag "icons/file_xml_md.png" %><span class="file_name" title='<%= file.name %>'><%= truncate(file.name, :length => 40) %></span>
- </div>
- <% end %>
- </div>
- <div class="lines">
- <table class="table table-hover table-striped">
- <thead>
- <tr>
- <th><%= t("import_tasks.show.table.line.name") %></th>
- <th><%= t("import_tasks.show.table.line.save") %></th>
- <th><%= t("import_tasks.show.table.line.routes") %></th>
- <th><%= t("import_tasks.show.table.line.connection_links") %></th>
- <th><%= t("import_tasks.show.table.line.time_tables") %></th>
- <th><%= t("import_tasks.show.table.line.stop_areas") %></th>
- <th><%= t("import_tasks.show.table.line.access_points") %></th>
- <th><%= t("import_tasks.show.table.line.vehicle_journeys") %></th>
- <th><%= t("import_tasks.show.table.line.journey_patterns") %></th>
- </tr>
- </thead>
- <tbody>
- <% @import.report.line_items.each_with_index do |line_item, index| %>
- <% tr_class = (line_item.status == "saved") ? '' : 'class=\'danger\''%>
- <tr <%= tr_class %>>
- <td><%= line_item.name %></td>
- <td><%= t("import_tasks.show.table.line." + line_item.status ) %></td>
- <td><%= line_item.routes %></td>
- <td><%= line_item.connection_links %></td>
- <td><%= line_item.time_tables %></td>
- <td><%= line_item.stop_areas %></td>
- <td><%= line_item.access_points %></td>
- <td><%= line_item.vehicle_journeys %></td>
- <td><%= line_item.journey_patterns %></td>
- </tr>
- <% end %>
- </tbody>
- </table>
- </div>
-</div>
-<%= javascript_include_tag referential_import_path(@referential, @import.id,:format => :js) %>
-
diff --git a/app/views/imports/show.html.erb b/app/views/imports/show.html.erb
index 796f7981e..90524eedc 100644
--- a/app/views/imports/show.html.erb
+++ b/app/views/imports/show.html.erb
@@ -1,10 +1,21 @@
<div class="test">
- <%= title_tag "#{title} #{@import.name} <span class='status status_#{@import.status}'>#{ t('imports.statuses.'+ @import.status) }</span>" %>
+ <%= title_tag job_status_title(@import) %>
</div>
+<% if !@import.aborted? %>
<div class="import_show">
- <%= render( :partial => "results_dashboard", :locals => { :referential => @referential} ) %>
+ <div class="links">
+ <%= 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 %>
+ <%= 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 %>
+ <%= link_to image_tag("icons/link_page.png") + t("imports.show.compliance_check"), compliance_check_referential_import_path(@referential, @import.id) %>
+ <% end %>
+ </div>
+ <%= render( :partial => "shared/ie_report.html", :locals => { :referential => @referential, :job => @import} ) %>
</div>
+<% end %>
<% content_for :sidebar do %>
<ul class="actions">
diff --git a/app/views/imports/show.js.coffee b/app/views/imports/show.js.coffee
deleted file mode 100644
index e2416e967..000000000
--- a/app/views/imports/show.js.coffee
+++ /dev/null
@@ -1,45 +0,0 @@
-jQuery ->
-
- get_import_results = (html_container, html_element) ->
- html_container.children().each ->
- if( $( this ).is(html_element) )
- $( this ).show()
- else
- $( this ).hide()
-
- Morris.Donut({
- element: 'files_statistics',
- data: [
- {label: "<%= t 'imports.show.graph.files.error' %>", value: <%= @import.report.error_files.count %> },
- {label: "<%= t 'imports.show.graph.files.ignored' %>", value: <%= @import.report.ignored_files.count %> },
- {label: "<%= t 'imports.show.graph.files.ok' %>", value: <%= @import.report.ok_files.count %> }
- ]
- colors: [ "#e22b1b", "#898e7f", "#8fc861" ]
- }).on('click', update = (i, row) ->
- switch i
- when 0 then get_import_results( $(".report"), $(".files_error"))
- when 1 then get_import_results( $(".report"), $(".files_ignored"))
- when 2 then get_import_results( $(".report"), $(".files_ok"))
- else console.log "Error no other value for donut chart")
-
- Morris.Bar({
- element: 'objects_statistics',
- data: [
- { object: "<%= t("imports.show.graph.lines.lines_stats").html_safe %>", value: <%= @import.report.lines %> },
- { object: "<%= t("imports.show.graph.lines.routes_stats").html_safe %>", value: <%= @import.report.routes %> },
- { object: "<%= t("imports.show.graph.lines.connection_links_stats").html_safe %>", value: <%= @import.report.connection_links %> },
- { object: "<%= t("imports.show.graph.lines.time_tables_stats").html_safe %>", value: <%= @import.report.time_tables %> },
- { object: "<%= t("imports.show.graph.lines.stop_areas_stats").html_safe %>", value: <%= @import.report.stop_areas %> },
- { object: "<%= t("imports.show.graph.lines.access_points_stats").html_safe %>", value: <%= @import.report.access_points %> },
- { object: "<%= t("imports.show.graph.lines.vehicle_journeys_stats").html_safe %>", value: <%= @import.report.vehicle_journeys %> },
- { object: "<%= t("imports.show.graph.lines.journey_patterns_stats").html_safe %>", value: <%= @import.report.journey_patterns %> },
- ],
- xkey: 'object',
- ykeys: ['value'],
- labels: ['<%= t "imports.show.graph.lines.objects_label" %>']
- xLabelAngle: 40,
- xAxisLabelTopPadding: 7,
- padding: 40,
- hideHover: true
- }).on('click', update = (i, row) ->
- get_import_results( $(".report"), $(".lines")) ) \ No newline at end of file