From 98ce21d67e5161457c6d02e61f754302ad2c189d Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Tue, 22 Mar 2016 18:00:05 +0800 Subject: [PATCH] can select one line and table --- .../personal_conferences_controller.rb | 60 +++++++++++++++---- app/models/writing_conference.rb | 40 ++++++++++--- config/locales/en.yml | 2 + config/locales/zh_tw.yml | 2 + lib/personal_conference/engine.rb | 2 +- 5 files changed, 87 insertions(+), 19 deletions(-) diff --git a/app/controllers/personal_conferences_controller.rb b/app/controllers/personal_conferences_controller.rb index 70b1af3..c705932 100644 --- a/app/controllers/personal_conferences_controller.rb +++ b/app/controllers/personal_conferences_controller.rb @@ -1,22 +1,60 @@ class PersonalConferencesController < ApplicationController def index + params = OrbitHelper.params writing_conferences = WritingConference.where(:is_hidden=>false).order_by(:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) + page = Page.where(:page_id => params[:page_id]).first rescue nil + if page.custom_string_field == "table" + fields_to_show = [ + "authors", + "paper_title", + "conference_title", + "location", + "paper_types", + "paper_levels" + ] + else + fields_to_show = [ + "year", + "paper_title" + ] + end - writing_conference_list = writing_conferences.collect do |writing_conference| - { - "year" => writing_conference.year, - "paper_title" => writing_conference.create_link, - "link_to_show" => OrbitHelper.url_to_show(writing_conference.to_param) + writing_conference_list = [] + writing_conferences.each do |writing_conference| + t = [] + fields_to_show.each do |fs| + case fs + when "paper_title" + if page.custom_string_field == "table" + t << {"value" => "#{writing_conference.paper_title}"} + else + t << {"value" => "#{writing_conference.create_link}"} + end + when "paper_levels" + t << {"value" => ( !writing_conference.conference_paper_levels.blank? ? "(#{writing_conference.conference_paper_levels.collect{|x| x.title}.join(', ')})" : nil)} + when "paper_types" + t << {"value" => ( !writing_conference.conference_paper_levels.blank? ? "(#{writing_conference.conference_paper_levels.collect{|x| x.title}.join(', ')})" : nil)} + else + t << {"value" => writing_conference.send(fs)} + end + end + writing_conference_list << {"cps" => t} + end + + headers = [] + fields_to_show.each do |fs| + col = 2 + col = 3 if fs == "paper_title" + headers << { + "head-title" => t("personal_conference.#{fs}"), + "col" => col } end + { "writing_conferences" => writing_conference_list, - "extras" => { - "widget-title" => t("module_name.personal_conference"), - "th_year" => t('personal_plugins.year'), - "th_title" => t("personal_conference.paper_title"), - "th_author" => t('personal_plugins.author') - }, + "extras" => { "widget-title" => t("module_name.personal_conference") }, + "headers" => headers, "total_pages" => writing_conferences.total_pages } end diff --git a/app/models/writing_conference.rb b/app/models/writing_conference.rb index f4680c9..bd7af37 100644 --- a/app/models/writing_conference.rb +++ b/app/models/writing_conference.rb @@ -64,12 +64,25 @@ class WritingConference title.join(', ') end + def self.get_plugin_datas_to_member(datas) - fields_to_show = [ - "year", - "paper_title" - ] + page = Page.where(:module => "personal_conference").first rescue nil + if page.custom_string_field == "table" + fields_to_show = [ + "authors", + "paper_title", + "conference_title", + "location", + "paper_types", + "paper_levels" + ] + else + fields_to_show = [ + "year", + "paper_title" + ] + end fields_to_remove = [] @@ -92,10 +105,23 @@ class WritingConference 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 "paper_types" + pd_data << {"data_title" => ( !p.conference_paper_types.blank? ? p.conference_paper_types.collect{|x| x.title}.join(', ') : "")} + when "paper_levels" + pd_data << {"data_title" => ( !p.conference_paper_levels.blank? ? p.conference_paper_levels.collect{|x| x.title}.join(', ') : "")} + 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/config/locales/en.yml b/config/locales/en.yml index c5b7b38..0c12e04 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -9,6 +9,8 @@ en: paper_title : "Paper Title" paper_type : "Paper Type" paper_level : "Paper Level" + paper_types : "Paper Type" + paper_levels : "Paper Level" conference_title : "Conference Name" conference_time: "Conference Time" period_start_date : "Start Date" diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 4438bc2..a1db55e 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -8,6 +8,8 @@ zh_tw: paper_title : "論文名稱" paper_type : "論文類型" paper_level: "論文等級" + paper_types : "論文類型" + paper_levels: "論文等級" conference_title : "會議名稱" conference_time: "會議時間" period_start_date : "會議開始時間" diff --git a/lib/personal_conference/engine.rb b/lib/personal_conference/engine.rb index 1af46fc..8825934 100644 --- a/lib/personal_conference/engine.rb +++ b/lib/personal_conference/engine.rb @@ -4,7 +4,7 @@ module PersonalConference OrbitApp.registration "PersonalConference",:type=> 'ModuleApp' do module_label 'module_name.personal_conference' base_url File.expand_path File.dirname(__FILE__) - personal_plugin :enable => true, :sort_number => '6', :app_name=>"WritingConference", :intro_app_name=>"PersonalConferenceIntro",:path=>"/plugin/personal_conference/profile",:front_path=>"/profile",:admin_path=>"/admin/writing_conferences",:i18n=>'module_name.personal_conference', :module_app_name=>'PersonalConference' + personal_plugin :enable => true, :sort_number => '6', :app_name=>"WritingConference", :intro_app_name=>"PersonalConferenceIntro",:path=>"/plugin/personal_conference/profile",:front_path=>"/profile",:admin_path=>"/admin/writing_conferences",:i18n=>'module_name.personal_conference', :module_app_name=>'PersonalConference', :one_line_title => true version "0.1" desktop_enabled true