rails_event 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +20 -0
- data/README.md +36 -0
- data/Rakefile +32 -0
- data/app/controllers/eventual/admin/base_controller.rb +4 -0
- data/app/controllers/eventual/admin/bookings_controller.rb +43 -0
- data/app/controllers/eventual/admin/crowd_members_controller.rb +43 -0
- data/app/controllers/eventual/admin/crowds_controller.rb +58 -0
- data/app/controllers/eventual/admin/event_crowds_controller.rb +71 -0
- data/app/controllers/eventual/admin/event_items_controller.rb +58 -0
- data/app/controllers/eventual/admin/event_participants_controller.rb +101 -0
- data/app/controllers/eventual/admin/event_taxons_controller.rb +55 -0
- data/app/controllers/eventual/admin/events_controller.rb +91 -0
- data/app/controllers/eventual/admin/place_taxons_controller.rb +57 -0
- data/app/controllers/eventual/admin/places_controller.rb +59 -0
- data/app/controllers/eventual/admin/plan_attenders_controller.rb +65 -0
- data/app/controllers/eventual/admin/plan_items_controller.rb +84 -0
- data/app/controllers/eventual/admin/plans_controller.rb +127 -0
- data/app/controllers/eventual/admin/seats_controller.rb +58 -0
- data/app/controllers/eventual/admin/time_items_controller.rb +82 -0
- data/app/controllers/eventual/admin/time_lists_controller.rb +72 -0
- data/app/controllers/eventual/base_controller.rb +4 -0
- data/app/controllers/eventual/me/base_controller.rb +4 -0
- data/app/controllers/eventual/me/plan_items_controller.rb +58 -0
- data/app/controllers/eventual/my/base_controller.rb +4 -0
- data/app/controllers/eventual/my/plan_items_controller.rb +55 -0
- data/app/controllers/eventual/places_controller.rb +27 -0
- data/app/controllers/eventual/time_controller.rb +14 -0
- data/app/models/eventual/application_record.rb +5 -0
- data/app/models/eventual/booking.rb +5 -0
- data/app/models/eventual/crowd.rb +5 -0
- data/app/models/eventual/crowd_member.rb +5 -0
- data/app/models/eventual/event.rb +6 -0
- data/app/models/eventual/event_crowd.rb +5 -0
- data/app/models/eventual/event_grant.rb +5 -0
- data/app/models/eventual/event_item.rb +5 -0
- data/app/models/eventual/event_participant.rb +6 -0
- data/app/models/eventual/event_taxon.rb +5 -0
- data/app/models/eventual/ext/recurrence.rb +86 -0
- data/app/models/eventual/model/agency.rb +18 -0
- data/app/models/eventual/model/booked.rb +10 -0
- data/app/models/eventual/model/booker.rb +15 -0
- data/app/models/eventual/model/booking.rb +37 -0
- data/app/models/eventual/model/crowd.rb +21 -0
- data/app/models/eventual/model/crowd_member.rb +20 -0
- data/app/models/eventual/model/event.rb +48 -0
- data/app/models/eventual/model/event_crowd.rb +54 -0
- data/app/models/eventual/model/event_grant.rb +14 -0
- data/app/models/eventual/model/event_item.rb +30 -0
- data/app/models/eventual/model/event_participant.rb +63 -0
- data/app/models/eventual/model/event_taxon.rb +13 -0
- data/app/models/eventual/model/member.rb +18 -0
- data/app/models/eventual/model/occurrence.rb +62 -0
- data/app/models/eventual/model/place.rb +25 -0
- data/app/models/eventual/model/place_taxon.rb +18 -0
- data/app/models/eventual/model/plan.rb +147 -0
- data/app/models/eventual/model/plan_attender.rb +31 -0
- data/app/models/eventual/model/plan_item.rb +84 -0
- data/app/models/eventual/model/plan_participant/crowd_participant.rb +17 -0
- data/app/models/eventual/model/plan_participant/normal_participant.rb +9 -0
- data/app/models/eventual/model/plan_participant.rb +30 -0
- data/app/models/eventual/model/planned.rb +11 -0
- data/app/models/eventual/model/planning.rb +44 -0
- data/app/models/eventual/model/recurrence.rb +64 -0
- data/app/models/eventual/model/seat.rb +17 -0
- data/app/models/eventual/model/time_item.rb +46 -0
- data/app/models/eventual/model/time_list.rb +57 -0
- data/app/models/eventual/place.rb +5 -0
- data/app/models/eventual/place_taxon.rb +6 -0
- data/app/models/eventual/plan.rb +7 -0
- data/app/models/eventual/plan_attender.rb +5 -0
- data/app/models/eventual/plan_item.rb +6 -0
- data/app/models/eventual/plan_participant.rb +5 -0
- data/app/models/eventual/seat.rb +5 -0
- data/app/models/eventual/time_item.rb +5 -0
- data/app/models/eventual/time_list.rb +5 -0
- data/app/models/eventual.rb +11 -0
- data/app/models/plan_participant/eventual/crowd_participant.rb +5 -0
- data/app/models/plan_participant/eventual/normal_participant.rb +5 -0
- data/app/views/admin/_event_nav.html.erb +14 -0
- data/app/views/admin/_nav_event.html.erb +9 -0
- data/app/views/eventual/admin/base/_nav.html.erb +3 -0
- data/app/views/eventual/admin/bookings/_booking.json.jbuilder +12 -0
- data/app/views/eventual/admin/bookings/_filter.html.erb +6 -0
- data/app/views/eventual/admin/bookings/_form.html.erb +8 -0
- data/app/views/eventual/admin/bookings/_show.json.jbuilder +1 -0
- data/app/views/eventual/admin/bookings/_show_table.html.erb +28 -0
- data/app/views/eventual/admin/bookings/index.html.erb +43 -0
- data/app/views/eventual/admin/bookings/index.json.jbuilder +1 -0
- data/app/views/eventual/admin/crowd_members/_filter_form.html.erb +7 -0
- data/app/views/eventual/admin/crowd_members/_form.html.erb +4 -0
- data/app/views/eventual/admin/crowd_members/index.html.erb +34 -0
- data/app/views/eventual/admin/crowds/_crowd.json.jbuilder +8 -0
- data/app/views/eventual/admin/crowds/_edit_form.html.erb +4 -0
- data/app/views/eventual/admin/crowds/_filter_form.html.erb +10 -0
- data/app/views/eventual/admin/crowds/_form.html.erb +4 -0
- data/app/views/eventual/admin/crowds/_index_tbody.html.erb +5 -0
- data/app/views/eventual/admin/crowds/_index_thead.html.erb +3 -0
- data/app/views/eventual/admin/crowds/_new_form.html.erb +4 -0
- data/app/views/eventual/admin/crowds/_show.json.jbuilder +1 -0
- data/app/views/eventual/admin/crowds/_show_table.html.erb +20 -0
- data/app/views/eventual/admin/crowds/index.html.erb +5 -0
- data/app/views/eventual/admin/crowds/index.json.jbuilder +1 -0
- data/app/views/eventual/admin/event_crowds/_breadcrumb.html.erb +7 -0
- data/app/views/eventual/admin/event_crowds/_crowd_student.html.erb +18 -0
- data/app/views/eventual/admin/event_crowds/_edit_form.html.erb +15 -0
- data/app/views/eventual/admin/event_crowds/_index_tbody.html.erb +19 -0
- data/app/views/eventual/admin/event_crowds/_index_thead.html.erb +10 -0
- data/app/views/eventual/admin/event_crowds/_new_form.html.erb +6 -0
- data/app/views/eventual/admin/event_crowds/_show_table.html.erb +12 -0
- data/app/views/eventual/admin/event_crowds/index.html.erb +2 -0
- data/app/views/eventual/admin/event_items/_breadcrumb.html.erb +7 -0
- data/app/views/eventual/admin/event_items/_edit_form.html.erb +4 -0
- data/app/views/eventual/admin/event_items/_event_item.json.jbuilder +12 -0
- data/app/views/eventual/admin/event_items/_filter_form.html.erb +9 -0
- data/app/views/eventual/admin/event_items/_form.html.erb +12 -0
- data/app/views/eventual/admin/event_items/_index_tbody.html.erb +8 -0
- data/app/views/eventual/admin/event_items/_index_thead.html.erb +5 -0
- data/app/views/eventual/admin/event_items/_new_form.html.erb +4 -0
- data/app/views/eventual/admin/event_items/_show.json.jbuilder +1 -0
- data/app/views/eventual/admin/event_items/_show_table.html.erb +12 -0
- data/app/views/eventual/admin/event_items/index.html.erb +1 -0
- data/app/views/eventual/admin/event_items/index.json.jbuilder +1 -0
- data/app/views/eventual/admin/event_participants/_breadcrumb.html.erb +7 -0
- data/app/views/eventual/admin/event_participants/_button.html.erb +3 -0
- data/app/views/eventual/admin/event_participants/_filter_form.html.erb +9 -0
- data/app/views/eventual/admin/event_participants/_filter_table.html.erb +11 -0
- data/app/views/eventual/admin/event_participants/_form.html.erb +4 -0
- data/app/views/eventual/admin/event_participants/_index_tbody.html.erb +15 -0
- data/app/views/eventual/admin/event_participants/_index_thead.html.erb +5 -0
- data/app/views/eventual/admin/event_participants/index.html.erb +1 -0
- data/app/views/eventual/admin/event_taxons/_breadcrumb.html.erb +6 -0
- data/app/views/eventual/admin/event_taxons/_edit_form.html.erb +4 -0
- data/app/views/eventual/admin/event_taxons/_event_taxon.json.jbuilder +5 -0
- data/app/views/eventual/admin/event_taxons/_filter_form.html.erb +10 -0
- data/app/views/eventual/admin/event_taxons/_form.html.erb +2 -0
- data/app/views/eventual/admin/event_taxons/_index_tbody.html.erb +1 -0
- data/app/views/eventual/admin/event_taxons/_index_thead.html.erb +2 -0
- data/app/views/eventual/admin/event_taxons/_new_form.html.erb +4 -0
- data/app/views/eventual/admin/event_taxons/_show.json.jbuilder +1 -0
- data/app/views/eventual/admin/event_taxons/index.html.erb +5 -0
- data/app/views/eventual/admin/event_taxons/index.json.jbuilder +1 -0
- data/app/views/eventual/admin/events/_edit_form.html.erb +4 -0
- data/app/views/eventual/admin/events/_event.json.jbuilder +17 -0
- data/app/views/eventual/admin/events/_filter_form.html.erb +9 -0
- data/app/views/eventual/admin/events/_filter_table.html.erb +15 -0
- data/app/views/eventual/admin/events/_form.html.erb +11 -0
- data/app/views/eventual/admin/events/_index_tbody.html.erb +11 -0
- data/app/views/eventual/admin/events/_index_thead.html.erb +10 -0
- data/app/views/eventual/admin/events/_new_form.html.erb +4 -0
- data/app/views/eventual/admin/events/_show/_breadcrumb.html.erb +7 -0
- data/app/views/eventual/admin/events/_show.json.jbuilder +1 -0
- data/app/views/eventual/admin/events/create.json.jbuilder +1 -0
- data/app/views/eventual/admin/events/index.html.erb +5 -0
- data/app/views/eventual/admin/events/index.json.jbuilder +1 -0
- data/app/views/eventual/admin/events/repeat_form.js.erb +14 -0
- data/app/views/eventual/admin/events/show.html.erb +16 -0
- data/app/views/eventual/admin/place_taxons/_breadcrumb.html.erb +6 -0
- data/app/views/eventual/admin/place_taxons/_edit_form.html.erb +4 -0
- data/app/views/eventual/admin/place_taxons/_filter_form.html.erb +9 -0
- data/app/views/eventual/admin/place_taxons/_form.html.erb +6 -0
- data/app/views/eventual/admin/place_taxons/_index_tbody.html.erb +17 -0
- data/app/views/eventual/admin/place_taxons/_index_thead.html.erb +4 -0
- data/app/views/eventual/admin/place_taxons/_new_form.html.erb +4 -0
- data/app/views/eventual/admin/place_taxons/_show_table.html.erb +12 -0
- data/app/views/eventual/admin/place_taxons/index.html.erb +5 -0
- data/app/views/eventual/admin/places/_breadcrumb.html.erb +5 -0
- data/app/views/eventual/admin/places/_edit_form.html.erb +4 -0
- data/app/views/eventual/admin/places/_filter_form.html.erb +10 -0
- data/app/views/eventual/admin/places/_form.html.erb +4 -0
- data/app/views/eventual/admin/places/_index_tbody.html.erb +6 -0
- data/app/views/eventual/admin/places/_index_thead.html.erb +10 -0
- data/app/views/eventual/admin/places/_index_tr.html.erb +19 -0
- data/app/views/eventual/admin/places/_new_form.html.erb +4 -0
- data/app/views/eventual/admin/places/_place.json.jbuilder +6 -0
- data/app/views/eventual/admin/places/_show.json.jbuilder +1 -0
- data/app/views/eventual/admin/places/_show_table.html.erb +8 -0
- data/app/views/eventual/admin/places/index.html.erb +5 -0
- data/app/views/eventual/admin/places/index.json.jbuilder +1 -0
- data/app/views/eventual/admin/plan_attenders/_breadcrumb.html.erb +9 -0
- data/app/views/eventual/admin/plan_attenders/_course_student.json.jbuilder +11 -0
- data/app/views/eventual/admin/plan_attenders/_edit_form.html.erb +4 -0
- data/app/views/eventual/admin/plan_attenders/_filter.html.erb +6 -0
- data/app/views/eventual/admin/plan_attenders/_form.html.erb +5 -0
- data/app/views/eventual/admin/plan_attenders/_new_form.html.erb +4 -0
- data/app/views/eventual/admin/plan_attenders/_plan_attender.json.jbuilder +9 -0
- data/app/views/eventual/admin/plan_attenders/_show.json.jbuilder +1 -0
- data/app/views/eventual/admin/plan_attenders/_show_table.html.erb +16 -0
- data/app/views/eventual/admin/plan_attenders/absent.json.jbuilder +0 -0
- data/app/views/eventual/admin/plan_attenders/attend.json.jbuilder +0 -0
- data/app/views/eventual/admin/plan_attenders/index.html.erb +51 -0
- data/app/views/eventual/admin/plan_attenders/index.json.jbuilder +2 -0
- data/app/views/eventual/admin/plan_attenders/indexs.json.jbuilder +6 -0
- data/app/views/eventual/admin/plan_items/_breadcrumb.html.erb +8 -0
- data/app/views/eventual/admin/plan_items/_edit.html.erb +23 -0
- data/app/views/eventual/admin/plan_items/_filter.html.erb +11 -0
- data/app/views/eventual/admin/plan_items/_menu.html.erb +4 -0
- data/app/views/eventual/admin/plan_items/_plan.html.erb +6 -0
- data/app/views/eventual/admin/plan_items/_plan_item.json.jbuilder +12 -0
- data/app/views/eventual/admin/plan_items/_plan_items.json.jbuilder +13 -0
- data/app/views/eventual/admin/plan_items/_show.json.jbuilder +1 -0
- data/app/views/eventual/admin/plan_items/_show_table.html.erb +20 -0
- data/app/views/eventual/admin/plan_items/index.html.erb +72 -0
- data/app/views/eventual/admin/plan_items/index.json.jbuilder +3 -0
- data/app/views/eventual/admin/plan_items/qrcode.js.erb +1 -0
- data/app/views/eventual/admin/plans/_edit_item.html.erb +24 -0
- data/app/views/eventual/admin/plans/_filter.html.erb +8 -0
- data/app/views/eventual/admin/plans/_index.html.erb +31 -0
- data/app/views/eventual/admin/plans/_plan.json.jbuilder +12 -0
- data/app/views/eventual/admin/plans/_select_table.html.erb +30 -0
- data/app/views/eventual/admin/plans/_show.json.jbuilder +1 -0
- data/app/views/eventual/admin/plans/_show_item.html.erb +22 -0
- data/app/views/eventual/admin/plans/_show_table.html.erb +20 -0
- data/app/views/eventual/admin/plans/_table.html.erb +34 -0
- data/app/views/eventual/admin/plans/calendar.js.erb +12 -0
- data/app/views/eventual/admin/plans/index.html.erb +3 -0
- data/app/views/eventual/admin/plans/index.js.erb +42 -0
- data/app/views/eventual/admin/plans/index.json.jbuilder +1 -0
- data/app/views/eventual/admin/plans/show.html.erb +3 -0
- data/app/views/eventual/admin/seats/_breadcrumb.html.erb +0 -0
- data/app/views/eventual/admin/seats/_edit_form.html.erb +4 -0
- data/app/views/eventual/admin/seats/_filter_form.html.erb +9 -0
- data/app/views/eventual/admin/seats/_form.html.erb +4 -0
- data/app/views/eventual/admin/seats/_index_tbody.html.erb +3 -0
- data/app/views/eventual/admin/seats/_index_thead.html.erb +4 -0
- data/app/views/eventual/admin/seats/_new_form.html.erb +4 -0
- data/app/views/eventual/admin/seats/_show_table.html.erb +12 -0
- data/app/views/eventual/admin/seats/index.html.erb +5 -0
- data/app/views/eventual/admin/time_items/_edit_form.html.erb +4 -0
- data/app/views/eventual/admin/time_items/_form.html.erb +3 -0
- data/app/views/eventual/admin/time_items/_new_form.html.erb +4 -0
- data/app/views/eventual/admin/time_items/_show.json.jbuilder +1 -0
- data/app/views/eventual/admin/time_items/_show_table.html.erb +12 -0
- data/app/views/eventual/admin/time_items/_time_item.json.jbuilder +3 -0
- data/app/views/eventual/admin/time_items/_time_items_options.html.erb +1 -0
- data/app/views/eventual/admin/time_items/default.json.jbuilder +1 -0
- data/app/views/eventual/admin/time_items/index.json.jbuilder +1 -0
- data/app/views/eventual/admin/time_items/select.js.erb +3 -0
- data/app/views/eventual/admin/time_lists/_edit_form.html.erb +4 -0
- data/app/views/eventual/admin/time_lists/_filter.html.erb +8 -0
- data/app/views/eventual/admin/time_lists/_form.html.erb +4 -0
- data/app/views/eventual/admin/time_lists/_index_tbody.html.erb +14 -0
- data/app/views/eventual/admin/time_lists/_index_thead.html.erb +8 -0
- data/app/views/eventual/admin/time_lists/_index_tr.html.erb +13 -0
- data/app/views/eventual/admin/time_lists/_new_form.html.erb +4 -0
- data/app/views/eventual/admin/time_lists/_show.json.jbuilder +1 -0
- data/app/views/eventual/admin/time_lists/_show_table.html.erb +8 -0
- data/app/views/eventual/admin/time_lists/_time_items.html.erb +27 -0
- data/app/views/eventual/admin/time_lists/_time_list.json.jbuilder +10 -0
- data/app/views/eventual/admin/time_lists/index.html.erb +5 -0
- data/app/views/eventual/admin/time_lists/index.json.jbuilder +1 -0
- data/app/views/eventual/me/plan_items/_plan_item.json.jbuilder +14 -0
- data/app/views/eventual/me/plan_items/index.json.jbuilder +3 -0
- data/app/views/eventual/my/plans/_show_table.html.erb +32 -0
- data/app/views/eventual/my/plans/_table.html.erb +34 -0
- data/app/views/eventual/my/plans/_time_plan.json.jbuilder +8 -0
- data/app/views/eventual/my/plans/calendar.js.erb +12 -0
- data/app/views/eventual/my/plans/edit.html.erb +9 -0
- data/app/views/eventual/my/plans/edit.js.erb +3 -0
- data/app/views/eventual/my/plans/index-ready.js +11 -0
- data/app/views/eventual/my/plans/index.html.erb +26 -0
- data/app/views/eventual/my/plans/index.js +35 -0
- data/app/views/eventual/my/plans/index.json.jbuilder +1 -0
- data/app/views/eventual/my/plans/new.html.erb +9 -0
- data/app/views/eventual/my/plans/show.html.erb +7 -0
- data/app/views/eventual/my/plans/show.js.erb +12 -0
- data/app/views/eventual/my/plans/show.json.jbuilder +1 -0
- data/app/views/eventual/places/_filter_table.html.erb +11 -0
- data/app/views/eventual/places/index.html.erb +35 -0
- data/app/views/eventual/places/show.html.erb +0 -0
- data/app/views/eventual/time/_finish_at.html.erb +1 -0
- data/app/views/eventual/time/_finish_at_once.html.erb +1 -0
- data/app/views/eventual/time/_form.html.erb +15 -0
- data/app/views/eventual/time/_monthly_checkboxes.html.erb +1 -0
- data/app/views/eventual/time/_once_date.html.erb +1 -0
- data/app/views/eventual/time/_start_at.html.erb +1 -0
- data/app/views/eventual/time/_start_at_once.html.erb +1 -0
- data/app/views/eventual/time/_weekly_checkboxes.html.erb +1 -0
- data/app/views/eventual/time/index.css +5 -0
- data/app/views/eventual/time/repeat_form.js.erb +14 -0
- data/app/views/eventual/time/show.css +3 -0
- data/config/locales/en.enum.yml +8 -0
- data/config/locales/zh.attributes.yml +50 -0
- data/config/locales/zh.controller.yml +59 -0
- data/config/locales/zh.enum.yml +12 -0
- data/config/routes.rb +98 -0
- data/lib/rails_event/config.rb +13 -0
- data/lib/rails_event/engine.rb +29 -0
- data/lib/rails_event/version.rb +5 -0
- data/lib/rails_event.rb +4 -0
- metadata +346 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
module Eventual
|
2
|
+
module Model::Member
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
has_many :event_participants, as: :member, dependent: :destroy
|
7
|
+
has_many :events, through: :event_participants
|
8
|
+
|
9
|
+
has_many :crowd_members, as: :member, dependent: :destroy
|
10
|
+
has_many :crowds, through: :crowd_members
|
11
|
+
|
12
|
+
has_many :plan_members, as: :member, dependent: :destroy
|
13
|
+
has_many :plan_attenders, as: :attender, dependent: :destroy
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Eventual
|
2
|
+
module Model::Occurrence
|
3
|
+
|
4
|
+
def next_occurrence(now: Time.current)
|
5
|
+
ti = time_items.find { |i| i.start_at.to_s(:time) > now.to_s(:time) }
|
6
|
+
if ti
|
7
|
+
date = next_occurred_days(limit: 1).first
|
8
|
+
hour, min = ti.start_at.to_s(:time).split(':')
|
9
|
+
date.to_datetime.change(hour: hour.to_i, min: min.to_i)
|
10
|
+
else
|
11
|
+
date = next_occurred_days(limit: 2).last
|
12
|
+
t2 = time_items.first
|
13
|
+
hour, min = t2.start_at.to_s(:time).split(':')
|
14
|
+
date.to_datetime.change(hour: hour.to_i, min: min.to_i)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def next_occurred_days(now: Time.current, limit: 1)
|
19
|
+
days = self.repeat_days.keys
|
20
|
+
r = []
|
21
|
+
case self.repeat_type
|
22
|
+
when 'weekly'
|
23
|
+
first_days = days.select { |day| day.to_i >= now.days_to_week_start }
|
24
|
+
first_days.each do |day|
|
25
|
+
r << now.beginning_of_week.days_since(day.to_i)
|
26
|
+
limit -= 1
|
27
|
+
return r if limit.zero?
|
28
|
+
end
|
29
|
+
(1..).each do |week|
|
30
|
+
days.each do |day|
|
31
|
+
r << now.weeks_since(week).beginning_of_week.days_since(day.to_i)
|
32
|
+
limit -= 1
|
33
|
+
return r if limit.zero?
|
34
|
+
end
|
35
|
+
end
|
36
|
+
when 'monthly'
|
37
|
+
first_days = days.select { |day| day.to_i >= now.day }
|
38
|
+
first_days.each do |day|
|
39
|
+
r << now.beginning_of_month.days_since(day.to_i)
|
40
|
+
limit -= 1
|
41
|
+
return r if limit.zero?
|
42
|
+
end
|
43
|
+
(1..).each do |month|
|
44
|
+
days.each do |day|
|
45
|
+
r << now.weeks_since(month).beginning_of_month.days_since(day.to_i)
|
46
|
+
limit -= 1
|
47
|
+
return r if limit.zero?
|
48
|
+
end
|
49
|
+
end
|
50
|
+
when 'once'
|
51
|
+
first_days = days.select { |day| day.to_date >= now.to_date }
|
52
|
+
first_days.each do |date|
|
53
|
+
r << date
|
54
|
+
limit -= 1
|
55
|
+
return r if limit.zero?
|
56
|
+
end
|
57
|
+
end
|
58
|
+
r
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Eventual
|
2
|
+
module Model::Place
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
attribute :name, :string
|
7
|
+
attribute :description, :string
|
8
|
+
attribute :color, :string
|
9
|
+
attribute :seats_count, :integer, default: 0
|
10
|
+
attribute :plans_count, :integer, default: 0
|
11
|
+
|
12
|
+
belongs_to :organ, optional: true
|
13
|
+
belongs_to :area, optional: true
|
14
|
+
belongs_to :place_taxon, counter_cache: true, optional: true
|
15
|
+
belongs_to :taxon, class_name: 'PlaceTaxon', optional: true, foreign_key: :place_taxon_id
|
16
|
+
has_many :plans
|
17
|
+
has_many :seats, dependent: :delete_all
|
18
|
+
|
19
|
+
validates :name, presence: true
|
20
|
+
|
21
|
+
has_taxons :place_taxon
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Eventual
|
2
|
+
module Model::PlaceTaxon
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
attribute :name, :string
|
7
|
+
attribute :position, :integer
|
8
|
+
attribute :profit_margin, :decimal, precision: 4, scale: 2
|
9
|
+
attribute :places_count, :integer
|
10
|
+
|
11
|
+
belongs_to :organ, optional: true
|
12
|
+
has_many :places, dependent: :nullify
|
13
|
+
|
14
|
+
acts_as_list
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
module Eventual
|
2
|
+
module Model::Plan
|
3
|
+
REPEAT = {
|
4
|
+
'once' => 0..6,
|
5
|
+
'weekly' => 0..6,
|
6
|
+
'monthly' => 0..30
|
7
|
+
}.freeze
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
attribute :title, :string
|
12
|
+
attribute :begin_on, :date, default: -> { Date.today }
|
13
|
+
attribute :end_on, :date
|
14
|
+
attribute :produced_begin_on, :date
|
15
|
+
attribute :produced_end_on, :date
|
16
|
+
attribute :produce_done, :boolean
|
17
|
+
attribute :repeat_type, :string, comment: '日、周、月、天'
|
18
|
+
attribute :repeat_count, :integer, comment: '每几周'
|
19
|
+
attribute :repeat_days, :json
|
20
|
+
|
21
|
+
belongs_to :planned, polymorphic: true
|
22
|
+
belongs_to :time_list
|
23
|
+
belongs_to :place, optional: true
|
24
|
+
|
25
|
+
has_many :time_items, through: :time_list
|
26
|
+
has_many :time_bookings, ->(o){ where(booked_type: o.plan_type) }, foreign_key: :booked_id, primary_key: :plan_id
|
27
|
+
has_many :plan_items, dependent: :destroy
|
28
|
+
|
29
|
+
default_scope -> { order(begin_on: :asc) }
|
30
|
+
|
31
|
+
validates :begin_on, presence: true
|
32
|
+
after_initialize if: :new_record? do
|
33
|
+
self.planned_type ||= 'Event'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def selected_ids(date, index)
|
38
|
+
case repeat_type
|
39
|
+
when 'yearly'
|
40
|
+
Array(self.repeat_days[date.to_s])
|
41
|
+
when 'monthly'
|
42
|
+
Array(self.repeat_days[index.to_s])
|
43
|
+
when 'weekly'
|
44
|
+
Array(self.repeat_days[index.to_s])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def same_scopes
|
49
|
+
self.class.where.not(id: self.id).default_where(planned_type: self.plan_type, planned_id: self.plan_id)
|
50
|
+
end
|
51
|
+
|
52
|
+
def toggle(index, time_item_id)
|
53
|
+
if repeat_type_changed? || time_list_id_changed?
|
54
|
+
self.repeat_days = {}
|
55
|
+
end
|
56
|
+
|
57
|
+
repeat_days.toggle! index => time_item_id
|
58
|
+
end
|
59
|
+
|
60
|
+
def diff_toggle(index, time_item_id)
|
61
|
+
if repeat_type_changed? || time_list_id_changed?
|
62
|
+
self.repeat_days = {}
|
63
|
+
end
|
64
|
+
|
65
|
+
repeat_days.diff_toggle index => time_item_id
|
66
|
+
end
|
67
|
+
|
68
|
+
def produce(start_on: Date.today.beginning_of_week, finish_on: Date.today.end_of_week)
|
69
|
+
removes, adds = self.present_days.diff_changes self.next_days(start: start_on, finish: finish_on)
|
70
|
+
|
71
|
+
self.class.transaction do
|
72
|
+
self.produced_begin_on = start_on
|
73
|
+
self.produced_end_on = finish_on
|
74
|
+
|
75
|
+
removes.each do |date, time_item_ids|
|
76
|
+
Array(time_item_ids).each do |time_item_id|
|
77
|
+
self.plan_items.where(plan_on: date, time_item_id: time_item_id).each(&:destroy!)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
adds.each do |date, time_item_ids|
|
82
|
+
Array(time_item_ids).each do |time_item_id|
|
83
|
+
pi = self.plan_items.find_or_initialize_by(plan_on: date, time_item_id: time_item_id)
|
84
|
+
pi.save!
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
self.save!
|
89
|
+
end
|
90
|
+
|
91
|
+
self
|
92
|
+
end
|
93
|
+
|
94
|
+
def present_days
|
95
|
+
self.plan_items.order(plan_on: :asc).group_by(&->(i){i.plan_on.to_s}).transform_values! do |v|
|
96
|
+
v.map(&:time_item_id)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
class_methods do
|
101
|
+
|
102
|
+
def recent(date = Date.today)
|
103
|
+
default_where('begin_on-lte': date).unscope(:order).order(begin_on: :desc).first
|
104
|
+
end
|
105
|
+
|
106
|
+
def xxx(start_on: Date.today.beginning_of_week, finish_on: Date.today.end_of_week, **filter_params)
|
107
|
+
# 时间范围与时间参数存在重叠
|
108
|
+
q = { 'end_on-gte': start_on, 'begin_on-lte': finish_on }.merge! filter_params
|
109
|
+
or_q = {
|
110
|
+
or: {
|
111
|
+
'produced_begin_on-gt': start_on,
|
112
|
+
'produced_end_on-lt': finish_on,
|
113
|
+
'begin_on': nil,
|
114
|
+
'end_on': nil,
|
115
|
+
'produced_begin_on': nil,
|
116
|
+
'produced_end_on': nil
|
117
|
+
},
|
118
|
+
allow: {
|
119
|
+
'begin_on': nil,
|
120
|
+
'end_on': nil,
|
121
|
+
'produced_begin_on': nil,
|
122
|
+
'produced_end_on': nil
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
Plan.default_where(q.merge!(or_q))
|
127
|
+
end
|
128
|
+
|
129
|
+
def xx
|
130
|
+
Date::DAYS_INTO_WEEK.map do |name, index|
|
131
|
+
if Date.beginning_of_week == :monday
|
132
|
+
i = (index - 1) % 7
|
133
|
+
else
|
134
|
+
i = index
|
135
|
+
end
|
136
|
+
[i, I18n.t("date.week_day.#{name}.name")]
|
137
|
+
end.sort.to_h
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# note
|
146
|
+
# 如果已经存在 A ~ B 日期范围内的数据;
|
147
|
+
# begin_on 位于 [A, B]之间, end_on
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Eventual
|
2
|
+
module Model::PlanAttender
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
attribute :attended, :boolean, default: false
|
7
|
+
attribute :state, :string
|
8
|
+
attribute :extra, :json
|
9
|
+
|
10
|
+
belongs_to :plan_participant, optional: true
|
11
|
+
belongs_to :attender, polymorphic: true
|
12
|
+
belongs_to :plan_item
|
13
|
+
belongs_to :plan
|
14
|
+
belongs_to :place
|
15
|
+
|
16
|
+
enum state: {
|
17
|
+
absent: 'absent' # 请假
|
18
|
+
}
|
19
|
+
|
20
|
+
after_initialize if: :new_record? do
|
21
|
+
if plan_item
|
22
|
+
self.assign_attributes plan_item.as_json(only: [:place_id])
|
23
|
+
end
|
24
|
+
if plan_participant
|
25
|
+
self.attender = plan_participant.participant
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Eventual
|
2
|
+
module Model::PlanItem
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
attribute :plan_on, :date
|
7
|
+
attribute :bookings_count, :integer, default: 0
|
8
|
+
attribute :plan_participants_count, :integer, default: 0
|
9
|
+
attribute :plan_on, :date
|
10
|
+
attribute :repeat_index, :string
|
11
|
+
attribute :extra, :json
|
12
|
+
|
13
|
+
|
14
|
+
belongs_to :time_item
|
15
|
+
belongs_to :time_list
|
16
|
+
belongs_to :plan, optional: true
|
17
|
+
belongs_to :planned, polymorphic: true
|
18
|
+
belongs_to :place, optional: true
|
19
|
+
belongs_to :event, optional: true
|
20
|
+
belongs_to :event_item, optional: true
|
21
|
+
has_many :bookings, dependent: :destroy
|
22
|
+
has_many :plan_attenders, dependent: :nullify
|
23
|
+
|
24
|
+
validates :plan_on, presence: true
|
25
|
+
|
26
|
+
default_scope -> { order(plan_on: :asc) }
|
27
|
+
scope :valid, -> { default_where('plan_on-gte': Date.today) }
|
28
|
+
|
29
|
+
before_validation :sync_from_plan
|
30
|
+
end
|
31
|
+
|
32
|
+
def attenders
|
33
|
+
plan_attenders.where(attended: true).pluck(:attender_type, :attender_id).map { |i| i.join('_') }
|
34
|
+
end
|
35
|
+
|
36
|
+
def start_at
|
37
|
+
time_item.start_at.change(plan_on.parts)
|
38
|
+
end
|
39
|
+
|
40
|
+
def finish_at
|
41
|
+
time_item.finish_at.change(plan_on.parts)
|
42
|
+
end
|
43
|
+
|
44
|
+
def sync_from_plan
|
45
|
+
if plan
|
46
|
+
self.place_id = plan.place_id
|
47
|
+
self.planned = plan.planned
|
48
|
+
self.repeat_index = self.plan.repeat_index(plan_on)
|
49
|
+
self.plan.plan_participants.each do |plan_participant|
|
50
|
+
self.plan_participants.build plan_participant.as_json(only: [:participant_type, :participant_id, :event_participant_id, :status])
|
51
|
+
end
|
52
|
+
end
|
53
|
+
if time_item
|
54
|
+
self.time_list_id = time_item.time_list_id
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class_methods do
|
59
|
+
|
60
|
+
def to_events(start_on: Date.today.beginning_of_week, finish_on: Date.today.end_of_week, **options)
|
61
|
+
options.merge! 'plan_on-gte': start_on, 'plan_on-lte': finish_on
|
62
|
+
cols = (start_on.to_date .. finish_on.to_date).map { |i| [i, []] }.to_h
|
63
|
+
if options[:time_list_id]
|
64
|
+
time_list = TimeList.find options[:time_list_id]
|
65
|
+
elsif options.key?(:organ_id)
|
66
|
+
time_list = TimeList.where(organ_id: options[:organ_id]).default
|
67
|
+
options.merge! time_list_id: time_list&.id
|
68
|
+
else
|
69
|
+
time_list = TimeList.where(organ_id: nil).default
|
70
|
+
options.merge! time_list_id: time_list&.id
|
71
|
+
end
|
72
|
+
rows = time_list.time_items.map { |i| [i, []] }.to_h
|
73
|
+
|
74
|
+
cols.merge! PlanItem.includes(:time_item).default_where(options).group_by(&->(i){i.plan_on})
|
75
|
+
cols.each do |date, items|
|
76
|
+
cols[date] = rows.merge items.group_by(&->(i){i.time_item})
|
77
|
+
end
|
78
|
+
cols
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Eventual
|
2
|
+
module Model::PlanParticipant::CrowdParticipant
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
belongs_to :crowd, foreign_key: :participant_id
|
7
|
+
has_many :members, through: :crowd
|
8
|
+
end
|
9
|
+
|
10
|
+
def sync
|
11
|
+
self.members.each do |member|
|
12
|
+
self.planning.plan_attenders.find_or_create_by(attender_type: member.class_name, attender_id: member.id)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Eventual
|
2
|
+
module Model::PlanParticipant
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
attribute :type, :string
|
7
|
+
attribute :status, :string, comment: '默认 event_participant 有效'
|
8
|
+
|
9
|
+
belongs_to :planning, polymorphic: true
|
10
|
+
belongs_to :event_participant, optional: true
|
11
|
+
belongs_to :participant, polymorphic: true
|
12
|
+
|
13
|
+
after_initialize if: :new_record? do
|
14
|
+
if self.event_participant
|
15
|
+
self.participant = event_participant.participant
|
16
|
+
end
|
17
|
+
if self.participant_type == 'Crowd'
|
18
|
+
self.type = 'CrowdParticipant'
|
19
|
+
else
|
20
|
+
self.type = 'NormalParticipant'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def sync
|
26
|
+
self.planning.plan_attenders.find_or_create_by(plan_participant_id: self.id)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|