diff options
Diffstat (limited to 'app/controllers')
| -rw-r--r-- | app/controllers/api_keys_controller.rb | 6 | ||||
| -rw-r--r-- | app/controllers/compliance_check_sets_controller.rb | 21 | ||||
| -rw-r--r-- | app/controllers/compliance_control_blocks_controller.rb | 12 | ||||
| -rw-r--r-- | app/controllers/compliance_control_sets_controller.rb | 33 | ||||
| -rw-r--r-- | app/controllers/compliance_controls_controller.rb | 49 | ||||
| -rw-r--r-- | app/controllers/concerns/ransack_date_filter.rb | 41 | ||||
| -rw-r--r-- | app/controllers/dashboards_controller.rb | 13 | ||||
| -rw-r--r-- | app/controllers/imports_controller.rb | 34 | ||||
| -rw-r--r-- | app/controllers/time_tables_controller.rb | 26 | ||||
| -rw-r--r-- | app/controllers/workbenches_controller.rb | 37 |
10 files changed, 155 insertions, 117 deletions
diff --git a/app/controllers/api_keys_controller.rb b/app/controllers/api_keys_controller.rb index f8b96afdc..7ae8d4732 100644 --- a/app/controllers/api_keys_controller.rb +++ b/app/controllers/api_keys_controller.rb @@ -6,7 +6,7 @@ class ApiKeysController < BreadcrumbController @api_key = Api::V1::ApiKey.new(api_key_params.merge(organisation: current_organisation)) create! do |format| format.html { - redirect_to workbenches_path + redirect_to dashboard_path } end end @@ -14,7 +14,7 @@ class ApiKeysController < BreadcrumbController def update update! do |format| format.html { - redirect_to workbenches_path + redirect_to dashboard_path } end end @@ -22,7 +22,7 @@ class ApiKeysController < BreadcrumbController def destroy destroy! do |format| format.html { - redirect_to workbenches_path + redirect_to dashboard_path } end end diff --git a/app/controllers/compliance_check_sets_controller.rb b/app/controllers/compliance_check_sets_controller.rb new file mode 100644 index 000000000..fce8dcc56 --- /dev/null +++ b/app/controllers/compliance_check_sets_controller.rb @@ -0,0 +1,21 @@ +class ComplianceCheckSetsController < BreadcrumbController + defaults resource_class: ComplianceCheckSet + include RansackDateFilter + before_action only: [:index] { set_date_time_params("created_at", DateTime) } + respond_to :html + + belongs_to :workbench + + def index + index! do |format| + scope = self.ransack_period_range(scope: @compliance_check_sets, error_message: t('compliance_check_sets.filters.error_period_filter'), query: :where_created_at_between) + @q_for_form = scope.ransack(params[:q]) + format.html { + @compliance_check_sets = ModelDecorator.decorate( + @q_for_form.result, + with: ComplianceCheckSetDecorator + ) + } + end + end +end
\ No newline at end of file diff --git a/app/controllers/compliance_control_blocks_controller.rb b/app/controllers/compliance_control_blocks_controller.rb new file mode 100644 index 000000000..2dd69a865 --- /dev/null +++ b/app/controllers/compliance_control_blocks_controller.rb @@ -0,0 +1,12 @@ +class ComplianceControlBlocksController < BreadcrumbController + defaults resource_class: ComplianceControlBlock + belongs_to :compliance_control_set + actions :all, :except => [:show, :index] + + private + + def compliance_control_block_params + params.require(:compliance_control_block).permit(:transport_mode, :transport_submode) + end + +end
\ No newline at end of file diff --git a/app/controllers/compliance_control_sets_controller.rb b/app/controllers/compliance_control_sets_controller.rb index c6f4288a9..9de90c21c 100644 --- a/app/controllers/compliance_control_sets_controller.rb +++ b/app/controllers/compliance_control_sets_controller.rb @@ -1,10 +1,13 @@ class ComplianceControlSetsController < BreadcrumbController defaults resource_class: ComplianceControlSet + include RansackDateFilter + before_action only: [:index] { set_date_time_params("updated_at", DateTime) } respond_to :html def index index! do |format| - @q_for_form = @compliance_control_sets.ransack(params[:q]) + scope = self.ransack_period_range(scope: @compliance_control_sets, error_message: t('imports.filters.error_period_filter'), query: :where_updated_at_between) + @q_for_form = scope.ransack(params[:q]) format.html { @compliance_control_sets = decorate_compliance_control_sets(@q_for_form.result) } @@ -12,11 +15,22 @@ class ComplianceControlSetsController < BreadcrumbController end def show - show! do - @compliance_control_set = @compliance_control_set.decorate + show! do |format| + format.html { + @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)) + } end end + protected + + def begin_of_association_chain + current_organisation + end + + private + def decorate_compliance_control_sets(compliance_control_sets) ModelDecorator.decorate( compliance_control_sets, @@ -24,13 +38,12 @@ class ComplianceControlSetsController < BreadcrumbController ) end - protected - - # def begin_of_association_chain - # current_organisation - # end - - private + def decorate_compliance_controls(compliance_controls) + ModelDecorator.decorate( + compliance_controls, + with: ComplianceControlDecorator, + ) + end def compliance_control_set_params params.require(:compliance_control_set).permit(:name, :id) diff --git a/app/controllers/compliance_controls_controller.rb b/app/controllers/compliance_controls_controller.rb index dad9b935a..e51d1eb74 100644 --- a/app/controllers/compliance_controls_controller.rb +++ b/app/controllers/compliance_controls_controller.rb @@ -1,38 +1,49 @@ class ComplianceControlsController < BreadcrumbController - include PolicyChecker defaults resource_class: ComplianceControl belongs_to :compliance_control_set - def index - index! do |format| - format.html { - @compliance_controls = decorate_compliance_controls(@compliance_controls) - } + def select_type + @sti_subclasses = ComplianceControl.subclasses + end + + def new + if params[:sti_class].blank? + flash[:notice] = I18n.t("compliance_controls.errors.mandatory_control_type") + redirect_to(action: :select_type) end + new! end def create - create!(notice: t('notice.compliance_control.created')) + puts build_resource.inspect + create! do |success, failure| + success.html { redirect_to compliance_control_set_path(parent) } + failure.html { render( :action => 'new' ) } + end end - def update - path = compliance_control_set_compliance_control_path(parent, resource) - update!(notice: t('notice.compliance_control.updated')) { path } - end + protected - def destroy - destroy!(notice: t('notice.compliance_control.destroyed')) + alias_method :compliance_control_set, :parent + alias_method :compliance_control, :resource + + def build_resource + get_resource_ivar || set_resource_ivar(compliance_control_class.send(:new, *resource_params)) end private - def decorate_compliance_controls(compliance_controls) - ModelDecorator.decorate( - compliance_controls, - with: ComplianceControlDecorator, - ) + + def compliance_control_class + (params[:sti_class] || params[:compliance_control][:type]).constantize + end + + def dynamic_attributes_params + compliance_control_class.dynamic_attributes end def compliance_control_params - params.require(:compliance_control).permit(:name, :code, :criticity, :comment, :control_attributes) + base = [:name, :code, :origin_code, :criticity, :comment, :control_attributes, :type, :compliance_control_block_id, :compliance_control_set_id] + permitted = base + dynamic_attributes_params + params.require(:compliance_control).permit(permitted) end end diff --git a/app/controllers/concerns/ransack_date_filter.rb b/app/controllers/concerns/ransack_date_filter.rb new file mode 100644 index 000000000..0fbde91d3 --- /dev/null +++ b/app/controllers/concerns/ransack_date_filter.rb @@ -0,0 +1,41 @@ +module RansackDateFilter + extend ActiveSupport::Concern + + included do + + def set_date_time_params(param_name, klass) + start_date = [] + end_date = [] + + if params[:q] && params[:q][param_name] && !params[:q][param_name].has_value?(nil) && !params[:q][param_name].has_value?("") + [1, 2, 3].each do |key| + start_date << params[:q][param_name]["start_date(#{key}i)"].to_i + end_date << params[:q][param_name]["end_date(#{key}i)"].to_i + end + + params[:q].delete([param_name]) + + if klass == DateTime + @begin_range = klass.new(*start_date,0,0,0) rescue nil + @end_range = klass.new(*end_date,23,59,59) rescue nil + else + @begin_range = klass.new(*start_date) rescue nil + @end_range = klass.new(*end_date) rescue nil + end + end + end + + # Fake ransack filter + def ransack_period_range **options + return options[:scope] unless !!@begin_range && !!@end_range + + if @begin_range > @end_range + flash.now[:error] = options[:error_message] + else + scope = options[:scope].send options[:query], @begin_range..@end_range + end + scope + end + end + +end
\ No newline at end of file diff --git a/app/controllers/dashboards_controller.rb b/app/controllers/dashboards_controller.rb new file mode 100644 index 000000000..2585dafca --- /dev/null +++ b/app/controllers/dashboards_controller.rb @@ -0,0 +1,13 @@ +# +# If you changed the default Dashboard implementation (see Dashboard), +# this controller will use a custom partial like +# custom/dashboards/_dashboard.html.slim for Custom::Dashboard +# +class DashboardsController < BreadcrumbController + respond_to :html, only: [:show] + + def show + @dashboard = Dashboard.create self + end + +end diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb index 3333dc535..3c52dc935 100644 --- a/app/controllers/imports_controller.rb +++ b/app/controllers/imports_controller.rb @@ -1,7 +1,9 @@ class ImportsController < BreadcrumbController + include PolicyChecker + include RansackDateFilter + before_action only: [:index] { set_date_time_params("started_at", DateTime) } skip_before_action :authenticate_user!, only: [:download] defaults resource_class: Import, collection_name: 'imports', instance_name: 'import' - before_action :ransack_started_at_params, only: [:index] before_action :ransack_status_params, only: [:index] respond_to :html belongs_to :workbench @@ -47,7 +49,8 @@ class ImportsController < BreadcrumbController protected def collection scope = parent.imports.where(type: "WorkbenchImport") - scope = ransack_period scope + + scope = self.ransack_period_range(scope: scope, error_message: t('imports.filters.error_period_filter'), query: :where_started_at_in) @q = scope.search(params[:q]) @@ -60,33 +63,6 @@ class ImportsController < BreadcrumbController private - def ransack_started_at_params - start_date = [] - end_date = [] - - if params[:q] && params[:q][:started_at] && !params[:q][:started_at].has_value?(nil) && !params[:q][:started_at].has_value?("") - [1, 2, 3].each do |key| - start_date << params[:q][:started_at]["begin(#{key}i)"].to_i - end_date << params[:q][:started_at]["end(#{key}i)"].to_i - end - params[:q].delete([:started_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_started_at_between(@begin_range, @end_range) - end - scope - end - def ransack_status_params if params[:q] return params[:q].delete(:status_eq_any) if params[:q][:status_eq_any].empty? || ( (Import.status.values & params[:q][:status_eq_any]).length >= 4 ) diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb index 0054963c9..2d24d5aa6 100644 --- a/app/controllers/time_tables_controller.rb +++ b/app/controllers/time_tables_controller.rb @@ -1,5 +1,7 @@ class TimeTablesController < ChouetteController include TimeTablesHelper + include RansackDateFilter + before_action only: [:index] { set_date_time_params("bounding_dates", Date) } defaults :resource_class => Chouette::TimeTable respond_to :html respond_to :xml @@ -131,7 +133,7 @@ class TimeTablesController < ChouetteController params[:q].delete("tag_search") scope = select_time_tables.tagged_with(tags, :any => true) if tags.any? end - scope = ransack_periode(scope) + scope = self.ransack_period_range(scope: scope, error_message: t('referentials.errors.validity_period'), query: :overlapping) @q = scope.search(params[:q]) if sort_column && sort_direction @@ -159,28 +161,6 @@ class TimeTablesController < ChouetteController end private - def ransack_periode scope - return scope unless params[:q] - return scope unless params[:q]['end_date_lteq(1i)'].present? - - begin_range = flatten_date('start_date_gteq') - end_range = flatten_date('end_date_lteq') - - if begin_range > end_range - flash.now[:error] = t('referentials.errors.validity_period') - else - scope = scope.overlapping(begin_range, end_range) - params[:q] = params[:q].slice('comment_cont', 'color_cont_any') - @begin_range = begin_range - @end_range = end_range - end - scope - end - - def flatten_date key - date_int = %w(1 2 3).map {|e| params[:q]["#{key}(#{e}i)"].to_i } - Date.new(*date_int) - end def sort_column referential.time_tables.column_names.include?(params[:sort]) ? params[:sort] : 'comment' diff --git a/app/controllers/workbenches_controller.rb b/app/controllers/workbenches_controller.rb index 54ddb8be1..e271007d6 100644 --- a/app/controllers/workbenches_controller.rb +++ b/app/controllers/workbenches_controller.rb @@ -1,20 +1,18 @@ class WorkbenchesController < BreadcrumbController before_action :query_params, only: [:show] - + include RansackDateFilter + before_action only: [:show] { set_date_time_params("validity_period", Date) } defaults resource_class: Workbench respond_to :html, only: [:show, :index] def index - # Only display Wb with selected name, according to #4108 - @workbench = current_organisation.workbenches.find_by(name: "Gestion de l'offre") - @referentials = @workbench.all_referentials - @calendars = Calendar.where('organisation_id = ? OR shared = ?', current_organisation.id, true) + redirect_to dashboard_path end def show scope = resource.all_referentials scope = ransack_associated_lines(scope) - scope = ransack_period(scope) + scope = self.ransack_period_range(scope: scope, error_message: t('referentials.errors.validity_period'), query: :in_periode) scope = ransack_status(scope) @q_for_form = scope.ransack(params[:q]) @@ -72,33 +70,6 @@ class WorkbenchesController < BreadcrumbController end # Fake ransack filter - def ransack_period scope - period = params[:q]['validity_period'] - return scope unless period - - begin - if period['begin_gteq'].kind_of?(Array) - begin_range = Date.new(*period['begin_gteq'].map(&:to_i)) - end_range = Date.new(*period['end_lteq'].map(&:to_i)) - else - begin_range = Date.new(period["begin_gteq(1i)"].to_i, period["begin_gteq(2i)"].to_i, period["begin_gteq(3i)"].to_i) - end_range = Date.new(period["end_lteq(1i)"].to_i, period["end_lteq(2i)"].to_i, period["end_lteq(3i)"].to_i) - end - rescue Exception => e - return scope - end - - if begin_range > end_range - flash.now[:error] = t('referentials.errors.validity_period') - else - scope = scope.in_periode(begin_range..end_range) - @begin_range = begin_range - @end_range = end_range - end - scope - end - - # Fake ransack filter def ransack_status scope archived = !params[:q]['archived_at_not_null'].to_i.zero? unarchived = !params[:q]['archived_at_null'].to_i.zero? |
