diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/compliance_control_sets_controller.rb | 8 | ||||
| -rw-r--r-- | app/controllers/stop_areas_controller.rb | 1 | ||||
| -rw-r--r-- | app/helpers/compliance_control_blocks_helper.rb | 10 | ||||
| -rw-r--r-- | app/helpers/compliance_controls_helper.rb | 11 | ||||
| -rw-r--r-- | app/helpers/table_builder_helper.rb | 24 | ||||
| -rw-r--r-- | app/models/compliance_control.rb | 72 | ||||
| -rw-r--r-- | app/models/import.rb | 3 | ||||
| -rw-r--r-- | app/views/compliance_control_sets/show.html.slim | 94 | ||||
| -rw-r--r-- | app/views/compliance_controls/_filters.html.slim | 46 | ||||
| -rw-r--r-- | app/views/layouts/navigation/_main_nav_left.html.slim | 21 | ||||
| -rw-r--r-- | app/workers/compliance_control_set_copy_worker.rb | 14 | ||||
| -rw-r--r-- | app/workers/workbench_import_worker.rb | 6 |
12 files changed, 208 insertions, 102 deletions
diff --git a/app/controllers/compliance_control_sets_controller.rb b/app/controllers/compliance_control_sets_controller.rb index f6002956b..cff67d5cb 100644 --- a/app/controllers/compliance_control_sets_controller.rb +++ b/app/controllers/compliance_control_sets_controller.rb @@ -17,8 +17,12 @@ class ComplianceControlSetsController < InheritedResources::Base def show show! do |format| format.html { + @q_controls_form = @compliance_control_set.compliance_controls.ransack(params[:q]) @compliance_control_set = @compliance_control_set.decorate - @compliance_controls_without_block = decorate_compliance_controls(@compliance_control_set.compliance_controls.where(compliance_control_block_id: nil)) + @compliance_controls = + decorate_compliance_controls( @q_controls_form.result) + .group_by(&:compliance_control_block) + @indirect_compliance_controls = @compliance_controls.delete nil } end end @@ -58,4 +62,4 @@ class ComplianceControlSetsController < InheritedResources::Base def compliance_control_set_params params.require(:compliance_control_set).permit(:name, :id) end -end
\ No newline at end of file +end diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb index 0c9f3067a..1d6f88068 100644 --- a/app/controllers/stop_areas_controller.rb +++ b/app/controllers/stop_areas_controller.rb @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- class StopAreasController < InheritedResources::Base include ApplicationHelper diff --git a/app/helpers/compliance_control_blocks_helper.rb b/app/helpers/compliance_control_blocks_helper.rb index 09e22d6e9..311e6fb46 100644 --- a/app/helpers/compliance_control_blocks_helper.rb +++ b/app/helpers/compliance_control_blocks_helper.rb @@ -1,10 +1,10 @@ module ComplianceControlBlocksHelper def transport_mode(transport_mode, transport_submode) - if (transport_mode) && (transport_submode) != "" - transportMode = "[" + t("enumerize.transport_mode.#{transport_mode}") + "]" + "[" + t("enumerize.transport_submode.#{transport_submode}") + "]" + return "[Tous les modes de transport]" if transport_mode == "" + if transport_submode == "" + "[" + t("enumerize.transport_mode.#{transport_mode}") + "]" else - transportMode = "[Tous les modes de transport]" + "[" + t("enumerize.transport_mode.#{transport_mode}") + "]" + "[" + t("enumerize.transport_submode.#{transport_submode}") + "]" end - transportMode end -end
\ No newline at end of file +end diff --git a/app/helpers/compliance_controls_helper.rb b/app/helpers/compliance_controls_helper.rb new file mode 100644 index 000000000..ba0c538c9 --- /dev/null +++ b/app/helpers/compliance_controls_helper.rb @@ -0,0 +1,11 @@ +module ComplianceControlsHelper + def subclass_selection_list + ComplianceControl.subclass_patterns.map(&method(:make_subclass_selection_item)) + end + + + def make_subclass_selection_item(key_pattern) + key, pattern = key_pattern + [t("compliance_controls.filters.subclasses.#{key}"), "-#{pattern}-"] + end +end diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index 95f53a90d..37f01ce0d 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -83,17 +83,21 @@ module TableBuilderHelper cls: '', # A set of content, over the th line... - overhead: [] + overhead: [], + + # Possibility to override the result of collection.model + model: nil + ) content_tag :table, - thead(collection, columns, sortable, selectable, links.any?, overhead) + + thead(collection, columns, sortable, selectable, links.any?, overhead, model || collection.model) + tbody(collection, columns, selectable, links, overhead), class: cls end private - def thead(collection, columns, sortable, selectable, has_links, overhead) + def thead(collection, columns, sortable, selectable, has_links, overhead, model ) content_tag :thead do # Inserts overhead content if any specified over_head = '' @@ -121,7 +125,7 @@ module TableBuilderHelper hcont << content_tag(:th, build_column_header( column, sortable, - collection.model, + model, params, params[:sort], params[:direction] @@ -137,7 +141,7 @@ module TableBuilderHelper hcont << content_tag(:th, build_column_header( column, sortable, - collection.model, + model, params, params[:sort], params[:direction] @@ -147,7 +151,7 @@ module TableBuilderHelper hcont << content_tag(:th, build_column_header( column, sortable, - collection.model, + model, params, params[:sort], params[:direction] @@ -160,7 +164,7 @@ module TableBuilderHelper hcont << content_tag(:th, build_column_header( column, sortable, - collection.model, + model, params, params[:sort], params[:direction] @@ -299,14 +303,14 @@ module TableBuilderHelper def build_column_header( column, table_is_sortable, - collection_model, + model, params, sort_on, sort_direction ) if !table_is_sortable || !column.sortable - return column.header_label(collection_model) + return column.header_label(model) end direction = @@ -331,7 +335,7 @@ module TableBuilderHelper arrow_icons = content_tag :span, arrow_up + arrow_down, class: 'orderers' ( - column.header_label(collection_model) + + column.header_label(model) + arrow_icons ).html_safe end diff --git a/app/models/compliance_control.rb b/app/models/compliance_control.rb index 08efa7e9a..49fb6513f 100644 --- a/app/models/compliance_control.rb +++ b/app/models/compliance_control.rb @@ -1,29 +1,7 @@ class ComplianceControl < ActiveRecord::Base - extend Enumerize - belongs_to :compliance_control_set - belongs_to :compliance_control_block - - enumerize :criticity, in: %i(warning error), scope: true, default: :warning - hstore_accessor :control_attributes, {} - - validates :criticity, presence: true - validates :name, presence: true - validates :code, presence: true, uniqueness: { scope: :compliance_control_set } - validates :origin_code, presence: true - validates :compliance_control_set, presence: true - - validate def coherent_control_set - return true if compliance_control_block_id.nil? - ids = [compliance_control_block.compliance_control_set_id, compliance_control_set_id] - return true if ids.first == ids.last - names = ids.map{|id| ComplianceControlSet.find(id).name} - errors.add(:coherent_control_set, - I18n.t('compliance_controls.errors.incoherent_control_sets', - indirect_set_name: names.first, - direct_set_name: names.last)) - end class << self + def criticities; %i(warning error) end def default_code; "" end def dynamic_attributes hstore_metadata_for_control_attributes.keys @@ -33,6 +11,17 @@ class ComplianceControl < ActiveRecord::Base ComplianceControlPolicy end + def subclass_patterns + { + generic: 'Generic', + journey_pattern: 'JourneyPattern', + line: 'Line', + route: 'Route', + routing_constraint_zone: 'RoutingConstraint', + vehicle_journey: 'VehicleJourney' + } + end + def inherited(child) child.instance_eval do def model_name @@ -43,12 +32,37 @@ class ComplianceControl < ActiveRecord::Base end end - def initialize(attributes = {}) - super - self.name ||= I18n.t("activerecord.models.#{self.class.name.underscore}.one") - self.code ||= self.class.default_code - self.origin_code ||= self.class.default_code - end + extend Enumerize + belongs_to :compliance_control_set + belongs_to :compliance_control_block + + enumerize :criticity, in: criticities, scope: true, default: :warning + hstore_accessor :control_attributes, {} + + validates :criticity, presence: true + validates :name, presence: true + validates :code, presence: true, uniqueness: { scope: :compliance_control_set } + validates :origin_code, presence: true + validates :compliance_control_set, presence: true + + validate def coherent_control_set + return true if compliance_control_block_id.nil? + ids = [compliance_control_block.compliance_control_set_id, compliance_control_set_id] + return true if ids.first == ids.last + names = ids.map{|id| ComplianceControlSet.find(id).name} + errors.add(:coherent_control_set, + I18n.t('compliance_controls.errors.incoherent_control_sets', + indirect_set_name: names.first, + direct_set_name: names.last)) +end + + +def initialize(attributes = {}) + super + self.name ||= I18n.t("activerecord.models.#{self.class.name.underscore}.one") + self.code ||= self.class.default_code + self.origin_code ||= self.class.default_code +end end diff --git a/app/models/import.rb b/app/models/import.rb index e0aae6ef1..20e7f2d8a 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -16,9 +16,10 @@ class Import < ActiveRecord::Base extend Enumerize enumerize :status, in: %i(new pending successful warning failed running aborted canceled), scope: true, default: :new + validates :name, presence: true validates :file, presence: true validates_presence_of :workbench, :creator - validates_format_of :file, with: %r{\.zip\z}i, message: I18n.t('activerecord.errors.models.imports.wrong_file_extension') + validates_format_of :file, with: %r{\.zip\z}i, message: I18n.t('activerecord.errors.models.import.attributes.file.wrong_file_extension') before_create :initialize_fields diff --git a/app/views/compliance_control_sets/show.html.slim b/app/views/compliance_control_sets/show.html.slim index cf236feb8..294df6a53 100644 --- a/app/views/compliance_control_sets/show.html.slim +++ b/app/views/compliance_control_sets/show.html.slim @@ -24,54 +24,21 @@ .col-lg-6.col-md-6.col-sm-12.col-xs-12 = definition_list t('metadatas'), ComplianceControlSet.human_attribute_name(:name) => @compliance_control_set.name + - if params[:q].present? or @compliance_controls.any? + .row + .col-lg-12 + = render '/compliance_controls/filters' + .row .col-lg-12 h2 = transport_mode("", "") - .row - .col-lg-12 - .select_table - = table_builder_2 @compliance_controls_without_block, - [ \ - TableBuilderHelper::Column.new( \ - key: :code, \ - attribute: 'code' \ - ), \ - TableBuilderHelper::Column.new( \ - key: :name, \ - attribute: 'name', \ - link_to: lambda do |compliance_control| \ - compliance_control_set_compliance_control_path(@compliance_control_set, compliance_control) \ - end \ - ), \ - TableBuilderHelper::Column.new( \ - key: :criticity, \ - attribute: 'criticity' \ - ), \ - TableBuilderHelper::Column.new( \ - key: :comment, \ - attribute: 'comment' \ - ), \ - ], - sortable: true, - cls: 'table has-filter has-search' - - @compliance_control_set.compliance_control_blocks.each do |block| - .row - .col-lg-12 - h2 - = transport_mode(block.transport_mode, block.transport_submode) - .btn-group - .btn.dropdown-toggle{ data-toggle="dropdown" } - .span.fa.fa-cog - ul.dropdown-menu - li - = link_to t('compliance_control_sets.actions.edit'), edit_compliance_control_set_compliance_control_block_path(@compliance_control_set.id, block.id) - = link_to t('compliance_control_sets.actions.destroy'), compliance_control_set_compliance_control_block_path(@compliance_control_set.id, block.id), :method => :delete, :data => {:confirm => t('compliance_control_sets.actions.destroy_confirm')} + - if @indirect_compliance_controls.try(:any?) .row .col-lg-12 .select_table - = table_builder_2 ModelDecorator.decorate(block.compliance_controls, with: ComplianceControlDecorator), + = table_builder_2 @indirect_compliance_controls, [ \ TableBuilderHelper::Column.new( \ key: :code, \ @@ -94,7 +61,52 @@ ), \ ], sortable: true, - cls: 'table has-filter has-search' + cls: 'table has-filter has-search', + model: ComplianceControl + + - @compliance_controls.each do |block, compliance_controls| + + - if compliance_controls.try(:any?) + .row + .col-lg-12 + h2 + = transport_mode(block.transport_mode, block.transport_submode) + .btn-group + .btn.dropdown-toggle{ data-toggle="dropdown" } + .span.fa.fa-cog + ul.dropdown-menu + li + = link_to t('compliance_control_sets.actions.edit'), edit_compliance_control_set_compliance_control_block_path(@compliance_control_set.id, block.id) + = link_to t('compliance_control_sets.actions.destroy'), compliance_control_set_compliance_control_block_path(@compliance_control_set.id, block.id), :method => :delete, :data => {:confirm => t('compliance_control_sets.actions.destroy_confirm')} + .row + .col-lg-12 + .select_table + = table_builder_2 compliance_controls, + [ \ + TableBuilderHelper::Column.new( \ + key: :code, \ + attribute: 'code' \ + ), \ + TableBuilderHelper::Column.new( \ + key: :name, \ + attribute: 'name', \ + link_to: lambda do |compliance_control| \ + compliance_control_set_compliance_control_path(@compliance_control_set, compliance_control) \ + end \ + ), \ + TableBuilderHelper::Column.new( \ + key: :criticity, \ + attribute: 'criticity' \ + ), \ + TableBuilderHelper::Column.new( \ + key: :comment, \ + attribute: 'comment' \ + ), \ + ], + sortable: true, + cls: 'table has-filter has-search', + model: ComplianceControl + .select_toolbox ul li.st_action.with_text diff --git a/app/views/compliance_controls/_filters.html.slim b/app/views/compliance_controls/_filters.html.slim new file mode 100644 index 000000000..c729190a0 --- /dev/null +++ b/app/views/compliance_controls/_filters.html.slim @@ -0,0 +1,46 @@ += search_form_for @q_controls_form, + url: compliance_control_set_path(@compliance_control_set), + 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('compliance_controls.filters.name') + span.input-group-btn + button.btn.btn-default type='submit' + span.fa.fa-search + + .ffg-row + .form-group.togglable#compliance_control_block-filter + = f.label t('activerecord.models.compliance_control_block.one'), required: false, class: 'control-label' + = f.input :compliance_control_block_id_eq_any, + collection: @compliance_control_set.compliance_control_blocks, + as: :check_boxes, + label: false, + label_method: lambda {|w| ("<span>#{transport_mode(w.transport_mode, w.transport_submode)}</span>").html_safe}, + required: false, + wrapper_html: {class: 'checkbox_list'} + .form-group.togglable#subclass-filter + = f.label t('compliance_controls.filters.subclass'), required: false, class: 'control-label' + = f.input :origin_code_cont_any, + collection: subclass_selection_list, + as: :check_boxes, + label: false, + label_method: lambda {|w| ("<span>#{w.first}</span>").html_safe}, + required: false, + wrapper_html: {class: 'checkbox_list'} + .form-group.togglable#severity-filter + = f.label t('compliance_controls.filters.criticity'), required: false, class: 'control-label' + = f.input :criticity_eq_any, + collection: ComplianceControl.criticities, + as: :check_boxes, + label: false, + label_method: lambda {|w| ("<span>#{w}</span>").html_safe}, + required: false, + wrapper_html: {class: 'checkbox_list'} + + .actions + = link_to t('actions.erase'), @compliance_control_set, class: 'btn btn-link' + = f.submit t('actions.filter'), class: 'btn btn-default', id: 'compliance_control_set_compliance_controls_filter_btn' diff --git a/app/views/layouts/navigation/_main_nav_left.html.slim b/app/views/layouts/navigation/_main_nav_left.html.slim index 062c9383c..837b9cb73 100644 --- a/app/views/layouts/navigation/_main_nav_left.html.slim +++ b/app/views/layouts/navigation/_main_nav_left.html.slim @@ -31,16 +31,17 @@ #miTwo.panel-collapse.collapse .list-group - = 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 - = link_to calendars_path, class: 'list-group-item' do - span Modèles de calendrier - = 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 + - if current_user + = 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 + = link_to calendars_path, class: 'list-group-item' do + span Modèles de calendrier + = 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 .menu-item.panel .panel-heading diff --git a/app/workers/compliance_control_set_copy_worker.rb b/app/workers/compliance_control_set_copy_worker.rb new file mode 100644 index 000000000..d18bb0c88 --- /dev/null +++ b/app/workers/compliance_control_set_copy_worker.rb @@ -0,0 +1,14 @@ +class ComplianceControlSetCopyWorker + include Sidekiq::Worker + + def perform(control_set_id, referential_id) + check_set = ComplianceControlSetCopier.new.copy(control_set_id, referential_id) + + begin + Net::HTTP.get(URI("#{Rails.configuration.iev_url}/boiv_iev/referentials/validator/new?id=#{check_set.id}")) + rescue Exception => e + logger.error "IEV server error : #{e.message}" + logger.error e.backtrace.inspect + end + end +end diff --git a/app/workers/workbench_import_worker.rb b/app/workers/workbench_import_worker.rb index 300fad9e2..de51efded 100644 --- a/app/workers/workbench_import_worker.rb +++ b/app/workers/workbench_import_worker.rb @@ -35,7 +35,7 @@ class WorkbenchImportWorker end def handle_corrupt_zip_file - @workbench_import.messages.create(criticity: :error, message_key: 'corrupt_zip_file', message_attributes: {import_name: @workbench_import.name}) + @workbench_import.messages.create(criticity: :error, message_key: 'corrupt_zip_file', message_attributes: {source_filename: @workbench_import.file.file.file}) end def upload zip_service @@ -55,8 +55,8 @@ class WorkbenchImportWorker criticity: :warning, message_key: 'inconsistent_zip_file', message_attributes: { - 'import_name' => @workbench_import.name, - 'spurious_dirs' => entry.spurious.join(', ') + 'source_filename' => @workbench_import.file.file.file, + 'spurious_dirs' => entry.spurious.join(', ') }) end end |
