add all day settting

This commit is contained in:
邱博亞 2021-10-21 15:03:35 +08:00
parent 90c411f378
commit 3867b8fc69
6 changed files with 25 additions and 11 deletions

View File

@ -21,7 +21,7 @@ class EventNewsController < ApplicationController
target = a.is_external_link ? "_blank" : "_self"
doc = Nokogiri::HTML(a.title)
title = doc.text.empty? ? 'no content' : doc.text
event_time = (a.event_date.strftime('%Y-%m-%d %H:%M') rescue "")
event_time = (a.event_date.strftime(a.date_parse_format) rescue "")
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
@ -532,7 +532,7 @@ class EventNewsController < ApplicationController
event_news = top_event_news + rest_event_news
end
end
event_news.each{|a| a["postdate"] = a["postdate"].in_time_zone(Time.zone.utc_offset / 3600).strftime('%Y-%m-%d %H:%M') rescue nil }
event_news.each{|a| a["postdate"] = a["postdate"].in_time_zone(Time.zone.utc_offset / 3600).strftime((a['all_day'] ? '%Y-%m-%d' : '%Y-%m-%d %H:%M')) rescue nil }
event_news
end
@ -623,7 +623,7 @@ class EventNewsController < ApplicationController
pause_btn_title = (I18n.locale.to_s =="zh_tw") ? "暫停播放" : "pause"
prev_btn_title = (I18n.locale.to_s =="zh_tw") ? "上一張" : "prev"
next_btn_title = (I18n.locale.to_s =="zh_tw") ? "下一張" : "next"
event_time = (event_news.event_date.strftime('%Y-%m-%d %H:%M') rescue "")
event_time = (event_news.event_date.strftime(event_news.date_parse_format) rescue "")
if event_news.event_end_date
event_time = "<span class=\"start_date\">#{event_time.split(" ")[0]}</span> ~ <span class=\"end_date\">#{event_news.event_end_date.strftime('%Y-%m-%d')}</span>"
end
@ -713,7 +713,7 @@ class EventNewsController < ApplicationController
event_date = DateTime.parse(event_news["event_date"].to_s) rescue nil
event_end_date = DateTime.parse(event_news["event_end_date"].to_s) rescue nil
event_time = (event_date.strftime('%Y-%m-%d %H:%M') rescue "")
event_time = (event_date.strftime(event_news.date_parse_format) rescue "")
if event_end_date
event_time = "<span class=\"start_date\">#{event_time.split(" ")[0]}</span> ~ <span class=\"end_date\">#{event_end_date.strftime('%Y-%m-%d')}</span>"
end
@ -809,7 +809,7 @@ class EventNewsController < ApplicationController
target = a.is_external_link ? "_blank" : "_self"
doc = Nokogiri::HTML(a.title)
title = doc.text.empty? ? 'no content' : doc.text
event_time = (a.event_date.strftime('%Y-%m-%d %H:%M') rescue "")
event_time = (a.event_date.strftime(a.date_parse_format) rescue "")
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

View File

@ -118,12 +118,13 @@ module EventNewsHelper
event_time_formated = a.event_time_formated
s = DateTime.parse(fa["event_date"]) rescue nil
e = DateTime.parse(fa["event_end_date"]) rescue nil
date_parse_format = fa["all_day"] ? '%Y-%m-%d' : '%Y-%m-%d %H:%M'
if s.blank? && e.blank?
event_time_formated = ""
elsif s.blank?
event_time_formated = s.strftime('%Y-%m-%d %H:%M')
event_time_formated = s.strftime(date_parse_format)
elsif e.blank?
event_time_formated = "~ " + e.strftime('%Y-%m-%d %H:%M')
event_time_formated = "~ " + e.strftime(date_parse_format)
else
if s.to_date == e.to_date
date_str = s.strftime('%Y-%m-%d')
@ -131,7 +132,7 @@ module EventNewsHelper
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')
event_time_formated = s.strftime(date_parse_format) + " ~ " + e.strftime(date_parse_format)
end
end
x = {

View File

@ -34,6 +34,7 @@ class EventNews
field :calendar_start_date, :type => DateTime
field :calendar_end_date, :type => DateTime
field :calendar_all_day,type: Boolean,default: false
field :all_day,type: Boolean,default: false
field :calendar_type_id
field :event_id
field :place, type: String, localize: true
@ -104,15 +105,19 @@ class EventNews
self
end
end
def date_parse_format
all_day ? '%Y-%m-%d' : '%Y-%m-%d %H:%M'
end
def event_time_formated
s = self.event_date
e = self.event_end_date
if s.blank? && e.blank?
""
elsif e.blank?
s.strftime('%Y-%m-%d %H:%M')
s.strftime(self.date_parse_format)
elsif s.blank?
"~ " + e.strftime('%Y-%m-%d %H:%M')
"~ " + e.strftime(self.date_parse_format)
else
if s.to_date == e.to_date
date_str = s.strftime('%Y-%m-%d')
@ -120,7 +125,7 @@ class EventNews
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')
s.strftime(self.date_parse_format) + " ~ " + e.strftime(self.date_parse_format)
end
end
end

View File

@ -76,6 +76,12 @@
<%= f.datetime_picker :event_end_date, :no_label => true, :new_record => @event_news.new_record?, :data=>{"picker-type" => "range", "range" => "start"} %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t("event_news.all_day") %></label>
<div class="controls">
<%= f.check_box :all_day %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t("event_news.start_date") %></label>
<div class="controls">

View File

@ -2,6 +2,7 @@ en:
module_name:
event_news: Event News
event_news:
all_day: All Day
show_today_data_first: Show today data first
custom_fields_title: Custom Fields Title
custom_carousel_image_width_hint: "If blank, width will be default value."

View File

@ -2,6 +2,7 @@ zh_tw:
module_name:
event_news: 活動公告
event_news:
all_day: 全天
show_today_data_first: 優先顯示當日資料
custom_fields_title: 欄位名稱設定
custom_carousel_image_width_hint: "未填寫,則使用預設寬度"