diff --git a/app/controllers/journal_papers_controller.rb b/app/controllers/journal_papers_controller.rb index c12d904..0b419e7 100644 --- a/app/controllers/journal_papers_controller.rb +++ b/app/controllers/journal_papers_controller.rb @@ -1,53 +1,50 @@ class JournalPapersController < ApplicationController def index - journal_papers = JournalPaper.where(:is_hidden=>false).order_by(:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) - journal_paper_list = journal_papers.collect do |journal_paper| - { + journal_papers = JournalPaper.where(:is_hidden=>false).order_by(:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) + journal_paper_list = journal_papers.collect do |journal_paper| + { "year" => journal_paper.year, - "paper_title" => journal_paper.paper_title, - "author" => journal_paper.authors, - "link_to_show" => OrbitHelper.url_to_show(journal_paper.to_param) - } - end - { - "journal_papers" => journal_paper_list, - "extras" => { + "paper_title" => journal_paper.create_link, + "author" => journal_paper.authors, + "link_to_show" => OrbitHelper.url_to_show(journal_paper.to_param) + } + end + { + "journal_papers" => journal_paper_list, + "extras" => { "widget-title" => t("module_name.journal_paper"), "th_year" => t('personal_plugins.year'), "th_title" => t("personal_conference.paper_title"), "th_author" => t('personal_plugins.author') }, "total_pages" => journal_papers.total_pages - } + } end def show params = OrbitHelper.params - journal_paper = JournalPaper.find_by(uid: params[:uid]) - field_to_show = ["year", "language", "vol_no", "issue_no", "form_to_start", "form_to_end", "total_pages", "isbn", "publication_date", "url", "note", "journal_title", "paper_title", "updated_at", "created_at", "uid", "journal_level_ids", "journal_paper_author_type_ids", "member_profile_id"] + plugin = JournalPaper.find_by(uid: params[:uid]) + fields_to_show = [ + "paper_title", + "journal_title", + "level_type", + "paper_type", + "authors", + "author_type", + "year", + "publication_date", + "language", + "vol_no", + "issue_no", + "form_to_start", + "form_to_end", + "total_pages", + "isbn", + "url", + "note", + "file" + ] - publication_date = journal_paper.publication_date.to_date.strftime("%Y/%m/%d") rescue nil - files = journal_paper.journal_paper_files.map{|file| { "file_url" => file.journal_file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title) } } rescue [] - { - "journal_paper_files" => files, - "data" => { - "title" => journal_paper.paper_title, - "journal_title" => journal_paper.journal_title, - "year" => journal_paper.year, - "authors" => journal_paper.authors, - "isbn" => journal_paper.isbn, - "vol_no" => journal_paper.vol_no, - "issue_no" => journal_paper.issue_no, - "form_to_start" => journal_paper.form_to_start, - "form_to_end" => journal_paper.form_to_end, - "language" => journal_paper.language, - "total_pages" => journal_paper.total_pages, - "keywords" => journal_paper.keywords, - "abstract" => journal_paper.abstract, - "publication_date" => publication_date, - "url" => journal_paper.url, - "note" => journal_paper.note - } - } + {"plugin_datas"=>plugin.get_plugin_data(fields_to_show)} end end diff --git a/app/models/journal_paper.rb b/app/models/journal_paper.rb index ba481ac..39426e4 100644 --- a/app/models/journal_paper.rb +++ b/app/models/journal_paper.rb @@ -65,7 +65,7 @@ class JournalPaper def authors authors = [] authors << self.member_profile.name if self.member_profile_id.present? - authors << (!self.journal_paper_authors.blank? ? "#{self.journal_paper_authors.collect{|j| j.name}.join(', ')}" : nil) + authors << self.journal_paper_authors.collect{|j| j.name}.join(', ') unless self.journal_paper_authors.blank? authors.join(', ') end @@ -98,14 +98,47 @@ class JournalPaper end end - def values_for_view - attribute_values = self.attributes.select{|k,v| v if (k.in?(["year","language","isbn","vol_no","issue_no","form_to_start","form_to_end","total_pages","keywords","abstract","publication_date","url","note"]) && v.present?)} - localized_fields = {"paper_title" => self.attributes["paper_title"][I18n.locale], "journal_title" => self.attributes["journal_title"][I18n.locale]} - authors = {"authors" => self.authors} - files = {} - files = self.journal_paper_files.collect do |f| {f.title => url_to_file(f.journal_file.url, f.title)} end - values = [attribute_values, localized_fields, authors] + files - values.inject(&:merge) + def get_plugin_data(fields_to_show) + plugin_datas = [] + fields_to_show.each do |field| + plugin_data = self.get_plugin_field_data(field) + next if plugin_data.blank? or plugin_data['value'].blank? + plugin_datas << plugin_data + end + plugin_datas + end + + def get_plugin_field_data(field) + case field + when "level_type" + value = self.journal_levels.collect{|level| level.title}.join(',') rescue "" + when "author_type" + value = self.journal_paper_author_types.collect{|type| type.title}.join(',') rescue "" + when "paper_type" + value = self.journal_paper_type.title rescue "" + when "publication_date" + value = self.publication_date.to_date.strftime("%Y-%m-%d") rescue "" + when "language" + value = I18n.t(self.language) rescue "" + when "file" + files = [] + self.journal_paper_files.each do |file| + url = file.journal_file.url + title = (file.title.blank? ? File.basename(file.journal_file.path) : file.title) + files << "