diff --git a/app/controllers/event_news_controller.rb b/app/controllers/event_news_controller.rb index fe7520d..c95ca4e 100644 --- a/app/controllers/event_news_controller.rb +++ b/app/controllers/event_news_controller.rb @@ -22,6 +22,10 @@ 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 "") + if a.event_end_date + event_time = "#{event_time.split(" ")[0]} ~ #{a.event_end_date.strftime('%Y-%m-%d')}" + end { "department" => author, "event_news_links" => links, @@ -37,7 +41,7 @@ class EventNewsController < ApplicationController "subtitle" => a.subtitle, "statuses" => statuses, "category" => (a.category.title rescue ""), - "postdate" => a.event_date, + "postdate" => event_time, "author" => author, "is_top" => (a.is_top? ? 1 : 0), "link_to_show" => link_to_show+"\" title=\"#{title}\"", @@ -541,11 +545,21 @@ class EventNewsController < ApplicationController subtitle_ann = event_news.subtitle if event_news.display_subtitle? img_src = (event_news.image.thumb.url || "/assets/event_news-default.jpg") if event_news.display_img? img_description = event_news.image_description if (event_news.image_description.present?) && (event_news.display_img?) - + event_carousel_images = event_news.event_carousel_images.map{|image| {"src"=>image.file.url,"description"=>image.description.to_s,"description_text"=>image.description_text }} + resume_btn_title = (I18n.locale.to_s =="zh_tw") ? "繼續播放" : "resume" + 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 "") + if event_news.event_end_date + event_time = "#{event_time.split(" ")[0]} ~ #{event_news.event_end_date.strftime('%Y-%m-%d')}" + end + { "tags" => tags, "event_news_files" => files, "event_news_links" => links, + "event_carousel_images" => event_carousel_images, "data" => { "speaker-head" => t('event_news.speaker'), "host-head" => t('event_news.host'), @@ -556,13 +570,19 @@ class EventNewsController < ApplicationController "title" => event_news.title, "subtitle_ann" => subtitle_ann, "update_user" => update_user, - "updated_at" => (event_news.event_date.strftime('%Y-%m-%d %H:%M') rescue ""), + "updated_at" => event_time, "body" =>event_news.text, "image" => event_news.image.url, "img_src" => img_src, "img_description" => img_description, "hide_class" => event_news.display_img? ? event_news.image_display_class : ' hide', "alt_title" => desc, + "resume_btn_title" => resume_btn_title, + "pause_btn_title" => pause_btn_title, + "prev_btn_title" => prev_btn_title, + "next_btn_title" => next_btn_title, + "carousel_display_style" => (event_carousel_images.count == 0 ? 'display: none' : "width: #{event_news.carousel_image_width};margin: auto;"), + "carousel_count" => event_carousel_images.count, "place_text" => (event_news.place.present? rescue false) ? "#{I18n.t("event_news.place")}: #{event_news.place}" : "" }, "impressionist" => (event_news.is_preview ? nil : event_news), @@ -602,7 +622,11 @@ class EventNewsController < ApplicationController update_user = event_news["author"] desc = event_news["image_description_translations"][locale] rescue "" desc = (desc.nil? || desc == "" ? "EventNews image" : desc) - + img_description = nil + img_description = event_news["image_description_translations"][I18n.locale] if event_news['display_img'] + img_src = nil + img_src = (event_news['image']['original'] || "/assets/event_news-default.jpg") if event_news['display_img'] + subtitle_ann = event_news['subtitle_ann'] request = OrbitHelper.request if event_news["subtitle_translations"].present? meta_desc = event_news["subtitle_translations"][locale] != "" ? event_news["subtitle_translations"][locale] : event_news["text_translations"][locale][0..200] rescue "" @@ -612,13 +636,28 @@ class EventNewsController < ApplicationController OrbitHelper.render_meta_tags([{"property" => "og:title", "content" => event_news["title_translations"][locale]},{"property" => "og:site_name", "content" => Site.first.title},{"property" => "og:url", "content" => request.original_url.split("?").first},{"property" => "og:description", "content" => meta_desc},{"property" => "og:image", "content" => event_news["image"]["original"]},{"property" => "og:type", "content" => "Article"}]) - datetime = DateTime.parse(event_news["event_date"].to_s) rescue "" - + 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 "") + if event_end_date + event_time = "#{event_time.split(" ")[0]} ~ #{event_end_date.strftime('%Y-%m-%d')}" + end + event_carousel_images = Array(event_news["event_carousel_images"]) + resume_btn_title = (I18n.locale.to_s =="zh_tw") ? "繼續播放" : "resume" + 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" { "tags" => tags, "event_news_files" => files, "event_news_links" => links, + "event_carousel_images" => event_carousel_images, "data" => { + "title" => event_news["title_translations"][locale], + "subtitle_ann" => subtitle_ann, + "update_user" => update_user, + "updated_at" => event_time, + "body" => event_news["text_translations"][locale], "speaker-head" => t('event_news.speaker'), "host-head" => t('event_news.host'), "notes-head" => t('event_news.notes'), @@ -626,12 +665,17 @@ class EventNewsController < ApplicationController "speaker" => (event_news["speaker_translations"][locale].to_s rescue ""), "host" => (event_news["host_translations"][locale].to_s rescue ""), "notes" => (event_news["notes_translations"][locale].to_s rescue ""), - "title" => event_news["title_translations"][locale], - "update_user" => update_user, - "updated_at" => (datetime.strftime('%Y-%m-%d %H:%M') rescue ""), - "body" => event_news["text_translations"][locale], "image" => event_news["image"]["original"], + "img_src" => img_src, + "img_description" => img_description, + "hide_class" => event_news["display_img"] ? '' : ' hide', "alt_title" => desc, + "resume_btn_title" => resume_btn_title, + "pause_btn_title" => pause_btn_title, + "prev_btn_title" => prev_btn_title, + "next_btn_title" => next_btn_title, + "carousel_display_style" => (event_carousel_images.count == 0 ? 'display: none' : "width: #{EventNewsSetting.last.carousel_image_width};margin: auto;"), + "carousel_count" => event_carousel_images.count, "place_text" => (event_news["place"].present? rescue false) ? "#{I18n.t("event_news.place")}: #{event_news["place"]}" : "" }, "impressionist" => nil, @@ -687,6 +731,10 @@ 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 "") + if a.event_end_date + event_time = "#{event_time.split(" ")[0]} ~ #{a.event_end_date.strftime('%Y-%m-%d')}" + end { "department" => author, "event_news_links" => links, @@ -702,7 +750,7 @@ class EventNewsController < ApplicationController "subtitle" => a.subtitle, "statuses" => statuses, "category" => (a.category.title rescue ""), - "postdate" => a.event_date, + "postdate" => event_time, "author" => author, "is_top" => (a.is_top? ? 1 : 0), "link_to_show" => link_to_show+"\" title=\"#{title}\"", diff --git a/app/controllers/event_news_feeds_controller.rb b/app/controllers/event_news_feeds_controller.rb index 1c9f704..bb1adfd 100644 --- a/app/controllers/event_news_feeds_controller.rb +++ b/app/controllers/event_news_feeds_controller.rb @@ -125,6 +125,7 @@ class EventNewsFeedsController < ApplicationController a["text_translations"]["en"] = smart_convertor(anns.text_translations["en"]) if !anns.text_translations["en"].blank? a["text_translations"]["zh_tw"] = smart_convertor(anns.text_translations["zh_tw"]) if !anns.text_translations["zh_tw"].blank? a["event_date"] = anns.event_date + a["event_end_date"] = anns.event_end_date a["postdate"] = anns.event_date#anns.postdate a["image_description_translations"] = anns.image_description_translations a["image"] = {} @@ -138,6 +139,7 @@ class EventNewsFeedsController < ApplicationController a["params"] = anns.to_param a["event_news_links"] = [] a["event_news_files"] = [] + a["event_carousel_images"] = anns.event_carousel_images.map{|image| {"src"=>"#{request.base_url}" + image.file.url,"description"=>image.description.to_s,"description_text"=>image.description_text }} anns.tags.each do |tag| if !tag_ids.include?(tag.id.to_s) tag_ids << tag.id.to_s diff --git a/app/models/event_carousel_image.rb b/app/models/event_carousel_image.rb new file mode 100644 index 0000000..3b646a2 --- /dev/null +++ b/app/models/event_carousel_image.rb @@ -0,0 +1,15 @@ +# encoding: utf-8 +class EventCarouselImage + + include Mongoid::Document + include Mongoid::Timestamps + + mount_uploader :file, AssetUploader + + field :description, localize: true + + belongs_to :event_news + def description_text + Nokogiri::HTML(self.description.to_s).css("body").text() rescue "" + end +end diff --git a/app/models/event_news.rb b/app/models/event_news.rb index 933fd28..2d21575 100644 --- a/app/models/event_news.rb +++ b/app/models/event_news.rb @@ -15,6 +15,7 @@ class EventNews before_destroy do EventNewsCache.all.destroy end + field :custom_carousel_image_width, type: String, default: "" field :image_display_class, type: String, default: "full-size-img" #3 choices: full-size-img , pull-left , pull-right field :add_to_calendar,type: Boolean,default: false field :calendar_start_date, :type => DateTime @@ -33,6 +34,7 @@ class EventNews field :update_user_id field :public, :type => Boolean, :default => true field :event_date , :type => DateTime, :default => Time.now + field :event_end_date , :type => DateTime, :default => Time.now field :postdate , :type => DateTime, :default => Time.now field :deadline , :type => DateTime field :rss2_sn @@ -59,10 +61,10 @@ class EventNews has_many :event_news_links, :autosave => true, :dependent => :destroy has_many :event_news_files, :autosave => true, :dependent => :destroy - + has_many :event_carousel_images, :autosave => true, :dependent => :destroy accepts_nested_attributes_for :event_news_files, :allow_destroy => true accepts_nested_attributes_for :event_news_links, :allow_destroy => true - + accepts_nested_attributes_for :event_carousel_images, :allow_destroy => true before_destroy :destroy_email scope :can_display_and_sorted, ->{where(:is_hidden=>false,:is_preview => false).any_of({:postdate.lte=>Time.now, :deadline.gte=>Time.now},{:postdate.lte=>Time.now, :deadline=>nil}).order(is_top: :desc,event_date: :desc,id: :desc)} @@ -171,4 +173,37 @@ class EventNews def display_img? self.display_img rescue false end + def statuses + statuses = [] + statuses << top_text if is_top? + statuses << hot_text if is_hot? + statuses << hidden_text if is_hidden? + statuses + end + def statuses_with_classname + statuses = [] + statuses << {"name" => top_text, "classname" => "top"} if is_top? + statuses << {"name" => hot_text, "classname" => "hot"} if is_hot? + statuses << {"name" => hidden_text, "classname" => "hidden"} if is_hidden? + statuses + end + def status_for_table + status = "" + status << "#{top_text} " if self.is_top + status << "#{hot_text} " if self.is_hot + status << "#{hidden_text}"if self.is_hidden + status.html_safe + end + def top_text + I18n.t("announcement.status.top") + end + def hot_text + I18n.t("announcement.status.hot") + end + def hidden_text + I18n.t("announcement.status.hidden") + end + def carousel_image_width + (self.custom_carousel_image_width.blank? ? AnnouncementSetting.last.carousel_image_width : self.custom_carousel_image_width) + end end diff --git a/app/models/event_news_setting.rb b/app/models/event_news_setting.rb index 2f46415..6f0a4a2 100644 --- a/app/models/event_news_setting.rb +++ b/app/models/event_news_setting.rb @@ -1,7 +1,7 @@ class EventNewsSetting include Mongoid::Document include Mongoid::Timestamps - + field :carousel_image_width, type: String, :default => "75%" field :top_limit, type: Integer, :default => 0 field :pro_enabled, type: Boolean, :default => false field :approvers, type: Array, :default => [] diff --git a/app/views/admin/event_news/_form.html.erb b/app/views/admin/event_news/_form.html.erb index 9fe2988..3b38c82 100644 --- a/app/views/admin/event_news/_form.html.erb +++ b/app/views/admin/event_news/_form.html.erb @@ -46,6 +46,7 @@ <% end %>
+ <%= hidden_field_tag 'bulletin_carousel_image_count', f.object.event_carousel_images.count %> + <%= t(:add) %> +
+