From 1e58dfdbfbecccda78e2fe3854b2ba04a72bd511 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Thu, 14 Sep 2017 16:28:54 +0200 Subject: create base structure for compliance_control_sets --- .gitignore | 1 + .../compliance_control_sets_controller.rb | 21 ++++++ app/decorators/compliance_control_set_decorator.rb | 26 +++++++ app/helpers/breadcrumb_helper.rb | 7 ++ app/helpers/compliance_control_sets_helper.rb | 2 + app/helpers/table_builder_helper.rb | 1 - app/helpers/table_builder_helper/url.rb | 2 +- app/policies/compliance_control_set_policy.rb | 7 ++ .../compliance_control_sets/_filters.html.slim | 33 +++++++++ app/views/compliance_control_sets/_form.html.slim | 53 ++++++++++++++ app/views/compliance_control_sets/edit.html.slim | 10 +++ app/views/compliance_control_sets/index.html.slim | 51 ++++++++++++++ app/views/compliance_control_sets/new.html.slim | 11 +++ app/views/compliance_control_sets/show.html.slim | 82 ++++++++++++++++++++++ .../layouts/navigation/_main_nav_left.html.slim | 14 ++-- config/locales/compliance_control_sets.fr.yml | 21 ++++++ config/routes.rb | 2 + .../compliance_control_sets_controller_spec.rb | 5 ++ .../compliance_control_set_decorator_spec.rb | 4 ++ .../helpers/compliance_control_sets_helper_spec.rb | 15 ++++ 20 files changed, 359 insertions(+), 9 deletions(-) create mode 100644 app/controllers/compliance_control_sets_controller.rb create mode 100644 app/decorators/compliance_control_set_decorator.rb create mode 100644 app/helpers/compliance_control_sets_helper.rb create mode 100644 app/policies/compliance_control_set_policy.rb create mode 100644 app/views/compliance_control_sets/_filters.html.slim create mode 100644 app/views/compliance_control_sets/_form.html.slim create mode 100644 app/views/compliance_control_sets/edit.html.slim create mode 100644 app/views/compliance_control_sets/index.html.slim create mode 100644 app/views/compliance_control_sets/new.html.slim create mode 100644 app/views/compliance_control_sets/show.html.slim create mode 100644 config/locales/compliance_control_sets.fr.yml create mode 100644 spec/controllers/compliance_control_sets_controller_spec.rb create mode 100644 spec/decorators/compliance_control_set_decorator_spec.rb create mode 100644 spec/helpers/compliance_control_sets_helper_spec.rb diff --git a/.gitignore b/.gitignore index 29cc18f2e..41d838ee0 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ public/assets/ chouette2.war vendor/bundle .ruby-version +.byebug_history start.sh coverage diff --git a/app/controllers/compliance_control_sets_controller.rb b/app/controllers/compliance_control_sets_controller.rb new file mode 100644 index 000000000..b0a719cdc --- /dev/null +++ b/app/controllers/compliance_control_sets_controller.rb @@ -0,0 +1,21 @@ +class ComplianceControlSetsController < BreadcrumbController + + defaults resource_class: ComplianceControlSet + respond_to :html + + def index + index! do + @compliance_control_sets = decorate_compliance_control_sets(@compliance_control_sets) + build_breadcrumb :show + end + end + + + def decorate_compliance_control_sets(compliance_control_sets) + ModelDecorator.decorate( + compliance_control_sets, + with: ComplianceControlSetDecorator + ) + end + +end diff --git a/app/decorators/compliance_control_set_decorator.rb b/app/decorators/compliance_control_set_decorator.rb new file mode 100644 index 000000000..876a54d09 --- /dev/null +++ b/app/decorators/compliance_control_set_decorator.rb @@ -0,0 +1,26 @@ +class ComplianceControlSetDecorator < Draper::Decorator + delegate_all + + def action_links + links = [] + + # if h.policy(object).destroy? + links << Link.new( + content: h.destroy_link_content, + href: h.compliance_control_set_path(object.id), + method: :delete, + data: { confirm: h.t('compliance_control_sets.actions.destroy_confirm') } + ) + # end + + # if h.policy(object).edit? + links << Link.new( + content: h.t('compliance_control_sets.actions.edit'), + href: h.edit_compliance_control_set_path(object.id) + ) + # end + links + end + +end + diff --git a/app/helpers/breadcrumb_helper.rb b/app/helpers/breadcrumb_helper.rb index 55031d4f3..a3ee9de72 100644 --- a/app/helpers/breadcrumb_helper.rb +++ b/app/helpers/breadcrumb_helper.rb @@ -50,6 +50,8 @@ module BreadcrumbHelper compliance_check_breadcrumb action when "ComplianceCheckTask" compliance_check_task_breadcrumb action + when "ComplianceControlSets" + compliance_control_sets_breadcrumb action when "RuleParameterSet" rule_parameter_breadcrumb action when "User" @@ -239,6 +241,11 @@ module BreadcrumbHelper add_breadcrumb breadcrumb_label(@compliance_check_task), referential_compliance_check_task_path(@referential, @compliance_check_task),:title => breadcrumb_tooltip(@compliance_check_task) if action == :edit end + def compliance_control_sets_breadcrumb (action) + add_breadcrumb I18n.t("breadcrumbs.referentials"), workbenches_path + #add_breadcrumb breadcrumb_label(@workbench), workbench_path(@workbench), :title => breadcrumb_tooltip(@workbench) + end + def rule_parameter_breadcrumb (action) organisation_breadcrumb add_breadcrumb Referential.human_attribute_name("rule_parameter_sets"), organisation_path unless action == :index diff --git a/app/helpers/compliance_control_sets_helper.rb b/app/helpers/compliance_control_sets_helper.rb new file mode 100644 index 000000000..3e02e0ef7 --- /dev/null +++ b/app/helpers/compliance_control_sets_helper.rb @@ -0,0 +1,2 @@ +module ComplianceControlSetsHelper +end diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index ec4d487c1..95f53a90d 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -344,7 +344,6 @@ module TableBuilderHelper ) end end - def gear_menu_link(link) content_tag( :li, diff --git a/app/helpers/table_builder_helper/url.rb b/app/helpers/table_builder_helper/url.rb index f7ba703ae..a53ac5620 100644 --- a/app/helpers/table_builder_helper/url.rb +++ b/app/helpers/table_builder_helper/url.rb @@ -3,7 +3,7 @@ module TableBuilderHelper def self.polymorphic_url_parts(item, referential) polymorph_url = [] - unless item.is_a?(Calendar) || item.is_a?(Referential) + unless item.is_a?(Calendar) || item.is_a?(Referential) || item.is_a?(ComplianceControlSet) if referential polymorph_url << referential polymorph_url << item.line if item.respond_to? :line diff --git a/app/policies/compliance_control_set_policy.rb b/app/policies/compliance_control_set_policy.rb new file mode 100644 index 000000000..12b829aa4 --- /dev/null +++ b/app/policies/compliance_control_set_policy.rb @@ -0,0 +1,7 @@ +class ComplianceControlSetPolicy < ApplicationPolicy + class Scope < Scope + def resolve + scope + end + end +end diff --git a/app/views/compliance_control_sets/_filters.html.slim b/app/views/compliance_control_sets/_filters.html.slim new file mode 100644 index 000000000..8da629e9c --- /dev/null +++ b/app/views/compliance_control_sets/_filters.html.slim @@ -0,0 +1,33 @@ += search_form_for @q_for_form, url: workbench_path(@workbench.id), builder: SimpleForm::FormBuilder, class: 'form form-filter' do |f| + .ffg-row + .input-group.search_bar + = f.search_field :name_cont, class: 'form-control', placeholder: t('referentials.filters.name') + span.input-group-btn + button.btn.btn-default type='submit' + span.fa.fa-search + + .ffg-row + .form-group + = f.label t('activerecord.models.line.one').upcase, required: false, class: 'control-label' + = f.input :associated_lines_id_eq, as: :select, collection: @workbench.lines.includes(:company).order(:name), input_html: { 'data-select2ed': 'true', 'data-select2ed-placeholder': t('referentials.filters.line') }, label: false, label_method: :display_name, wrapper_html: { class: 'select2ed'} + + .form-group.togglable + = f.label Referential.human_attribute_name(:status), required: false, class: 'control-label' + .form-group.checkbox_list + = f.input :archived_at_not_null, label: ("#{t('activerecord.attributes.referential.archived_at')}").html_safe, as: :boolean, wrapper_html: { class: 'checkbox-wrapper' } + = f.input :archived_at_null, label: ("#{t('activerecord.attributes.referential.archived_at_null')}").html_safe, as: :boolean, wrapper_html: { class: 'checkbox-wrapper' } + + .form-group.togglable + = f.label t('activerecord.models.organisation.one'), required: false, class: 'control-label' + = f.input :organisation_name_eq_any, collection: Organisation.order('name').pluck(:name), as: :check_boxes, label: false, label_method: lambda{|w| ("#{w}").html_safe}, required: false, wrapper_html: { class: 'checkbox_list' } + + .form-group.togglable + = f.label Referential.human_attribute_name(:validity_period), required: false, class: 'control-label' + .filter_menu + = f.simple_fields_for :validity_period do |p| + = p.input :begin_gteq, as: :date, label: t('simple_form.from'), wrapper_html: { class: 'date smart_date filter_menu-item' }, default: @begin_range, include_blank: @begin_range ? false : true + = p.input :end_lteq, as: :date, label: t('simple_form.to'), wrapper_html: { class: 'date smart_date filter_menu-item' }, default: @end_range, include_blank: @end_range ? false : true + + .actions + = link_to t('actions.erase'), @workbench, class: 'btn btn-link' + = f.submit t('actions.filter'), class: 'btn btn-default', id: 'referential_filter_btn' diff --git a/app/views/compliance_control_sets/_form.html.slim b/app/views/compliance_control_sets/_form.html.slim new file mode 100644 index 000000000..ba14edf41 --- /dev/null +++ b/app/views/compliance_control_sets/_form.html.slim @@ -0,0 +1,53 @@ += simple_form_for @compliance_control_sets, html: { class: 'form-horizontal', id: 'calendar_form' }, wrapper: :horizontal_form do |f| + .row + .col-lg-12 + = f.input :name + = f.input :short_name + + - if policy(@compliance_control_sets).share? + .form-group.has_switch + = f.label :shared, class: 'col-sm-4 col-xs-5 control-label' + = f.input :shared, as: :boolean, checked_value: true, unchecked_value: false, label: content_tag(:span, t("#{@calendar.shared}"), class: 'switch-label', data: {checkedValue: t('true'), uncheckedValue: t('false')}), wrapper_html: { class: 'col-sm-8 col-xs-7'} + + .separator + + .row + .col-lg-12 + .subform + .nested-head + .wrapper + div + .form-group + label.control-label + = Calendar.human_attribute_name(:date) + div + + = f.simple_fields_for :date_values do |date_value| + = render 'date_value_fields', f: date_value + + .links.nested-linker + = link_to_add_association t('simple_form.labels.calendar.add_a_date'), f, :date_values, class: 'btn btn-outline-primary' + + .separator + + .row + .col-lg-12 + .subform + .nested-head + .wrapper + div + .form-group + label.control-label + = t('simple_form.labels.calendar.ranges.begin') + div + .form-group + label.control-label + = t('simple_form.labels.calendar.ranges.end') + div + + = f.simple_fields_for :periods do |period| + = render 'period_fields', f: period + .links.nested-linker + = link_to_add_association t('simple_form.labels.calendar.add_a_date_range'), f, :periods, class: 'btn btn-outline-primary' + + = f.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'calendar_form' diff --git a/app/views/compliance_control_sets/edit.html.slim b/app/views/compliance_control_sets/edit.html.slim new file mode 100644 index 000000000..73381be34 --- /dev/null +++ b/app/views/compliance_control_sets/edit.html.slim @@ -0,0 +1,10 @@ +/ PageHeader += pageheader 'modele-calendrier', + t('compliance_control_sets.index.edit') + +/ PageContent +.page_content + .container-fluid + .row + .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1 + /= render 'form' diff --git a/app/views/compliance_control_sets/index.html.slim b/app/views/compliance_control_sets/index.html.slim new file mode 100644 index 000000000..16879af5a --- /dev/null +++ b/app/views/compliance_control_sets/index.html.slim @@ -0,0 +1,51 @@ +/ PageHeader +- header_params = ['jeux-de-donnees', + t('compliance_control_sets.index.title'), + ''] +- header_params << link_to(t('compliance_control_sets.actions.new'), new_compliance_control_set_path, class: 'btn btn-default') if policy(Calendar).create? += pageheader(*header_params) do + + / Below is secundary actions & optional contents (filters, ...) + .row.mb-sm + .col-lg-12.text-right + +/ PageContent +.page_content + .container-fluid + .row + .col-lg-12 + /= render 'filters' + .row + .col-lg-12 + .select_table + = table_builder_2 @compliance_control_sets, + [ \ + TableBuilderHelper::Column.new( \ + key: :name, \ + attribute: 'name', \ + link_to: lambda do |compliance_control_set| \ + compliance_control_set_path(@compliance_control_sets, compliance_control_set) \ + end \ + ), \ + TableBuilderHelper::Column.new( \ + key: :assignment, \ + attribute: 'assignment' \ + ), \ + TableBuilderHelper::Column.new( \ + key: :owner_jdc, \ + attribute: 'owner_jdc' \ + ), \ + TableBuilderHelper::Column.new( \ + key: :control_numbers, \ + attribute: 'control_numbers' \ + ), \ + TableBuilderHelper::Column.new( \ + key: :update, \ + attribute: '' \ + ) \ + ], + sortable: true, + links: [:show], + cls: 'table has-filter has-search' + + diff --git a/app/views/compliance_control_sets/new.html.slim b/app/views/compliance_control_sets/new.html.slim new file mode 100644 index 000000000..93475974a --- /dev/null +++ b/app/views/compliance_control_sets/new.html.slim @@ -0,0 +1,11 @@ +/ PageHeader += pageheader 'modele-calendrier', + t('compliance_control_sets.index.new') + + +/ PageContent +.page_content + .container-fluid + .row + .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1 + /= render 'form' diff --git a/app/views/compliance_control_sets/show.html.slim b/app/views/compliance_control_sets/show.html.slim new file mode 100644 index 000000000..12ecc1894 --- /dev/null +++ b/app/views/compliance_control_sets/show.html.slim @@ -0,0 +1,82 @@ +/ PageHeader += pageheader 'jeux-de-donnees', + @compliance_control_set.name, + 'Lorem ipsum dolor sit amet' + + / Below is secondary actions & optional contents (filters, ...) + .row.mb-sm + .col-lg-12.text-right + /- @compliance_control_set.action_links.each do |link| + / - if link.is_a?(HTMLElement) + / = link.to_html(class: 'btn btn-primary') + / - else + / = link_to link.href, + / method: link.method, + / data: link.data, + / class: 'btn btn-primary' do + / = link.content + +/ PageContent +.page_content + .container-fluid + .row + .col-lg-6.col-md-6.col-sm-12.col-xs-12 + /= definition_list t('metadatas'), + / { t('activerecord.attributes.referential.status') => @referential.archived? ? "
#{t('activerecord.attributes.referential.archived_at')}
".html_safe : "
#{t('activerecord.attributes.referential.archived_at_null')}
".html_safe, + / @referential.human_attribute_name(:validity_period) => (@referential.validity_period.present? ? t('validity_range', debut: l(@referential.try(:validity_period).try(:begin), format: :short), end: l(@referential.try(:validity_period).try(:end), format: :short)) : '-'), + / @referential.human_attribute_name(:organisation) => @referential.organisation.name, + / @referential.human_attribute_name(:published_at) => '-' } + + /- if params[:q].present? or @reflines.any? + .row + .col-lg-12 + /= render 'filters' + + /- if @reflines.any? + .row + .col-lg-12 + / ID Codif, nom court, nom de la ligne, réseau, mode, transporteur principal, actions = [show, edit_notes] + = table_builder_2 @reflines, + [ \ + TableBuilderHelper::Column.new( \ + name: t('id_codif'), \ + attribute: Proc.new { |n| n.objectid.local_id }, \ + sortable: false \ + ), \ + TableBuilderHelper::Column.new( \ + key: :number, \ + attribute: 'number' \ + ), \ + TableBuilderHelper::Column.new( \ + key: :name, \ + attribute: 'name', \ + link_to: lambda do |line| \ + referential_line_path(@referential, line) \ + end \ + ), \ + TableBuilderHelper::Column.new( \ + key: :deactivated, \ + attribute: Proc.new { |n| n.deactivated? ? t('false') : t('true') } \ + ), \ + TableBuilderHelper::Column.new( \ + key: :transport_mode, \ + attribute: Proc.new { |n| n.transport_mode ? t("enumerize.line.transport_mode.#{n.transport_mode}") : '' }, \ + ), \ + TableBuilderHelper::Column.new( \ + key: 'networks.name', \ + attribute: Proc.new { |n| n.try(:network).try(:name) } \ + ), \ + TableBuilderHelper::Column.new( \ + key: 'companies.name', \ + attribute: Proc.new { |n| n.try(:company).try(:name) } \ + ) \ + ], + links: [:show], + cls: 'table has-filter has-search' + + = new_pagination @reflines, 'pull-right' + + /- unless @reflines.any? + .row.mt-xs + .col-lg-12 + = replacement_msg t('referential_lines.search_no_results') \ No newline at end of file diff --git a/app/views/layouts/navigation/_main_nav_left.html.slim b/app/views/layouts/navigation/_main_nav_left.html.slim index 4560f5fa0..12139c93b 100644 --- a/app/views/layouts/navigation/_main_nav_left.html.slim +++ b/app/views/layouts/navigation/_main_nav_left.html.slim @@ -11,7 +11,7 @@ .menu-item.panel .panel-heading h4.panel-title - = link_to '#miOne', data: { toggle: 'collapse', parent: '#menu-items' }, 'aria-expanded' => 'false' do + = link_to '#miOne', data: {toggle: 'collapse', parent: '#menu-items'}, 'aria-expanded' => 'false' do |Offres courantes #miOne.panel-collapse.collapse @@ -26,7 +26,7 @@ .menu-item.panel .panel-heading h4.panel-title - = link_to '#miTwo', data: { toggle: 'collapse', parent: '#menu-items' }, 'aria-expanded' => 'false' do + = link_to '#miTwo', data: {toggle: 'collapse', parent: '#menu-items'}, 'aria-expanded' => 'false' do |Espace de travail #miTwo.panel-collapse.collapse @@ -34,18 +34,18 @@ = link_to workbench_path(current_offer_workbench), class: "list-group-item #{params[:controller] == 'workbenches' ? 'active' : ''}" do span Jeux de données = link_to workbench_imports_path(current_offer_workbench), class: "list-group-item #{(params[:controller] == 'imports') ? 'active' : ''}" do - span Import + span Import = link_to calendars_path, class: 'list-group-item' do span Modèles de calendrier = link_to '#', class: 'list-group-item' do span Rapport de contrôle - = link_to '#', class: 'list-group-item' do + = link_to compliance_control_sets_path, class: 'list-group-item' do span Jeux de contrôle .menu-item.panel .panel-heading h4.panel-title - = link_to '#miThree', data: { toggle: 'collapse', parent: '#menu-items' }, 'aria-expanded' => 'false' do + = link_to '#miThree', data: {toggle: 'collapse', parent: '#menu-items'}, 'aria-expanded' => 'false' do |Données #miThree.panel-collapse.collapse @@ -74,7 +74,7 @@ .menu-item.panel .panel-heading h4.panel-title - = link_to '#miFour', data: { toggle: 'collapse', parent: '#menu-items' }, 'aria-expanded' => 'false' do + = link_to '#miFour', data: {toggle: 'collapse', parent: '#menu-items'}, 'aria-expanded' => 'false' do |Synchronisation #miFour.panel-collapse.collapse @@ -87,7 +87,7 @@ .menu-item.panel .panel-heading h4.panel-title - = link_to '#miFive', data: { toggle: 'collapse', parent: '#menu-items' }, 'aria-expanded' => 'false' do + = link_to '#miFive', data: {toggle: 'collapse', parent: '#menu-items'}, 'aria-expanded' => 'false' do |Outils #miFive.panel-collapse.collapse diff --git a/config/locales/compliance_control_sets.fr.yml b/config/locales/compliance_control_sets.fr.yml new file mode 100644 index 000000000..c230d593c --- /dev/null +++ b/config/locales/compliance_control_sets.fr.yml @@ -0,0 +1,21 @@ +fr: + compliance_control_sets: + index: + title: Jeux de contrôle + new: Création d'un jeux de contrôle + edit: Édition d'un jeux de contrôle + actions: + new: Ajouter + edit: Editer + destroy: Supprimer + destroy_confirm: Etes vous sûr de supprimer ce jeux de contrôle ? + activerecord: + models: + compliance_control_set: Calendrier + attributes: + compliance_control_set: + name: Nom + assignment: Affectation + owner_jdc: Propriétaire du jeu de contrôle + control_numbers: Nb contrôle + update: Mis a jour \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 0f1b22e44..314f99888 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,6 +12,8 @@ ChouetteIhm::Application.routes.draw do end end + resources :compliance_control_sets + devise_for :users, :controllers => { :registrations => 'users/registrations', :invitations => 'users/invitations' } diff --git a/spec/controllers/compliance_control_sets_controller_spec.rb b/spec/controllers/compliance_control_sets_controller_spec.rb new file mode 100644 index 000000000..12500174b --- /dev/null +++ b/spec/controllers/compliance_control_sets_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ComplianceControlSetsController, type: :controller do + +end diff --git a/spec/decorators/compliance_control_set_decorator_spec.rb b/spec/decorators/compliance_control_set_decorator_spec.rb new file mode 100644 index 000000000..64e9ff9e7 --- /dev/null +++ b/spec/decorators/compliance_control_set_decorator_spec.rb @@ -0,0 +1,4 @@ +require 'spec_helper' + +describe ComplianceControlSetDecorator do +end diff --git a/spec/helpers/compliance_control_sets_helper_spec.rb b/spec/helpers/compliance_control_sets_helper_spec.rb new file mode 100644 index 000000000..981368561 --- /dev/null +++ b/spec/helpers/compliance_control_sets_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the ComplianceControlSetsHelper. For example: +# +# describe ComplianceControlSetsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe ComplianceControlSetsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end -- cgit v1.2.3