From 9ea1b5b81a479e22860cc18bef5a620357a14be5 Mon Sep 17 00:00:00 2001 From: bohung Date: Tue, 26 Jul 2022 13:00:47 +0800 Subject: [PATCH] Fix bug. --- app/controllers/calendars_controller.rb | 26 +++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index 134ce32..b4b7057 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -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)