add event date

This commit is contained in:
邱博亞 2021-10-21 12:54:14 +08:00
parent 8c8aeb451b
commit 111dad12c4
3 changed files with 53 additions and 1 deletions

View File

@ -25,6 +25,7 @@ class EventNewsController < ApplicationController
if a.event_end_date
event_time = "<span class=\"start_date\">#{event_time.split(" ")[0]}</span> ~ <span class=\"end_date\">#{a.event_end_date.strftime('%Y-%m-%d')}</span>"
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 = "<span class=\"start_date\">#{event_time.split(" ")[0]}</span> ~ <span class=\"end_date\">#{a.event_end_date.strftime('%Y-%m-%d')}</span>"
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,

View File

@ -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 ""),

View File

@ -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