make a json format for view of journal_p

This commit is contained in:
Rueshyna 2012-11-13 17:21:23 +08:00
parent 1ecb8a0c8b
commit bfdd155c1e
1 changed files with 77 additions and 60 deletions

View File

@ -1,74 +1,91 @@
class DesktopPublicationsController< ApplicationController class DesktopPublicationsController< ApplicationController
def journal_p def journal_p
render "desktop/journal_p", :layout => false render "desktop/journal_p", :layout => false
end end
def journal_p_list
render "desktop/journal_pages/list", :layout => false
end
def journal_p_add
render "desktop/journal_pages/add", :layout => false
end
def books def journal_p_list
render "desktop/books", :layout => false render "desktop/journal_pages/list", :layout => false
end end
def books_list def journal_p_add
render "desktop/books/list", :layout => false render "desktop/journal_pages/add", :layout => false
end end
def books_add def books
render "desktop/books/add", :layout => false render "desktop/books", :layout => false
end end
def seminar_p def books_list
render "desktop/seminar_p", :layout => false render "desktop/books/list", :layout => false
end end
def seminar_p_list def books_add
render "desktop/seminar_pages/list", :layout => false render "desktop/books/add", :layout => false
end end
def seminar_p_add def seminar_p
render "desktop/seminar_pages/add", :layout => false render "desktop/seminar_p", :layout => false
end end
def create_journal def seminar_p_list
Journal.create(user_id: current_user.id, title: "Ice Cream Sandwich") render "desktop/seminar_pages/list", :layout => false
b = Array.new end
b << {"success"=>"true"}
render :json=>b.to_json
end
def getjournals def seminar_p_add
@journals = current_user.journals render "desktop/seminar_pages/add", :layout => false
data = Array.new end
@journals.each do |journal|
@papers = journal.papers.all
data << {"title" => journal.title, "papers" => @papers}
end
render :json=>data.to_json
end
def delete_journal def create_journal
@journals = Journal.find("") Journal.create(user_id: current_user.id, title: "Ice Cream Sandwich")
@journals.delete b = Array.new
b = Array.new b << {"success"=>"true"}
b << {"success"=>"true"} render :json=>b.to_json
render :json=>b.to_json end
end
def update_journal def getjournals
@journal = Journal.find("4ff2d6ebbd98eb02b9000017") publications = WritingJournal.where(:create_user_id => current_user.id)
@papers = @journal.papers
@papers.each do |paper| sort_publications= Hash.new
paper.update_attributes(:user_id => current_user.id) data = Array.new
publications.each do |publication|
if sort_publications[publication.journal_title].nil?
sort_publications[publication.journal_title] = Array.new
end end
b = Array.new sort_publications[publication.journal_title] <<
{ title: publication.paper_title,
b << {"success"=>"true"} keywords: publication.keywords,
render :json=>b.to_json abstract: publication.abstract,
level: publication.journal_paper_type_id,
coauthors: publication.authors,
year: publication.year
}
end end
sort_publications.each do |journal, papers|
data << {title: journal, papers: papers}
end
render json: JSON.pretty_generate(data)
end
def delete_journal
@journals = Journal.find("")
@journals.delete
b = Array.new
b << {"success"=>"true"}
render :json=>b.to_json
end
def update_journal
@journal = Journal.find("4ff2d6ebbd98eb02b9000017")
@papers = @journal.papers
@papers.each do |paper|
paper.update_attributes(:user_id => current_user.id)
end
b = Array.new
b << {"success"=>"true"}
render :json=>b.to_json
end
end end