diff options
| author | jpl | 2017-05-02 13:04:54 +0200 |
|---|---|---|
| committer | Robert | 2017-05-02 16:44:25 +0200 |
| commit | e9a07b3d9208e4adba0947fd46c931472244ea9e (patch) | |
| tree | 580e5781e6cf89c5f0428c638fe42317df965f9d /app | |
| parent | fbb0d5ce53dc1aeedd3b599b59353eb65502e020 (diff) | |
| download | chouette-core-e9a07b3d9208e4adba0947fd46c931472244ea9e.tar.bz2 | |
RefsĀ #3264: change shared boolean filter by select (to permit join)
Diffstat (limited to 'app')
| -rw-r--r-- | app/assets/stylesheets/components/_forms.sass | 2 | ||||
| -rw-r--r-- | app/controllers/calendars_controller.rb | 19 | ||||
| -rw-r--r-- | app/views/calendars/_filters.html.slim | 9 | ||||
| -rw-r--r-- | app/views/calendars/index.html.slim | 2 |
4 files changed, 25 insertions, 7 deletions
diff --git a/app/assets/stylesheets/components/_forms.sass b/app/assets/stylesheets/components/_forms.sass index c24b7abda..46f40291a 100644 --- a/app/assets/stylesheets/components/_forms.sass +++ b/app/assets/stylesheets/components/_forms.sass @@ -159,7 +159,7 @@ input top: 0 bottom: 0 right: 60% - z-index: 2 + z-index: 5 width: auto > .btn diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index c33aa9373..d18e165d2 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -33,8 +33,12 @@ class CalendarsController < BreadcrumbController def collection return @calendars if @calendars + scope = Calendar.where('organisation_id = ?', current_organisation.id) + + scope = shared_scope(scope) + + @q = scope.ransack(params[:q]) - @q = Calendar.where('organisation_id = ? OR shared = true', current_organisation.id).search(params[:q]) calendars = @q.result calendars = calendars.order(sort_column + ' ' + sort_direction) if sort_column && sort_direction @calendars = calendars.paginate(page: params[:page]) @@ -51,5 +55,16 @@ class CalendarsController < BreadcrumbController params[:q]['contains_date'] = Date.parse(date.join('-')) end end -end + def shared_scope scope + return scope unless params[:q] + + if params[:q][:shared_true] == params[:q][:shared_false] + params[:q].delete(:shared_true) + params[:q].delete(:shared_false) + end + + scope + end + +end diff --git a/app/views/calendars/_filters.html.slim b/app/views/calendars/_filters.html.slim index d8707ba0f..4f625e4f0 100644 --- a/app/views/calendars/_filters.html.slim +++ b/app/views/calendars/_filters.html.slim @@ -7,13 +7,16 @@ span.fa.fa-search .ffg-row - .form-group.has_switch style='width: 260px' - = f.label Calendar.human_attribute_name(:shared), class: 'col-sm-4 control-label' - = f.input :shared_true, as: :boolean, checked_value: true, unchecked_value: false, label: content_tag(:span, '', class: 'switch-label', data: {checkedValue: t('true'), uncheckedValue: t('false')}), wrapper_html: { class: 'col-sm-8' } + .form-group.togglable + = f.label Calendar.human_attribute_name(:shared), required: false, class: 'control-label' + .form-group.checkbox_list + = f.input :shared_true, as: :boolean, label: ("<span>Oui</span>").html_safe, wrapper_html: { class: 'checkbox-wrapper' } + = f.input :shared_false, as: :boolean, label: ("<span>Non</span>").html_safe, wrapper_html: { class: 'checkbox-wrapper' } .form-group = f.label Calendar.human_attribute_name(:date), class: 'control-label' = f.input :contains_date, as: :date, label: false, wrapper_html: { class: 'date' }, class: 'form-control', include_blank: true + .actions = link_to 'Effacer', calendars_path, class: 'btn btn-link' = f.submit 'Filtrer', id: 'filter_btn', class: 'btn btn-default' diff --git a/app/views/calendars/index.html.slim b/app/views/calendars/index.html.slim index 864d1e197..fbb9f889d 100644 --- a/app/views/calendars/index.html.slim +++ b/app/views/calendars/index.html.slim @@ -21,7 +21,7 @@ .row .col-lg-12 = table_builder @calendars, - { :name => 'name', :short_name => 'short_name', :shared => 'shared' }, + { :name => 'name', :short_name => 'short_name', :shared => Proc.new{|c| t("#{c.try(:shared)}") } }, [:show, :edit, :delete], [], 'table has-filter' |
