diff options
| author | Guillaume | 2017-09-25 18:19:21 +0200 |
|---|---|---|
| committer | Guillaume | 2017-09-25 18:19:21 +0200 |
| commit | 82f611cd417d7e3a98f4fa7d21e2f94e6bc9a011 (patch) | |
| tree | 9383afa60f3430930cc0ac1ba669d0b52af7f548 /app | |
| parent | 2fa5b41379f33b399121dca1149dd7b20cf6d00d (diff) | |
| download | chouette-core-82f611cd417d7e3a98f4fa7d21e2f94e6bc9a011.tar.bz2 | |
add compliance_check_sets structure Refs #3564
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/compliance_check_sets_controller.rb | 54 | ||||
| -rw-r--r-- | app/decorators/compliance_check_set_decorator.rb | 8 | ||||
| -rw-r--r-- | app/helpers/compliance_check_set_helper.rb | 2 | ||||
| -rw-r--r-- | app/models/compliance_check_set.rb | 5 | ||||
| -rw-r--r-- | app/models/workbench.rb | 1 | ||||
| -rw-r--r-- | app/policies/compliance_check_set_policy.rb | 7 | ||||
| -rw-r--r-- | app/views/compliance_check_sets/_filters.html.slim | 24 | ||||
| -rw-r--r-- | app/views/compliance_check_sets/index.html.slim | 54 | ||||
| -rw-r--r-- | app/views/compliance_check_sets/show.html.slim | 12 | ||||
| -rw-r--r-- | app/views/layouts/navigation/_main_nav_left.html.slim | 2 |
10 files changed, 168 insertions, 1 deletions
diff --git a/app/controllers/compliance_check_sets_controller.rb b/app/controllers/compliance_check_sets_controller.rb new file mode 100644 index 000000000..989db1aeb --- /dev/null +++ b/app/controllers/compliance_check_sets_controller.rb @@ -0,0 +1,54 @@ +class ComplianceCheckSetsController < BreadcrumbController + defaults resource_class: ComplianceCheckSet + before_action :ransack_created_at_params, only: [:index] + respond_to :html + + belongs_to :workbench + + def index + index! do |format| + scope = ransack_period @compliance_check_sets + @q_for_form = scope.ransack(params[:q]) + format.html { + @compliance_check_sets = decorate_compliance_check_sets(@q_for_form.result) + } + end + end + + def decorate_compliance_check_sets(compliance_check_sets) + ModelDecorator.decorate( + compliance_check_sets, + with: ComplianceCheckSetDecorator + ) + end + + private + + def ransack_created_at_params + start_date = [] + end_date = [] + + if params[:q] && params[:q][:created_at] && !params[:q][:created_at].has_value?(nil) && !params[:q][:created_at].has_value?("") + [1, 2, 3].each do |key| + start_date << params[:q][:created_at]["begin(#{key}i)"].to_i + end_date << params[:q][:created_at]["end(#{key}i)"].to_i + end + params[:q].delete([:created_at]) + @begin_range = DateTime.new(*start_date, 0, 0, 0) rescue nil + @end_range = DateTime.new(*end_date, 23, 59, 59) rescue nil + end + end + + # Fake ransack filter + def ransack_period scope + return scope unless !!@begin_range && !!@end_range + + if @begin_range > @end_range + flash.now[:error] = t('imports.filters.error_period_filter') + else + scope = scope.where_created_at_between(@begin_range, @end_range) + end + scope + end + +end
\ No newline at end of file diff --git a/app/decorators/compliance_check_set_decorator.rb b/app/decorators/compliance_check_set_decorator.rb new file mode 100644 index 000000000..5f3821cbe --- /dev/null +++ b/app/decorators/compliance_check_set_decorator.rb @@ -0,0 +1,8 @@ +class ComplianceCheckSetDecorator < Draper::Decorator + delegate_all + + def action_links + links = [] + end + +end diff --git a/app/helpers/compliance_check_set_helper.rb b/app/helpers/compliance_check_set_helper.rb new file mode 100644 index 000000000..82680b304 --- /dev/null +++ b/app/helpers/compliance_check_set_helper.rb @@ -0,0 +1,2 @@ +module ComplianceCheckSetHelper +end diff --git a/app/models/compliance_check_set.rb b/app/models/compliance_check_set.rb index 7b6400a21..3c62221f0 100644 --- a/app/models/compliance_check_set.rb +++ b/app/models/compliance_check_set.rb @@ -7,4 +7,9 @@ class ComplianceCheckSet < ActiveRecord::Base belongs_to :parent, polymorphic: true enumerize :status, in: %w[new pending successful warning failed running aborted canceled] + + scope :where_created_at_between, ->(start_date, end_date) do + where('created_at BETWEEN ? AND ?', start_date, end_date) + end + end diff --git a/app/models/workbench.rb b/app/models/workbench.rb index 30692e625..cd90f8253 100644 --- a/app/models/workbench.rb +++ b/app/models/workbench.rb @@ -10,6 +10,7 @@ class Workbench < ActiveRecord::Base has_many :stop_areas, through: :stop_area_referential has_many :imports has_many :workbench_imports + has_many :compliance_check_sets validates :name, presence: true validates :organisation, presence: true diff --git a/app/policies/compliance_check_set_policy.rb b/app/policies/compliance_check_set_policy.rb new file mode 100644 index 000000000..3f715649e --- /dev/null +++ b/app/policies/compliance_check_set_policy.rb @@ -0,0 +1,7 @@ +class ComplianceCheckSetPolicy < ApplicationPolicy + class Scope < Scope + def resolve + scope + end + end +end diff --git a/app/views/compliance_check_sets/_filters.html.slim b/app/views/compliance_check_sets/_filters.html.slim new file mode 100644 index 000000000..b589e381f --- /dev/null +++ b/app/views/compliance_check_sets/_filters.html.slim @@ -0,0 +1,24 @@ += search_form_for @q_for_form, url: workbench_compliance_check_sets_path(current_offer_workbench), builder: SimpleForm::FormBuilder, class: 'form form-filter' do |f| + .ffg-row + .input-group.search_bar + = f.search_field :referential_name_cont, class: 'form-control', placeholder: t('compliance_check_sets.filters.name') + span.input-group-btn + button.btn.btn-default type='submit' + span.fa.fa-search + + .ffg-row + .form-group.togglable + = f.label t('activerecord.attributes.compliance_check_set.assignment'), required: false, class: 'control-label' + = f.input :parent_type_eq_any, collection: ComplianceCheckSet.order('parent_type'), as: :check_boxes, label: false, label_method: lambda {|w| ("<span>#{w}</span>").html_safe}, required: false, wrapper_html: {class: 'checkbox_list'} + + .form-group.togglable + = f.label Import.human_attribute_name(:created_at), required: false, class: 'control-label' + .filter_menu + = f.simple_fields_for :created_at do |p| + = p.input :begin, as: :date, label: false, wrapper_html: {class: 'date smart_date filter_menu-item'}, default: @begin_range, include_blank: @begin_range ? false : true + = p.input :end, as: :date, label: false, wrapper_html: {class: 'date smart_date filter_menu-item'}, default: @end_range, include_blank: @end_range ? false : true + + .actions + = link_to t('actions.erase'), @compliance_checks_sets, class: 'btn btn-link' + = f.submit t('actions.filter'), class: 'btn btn-default', id: 'referential_filter_btn' + diff --git a/app/views/compliance_check_sets/index.html.slim b/app/views/compliance_check_sets/index.html.slim new file mode 100644 index 000000000..cad20172b --- /dev/null +++ b/app/views/compliance_check_sets/index.html.slim @@ -0,0 +1,54 @@ +/ PageHeader +- header_params = ['jeux-de-donnees', + t('compliance_check_sets.index.title'), + ''] += 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_check_sets, + [ \ + TableBuilderHelper::Column.new( \ + key: :ref, \ + attribute: 'referential_id' \ + ), \ + TableBuilderHelper::Column.new( \ + key: :creation_date, \ + attribute: Proc.new { |n| l(n.created_at, format: :long) if n.created_at } \ + ), \ + TableBuilderHelper::Column.new( \ + key: :associated_object, \ + attribute: Proc.new{|n| n.referential.name}, \ + link_to: lambda do |referential| \ + referential_path(referential, current_workbench_id: params[:id]) \ + end \ + ), \ + TableBuilderHelper::Column.new( \ + key: :assignment, \ + attribute: 'parent_type' \ + ), \ + TableBuilderHelper::Column.new(\ + key: :control_game, \ + attribute: 'control_game' \ + ), \ + ], + sortable: true, + links: [:show], + cls: 'table has-filter has-search' + - unless @compliance_check_sets.any? + .row.mt-xs + .col-lg-12 + = replacement_msg t('compliance_check_sets.search_no_results') + + diff --git a/app/views/compliance_check_sets/show.html.slim b/app/views/compliance_check_sets/show.html.slim new file mode 100644 index 000000000..1b96b70fc --- /dev/null +++ b/app/views/compliance_check_sets/show.html.slim @@ -0,0 +1,12 @@ +/ PageHeader += pageheader 'jeux-de-donnees', + @compliance_check_set.referential.name, + 'Lorem ipsum dolor sit amet' +/ PageContent +.page_content + .container-fluid + .row + .col-lg-6.col-md-6.col-sm-12.col-xs-12 + = definition_list t('metadatas'), + ComplianceCheckSet.human_attribute_name(:id) => @compliance_check_set.referential.id, + ComplianceCheckSet.human_attribute_name(:name) => @compliance_check_set.referential.name
\ 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 12139c93b..062c9383c 100644 --- a/app/views/layouts/navigation/_main_nav_left.html.slim +++ b/app/views/layouts/navigation/_main_nav_left.html.slim @@ -37,7 +37,7 @@ span Import = link_to calendars_path, class: 'list-group-item' do span Modèles de calendrier - = link_to '#', class: 'list-group-item' do + = link_to workbench_compliance_check_sets_path(current_offer_workbench), class: 'list-group-item' do span Rapport de contrôle = link_to compliance_control_sets_path, class: 'list-group-item' do span Jeux de contrôle |
