aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/compliance_check_messages_controller.rb34
-rw-r--r--app/controllers/import_messages_controller.rb2
-rw-r--r--app/helpers/compliance_check_resources_helper.rb12
-rw-r--r--app/models/compliance_check_message_export.rb46
-rw-r--r--app/models/import_message_export.rb4
-rw-r--r--app/views/compliance_check_sets/show.html.slim10
-rw-r--r--config/routes.rb1
-rw-r--r--db/schema.rb8
8 files changed, 109 insertions, 8 deletions
diff --git a/app/controllers/compliance_check_messages_controller.rb b/app/controllers/compliance_check_messages_controller.rb
new file mode 100644
index 000000000..1e4fff6e5
--- /dev/null
+++ b/app/controllers/compliance_check_messages_controller.rb
@@ -0,0 +1,34 @@
+class ComplianceCheckMessagesController < ChouetteController
+ defaults resource_class: ComplianceCheckMessage, collection_name: 'compliance_check_messages', instance_name: 'compliance_check_message'
+ respond_to :csv
+ belongs_to :compliance_check_set, :parent_class => ComplianceCheckSet
+
+
+ def index
+ index! do |format|
+ format.csv {
+ send_data ComplianceCheckMessageExport.new(compliance_check_messages: collection).to_csv(:col_sep => "\;", :quote_char=>'"', force_quotes: true) , :filename => "compliance_check_set_errors_#{line_code}_#{Time.now.to_i}.csv"
+ }
+ end
+ end
+
+ protected
+ def collection
+ parent.compliance_check_messages.where(compliance_check_resource_id: params[:compliance_check_resource_id])
+ end
+
+ def parent
+ @compliance_check_set ||= ComplianceCheckSet.find(params[:compliance_check_set_id])
+ end
+
+ def compliance_check_resource
+ ComplianceCheckResource.find(params[:compliance_check_resource_id])
+ end
+
+ private
+
+ def line_code
+ Chouette::Line.find_by_objectid("#{compliance_check_resource.reference}").get_objectid.local_id
+ end
+
+end
diff --git a/app/controllers/import_messages_controller.rb b/app/controllers/import_messages_controller.rb
index 6546b25f8..286bb0ce8 100644
--- a/app/controllers/import_messages_controller.rb
+++ b/app/controllers/import_messages_controller.rb
@@ -9,7 +9,7 @@ class ImportMessagesController < ChouetteController
def index
index! do |format|
format.csv {
- send_data ImportMessageExport.new(:import_messages => @import_messages).to_csv(:col_sep => ";") , :filename => "#{File.basename(@import_resource.name)}_#{Time.now.to_i}.csv"
+ send_data ImportMessageExport.new(:import_messages => @import_messages).to_csv(:col_sep => "\;", :quote_char=>'"', force_quotes: true) , :filename => "import_errors_#{@import_resource.name.gsub('.xml', '')}_#{Time.now.to_i}.csv"
}
end
end
diff --git a/app/helpers/compliance_check_resources_helper.rb b/app/helpers/compliance_check_resources_helper.rb
new file mode 100644
index 000000000..95cabed88
--- /dev/null
+++ b/app/helpers/compliance_check_resources_helper.rb
@@ -0,0 +1,12 @@
+module ComplianceCheckResourcesHelper
+
+ # Comlpiance Check Resources statuses helper
+ def compliance_check_resource_status(status)
+ cls = ''
+ cls = 'success' if status == 'OK'
+ cls = 'warning' if status == 'WARNING'
+ cls = 'danger' if %w[ERROR IGNORED].include? status
+
+ content_tag :span, '', class: "fa fa-circle text-#{cls}"
+ end
+end
diff --git a/app/models/compliance_check_message_export.rb b/app/models/compliance_check_message_export.rb
new file mode 100644
index 000000000..b3e3f80cf
--- /dev/null
+++ b/app/models/compliance_check_message_export.rb
@@ -0,0 +1,46 @@
+# -*- coding: utf-8 -*-
+require "csv"
+require "zip"
+
+class ComplianceCheckMessageExport
+ include ActiveModel::Validations
+ include ActiveModel::Conversion
+ extend ActiveModel::Naming
+
+ attr_accessor :compliance_check_messages
+
+ def initialize(attributes = {})
+ attributes.each { |name, value| send("#{name}=", value) }
+ end
+
+ def persisted?
+ false
+ end
+
+ def label(name)
+ I18n.t "vehicle_journey_exports.label.#{name}"
+ end
+
+ def column_names
+ ["criticity", "message key", "message", "resource objectid"]
+ end
+
+ def to_csv(options = {})
+ CSV.generate(options) do |csv|
+ csv << column_names
+ compliance_check_messages.each do |compliance_check_message|
+ csv << [compliance_check_message.compliance_check.criticity, compliance_check_message.message_attributes[:test_id], I18n.t("compliance_check_messages.#{compliance_check_message.message_key}", compliance_check_message.message_attributes.deep_symbolize_keys), compliance_check_message.resource_attributes[:objectid] ]
+ end
+ end
+ end
+
+ def to_zip(temp_file,options = {})
+ ::Zip::OutputStream.open(temp_file) { |zos| }
+ ::Zip::File.open(temp_file.path, ::Zip::File::CREATE) do |zipfile|
+ zipfile.get_output_stream(label("vj_filename")+route.id.to_s+".csv") { |f| f.puts to_csv(options) }
+ zipfile.get_output_stream(label("tt_filename")+".csv") { |f| f.puts time_tables_to_csv(options) }
+ zipfile.get_output_stream(label("ftn_filename")+".csv") { |f| f.puts footnotes_to_csv(options) }
+ end
+ end
+
+end
diff --git a/app/models/import_message_export.rb b/app/models/import_message_export.rb
index 88d0f27e2..eeb6ebb18 100644
--- a/app/models/import_message_export.rb
+++ b/app/models/import_message_export.rb
@@ -22,14 +22,14 @@ class ImportMessageExport
end
def column_names
- ["criticity", "message key", "message"]
+ ["criticity", "message key", "message", "file name", "line", "column"]
end
def to_csv(options = {})
CSV.generate(options) do |csv|
csv << column_names
import_messages.each do |import_message|
- csv << [import_message.criticity, import_message.message_key, I18n.t("import_messages.compliance_check_messages.#{import_message.message_key}", import_message.message_attributes.deep_symbolize_keys) ]
+ csv << [import_message.criticity, import_message.message_key, I18n.t("import_messages.compliance_check_messages.#{import_message.message_key}", import_message.message_attributes.deep_symbolize_keys), *import_message.resource_attributes.values_at("filename", "line_number", "column_number") ]
end
end
end
diff --git a/app/views/compliance_check_sets/show.html.slim b/app/views/compliance_check_sets/show.html.slim
index 5d8e3fa15..35a60eb52 100644
--- a/app/views/compliance_check_sets/show.html.slim
+++ b/app/views/compliance_check_sets/show.html.slim
@@ -46,11 +46,19 @@
), \
TableBuilderHelper::Column.new( \
key: :status, \
- attribute: Proc.new { |n| compliance_check_set_status(n.status) } \
+ attribute: Proc.new { |n| compliance_check_resource_status(n.status) } \
), \
TableBuilderHelper::Column.new( \
key: :metrics, \
attribute: Proc.new { |n| I18n.t('compliance_check_sets.show.metrics', n.metrics.deep_symbolize_keys) } \
+ ), \
+ TableBuilderHelper::Column.new( \
+ name: 'Téléchargement' , \
+ attribute: Proc.new { |n| '<i class="fa fa-download" aria-hidden="true"></i>'.html_safe }, \
+ sortable: false, \
+ link_to: lambda do |compliance_check_resource| \
+ workbench_compliance_check_set_compliance_check_messages_path(@compliance_check_set.workbench, @compliance_check_set, format: 'csv', compliance_check_resource_id: compliance_check_resource.id ) \
+ end \
) \
],
sortable: false, \
diff --git a/config/routes.rb b/config/routes.rb
index 8b5faff03..0f60733af 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -14,6 +14,7 @@ ChouetteIhm::Application.routes.draw do
resources :compliance_check_sets, only: [:index, :show] do
get :executed, on: :member
resources :compliance_checks, only: [:show]
+ resources :compliance_check_messages, only: [:index]
end
resource :output, controller: :workbench_outputs
diff --git a/db/schema.rb b/db/schema.rb
index f2cf6b4b6..0f5d796c5 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -416,9 +416,9 @@ ActiveRecord::Schema.define(version: 20180111200406) do
t.string "type"
t.integer "parent_id", limit: 8
t.string "parent_type"
- t.datetime "notified_parent_at"
t.integer "current_step", default: 0
t.integer "total_steps", default: 0
+ t.datetime "notified_parent_at"
t.string "creator"
end
@@ -956,7 +956,7 @@ ActiveRecord::Schema.define(version: 20180111200406) do
t.integer "route_id", limit: 8
t.integer "journey_pattern_id", limit: 8
t.integer "company_id", limit: 8
- t.string "objectid", null: false
+ t.string "objectid", null: false
t.integer "object_version", limit: 8
t.string "comment"
t.string "status_value"
@@ -968,13 +968,13 @@ ActiveRecord::Schema.define(version: 20180111200406) do
t.integer "number", limit: 8
t.boolean "mobility_restricted_suitability"
t.boolean "flexible_service"
- t.integer "journey_category", default: 0, null: false
+ t.integer "journey_category", default: 0, null: false
t.datetime "created_at"
t.datetime "updated_at"
t.string "checksum"
t.text "checksum_source"
t.string "data_source_ref"
- t.jsonb "custom_field_values"
+ t.jsonb "custom_field_values", default: {}
end
add_index "vehicle_journeys", ["objectid"], name: "vehicle_journeys_objectid_key", unique: true, using: :btree