From 33acff9f10eaf4176f6ba10fb30c95d16912c3df Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Tue, 22 Mar 2016 17:58:37 +0800 Subject: [PATCH] now can select between one line and table --- .../personal_journals_controller.rb | 59 +++++++++++++++---- app/models/journal_paper.rb | 39 +++++++++--- lib/personal_journal/engine.rb | 2 +- 3 files changed, 81 insertions(+), 19 deletions(-) diff --git a/app/controllers/personal_journals_controller.rb b/app/controllers/personal_journals_controller.rb index b85f38f..9219f3e 100644 --- a/app/controllers/personal_journals_controller.rb +++ b/app/controllers/personal_journals_controller.rb @@ -1,21 +1,58 @@ class PersonalJournalsController < ApplicationController def index + params = OrbitHelper.params 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.create_link, - "link_to_show" => OrbitHelper.url_to_show(journal_paper.to_param) + page = Page.where(:page_id => params[:page_id]).first rescue nil + if page.custom_string_field == "table" + fields_to_show = [ + "paper_title", + "journal_title", + "authors", + "year", + "issue_no", + "vol_no", + "level_type" + ] + else + fields_to_show = [ + "year", + "paper_title" + ] + end + journal_paper_list = [] + journal_papers.each do |journal_paper| + t = [] + fields_to_show.each do |fs| + case fs + when "paper_title" + if page.custom_string_field == "table" + t << {"value" => "#{journal_paper.paper_title}"} + else + t << {"value" => "#{journal_paper.create_link}"} + end + when "level_type" + t << {"value" => ( !journal_paper.journal_levels.blank? ? "(#{journal_paper.journal_levels.collect{|x| x.title}.join(', ')})" : nil)} + else + t << {"value" => journal_paper.send(fs)} + end + end + journal_paper_list << {"jps" => t} + end + + headers = [] + fields_to_show.each do |fs| + col = 2 + col = 3 if fs == "paper_title" + headers << { + "head-title" => t("personal_journal.#{fs}"), + "col" => col } 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') - }, + "headers" => headers, + "extras" => {"widget-title" => t("module_name.journal_paper")}, "total_pages" => journal_papers.total_pages } end diff --git a/app/models/journal_paper.rb b/app/models/journal_paper.rb index 78e138f..fb8e694 100644 --- a/app/models/journal_paper.rb +++ b/app/models/journal_paper.rb @@ -70,10 +70,24 @@ class JournalPaper end def self.get_plugin_datas_to_member(datas) - fields_to_show = [ - "year", - "paper_title" - ] + page = Page.where(:module => "personal_journal").first rescue nil + + if page.custom_string_field == "table" + fields_to_show = [ + "paper_title", + "journal_title", + "authors", + "year", + "issue_no", + "vol_no", + "level_type" + ] + else + fields_to_show = [ + "year", + "paper_title" + ] + end fields_to_remove = [] @@ -96,10 +110,21 @@ class JournalPaper pd_data = [] fields_to_show.collect do |t| - if t == "paper_title" - pd_data << { "data_title" => "#{p.create_link}" } + if page.custom_string_field == "table" + case t + when "paper_title" + pd_data << { "data_title" => "#{p.paper_title}" } + when "level_type" + pd_data << {"data_title" => ( !p.journal_levels.blank? ? "(#{p.journal_levels.collect{|x| x.title}.join(', ')})" : nil)} + else + pd_data << {"data_title" => p.send(t)} + end else - pd_data << { "data_title" => p.send(t) } + if t == "paper_title" + pd_data << { "data_title" => "#{p.create_link}" } + else + pd_data << { "data_title" => p.send(t) } + end end end diff --git a/lib/personal_journal/engine.rb b/lib/personal_journal/engine.rb index 9ceeb58..ae24e7a 100644 --- a/lib/personal_journal/engine.rb +++ b/lib/personal_journal/engine.rb @@ -4,7 +4,7 @@ module PersonalJournal OrbitApp.registration "PersonalJournal",:type=> 'ModuleApp' do module_label 'module_name.journal_paper' base_url File.expand_path File.dirname(__FILE__) - personal_plugin :enable => true, :sort_number => '5', :app_name=>"JournalPaper", :intro_app_name=>"JournalPaperlIntro",:path=>"/plugin/personal_journal/profile",:front_path=>"/profile",:admin_path=>"/admin/journal_papers/",:i18n=>'module_name.journal_paper', :module_app_name=>'PersonalJournal' + personal_plugin :enable => true, :sort_number => '5', :app_name=>"JournalPaper", :intro_app_name=>"JournalPaperlIntro",:path=>"/plugin/personal_journal/profile",:front_path=>"/profile",:admin_path=>"/admin/journal_papers/",:i18n=>'module_name.journal_paper', :module_app_name=>'PersonalJournal', :one_line_title => true version "0.1" desktop_enabled true