aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorLuc Donnet2017-12-15 10:11:17 +0100
committerLuc Donnet2017-12-21 13:54:07 +0100
commit0cf1d52d1dfc83fe304c7f3b7f7e1114ade28c11 (patch)
tree07cc76b653c49c28d9a3aed19619d728f22fa560 /app
parent8af4523f211519035d47e003c0eee4291dd2459d (diff)
downloadchouette-core-0cf1d52d1dfc83fe304c7f3b7f7e1114ade28c11.tar.bz2
Fix migrations, locales, view and exclude calendar timetable in concern Refs #5301
Diffstat (limited to 'app')
-rw-r--r--app/controllers/business_calendars_controller.rb4
-rw-r--r--app/models/calendar.rb4
-rw-r--r--app/models/concerns/calendar_support.rb9
-rw-r--r--app/views/business_calendars/_date_value_fields.html.slim13
-rw-r--r--app/views/business_calendars/_form.html.slim20
-rw-r--r--app/views/business_calendars/_period_fields.html.slim15
6 files changed, 48 insertions, 17 deletions
diff --git a/app/controllers/business_calendars_controller.rb b/app/controllers/business_calendars_controller.rb
index ee990dfba..617a07855 100644
--- a/app/controllers/business_calendars_controller.rb
+++ b/app/controllers/business_calendars_controller.rb
@@ -21,7 +21,7 @@ class BusinessCalendarsController < ChouetteController
private
def business_calendar_params
- permitted_params = [:id, :name, :short_name, periods_attributes: [:id, :begin, :end, :_destroy], date_values_attributes: [:id, :value, :_destroy]]
+ permitted_params = [:id, :name, :short_name, :color, periods_attributes: [:id, :begin, :end, :_destroy], date_values_attributes: [:id, :value, :_destroy]]
params.require(:business_calendar).permit(*permitted_params)
end
@@ -30,4 +30,4 @@ class BusinessCalendarsController < ChouetteController
business_calendars,
with: BusinessCalendarDecorator)
end
-end \ No newline at end of file
+end
diff --git a/app/models/calendar.rb b/app/models/calendar.rb
index 4e8cd0977..5df2bb1da 100644
--- a/app/models/calendar.rb
+++ b/app/models/calendar.rb
@@ -4,7 +4,9 @@ require_relative 'calendar/period'
class Calendar < ActiveRecord::Base
include CalendarSupport
-
+
+ has_many :time_tables
+
scope :contains_date, ->(date) { where('date ? = any (dates) OR date ? <@ any (date_ranges)', date, date) }
def self.ransackable_scopes(auth_object = nil)
diff --git a/app/models/concerns/calendar_support.rb b/app/models/concerns/calendar_support.rb
index 9d27f4c0d..73bb201ec 100644
--- a/app/models/concerns/calendar_support.rb
+++ b/app/models/concerns/calendar_support.rb
@@ -1,16 +1,15 @@
module CalendarSupport
extend ActiveSupport::Concern
-
+
included do
has_paper_trail
belongs_to :organisation
- has_many :time_tables
validates_presence_of :name, :short_name, :organisation
validates_uniqueness_of :short_name
after_initialize :init_dates_and_date_ranges
-
-
+
+
def init_dates_and_date_ranges
self.dates ||= []
self.date_ranges ||= []
@@ -154,4 +153,4 @@ module CalendarSupport
private :clear_date_values
end
-end \ No newline at end of file
+end
diff --git a/app/views/business_calendars/_date_value_fields.html.slim b/app/views/business_calendars/_date_value_fields.html.slim
new file mode 100644
index 000000000..7bde06a94
--- /dev/null
+++ b/app/views/business_calendars/_date_value_fields.html.slim
@@ -0,0 +1,13 @@
+.nested-fields
+ - if f.object.errors.has_key? :base
+ .row
+ .col-lg-12
+ .alert.alert-danger
+ - f.object.errors[:base].each do |message|
+ p.small = message
+
+ .wrapper
+ div
+ = f.input :value, as: :date, label: false, wrapper_html: { class: 'date smart_date' }
+ div
+ = link_to_remove_association '', f, class: 'fa fa-trash', data: { confirm: 'Etes-vous sûr(e) ?' }, title: t('actions.delete')
diff --git a/app/views/business_calendars/_form.html.slim b/app/views/business_calendars/_form.html.slim
index c2c9fb3a1..a7c0d8c4a 100644
--- a/app/views/business_calendars/_form.html.slim
+++ b/app/views/business_calendars/_form.html.slim
@@ -2,9 +2,11 @@
.row
.col-lg-12
= f.input :name
+ = f.input :short_name
+ = f.input :color
.separator
-
+
.row
.col-lg-12
.subform
@@ -13,17 +15,17 @@
div
.form-group
label.control-label
- = BusinessCalendar.human_attribute_name(:date)
+ = Calendar.human_attribute_name(:date)
div
= f.simple_fields_for :date_values do |date_value|
- = render 'calendars/date_fields', f: date_value
+ = render 'date_value_fields', f: date_value
.links.nested-linker
- = link_to_add_association t('simple_form.labels.calendar.add_a_date'), f, :dates, class: 'btn btn-outline-primary'
-
+ = link_to_add_association t('simple_form.labels.business_calendar.add_a_date'), f, :date_values, class: 'btn btn-outline-primary'
+
.separator
-
+
.row
.col-lg-12
.subform
@@ -32,16 +34,16 @@
div
.form-group
label.control-label
- = t('simple_form.labels.calendar.ranges.begin')
+ = t('simple_form.labels.business_calendar.ranges.begin')
div
.form-group
label.control-label
- = t('simple_form.labels.calendar.ranges.end')
+ = t('simple_form.labels.business_calendar.ranges.end')
div
= f.simple_fields_for :periods do |period|
= render 'period_fields', f: period
.links.nested-linker
- = link_to_add_association t('simple_form.labels.calendar.add_a_date_range'), f, :periods, class: 'btn btn-outline-primary'
+ = link_to_add_association t('simple_form.labels.business_calendar.add_a_date_range'), f, :periods, class: 'btn btn-outline-primary'
= f.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'business_calendar_form'
diff --git a/app/views/business_calendars/_period_fields.html.slim b/app/views/business_calendars/_period_fields.html.slim
new file mode 100644
index 000000000..95e204554
--- /dev/null
+++ b/app/views/business_calendars/_period_fields.html.slim
@@ -0,0 +1,15 @@
+.nested-fields
+ - if f.object.errors.has_key? :base
+ .row
+ .col-lg-12
+ .alert.alert-danger
+ - f.object.errors[:base].each do |message|
+ p.small = message
+
+ .wrapper
+ div
+ = f.input :begin, as: :date, label: false, wrapper_html: { class: 'date smart_date' }
+ div
+ = f.input :end, as: :date, label: false, wrapper_html: { class: 'date smart_date' }
+ div
+ = link_to_remove_association '', f, class: 'fa fa-trash', data: { confirm: 'Etes-vous sûr(e) ?' }, title: t('actions.delete')