modified announcement json format but it have some bugs...

This commit is contained in:
Rueshyna 2012-11-14 12:01:18 +08:00
parent 9095713769
commit ad429af58c
2 changed files with 30 additions and 21 deletions

View File

@ -23,11 +23,26 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
end
def get_bulletins_json
@bulletins = Bulletin.all
@data = Hash.new
@data[I18n.t("category")] = Hash.new
categorys = BulletinCategory.all
data = Array.new
@bulletins.each do |b|
categorys.each do |c|
data << {
category: c.title
link: path_get_bulletin_json(c)
}
end
#render :json => @data.to_json
#to print readable json
render :json => JSON.pretty_generate(@data)
end
def get_bulletin_json
bulletin = Bulletin.find(params[:category_id])
data = Array.new
bulletin.each do |b|
deadline = b.deadline
if not deadline.nil?
@ -35,24 +50,17 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
else
deadline = I18n.t("no_deadline")
end
if @data[I18n.t("category")][b.bulletin_category.title].nil?
@data[I18n.t("category")][b.bulletin_category.title] = Array.new
@data[I18n.t("category")][b.bulletin_category.title] << { title: b.title,
postdate: display_date_time(b.postdate),
deadline: deadline,
tag: b.sorted_tags.to_a,
}
else
@data[I18n.t("category")][b.bulletin_category.title] << { title: b.title,
postdate: display_date_time(b.postdate),
deadline: deadline,
tag: b.sorted_tags.to_a,
}
end
data << {
title: b.title,
link: panel_announcement_front_end_bulletin_path(bulletin, :category_id => b.bulletin_category.id)
postdate: display_date_time(b.postdate),
deadline: deadline,
tag: b.sorted_tags.to_a,
}
end
#render :json => @data.to_json
#to print readable json
render :json => JSON.pretty_generate(@data)
render :json => JSON.pretty_generate(data)
end
def index

View File

@ -12,6 +12,7 @@ Rails.application.routes.draw do
match "approve/:bulletin_id" => "approvals#approve",:as => :approve,:via => :post
match "link_quick_add/:bulletin_id" => "bulletins#link_quick_add" ,:as => :link_quick_add
match "link_quick_edit/:bulletin_id" => "bulletins#link_quick_edit" ,:as => :link_quick_edit
match 'get_bulletin_json/:category_id' => "bulletins#get_bulletin_json", :as => :get_bulletin_json
member do
get 'load_quick_edit'
end