aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZakaria BOUZIANE2015-05-06 10:38:34 +0200
committerZakaria BOUZIANE2015-05-06 10:38:34 +0200
commited6fd2af69ebecb8d6af496135f1398ef6332b06 (patch)
tree6e69aa36cd98edad74091aea3916ec0b445872ae
parent1f9feab16cc9d7722be1ed0c495c7eeba555ab9a (diff)
downloadchouette-core-ed6fd2af69ebecb8d6af496135f1398ef6332b06.tar.bz2
Showing validation of imports (still css to fix)
-rw-r--r--app/controllers/compliance_check_results_controller.rb17
-rw-r--r--app/controllers/compliance_checks_controller.rb28
-rw-r--r--app/controllers/imports_controller.rb5
-rw-r--r--app/models/import.rb10
-rw-r--r--app/views/compliance_check_results/index.html.erb46
-rw-r--r--app/views/compliance_checks/show.html.erb4
-rw-r--r--app/views/compliance_checks/show_for_import.js.coffee52
-rw-r--r--config/routes.rb2
8 files changed, 148 insertions, 16 deletions
diff --git a/app/controllers/compliance_check_results_controller.rb b/app/controllers/compliance_check_results_controller.rb
index 3195e4c82..d1f445e45 100644
--- a/app/controllers/compliance_check_results_controller.rb
+++ b/app/controllers/compliance_check_results_controller.rb
@@ -6,7 +6,6 @@ class ComplianceCheckResultsController < ChouetteController
respond_to :js, :only => :index
def index
- #puts "params = #{params.inspect}"
index! do |format|
format.html { render :layout => false }
end
@@ -17,13 +16,25 @@ class ComplianceCheckResultsController < ChouetteController
def compliance_check_service
ComplianceCheckService.new(@referential)
end
-
+
def compliance_check
@compliance_check ||= compliance_check_service.find( params[:compliance_check_id] )
end
+ def import_service
+ import_service = ImportService.new(@referential)
+ end
+
+ def import
+ @import = import_service.find(params[:import_id])
+ end
+
def compliance_check_validation_report
- @compliance_check_validation_report ||= compliance_check.compliance_check_validation_report
+ if params[:import_id]
+ compliance_check_validation_report ||= import.compliance_check_validation_report
+ else
+ compliance_check_validation_report ||= compliance_check.compliance_check_validation_report
+ end
end
def collection
diff --git a/app/controllers/compliance_checks_controller.rb b/app/controllers/compliance_checks_controller.rb
index 3ce961d72..976ced921 100644
--- a/app/controllers/compliance_checks_controller.rb
+++ b/app/controllers/compliance_checks_controller.rb
@@ -6,7 +6,7 @@ class ComplianceChecksController < ChouetteController
respond_to :html, :js
respond_to :zip, :only => :export
belongs_to :referential
-
+
def index
begin
index! do
@@ -18,6 +18,20 @@ class ComplianceChecksController < ChouetteController
redirect_to referential_path(@referential)
end
end
+
+ def show
+ @import = resource if resource.kind_of?(Import)
+ begin
+ show! do |format|
+ build_breadcrumb :show
+ format.js { render 'show_for_import.js.coffee' if @import}
+ end
+ rescue Ievkit::Error => error
+ logger.error("Iev failure : #{error.message}")
+ flash[:error] = t('iev.failure')
+ redirect_to referential_path(@referential)
+ end
+ end
def references
@references = referential.send(params[:type]).where("name ilike ?", "%#{params[:q]}%")
@@ -29,7 +43,6 @@ class ComplianceChecksController < ChouetteController
end
def rule_parameter_set
- #@rule_parameter_set = compliance_check.rule_parameter_set_archived
@rule_parameter_set = resource.rule_parameter_set
build_breadcrumb :edit
render "rule_parameter_sets/show"
@@ -54,13 +67,22 @@ class ComplianceChecksController < ChouetteController
def compliance_check_service
ComplianceCheckService.new(@referential)
end
+
+ def import_service
+ ImportService.new(@referential)
+ end
def build_resource(attributes = {})
@compliance_check ||= ComplianceCheck.new
end
def resource
- @compliance_check ||= compliance_check_service.find(params[:id] )
+ compliance_check ||= compliance_check_service.find(params[:id])
+ if compliance_check.datas[:action] == "importer"
+ @importer = import_service.find(params[:id])
+ else
+ @compliance_check = compliance_check
+ end
end
def collection
diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb
index ae0ac063b..752c08f5b 100644
--- a/app/controllers/imports_controller.rb
+++ b/app/controllers/imports_controller.rb
@@ -5,8 +5,8 @@ require 'open-uri'
class ImportsController < ChouetteController
defaults :resource_class => Import
- respond_to :html, :only => [:show, :index, :destroy, :imported_file, :rule_parameter_set]
- respond_to :js, :only => [:show, :index]
+ respond_to :html, :only => [:show, :index, :destroy, :imported_file, :rule_parameter_set, :compliance_check]
+ respond_to :js, :only => [:show, :index, :compliance_check]
belongs_to :referential
def index
@@ -69,7 +69,6 @@ class ImportsController < ChouetteController
begin
build_breadcrumb :show
@import = resource
- #@compliance_check = ComplianceCheck.new @import.datas
render "compliance_checks/show"
rescue Ievkit::Error => error
logger.error("Iev failure : #{error.message}")
diff --git a/app/models/import.rb b/app/models/import.rb
index b51a341b3..903da32aa 100644
--- a/app/models/import.rb
+++ b/app/models/import.rb
@@ -19,6 +19,16 @@ class Import
end
end
+ def compliance_check_validation_report
+ report_path = links["validation_report"]
+ if report_path
+ response = Ievkit.get(report_path)
+ ComplianceCheckResult.new(response)
+ else
+ raise Ievkit::IevError("Impossible to access report path link for validation of import")
+ end
+ end
+
def report
report_path = links["action_report"]
if report_path
diff --git a/app/views/compliance_check_results/index.html.erb b/app/views/compliance_check_results/index.html.erb
index 5978d06fd..5198c4330 100644
--- a/app/views/compliance_check_results/index.html.erb
+++ b/app/views/compliance_check_results/index.html.erb
@@ -27,10 +27,26 @@
<span class="title_error">
<i class="fa fa-plus-square"></i><%= compliance_check_validation_report.error_count.to_s + " " + ComplianceCheckResult.human_attribute_name(:violation_count) %>
</span>
+
+
+<!-- error : 1 error_id (string)
+ 0..1 source :
+ 0..1 file :
+ 1 filename (string)
+ 0..1 line_number (int)
+ 0..1 column_number (int)
+ 0..1 objectid (string)
+ 0..1 label (string)
+ 0.. object_path :
+ 1 type : {"network", "company", etc...}
+ 1 id (long)
+ 0.. target : (same as source)
+ 0..1 error_value (string)
+ 0..1 reference_value (striung) -->
<div class="details_error">
<% compliance_check_validation_report.errors.first(10).each do |error| %>
<p class="detail_error">
- <% if error["source"].present? %>
+ <% if error["source"].present? %>
<% if error["source"].objectid.present? %>
<% data_content_1 = t("activemodel.attributes.compliance_check_result." + compliance_check_validation_report.test_id) + ". " +
t("compliance_check_result.details.detail_" + error[:error_id], object_labels_hash(error) ) %>
@@ -41,9 +57,28 @@
<% data_title_2 = t("activemodel.attributes.validation_result.detail") %>
|- <button data-content='<%= data_content_2 %>' data-title='<%= data_title_2 %>' data-toggle="popover" class="notice btn btn-info btn-xs"><i class="fa fa-info"></i></button>
<% end %>
+
<% if error[:source].object_path.present? %>
- <%= link_to error[:source].label, object_url(@referential.id, error) %>
+ <% if error[:source].label.present? %>
+ <%= link_to error[:source].label, object_url(@referential.id, error) %>
+ <% else %>
+ <%= link_to "#{error[:source].object_path.type} (#{error[:source].object_path.id})", object_url(@referential.id, error) %>
+ <% end %>
<% end %>
+ <% if error[:source].file.present? %>
+ <% if error[:source].objectid.present? %>
+ <%= "#{error[:source].objectid}" %>
+ <p>
+ <% end %>
+ <%= error[:source].file.filename %>
+ <% if error[:source].file.line_number.present? %>
+ <%= ", li: #{error[:source].file.line_number}" %>
+ <% end %>
+ <% if error[:source].file.column_number.present? %>
+ <%= ", co: #{error[:source].file.column_number}" %>
+ <% end %>
+ <% end %>
+
<% end %>
</p>
<% end %>
@@ -55,5 +90,8 @@
<% end %>
</tbody>
</table>
-<%= javascript_include_tag referential_compliance_check_compliance_check_results_path(@referential, @compliance_check.id, :format => :js) %>
-
+<% if @import %>
+ <%= javascript_include_tag referential_import_compliance_check_results_path(@referential, @import.id, :format => :js) %>
+<% else %>
+ <%= javascript_include_tag referential_compliance_check_compliance_check_results_path(@referential, @compliance_check.id, :format => :js) %>
+<% end %>
diff --git a/app/views/compliance_checks/show.html.erb b/app/views/compliance_checks/show.html.erb
index f83c3f7d2..70b94d726 100644
--- a/app/views/compliance_checks/show.html.erb
+++ b/app/views/compliance_checks/show.html.erb
@@ -40,9 +40,9 @@
<div class="report"></div>
<% end %>
<% if @import %>
- <%= javascript_include_tag referential_compliance_check_path(@referential, @import.id,:format => :js) %>
+ <%= javascript_include_tag referential_compliance_check_path(@referential, @import.id,:format => :js) %>
<% else %>
- <%= javascript_include_tag referential_compliance_check_path(@referential, @compliance_check.id,:format => :js) %>
+ <%= javascript_include_tag referential_compliance_check_path(@referential, @compliance_check.id,:format => :js) %>
<% end %>
</div>
<% content_for :sidebar do %>
diff --git a/app/views/compliance_checks/show_for_import.js.coffee b/app/views/compliance_checks/show_for_import.js.coffee
new file mode 100644
index 000000000..0a268740e
--- /dev/null
+++ b/app/views/compliance_checks/show_for_import.js.coffee
@@ -0,0 +1,52 @@
+jQuery ->
+
+ get_compliance_check_results = (html_container, status, severity) ->
+ h = new Object()
+ h["status"] = status if status
+ h["severity"] = severity if severity
+
+ $.get(
+ "compliance_check_results",
+ h,
+ update = (data) ->
+ html_container.empty()
+ html_container.append(data)
+ )
+
+ Morris.Donut({
+ element: 'error',
+ data: [
+ {label: "<%= t 'nok', :scope => 'compliance_check_result.statuses' %>", value: <%= @import.compliance_check_validation_report.nok_error.count %>},
+ {label: "<%= t 'na', :scope => 'compliance_check_result.statuses' %>", value: <%= @import.compliance_check_validation_report.na_error.count %>},
+ {label: "<%= t 'ok', :scope => 'compliance_check_result.statuses' %>", value: <%= @import.compliance_check_validation_report.ok_error.count %>}
+ ]
+ colors: [ "#e22b1b", "#898e7f", "#8fc861" ]
+ }).on('click', update = (i, row) ->
+ switch i
+ when 0 then get_compliance_check_results( $(".report"), "NOK", "ERROR")
+ when 1 then get_compliance_check_results( $(".report"), "UNCHECK", "ERROR")
+ when 2 then get_compliance_check_results( $(".report"), "OK", "ERROR")
+ else console.log "Error no other value for donut chart")
+
+ Morris.Donut({
+ element: 'warning',
+ data: [
+ {label: "<%= t 'nok', :scope => 'compliance_check_result.statuses' %>", value: <%= @import.compliance_check_validation_report.nok_warning.count %>},
+ {label: "<%= t 'na', :scope => 'compliance_check_result.statuses' %>", value: <%= @import.compliance_check_validation_report.na_warning.count %>},
+ {label: "<%= t 'ok', :scope => 'compliance_check_result.statuses' %>", value: <%= @import.compliance_check_validation_report.ok_warning.count %>}
+ ]
+ colors: [ "#ffbd2b", "#898e7f", "#8fc861" ]
+ }).on('click', update = (i, row) ->
+ switch i
+ when 0 then get_compliance_check_results( $(".report"), "NOK", "WARNING")
+ when 1 then get_compliance_check_results( $(".report"), "UNCHECK", "WARNING")
+ when 2 then get_compliance_check_results( $(".report"), "OK", "WARNING")
+ else console.log "Error no other value for donut chart")
+
+ $(".resume .col1 .caption").click ->
+ get_compliance_check_results( $(".report"), null, "ERROR")
+
+ $(".resume .col2 .caption").click ->
+ get_compliance_check_results( $(".report"), null, "WARNING")
+
+
diff --git a/config/routes.rb b/config/routes.rb
index abf381bb8..9116fba64 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -85,7 +85,7 @@ ChouetteIhm::Application.routes.draw do
get "rule_parameter_set"
get "compliance_check"
end
- #resources :compliance_checks, :only => [:show]
+
resources :compliance_check_results
end