diff options
| author | Zakaria BOUZIANE | 2014-11-17 14:24:56 +0100 |
|---|---|---|
| committer | Zakaria BOUZIANE | 2014-11-17 14:24:56 +0100 |
| commit | 252c0caef2d9efb7d18c59653e1cd4453b9435b1 (patch) | |
| tree | dea0930d38252bffa596ba8c4384bd6f6d3be453 | |
| parent | 68408c39a958e3706342fbbbdb701e0609eefb8b (diff) | |
| download | chouette-core-252c0caef2d9efb7d18c59653e1cd4453b9435b1.tar.bz2 | |
Compliance check report in CSV file
| -rw-r--r-- | app/controllers/compliance_check_results_controller.rb | 5 | ||||
| -rw-r--r-- | app/models/compliance_check_task.rb | 25 | ||||
| -rw-r--r-- | app/views/compliance_check_results/index.csv.erb | 3 | ||||
| -rw-r--r-- | app/views/compliance_check_tasks/show.html.erb | 1 | ||||
| -rw-r--r-- | config/locales/compliance_check_results.yml | 24 | ||||
| -rw-r--r-- | config/locales/compliance_check_tasks.yml | 2 |
6 files changed, 55 insertions, 5 deletions
diff --git a/app/controllers/compliance_check_results_controller.rb b/app/controllers/compliance_check_results_controller.rb index a4ef40509..85ba23e38 100644 --- a/app/controllers/compliance_check_results_controller.rb +++ b/app/controllers/compliance_check_results_controller.rb @@ -1,11 +1,14 @@ class ComplianceCheckResultsController < ChouetteController + respond_to :json respond_to :js, :only => :index + respond_to :csv, :only => :index belongs_to :compliance_check_task - def index + def index index! do |format| format.html { render :layout => false } + format.csv { send_file collection[0].compliance_check_task.file, :type => "text/html; charset=utf-8" } end end diff --git a/app/models/compliance_check_task.rb b/app/models/compliance_check_task.rb index 80fbad38f..9240639a5 100644 --- a/app/models/compliance_check_task.rb +++ b/app/models/compliance_check_task.rb @@ -1,5 +1,9 @@ +require 'tempfile' + class ComplianceCheckTask < ActiveRecord::Base - attr_accessor :rule_parameter_set_id + include ERB::Util + + attr_accessor :rule_parameter_set_id, :template belongs_to :referential belongs_to :import_task @@ -101,5 +105,22 @@ class ComplianceCheckTask < ActiveRecord::Base end end - + after_destroy :destroy_file + def destroy_file + file.close if File.exists? file + file.unlink if File.exists? file + FileUtils.rm file if File.exists? file + end + + def file + @template = File.open('app/views/compliance_check_results/index.csv.erb' ){ |f| f.read } + file = Tempfile.new('compliance_check_results.csv') + file.write(render) + file.flush + return file + end + + def render() + ERB.new(@template).result(binding) + end end diff --git a/app/views/compliance_check_results/index.csv.erb b/app/views/compliance_check_results/index.csv.erb new file mode 100644 index 000000000..e042d8007 --- /dev/null +++ b/app/views/compliance_check_results/index.csv.erb @@ -0,0 +1,3 @@ +<%= ComplianceCheckResult.human_attribute_name(:severity) %>;<%= ComplianceCheckResult.human_attribute_name(:status) %>;<%= ComplianceCheckResult.human_attribute_name(:rule_code) %>;<%= ComplianceCheckResult.human_attribute_name(:detail) %>;<%= ComplianceCheckResult.human_attribute_name(:url) %>;<%= ComplianceCheckResult.human_attribute_name(:violation_count) %>;<%= ComplianceCheckResult.human_attribute_name(:one) %>;<%= ComplianceCheckResult.human_attribute_name(:two) %>;<%= ComplianceCheckResult.human_attribute_name(:three) %>;<%= ComplianceCheckResult.human_attribute_name(:four) %>;<%= ComplianceCheckResult.human_attribute_name(:five) %>;<%= ComplianceCheckResult.human_attribute_name(:six) %>;<%= ComplianceCheckResult.human_attribute_name(:seven) %>;<%= ComplianceCheckResult.human_attribute_name(:eight) %>;<%= ComplianceCheckResult.human_attribute_name(:nine) %>;<%= ComplianceCheckResult.human_attribute_name(:ten) %> +<% compliance_check_results.each do |r| %><%= r.severity %>;<%= r.status %>;<%= r.rule_code %>;<%= ComplianceCheckResult.human_attribute_name(r.rule_code) %>;<%= Rails.application.config.validation_spec + I18n.locale.to_s + "/" + r.rule_code + ".html" %>;<%= r.violation_count %><% if r.violation_count > 0 %><% for i in 0..10 %><% if (i < r.violation_count) %>;<%= r.detail["detail"][i]["location"]["url"] %><% else %><% break %><% end %><% end %><% end %> +<% end %>
\ No newline at end of file diff --git a/app/views/compliance_check_tasks/show.html.erb b/app/views/compliance_check_tasks/show.html.erb index c72d9350f..5bb270ffb 100644 --- a/app/views/compliance_check_tasks/show.html.erb +++ b/app/views/compliance_check_tasks/show.html.erb @@ -31,6 +31,7 @@ </div> <% content_for :sidebar do %> <ul class="actions"> + <li><%= link_to t('compliance_check_tasks.actions.download'), referential_compliance_check_task_compliance_check_results_path(@referential, @compliance_check_task)+".csv" %></il> <li><%= link_to t('compliance_check_tasks.actions.destroy'), referential_compliance_check_task_path(@referential, @compliance_check_task), :method => :delete, :data => {:confirm => t('compliance_check_tasks.actions.destroy_confirm')}, :class => "remove" %></li> </ul> diff --git a/config/locales/compliance_check_results.yml b/config/locales/compliance_check_results.yml index 96ac952fe..808db4efa 100644 --- a/config/locales/compliance_check_results.yml +++ b/config/locales/compliance_check_results.yml @@ -262,7 +262,17 @@ en: rule_code: "Code" violation_count: "Violation(s)" detail: "Detail" - + url: "URL" + one: "Violation n° 1" + two: "Violation n° 2" + three: "Violation n° 3" + four: "Violation n° 4" + five: "Violation n° 5" + six: "Violation n° 6" + seven: "Violation n° 7" + eight: "Violation n° 8" + nine: "Violation n° 9" + ten: "Violation n° 10" fr: compliance_check_results: index: @@ -402,7 +412,6 @@ fr: detail_3_vehiclejourney_6: "La course %{objectId} a un mode de transport interdit %{transportMode}" detail_3_facility_1: "L'équipement %{name} (%{objectId}) n'est pas géolocalisé" detail_3_facility_2: "L'équipement %{name} (%{objectId}) est localisé trop loin de son parent %{areaName} (%{areaId}) : distance %{distance} > %{distanceLimit}" - activerecord: models: compliance_check_result: @@ -526,4 +535,15 @@ fr: rule_code: "Code" violation_count: "Violation(s)" detail: "Détail" + url: "URL" + one: "Violation n° 1" + two: "Violation n° 2" + three: "Violation n° 3" + four: "Violation n° 4" + five: "Violation n° 5" + six: "Violation n° 6" + seven: "Violation n° 7" + eight: "Violation n° 8" + nine: "Violation n° 9" + ten: "Violation n° 10" diff --git a/config/locales/compliance_check_tasks.yml b/config/locales/compliance_check_tasks.yml index 00376c2bf..9dcebc024 100644 --- a/config/locales/compliance_check_tasks.yml +++ b/config/locales/compliance_check_tasks.yml @@ -23,6 +23,7 @@ en: destroy: "Destroy this validation" edit: "Edit this validation" rule_parameter_set: "Rule parameter set" + download: "Download" statuses: pending: "Pending" processing: "Processing" @@ -89,6 +90,7 @@ fr: destroy: "Supprimer cette validation" edit: "Editer cette validation" rule_parameter_set: "Jeu de paramètres" + download: "Télécharger" statuses: pending: "En attente ..." processing: "En cours ..." |
