diff options
| author | Alban Peignier | 2015-05-20 15:55:54 +0200 | 
|---|---|---|
| committer | Alban Peignier | 2015-05-20 15:57:13 +0200 | 
| commit | 31b66390ed9811105f3bd55445b9b007ac3d4826 (patch) | |
| tree | cb8ba31273f6e668edb912b0dd3f4e74227ef674 | |
| parent | 085b483d720116a50571020fed4c4fbcdcf56a07 (diff) | |
| download | chouette-core-31b66390ed9811105f3bd55445b9b007ac3d4826.tar.bz2 | |
Refactor compliance_checks#show to display objects statistics
| -rw-r--r-- | app/assets/javascripts/compliance_checks/report.js.coffee (renamed from app/assets/javascripts/compliance_checks/show.js.coffee) | 2 | ||||
| -rw-r--r-- | app/assets/javascripts/partials/ie_report.js.coffee.erb | 47 | ||||
| -rw-r--r-- | app/assets/stylesheets/main/compliance_checks.css.scss | 27 | ||||
| -rw-r--r-- | app/controllers/compliance_checks_controller.rb | 23 | ||||
| -rw-r--r-- | app/controllers/imports_controller.rb | 18 | ||||
| -rw-r--r-- | app/helpers/breadcrumb_helper.rb | 5 | ||||
| -rw-r--r-- | app/views/compliance_checks/_compliance_check.html.erb | 6 | ||||
| -rw-r--r-- | app/views/compliance_checks/report.html.erb | 53 | ||||
| -rw-r--r-- | app/views/compliance_checks/show.html.erb | 60 | ||||
| -rw-r--r-- | app/views/shared/_ie_report.html.erb | 2 | ||||
| -rw-r--r-- | config/locales/compliance_checks.yml | 4 | ||||
| -rw-r--r-- | config/routes.rb | 9 | 
12 files changed, 148 insertions, 108 deletions
| diff --git a/app/assets/javascripts/compliance_checks/show.js.coffee b/app/assets/javascripts/compliance_checks/report.js.coffee index 3a6cf0ace..cd09cbd5d 100644 --- a/app/assets/javascripts/compliance_checks/show.js.coffee +++ b/app/assets/javascripts/compliance_checks/report.js.coffee @@ -1,4 +1,4 @@ -$(".compliance_checks.show, .imports.compliance_check").ready -> +$(".compliance_checks.report, .imports.compliance_check").ready ->    get_compliance_check_results = (html_container, css_class) ->      html_container.each -> diff --git a/app/assets/javascripts/partials/ie_report.js.coffee.erb b/app/assets/javascripts/partials/ie_report.js.coffee.erb index ec9e5f836..25ea7dfc0 100644 --- a/app/assets/javascripts/partials/ie_report.js.coffee.erb +++ b/app/assets/javascripts/partials/ie_report.js.coffee.erb @@ -1,4 +1,4 @@ -$(".imports.show, .exports.show").ready -> +$(".imports.show, .exports.show, .compliance_checks.show").ready ->    get_export_results = (html_container, html_element) ->      html_container.children().each -> @@ -7,28 +7,29 @@ $(".imports.show, .exports.show").ready ->        else          $( this ).hide() -  Morris.Donut({ -    element: 'files_statistics', -    data: [ -      { -        label: $(".files_error").data('label'), -        value: $('.files_error span.file_name').size() -      }, -      { -        label: $(".files_ignored").data('label'), -        value: $('.files_ignored span.file_name').size() -      }, -      { -        label: $(".files_ok").data('label'), -        value: $('.files_ok span.file_name').size() -      } -    ], -    colors: [ "#e22b1b", "#898e7f", "#8fc861" ] -  }).on('click', update = (i, row) -> -    switch i -      when 0 then get_export_results( $(".report"), $(".files_error")) -      when 1 then get_export_results( $(".report"), $(".files_ignored")) -      when 2 then get_export_results( $(".report"), $(".files_ok")) ) +  if $( "#files_statistics" ).length +    Morris.Donut({ +      element: 'files_statistics', +      data: [ +        { +          label: $(".files_error").data('label'), +          value: $('.files_error span.file_name').size() +        }, +        { +          label: $(".files_ignored").data('label'), +          value: $('.files_ignored span.file_name').size() +        }, +        { +          label: $(".files_ok").data('label'), +          value: $('.files_ok span.file_name').size() +        } +      ], +      colors: [ "#e22b1b", "#898e7f", "#8fc861" ] +    }).on('click', update = (i, row) -> +      switch i +        when 0 then get_export_results( $(".report"), $(".files_error")) +        when 1 then get_export_results( $(".report"), $(".files_ignored")) +        when 2 then get_export_results( $(".report"), $(".files_ok")) )    Morris.Bar({      element: 'objects_statistics', diff --git a/app/assets/stylesheets/main/compliance_checks.css.scss b/app/assets/stylesheets/main/compliance_checks.css.scss index 68db0deb9..34226e9d0 100644 --- a/app/assets/stylesheets/main/compliance_checks.css.scss +++ b/app/assets/stylesheets/main/compliance_checks.css.scss @@ -2,14 +2,21 @@  {  } -#workspace.compliance_checks.show, #workspace.imports.compliance_check{ +#workspace.compliance_checks.show {    @import "../modules/job_status_colors";    @import "../modules/job_status_title"; -  @import "../modules/links";   +  @import "../partials/ie_report"; +  @import "../modules/links"; +} + +#workspace.compliance_checks.report, #workspace.imports.compliance_check{ +  @import "../modules/job_status_colors"; +  @import "../modules/job_status_title"; +  @import "../modules/links";      .status { -        margin-left: 10px;                  -    }    +        margin-left: 10px; +    }      .order{          margin-bottom: 10px; @@ -21,11 +28,11 @@      .status_ok_error { color: #8fc861; }      .status_nok_error { color: #e22b1b;  }      .status_uncheck_error { color: #898e7f; } -     +      .status_ok_warning { color: #8fc861; } -    .status_nok_warning { color: #ffbd2b;  }  +    .status_nok_warning { color: #ffbd2b;  }      .status_uncheck_warning { color: #898e7f; } -     +      .resume {          &:after{              content: " "; @@ -133,10 +140,10 @@      }      .td_error { -        width: 30%;        +        width: 30%;          .title_error i { margin-right: 5px; } -         +          div.details_error{              margin: 0px 0px 0px 3px !important;              display: none; @@ -144,7 +151,7 @@              p.detail_error{                  margin: 0px 0px 5px 0px !important;              } -             +              .file_error{                  margin-left: 26px;                  font-size: 10px; diff --git a/app/controllers/compliance_checks_controller.rb b/app/controllers/compliance_checks_controller.rb index 4949edbd7..9b29692c2 100644 --- a/app/controllers/compliance_checks_controller.rb +++ b/app/controllers/compliance_checks_controller.rb @@ -6,10 +6,10 @@ class ComplianceChecksController < ChouetteController    respond_to :html, :js    respond_to :zip, :only => :export    belongs_to :referential -   +    def index      begin -      index! do  +      index! do          build_breadcrumb :index        end      rescue Ievkit::Error, Faraday::Error => error @@ -30,7 +30,12 @@ class ComplianceChecksController < ChouetteController        redirect_to referential_path(@referential)      end    end -   + +  def report +    resource +    build_breadcrumb :report +  end +    def references      @references = referential.send(params[:type]).where("name ilike ?", "%#{params[:q]}%")      respond_to do |format| @@ -51,7 +56,7 @@ class ComplianceChecksController < ChouetteController        redirect_to referential_path(@referential)      end    end -   +    def export      respond_to do |format|        format.zip { send_file ComplianceCheckExport.new(resource, @referential.id, request).export, :type => :zip } @@ -59,19 +64,19 @@ class ComplianceChecksController < ChouetteController    end    protected -   +    alias_method :compliance_check, :resource -   +    def compliance_check_service      ComplianceCheckService.new(@referential)    end -   +    def resource      @compliance_check ||= compliance_check_service.find(params[:id])    end -   +    def collection      @compliance_checks ||= compliance_check_service.all.paginate(:page => params[:page])    end -   +  end diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb index b056af1fa..2d4782d50 100644 --- a/app/controllers/imports_controller.rb +++ b/app/controllers/imports_controller.rb @@ -4,14 +4,14 @@ require 'open-uri'  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 => [:index, :compliance_check]    belongs_to :referential    def index      begin -      index! do  +      index! do          build_breadcrumb :index        end      rescue Ievkit::Error, Faraday::Error => error @@ -20,7 +20,7 @@ class ImportsController < ChouetteController        redirect_to referential_path(@referential)      end    end -   +    def show      begin        show! @@ -29,7 +29,7 @@ class ImportsController < ChouetteController        flash[:error] = t('iev.exception.default')        redirect_to referential_path(@referential)      end -  end   +  end    def destroy      begin @@ -58,7 +58,7 @@ class ImportsController < ChouetteController    def rule_parameter_set      begin        @rule_parameter_set = resource.rule_parameter_set -      build_breadcrumb :rule_parameter_set      +      build_breadcrumb :rule_parameter_set        render "rule_parameter_sets/show"      rescue Ievkit::Error, Faraday::Error => error        logger.error("Iev failure : #{error.message}") @@ -77,21 +77,21 @@ class ImportsController < ChouetteController      begin        @compliance_check = resource        build_breadcrumb :compliance_check -      render "compliance_checks/show" +      render "compliance_checks/report"      rescue Ievkit::Error, Faraday::Error => error        logger.error("Iev failure : #{error.message}")        flash[:error] = t('iev.exception.default')        redirect_to referential_path(@referential)      end    end -   +    protected    alias_method :import, :resource    def import_service      ImportService.new(@referential)    end -   +    def resource      @import ||= import_service.find( params[:id] )    end @@ -99,5 +99,5 @@ class ImportsController < ChouetteController    def collection      @imports ||= import_service.all.paginate(:page => params[:page])    end -   +  end diff --git a/app/helpers/breadcrumb_helper.rb b/app/helpers/breadcrumb_helper.rb index ca7b7d946..3594ac838 100644 --- a/app/helpers/breadcrumb_helper.rb +++ b/app/helpers/breadcrumb_helper.rb @@ -135,7 +135,7 @@ module BreadcrumbHelper    end    def import_breadcrumb (action) -    referential_breadcrumb  +    referential_breadcrumb      add_breadcrumb Referential.human_attribute_name("imports"), referential_imports_path(@referential) unless action == :index      add_breadcrumb @rule_parameter_set.import.name, compliance_check_referential_import_path(@referential, @rule_parameter_set.import.id) if action == :rule_parameter_set      add_breadcrumb @compliance_check.name, referential_import_path(@referential, @compliance_check.id) if action == :compliance_check @@ -149,7 +149,8 @@ module BreadcrumbHelper    def compliance_check_breadcrumb (action)      referential_breadcrumb      add_breadcrumb Referential.human_attribute_name("compliance_checks"), referential_compliance_checks_path(@referential) unless action == :index -    add_breadcrumb @rule_parameter_set.compliance_check.name, referential_compliance_check_path(@referential, @rule_parameter_set.compliance_check.id) if action == :rule_parameter_set +    add_breadcrumb @compliance_check.name, referential_compliance_check_path(@referential, @compliance_check.id) if @compliance_check +    add_breadcrumb t("compliance_checks.rule_parameter_set"), rule_parameter_set_referential_compliance_check_path(@referential, @rule_parameter_set.compliance_check.id) if action == :rule_parameter_set    end    def compliance_check_task_breadcrumb (action) diff --git a/app/views/compliance_checks/_compliance_check.html.erb b/app/views/compliance_checks/_compliance_check.html.erb index 6581d9d48..8fc21d6ab 100644 --- a/app/views/compliance_checks/_compliance_check.html.erb +++ b/app/views/compliance_checks/_compliance_check.html.erb @@ -7,14 +7,14 @@          <% end %>        </span>        <h5> -        <%= link_to( referential_compliance_check_path(@referential, compliance_check.id), :class => "preview", :title => "#{ComplianceCheck.model_name.human.capitalize} #{compliance_check.name}") do %>         +        <%= link_to( referential_compliance_check_path(@referential, compliance_check.id), :class => "preview", :title => "#{ComplianceCheck.model_name.human.capitalize} #{compliance_check.name}") do %>  	  <%= job_status_title(compliance_check) %>          <% end %>        </h5> -    </div>                           +    </div>    </div>    <div class="panel-body"> -      <p><%= link_to( font_awesome_classic_tag("fa-external-link") + t("compliance_checks.actions.rule_parameter_set"), rule_parameter_set_referential_compliance_check_path(@referential, compliance_check.id)) if compliance_check.rule_parameter_set? %></p> +    <p><%= link_to( font_awesome_classic_tag("fa-external-link") + t("compliance_checks.actions.report"), report_referential_compliance_check_path(@referential, compliance_check.id)) if compliance_check.report? %></p>    </div>    <div class="panel-footer">      <div class="history"> diff --git a/app/views/compliance_checks/report.html.erb b/app/views/compliance_checks/report.html.erb new file mode 100644 index 000000000..f91dfae96 --- /dev/null +++ b/app/views/compliance_checks/report.html.erb @@ -0,0 +1,53 @@ +<%= title_tag job_status_title(@compliance_check) %> + +<div class="compliance_check_show"> +  <div class="links"> +    <% if @compliance_check.class == Import  %> +      <%= link_to font_awesome_classic_tag("fa-external-link") + t("compliance_checks.rule_parameter_set"), rule_parameter_set_referential_import_path(@referential, @compliance_check.id) if @compliance_check.rule_parameter_set? %> +    <% else %> +      <%= link_to font_awesome_classic_tag("fa-external-link") + t("compliance_checks.rule_parameter_set"), rule_parameter_set_referential_compliance_check_path(@referential, @compliance_check.id) if @compliance_check.rule_parameter_set? %> +    <% end %> +     <div class="btn-group pull-right"> +       <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false"> +         <%= t(".export") %> <span class="caret"></span> +       </button> +       <ul class="dropdown-menu" role="menu"> +         <li> +	   <% if @compliance_check.class == Import  %> +	     <%= link_to t(".export_csv"), export_referential_import_path(@referential, @compliance_check.id) %> +	   <% else %> +	     <%= link_to t(".export_csv"), export_referential_compliance_check_path(@referential, @compliance_check.id) %> +	   <% end %> +	 </li> +       </ul> +     </div> +   </div> + +   <div class="resume"> +     <div class="col1"> +       <div class="caption"><%= t "error", :scope => "compliance_check_result.severities" %></div> +       <div class="graph" id="error"></div> +     </div> +     <div class="col2"> +       <div class="caption"><%= t "warning", :scope => "compliance_check_result.severities" %></div> +       <div class="graph" id="warning"></div> +     </div> +   </div> + +   <div class="report" data-refresh-interval="<%= job_refresh_interval(@compliance_check) %>"> +     <%= render :partial => "compliance_checks/compliance_check_results", :locals => { :compliance_check_validation_report => @compliance_check.compliance_check_validation_report } %> +   </div> +</div> + +<% content_for :sidebar do %> +<ul class="actions"> +  <li> +    <% if @compliance_check.class != Import %> +      <%= link_to  t('compliance_checks.actions.destroy'), referential_compliance_check_path(@referential, @compliance_check.id), :method => :delete,  :data => {:confirm =>  t('compliance_checks.actions.destroy_confirm')}, :class => "remove" %> +    <% end %> +  </li> +</ul> + +<%= history_tag(@compliance_check) %> + +<% end %> diff --git a/app/views/compliance_checks/show.html.erb b/app/views/compliance_checks/show.html.erb index f91dfae96..182945064 100644 --- a/app/views/compliance_checks/show.html.erb +++ b/app/views/compliance_checks/show.html.erb @@ -1,53 +1,21 @@ -<%= title_tag job_status_title(@compliance_check) %> - -<div class="compliance_check_show"> +<div class="test"> +  <%= title_tag job_status_title(@compliance_check) %> +</div> +<div class="progress_bars"> +  <%= progress_bar_tag(@compliance_check) %> +</div> +<div class="compliance_check show">    <div class="links"> -    <% if @compliance_check.class == Import  %> -      <%= link_to font_awesome_classic_tag("fa-external-link") + t("compliance_checks.rule_parameter_set"), rule_parameter_set_referential_import_path(@referential, @compliance_check.id) if @compliance_check.rule_parameter_set? %> -    <% else %> -      <%= link_to font_awesome_classic_tag("fa-external-link") + t("compliance_checks.rule_parameter_set"), rule_parameter_set_referential_compliance_check_path(@referential, @compliance_check.id) if @compliance_check.rule_parameter_set? %> -    <% end %> -     <div class="btn-group pull-right"> -       <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false"> -         <%= t(".export") %> <span class="caret"></span> -       </button> -       <ul class="dropdown-menu" role="menu"> -         <li> -	   <% if @compliance_check.class == Import  %> -	     <%= link_to t(".export_csv"), export_referential_import_path(@referential, @compliance_check.id) %> -	   <% else %> -	     <%= link_to t(".export_csv"), export_referential_compliance_check_path(@referential, @compliance_check.id) %> -	   <% end %> -	 </li> -       </ul> -     </div> -   </div> - -   <div class="resume"> -     <div class="col1"> -       <div class="caption"><%= t "error", :scope => "compliance_check_result.severities" %></div> -       <div class="graph" id="error"></div> -     </div> -     <div class="col2"> -       <div class="caption"><%= t "warning", :scope => "compliance_check_result.severities" %></div> -       <div class="graph" id="warning"></div> -     </div> -   </div> - -   <div class="report" data-refresh-interval="<%= job_refresh_interval(@compliance_check) %>"> -     <%= render :partial => "compliance_checks/compliance_check_results", :locals => { :compliance_check_validation_report => @compliance_check.compliance_check_validation_report } %> -   </div> +    <%= link_to font_awesome_classic_tag("fa-external-link") + t("compliance_checks.actions.report"), report_referential_compliance_check_path(@referential, @compliance_check.id) if @compliance_check.report? %> +  </div> +  <%= render( :partial => "shared/ie_report.html", :locals => { :referential => @referential, :job => @compliance_check} ) %>  </div>  <% content_for :sidebar do %> -<ul class="actions"> -  <li> -    <% if @compliance_check.class != Import %> -      <%= link_to  t('compliance_checks.actions.destroy'), referential_compliance_check_path(@referential, @compliance_check.id), :method => :delete,  :data => {:confirm =>  t('compliance_checks.actions.destroy_confirm')}, :class => "remove" %> -    <% end %> -  </li> -</ul> +  <ul class="actions"> +    <li><%= link_to t('compliance_checks.actions.destroy'), referential_compliance_check_path(@referential, @compliance_check.id), :method => :delete, :data => {:confirm => t('compliance_checks.actions.destroy_confirm')}, :class => "remove" %></li> +  </ul> -<%= history_tag(@compliance_check) %> +  <%= history_tag(@compliance_check) %>  <% end %> diff --git a/app/views/shared/_ie_report.html.erb b/app/views/shared/_ie_report.html.erb index 709735f1d..0b3be8afa 100644 --- a/app/views/shared/_ie_report.html.erb +++ b/app/views/shared/_ie_report.html.erb @@ -1,8 +1,10 @@  <div class="resume row"> +  <% if job.respond_to?(:file_path) %>    <div class="col-md-4">      <div class="caption"><%= t(".graph.files.title_default", {:job => job.class.model_name.human, :extension => job.filename_extension} ) %></div>      <div id="files_statistics"></div>    </div> +  <% end %>    <div class="col-md-8">      <div class="caption"><%= t ".graph.lines.title" %></div>      <div id="objects_statistics"></div> diff --git a/config/locales/compliance_checks.yml b/config/locales/compliance_checks.yml index f538bd42b..5917754cb 100644 --- a/config/locales/compliance_checks.yml +++ b/config/locales/compliance_checks.yml @@ -18,6 +18,7 @@ en:        destroy_confirm: "Do you confirm to destroy this validation ?"        destroy: "Destroy this validation"        edit: "Edit this validation" +      report: "Report"        rule_parameter_set: "Rule parameter set"        download: "Download"      statuses: @@ -25,7 +26,7 @@ en:        processing: "Processing"        completed: "Completed"        failed: "Failed" -      started: "Started"       +      started: "Started"        scheduled: "Processing ..."        terminated: "Completed"        canceled: "Canceled" @@ -86,6 +87,7 @@ fr:        destroy_confirm: "Voulez-vous supprimer ce résultat de validation ?"        destroy: "Supprimer cette validation"        edit: "Editer cette validation" +      report: "Rapport"        rule_parameter_set: "Jeu de paramètres"        download: "Télécharger"      statuses: diff --git a/config/routes.rb b/config/routes.rb index 88fe912c2..e0843fba3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,7 @@  ChouetteIhm::Application.routes.draw do    devise_for :users, :controllers => { :registrations => "registrations", :invitations => 'invitations' } -   +    devise_scope :user do      authenticated :user do        root :to => 'referentials#index', as: :authenticated_root @@ -85,7 +85,7 @@ ChouetteIhm::Application.routes.draw do          get "rule_parameter_set"          get "compliance_check"          get 'export', defaults: { format: 'zip' } -      end      +      end      end      resources :export_tasks, :only => [:new, :create] do @@ -93,7 +93,7 @@ ChouetteIhm::Application.routes.draw do          get 'references'        end      end -     +      resources :exports, :only => [:index, :show, :destroy]  do        member do          get "exported_file" @@ -105,10 +105,11 @@ ChouetteIhm::Application.routes.draw do          get 'references'        end      end -     +      resources :compliance_checks, :only => [:index, :show, :destroy] do        member do          get 'export', defaults: { format: 'zip' } +        get 'report'          get 'rule_parameter_set'        end        collection do | 
