diff options
| author | Guillaume | 2017-09-26 11:56:33 +0200 | 
|---|---|---|
| committer | Guillaume | 2017-09-26 11:56:33 +0200 | 
| commit | 00aad1349ae72d80d034f84c3b4ec360e1033511 (patch) | |
| tree | 3244df100f903966528560d05a329cc7b2143c28 /app/controllers | |
| parent | 733548a996d5e66c740f59d313eb031ddfcc9116 (diff) | |
| download | chouette-core-00aad1349ae72d80d034f84c3b4ec360e1033511.tar.bz2 | |
add date filter to compliance_control_sets Refs #4466
Diffstat (limited to 'app/controllers')
| -rw-r--r-- | app/controllers/compliance_control_sets_controller.rb | 31 | 
1 files changed, 30 insertions, 1 deletions
diff --git a/app/controllers/compliance_control_sets_controller.rb b/app/controllers/compliance_control_sets_controller.rb index c6f4288a9..20ddcbe97 100644 --- a/app/controllers/compliance_control_sets_controller.rb +++ b/app/controllers/compliance_control_sets_controller.rb @@ -1,10 +1,12 @@  class ComplianceControlSetsController < BreadcrumbController    defaults resource_class: ComplianceControlSet +  before_action :ransack_updated_at_params, only: [:index]    respond_to :html    def index      index! do |format| -      @q_for_form = @compliance_control_sets.ransack(params[:q]) +      scope = ransack_period @compliance_control_sets +      @q_for_form = scope.ransack(params[:q])        format.html {          @compliance_control_sets = decorate_compliance_control_sets(@q_for_form.result)        } @@ -32,6 +34,33 @@ class ComplianceControlSetsController < BreadcrumbController    private +  def ransack_updated_at_params +    start_date = [] +    end_date = [] + +    if params[:q] && params[:q][:updated_at] && !params[:q][:updated_at].has_value?(nil) && !params[:q][:updated_at].has_value?("") +      [1, 2, 3].each do |key| +        start_date <<  params[:q][:updated_at]["begin(#{key}i)"].to_i +        end_date <<  params[:q][:updated_at]["end(#{key}i)"].to_i +      end +      params[:q].delete([:updated_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_updated_at_between(@begin_range, @end_range) +    end +    scope +  end +    def compliance_control_set_params      params.require(:compliance_control_set).permit(:name, :id)    end  | 
