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/controllers | |
| parent | 2fa5b41379f33b399121dca1149dd7b20cf6d00d (diff) | |
| download | chouette-core-82f611cd417d7e3a98f4fa7d21e2f94e6bc9a011.tar.bz2 | |
add compliance_check_sets structure Refs #3564
Diffstat (limited to 'app/controllers')
| -rw-r--r-- | app/controllers/compliance_check_sets_controller.rb | 54 | 
1 files changed, 54 insertions, 0 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  | 
