This commit is contained in:
BoHung Chiu 2022-07-26 13:00:47 +08:00
parent 4d0925767b
commit 9ea1b5b81a
1 changed files with 20 additions and 6 deletions

View File

@ -68,10 +68,14 @@ class CalendarsController < ApplicationController
if calendar_types.include?('all')
calendar_types = []
end
tags = page.tags
if tags.include?('all')
tags = []
end
if params[:start].present? && params[:end].present?
sdt = Time.at(params[:start].to_i).utc
edt = Time.at(params[:end].to_i).utc
events = Event.with_categories(calendar_types).where("title_translations.#{locale}".to_sym.ne=>"").monthly_event(sdt,edt).convert_front+Event.recurring_event(sdt,edt)
events = Event.with_categories(calendar_types).with_tags(tags).where("title_translations.#{locale}".to_sym.ne=>"").agenda_events(sdt,edt)
end
end
respond_to do |format|
@ -88,20 +92,25 @@ class CalendarsController < ApplicationController
if !params[:subpart_id].nil?
subpartid = params[:subpart_id]
page = Page.where(page_id: subpartid).first
calendar_types = page.categories
calendar_types = page.categories rescue []
if calendar_types.include?('all')
calendar_types = []
end
tags = page.tags rescue []
if tags.include?('all')
tags = []
end
else
calendar_types = []
tags = []
end
if params[:unix_start].present? && params[:unix_end].present?
agenda_start = Time.at(params[:unix_start].to_i).utc
agenda_end = Time.at(params[:unix_end].to_i).utc
event = Event.where("title_translations.#{locale}".to_sym.ne=>"")
events = event.with_categories(calendar_types).agenda_events(agenda_start,agenda_end).sort_by{|e| e[:start]}
events = event.with_categories(calendar_types).with_tags(tags).agenda_events(agenda_start,agenda_end).sort_by{|e| e[:start]}
end
render json: {"events" => events,"calendar_title"=>get_calendar_title(Time.at(params[:month_start].to_i).utc)}.to_json({"frontend" => true})
render json: {"events" => events,"calendar_title"=>get_calendar_title(params[:month_start] ? Time.at(params[:month_start].to_i).utc : Time.at(params[:unix_start].to_i))}.to_json({"frontend" => true})
end
end
@ -113,16 +122,21 @@ class CalendarsController < ApplicationController
subpartid = params[:subpart_id]
widget = SubPart.find(subpartid)
calendar_types = widget.custom_array_field
tags = widget.tags
if tags.include?('all')
tags = []
end
else
calendar_types = []
tags = []
end
if params[:unix_start].present? && params[:unix_end].present?
agenda_start = Time.at(params[:unix_start].to_i).utc
agenda_end = Time.at(params[:unix_end].to_i).utc
event = Event.where("title_translations.#{locale}".to_sym.ne=>"")
events = event.with_categories(calendar_types).agenda_events(agenda_start,agenda_end).sort_by{|e| e[:start]}
events = event.with_categories(calendar_types).with_tags(tags).agenda_events(agenda_start,agenda_end).sort_by{|e| e[:start]}
end
render json: {"events" => events,"calendar_title"=>get_calendar_title(Time.at(params[:month_start].to_i).utc)}.to_json({"frontend" => true})
render json: {"events" => events,"calendar_title"=>get_calendar_title(params[:month_start] ? Time.at(params[:month_start].to_i).utc : Time.at(params[:unix_start].to_i))}.to_json({"frontend" => true})
end
end
def get_calendar_title(now_date=nil)