added new widget for nccu

This commit is contained in:
Harry Bomrah 2015-08-13 19:50:49 +08:00
parent caf727cb59
commit 88c66108b1
2 changed files with 62 additions and 1 deletions

View File

@ -180,6 +180,67 @@ class NewsController < ApplicationController
} }
end end
def widget2
more_stories = {"en" => "More Stories+", "zh_tw" => "更多新聞+"}
categories = OrbitHelper.widget_categories
ma = ModuleApp.find_by_key("news")
page = Page.where(:module => "news").first rescue nil
if categories.first == "all" || categories.count == 0
categories = ma.categories.enabled.limit(3)
else
if categories.count > 3
categories = Category.find(categories.sample(3))
else
categories = Category.find(categories)
end
end
categories_data = []
categories_for_dropdown = ma.categories.enabled.collect do |cat|
link = page.nil? ? "#" : "/#{I18n.locale.to_s + page.url}/?category=#{cat.to_param}"
{
"name" => cat.title,
"category-link" => link
}
end
link = page.nil? ? "#" : "/#{I18n.locale.to_s + page.url}/"
categories_for_dropdown.unshift({"name" => t("news.all"), "category-link" => link})
hot_news = NewsBulletin.where(:title.ne => "",:is_preview.in=>[false,nil], :category_id.in => categories.collect{|cat| cat.id}, :is_hot => true).can_display.is_approved.desc(:created_at).limit(1)
hot_news = hot_news.first
categories.each_with_index do |category,index|
if hot_news.nil?
nbs = NewsBulletin.where(:title.ne => "",:is_preview.in=>[false,nil], :category_id => category.id).can_display.is_approved.desc(:created_at).limit(OrbitHelper.widget_data_count)
else
nbs = NewsBulletin.where(:id.ne => hot_news.id, :title.ne => "",:is_preview.in=>[false,nil], :category_id => category.id).can_display.is_approved.desc(:created_at).limit(OrbitHelper.widget_data_count)
end
temp = nbs.collect do |nb|
{
"title" => nb.title,
"link_to_show" => OrbitHelper.widget_item_url(nb.to_param)
}
end
link = page.nil? ? "#" : "/#{I18n.locale.to_s + page.url}/?category=#{category.to_param}"
categories_data << {
"name" => category.title,
"category-link" => link,
"news" => temp
}
end
image_description = hot_news.nil? || hot_news.image_description.blank? ? "裝飾性圖片" : hot_news.image_description
{
"categorized_news" => categories_data,
"categories" => categories_for_dropdown,
"extras" => {
"more_stories" => more_stories[I18n.locale.to_s],
"hot_news_title" => (hot_news.nil? ? "" : hot_news.title),
"hot_news_subtitle" => (hot_news.nil? ? "" : hot_news.subtitle),
"hot_news_image" => (hot_news.nil? ? "" : hot_news.image.mobile.url),
"hot_news_image_description" => image_description,
"hot_news_link_to_show" => (hot_news.nil? ? "" : OrbitHelper.widget_item_url(hot_news.to_param))
}
}
end
def show def show
params = OrbitHelper.params params = OrbitHelper.params
news = NewsBulletin.find_by(:uid=>params[:uid]) news = NewsBulletin.find_by(:uid=>params[:uid])

View File

@ -4,7 +4,7 @@ module News
OrbitApp.registration "News", :type => "ModuleApp" do OrbitApp.registration "News", :type => "ModuleApp" do
module_label "news.news" module_label "news.news"
base_url File.expand_path File.dirname(__FILE__) base_url File.expand_path File.dirname(__FILE__)
widget_methods ["widget"] widget_methods ["widget","widget2"]
widget_settings [{"data_count"=>12}] widget_settings [{"data_count"=>12}]
models_to_cache [:news_bulletin] models_to_cache [:news_bulletin]
# taggable "NewsBulletin" # taggable "NewsBulletin"