generate journal page by rails side and fixed model name bug

This commit is contained in:
Rueshyna 2013-02-26 15:15:09 +08:00
parent 8b0ffe747c
commit 4ac0f19011
11 changed files with 102 additions and 48 deletions

View File

@ -11,7 +11,7 @@
<li class="d_cate"><a callback-method='' href="" class="widget_fn wh3 hh3" id='d_publication' onclick="return false;"><span class="widget_icon"><img src="" alt="Publication" id="publication_icon" width="30" height="30"/></span></a> <li class="d_cate"><a callback-method='' href="" class="widget_fn wh3 hh3" id='d_publication' onclick="return false;"><span class="widget_icon"><img src="" alt="Publication" id="publication_icon" width="30" height="30"/></span></a>
<ul class="dock_child hh3 thmc4" style="width: 180px;"> <ul class="dock_child hh3 thmc4" style="width: 180px;">
<li class="dock_item"><a callback-method='initializeJournalPapers' href="<%= panel_personal_journal_desktop_journal_p_path %>" class="widget_fn wh3 hh3" id='d_journal_p' custom-load="journal" onclick="return false;"><span class="widget_icon"><img src="" alt="Journal Papers" id="journal_p_icon" width="30" height="30"/></span></a></li> <li class="dock_item"><a callback-method='initializeJournalPapers' href="<%= panel_personal_journal_desktop_journal_window_path %>" class="widget_fn wh3 hh3" id='d_journal_p' custom-load="journal" onclick="return false;"><span class="widget_icon"><img src="" alt="Journal Papers" id="journal_p_icon" width="30" height="30"/></span></a></li>
<li class="dock_item"><a callback-method='initializeConference' href="<%= panel_personal_conference_desktop_conference_window_path %>" class="widget_fn wh3 hh3" id='d_conference_p' custom-load="conference" onclick="return false;"><span class="widget_icon"><img src="" alt="Conference Papers" id="conference_p_icon" width="30" height="30"/></span></a></li> <li class="dock_item"><a callback-method='initializeConference' href="<%= panel_personal_conference_desktop_conference_window_path %>" class="widget_fn wh3 hh3" id='d_conference_p' custom-load="conference" onclick="return false;"><span class="widget_icon"><img src="" alt="Conference Papers" id="conference_p_icon" width="30" height="30"/></span></a></li>

View File

@ -1,5 +0,0 @@
class Panel::PersonalJournal::Desktop::JournalPController < ApplicationController
def journal_p
render panel_personal_journal_desktop_journal_p_path, :layout => false
end
end

View File

@ -1,7 +1,16 @@
class Panel::PersonalJournal::Desktop::JournalPagesController < ApplicationController class Panel::PersonalJournal::Desktop::JournalPagesController < ApplicationController
def index def index
@writing_journal = WritingJournal.where(create_user_id: current_user.id) @writing_journals = WritingJournal.where(create_user_id: current_user.id)
@level_types = JournalLevelType.all @level_types = JournalLevelType.all
@view_by = params[:view]
if @view_by.nil?
@writing_journals = @writing_journals.asc(:paper_title)
else
@writing_journals = @writing_journals.asc(@view_by).asc(:paper_title)
end
@level_types = ConferencePaperType.all
respond_to do |format| respond_to do |format|
format.html { render :layout => false} format.html { render :layout => false}
@ -73,37 +82,6 @@ class Panel::PersonalJournal::Desktop::JournalPagesController < ApplicationContr
render :json => {success: true, msg: t('delete.success.paper')} render :json => {success: true, msg: t('delete.success.paper')}
end end
def get_journals_json
publications = WritingJournal.where(create_user_id: current_user.id)
sort_publications= Hash.new
data = Array.new
publications.each do |publication|
if sort_publications[publication.journal_title].nil?
sort_publications[publication.journal_title] = Array.new
end
sort_publications[publication.journal_title] <<
{ title: publication.paper_title,
keywords: publication.keywords,
abstract: publication.abstract,
coauthors: publication.authors,
year: publication.year,
url_edit: edit_panel_personal_journal_desktop_journal_page_path(publication),
url_delete: panel_personal_journal_desktop_journal_page_path(publication),
files: publication.writing_journal_files.collect{|file|
{title: file.title, url: file.file.url, icon: check_file_type(file.file.url)}
}
}
end
sort_publications.each do |journal, papers|
data << {title: journal, papers: papers}
end
render json: JSON.pretty_generate(data)
end
def journal_type def journal_type
level_types = JournalLevelType.all level_types = JournalLevelType.all
all_journal_lists = WritingJournal.where(create_user_id: current_user.id) all_journal_lists = WritingJournal.where(create_user_id: current_user.id)

View File

@ -0,0 +1,5 @@
class Panel::PersonalJournal::Desktop::JournalWindowsController < ApplicationController
def journal_window
render panel_personal_journal_desktop_journal_window_path, :layout => false
end
end

View File

@ -0,0 +1,74 @@
module Panel::PersonalJournal::Desktop::JournalPagesHelper
def publication_record publication, view
content_tag :li,
:class => "list_t_item" do
marker + \
content(publication, view) + \
edit_or_delete(publication)
end
end
def marker
content_tag :div,
:class => "list_item_action"
content_tag(:a, "", :class => "icon-check-empty") + \
content_tag(:a, "", :class => "icon-star-empty")
end
def content publication, view
case view
when "journal_title"
des = content_tag(:div, publication.journal_title,
:class => "list_t_des")
when "keywords"
des = content_tag(:div, publication.keywords,
:class => "list_t_des")
when "abstract"
des = content_tag(:div, publication.abstract,
:class => "list_t_des")
when "file"
des = content_tag(:div, link_publication_file(publication),
:class => "list_t_des")
else
end
content_tag(:div, publication.paper_title,
:class => "list_t_title") + des
end
def edit_or_delete publication
content_tag :div,
:class => "list_item_function" do
content_tag(:a, t("edit"),
:class => "journal_paper_edit admbg2 admtxt",
:href => edit_panel_personal_journal_desktop_journal_page_path(publication),
"ajax-remote" => "get") + \
content_tag(:a, t("delete"),
"ajax-remote" => "delete",
"confirm-message" => t("sure?"),
"callback-method" => "paperDelete",
:class => "journal_paper_delete admbg2 admtxt",
:href => panel_personal_journal_desktop_journal_page_path(publication))
end
end
def link_publication_file publication
publication.writing_journal_files.map{|file|
link_to(image_tag(check_file_type(file.file.url)) + \
content_tag(:span, file.title, :class => "filetitle"),
file.file.url,
:class => "file",
"target" => "_blank")
}.inject(:+)
end
def check_file_type file
if not file.nil?
file_type = MIME::Types.type_for(file).first.to_s.split("/")[1]
file_type = "/assets/ft-icons/#{file_type}/#{file_type}-48_32.png"
else
file_type = ""
end
end
end

View File

@ -47,11 +47,11 @@ class WritingJournal
current_user = update_user_id current_user = update_user_id
end end
authors_db = CoAuthor.where(:name_id => current_user).map(&:co_author) authors_db = JournalCoAuthor.where(:name_id => current_user).map(&:co_author)
authors_list.delete(User.find(current_user).name) authors_list.delete(User.find(current_user).name)
authors_list = authors_list.delete_if{|author| authors_db.include?author} authors_list = authors_list.delete_if{|author| authors_db.include?author}
authors_list.each do |author| authors_list.each do |author|
CoAuthor.new(:co_author => author, :name_id => current_user).save JournalCoAuthor.new(:co_author => author, :name_id => current_user).save
end end
end end

View File

@ -143,7 +143,7 @@
</li> </li>
<li class="s_grid_row"> <li class="s_grid_row">
<%= f.text_field :tags, size: "20", placeholder: t("personal_journal.tags"), class: "s_grid_6 s_grid"%> <li class="s_grid_row"><input class="s_grid s_grid_6" type="text" placeholder=<%= t("personal_journal.tags") %>><span class="icon-plus input_append"></li>
<span class="icon-plus input_append"></span> <span class="icon-plus input_append"></span>
</li> </li>
<li class="s_grid_row"> <li class="s_grid_row">

View File

@ -41,11 +41,11 @@
<div class="sdm_t hh2">View</div> <div class="sdm_t hh2">View</div>
<div class="admbg sdm_o"> <div class="admbg sdm_o">
<ul id="journal_view_selection"> <ul id="journal_view_selection">
<li><a class="hp hh2 admtxt" href="journal">Journal</a></li> <li><%= link_to "Journal", panel_personal_journal_desktop_journal_pages_path + "?view=journal_title", :class => "hp hh2 admtxt", "ajax-remote" => "get" %></li>
<li><a class="hp hh2 admtxt" href="title">Title</a></li> <li><%= link_to "Title", panel_personal_journal_desktop_journal_pages_path + "?view=paper_title", :class => "hp hh2 admtxt", "ajax-remote" => "get" %></li>
<li><a class="hp hh2 admtxt" href="file">File</a></li> <li><%= link_to "File", panel_personal_journal_desktop_journal_pages_path + "?view=file", :class => "hp hh2 admtxt", "ajax-remote" => "get" %></li>
<li><a class="hp hh2 admtxt" href="keywords">Keywords</a></li> <li><%= link_to "Keywords", panel_personal_journal_desktop_journal_pages_path + "?view=keywords", :class => "hp hh2 admtxt", "ajax-remote" => "get" %></li>
<li><a class="hp hh2 admtxt" href="abstract">Abstract</a></li> <li><%= link_to "Abstract", panel_personal_journal_desktop_journal_pages_path + "?view=abstract", :class => "hp hh2 admtxt", "ajax-remote" => "get" %></li>
</ul> </ul>
</div> </div>
</div> </div>
@ -81,7 +81,9 @@
<div class="scrollbar sb_h vp"><div class="track"><div class="thumb thmc2"><div class="end"></div></div></div></div> <div class="scrollbar sb_h vp"><div class="track"><div class="thumb thmc2"><div class="end"></div></div></div></div>
<div class="viewport"> <div class="viewport">
<div class="overview"> <div class="overview">
<% @writing_journals.each do |w| %>
<%= publication_record w, @view_by%>
<% end %>
</div> </div>
</div> </div>
</div> </div>

View File

@ -2,7 +2,7 @@ Rails.application.routes.draw do
namespace :panel do namespace :panel do
namespace :personal_journal do namespace :personal_journal do
namespace :desktop do namespace :desktop do
match 'journal_p'=>'journal_p#journal_p' match 'journal_window'=>'journal_windows#journal_window'
match 'get_journals_json' => 'journal_pages#get_journals_json' match 'get_journals_json' => 'journal_pages#get_journals_json'
match 'journal_type' => 'journal_pages#journal_type' match 'journal_type' => 'journal_pages#journal_type'
resources :journal_pages, except: :show resources :journal_pages, except: :show