From 111dad12c42f174563482fd6fc8bca5d0dde1e5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Thu, 21 Oct 2021 12:54:14 +0800 Subject: [PATCH] add event date --- app/controllers/event_news_controller.rb | 6 +++++ app/helpers/event_news_helper.rb | 28 +++++++++++++++++++++++- app/models/event_news.rb | 20 +++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/app/controllers/event_news_controller.rb b/app/controllers/event_news_controller.rb index 3fe0788..7d25d1e 100644 --- a/app/controllers/event_news_controller.rb +++ b/app/controllers/event_news_controller.rb @@ -25,6 +25,7 @@ class EventNewsController < ApplicationController if a.event_end_date event_time = "#{event_time.split(" ")[0]} ~ #{a.event_end_date.strftime('%Y-%m-%d')}" end + event_time_formated = a.event_time_formated { "department" => author, "event_news_links" => links, @@ -44,6 +45,8 @@ class EventNewsController < ApplicationController "statuses" => statuses, "category" => (a.category.title rescue ""), "postdate" => event_time, + "event-time-formated" => event_time_formated, + "event-time-css" => (event_time_formated.blank? ? "display: none;" : ""), "author" => author, "is_top" => (a.is_top? ? 1 : 0), "link_to_show" => link_to_show+"\" title=\"#{title}\"", @@ -810,6 +813,7 @@ class EventNewsController < ApplicationController if a.event_end_date event_time = "#{event_time.split(" ")[0]} ~ #{a.event_end_date.strftime('%Y-%m-%d')}" end + event_time_formated = a.event_time_formated { "department" => author, "event_news_links" => links, @@ -818,6 +822,8 @@ class EventNewsController < ApplicationController "speaker-css" => (a.speaker.blank? ? "display: none;" : ""), "host-css" => (a.host.blank? ? "display: none;" : ""), "place-css" => (a.place.blank? ? "display: none;" : ""), + "event-time-formated" => event_time_formated, + "event-time-css" => (event_time_formated.blank? ? "display: none;" : ""), "speaker" => a.speaker, "place" => a.place, "host" => a.host, diff --git a/app/helpers/event_news_helper.rb b/app/helpers/event_news_helper.rb index df97e9d..962edc9 100644 --- a/app/helpers/event_news_helper.rb +++ b/app/helpers/event_news_helper.rb @@ -42,6 +42,7 @@ module EventNewsHelper else image_url = a.image.url end + event_time_formated = a.event_time_formated { "event_news_links" => links, "event_news_files" => files, @@ -49,6 +50,8 @@ module EventNewsHelper "speaker-css" => (a.speaker.blank? ? "display: none;" : ""), "host-css" => (a.host.blank? ? "display: none;" : ""), "place-css" => (a.place.blank? ? "display: none;" : ""), + "event-time-formated" => event_time_formated, + "event-time-css" => (event_time_formated.blank? ? "display: none;" : ""), "speaker" => a.speaker, "place" => a.place, "host" => a.host, @@ -112,12 +115,35 @@ module EventNewsHelper files = fa["event_news_files"].collect{|bf| { "file_url" => bf["url"], "file_title" => (fa["title_translations"][locale].blank? ? File.basename(fa["url"]) : fa["title_translations"][locale] rescue '') }} rescue [] links = fa["event_news_links"].map{|link| { "link_url" => link["url"], "link_title" => (link["title_translations"][locale].blank? ? link["url"] : link["title_translations"][locale]) } } rescue [] - + event_time_formated = a.event_time_formated + s = DateTime.parse(fa["event_date"]) rescue nil + e = DateTime.parse(fa["end_date"]) rescue nil + if s.blank? && e.blank? + event_time_formated = "" + elsif s.blank? + event_time_formated = s.strftime('%Y-%m-%d %H:%M') + elsif e.blank? + event_time_formated = "~ " + e.strftime('%Y-%m-%d %H:%M') + else + if s.to_date == e.to_date + date_str = s.strftime('%Y-%m-%d') + s_time = s.strftime('%H:%M') + e_time = e.strftime('%H:%M') + event_time_formated = "#{date_str} #{s_time} ~ #{e_time}" + else + event_time_formated = s.strftime('%Y-%m-%d %H:%M') + " ~ " + e.strftime('%Y-%m-%d %H:%M') + end + end x = { "event_news_links" => links, "event_news_files" => files, "event_carousel_images" => fa["bulletin_carousel_images"].to_a, "title" => fa["title_translations"][locale], + "speaker-css" => (fa["speaker_translations"][locale].blank? ? "display: none;" : ""), + "host-css" => (fa["host_translations"][locale].blank? ? "display: none;" : ""), + "place-css" => (fa["place_translations"][locale].blank? ? "display: none;" : ""), + "event-time-formated" => event_time_formated, + "event-time-css" => (event_time_formated.blank? ? "display: none;" : ""), "speaker" => (fa["speaker_translations"][locale].to_s rescue ""), "place" => (fa["place_translations"][locale].to_s rescue ""), "host" => (fa["host_translations"][locale].to_s rescue ""), diff --git a/app/models/event_news.rb b/app/models/event_news.rb index 88419b6..d50ed3f 100644 --- a/app/models/event_news.rb +++ b/app/models/event_news.rb @@ -104,6 +104,26 @@ class EventNews self end end + def event_time_formated + s = self.event_date + e = self.end_date + if s.blank? && e.blank? + "" + elsif s.blank? + s.strftime('%Y-%m-%d %H:%M') + elsif e.blank? + "~ " + e.strftime('%Y-%m-%d %H:%M') + else + if s.to_date == e.to_date + date_str = s.strftime('%Y-%m-%d') + s_time = s.strftime('%H:%M') + e_time = e.strftime('%H:%M') + "#{date_str} #{s_time} ~ #{e_time}" + else + s.strftime('%Y-%m-%d %H:%M') + " ~ " + e.strftime('%Y-%m-%d %H:%M') + end + end + end def to_calendar_param self.to_param end