aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/calendars_controller.rb3
-rw-r--r--app/models/calendar.rb9
-rw-r--r--app/views/calendars/_form.html.slim4
-rw-r--r--app/views/calendars/index.html.slim2
4 files changed, 13 insertions, 5 deletions
diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb
index 563c126e4..afa4c129c 100644
--- a/app/controllers/calendars_controller.rb
+++ b/app/controllers/calendars_controller.rb
@@ -4,7 +4,7 @@ class CalendarsController < BreadcrumbController
private
def calendar_params
- params.require(:calendar).permit(:id, :name, :short_name, :shared, ranges_attributes: [:id, :begin, :end, :_destroy], dates: [])
+ params.require(:calendar).permit(:id, :name, :short_name, :shared, periods_attributes: [:id, :begin, :end, :_destroy], dates: [])
end
def sort_column
@@ -35,6 +35,7 @@ class CalendarsController < BreadcrumbController
@q = current_organisation.calendars.search(params[:q])
calendars = @q.result(distinct: true)
+ ap "FILTERED COLLECTION LENGTH : #{@q.result.length}"
calendars = calendars.order(sort_column + ' ' + sort_direction) if sort_column && sort_direction
@calendars = calendars.paginate(page: params[:page])
end
diff --git a/app/models/calendar.rb b/app/models/calendar.rb
index fc339caad..b1fac536c 100644
--- a/app/models/calendar.rb
+++ b/app/models/calendar.rb
@@ -7,6 +7,8 @@ class Calendar < ActiveRecord::Base
after_initialize :init_dates_and_date_ranges
+ scope :contains_date, ->(date) { where('date ? = any (dates) OR date ? <@ any (date_ranges)', date, date) }
+
def init_dates_and_date_ranges
self.dates ||= []
self.date_ranges ||= []
@@ -31,6 +33,10 @@ class Calendar < ActiveRecord::Base
errors.add(:dates, I18n.t('activerecord.errors.models.calendar.attributes.dates.date_in_dates')) if dates && dates.length > dates.uniq.length
end
+ def self.ransackable_scopes(auth_object = nil)
+ [:contains_date]
+ end
+
class Period
include ActiveAttr::Model
@@ -78,11 +84,11 @@ class Calendar < ActiveRecord::Base
def new_record?
!persisted?
end
+
def persisted?
id.present?
end
-
def mark_for_destruction
self._destroy = true
end
@@ -153,6 +159,7 @@ class Calendar < ActiveRecord::Base
def clear_periods
@periods = nil
end
+
private :clear_periods
def self.new_from from
diff --git a/app/views/calendars/_form.html.slim b/app/views/calendars/_form.html.slim
index ea2e0b30b..2d36d7d9e 100644
--- a/app/views/calendars/_form.html.slim
+++ b/app/views/calendars/_form.html.slim
@@ -9,8 +9,8 @@
/ = render 'date_fields', f: date
/ .links
/ = link_to_add_association '+', f, :dates
- /= f.label :date_ranges
- /= f.simple_fields_for :periods do |period|
+ = f.label :date_ranges
+ = f.simple_fields_for :periods do |period|
= render 'period_fields', f: period
.links
/= link_to_add_association '+', f, :periods
diff --git a/app/views/calendars/index.html.slim b/app/views/calendars/index.html.slim
index 57f30eaef..a857078a1 100644
--- a/app/views/calendars/index.html.slim
+++ b/app/views/calendars/index.html.slim
@@ -13,7 +13,7 @@
= f.select :shared_eq, [[t('.shared'), true], [t('.not_shared'), false]], { include_blank: '' }, { class: 'form-control', style: 'width: 100%', 'data-select2ed': 'true', 'data-select2ed-placeholder': t('.all') }
.col-md-3
= f.label t('.date')
- = f.date_field :dates_or_date_ranges_cont, class: 'form-control'
+ = f.date_field :contains_date, class: 'form-control'
.col-md-3
button.btn.btn-primary#search-btn type='submit'