diff --git a/app/controllers/personal_journals_controller.rb b/app/controllers/personal_journals_controller.rb index 9219f3e..4a0a6b6 100644 --- a/app/controllers/personal_journals_controller.rb +++ b/app/controllers/personal_journals_controller.rb @@ -4,6 +4,7 @@ class PersonalJournalsController < ApplicationController journal_papers = JournalPaper.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 = page.custom_array_field rescue [] fields_to_show = [ "paper_title", "journal_title", @@ -12,7 +13,7 @@ class PersonalJournalsController < ApplicationController "issue_no", "vol_no", "level_type" - ] + ] if fields_to_show.blank? else fields_to_show = [ "year", @@ -32,6 +33,8 @@ class PersonalJournalsController < ApplicationController end when "level_type" t << {"value" => ( !journal_paper.journal_levels.blank? ? "(#{journal_paper.journal_levels.collect{|x| x.title}.join(', ')})" : nil)} + when "publication_date" + t << {"value" => (journal_paper.send(fs).strftime("%Y/%m/%d") rescue "")} else t << {"value" => journal_paper.send(fs)} end @@ -84,4 +87,44 @@ class PersonalJournalsController < ApplicationController {"plugin_datas"=>plugin.get_plugin_data(fields_to_show)} end + def get_fields_for_index + @page = Page.find(params[:page_id]) rescue nil + @fields_to_show = [ + "year", + "authors", + "author_type", + "paper_title", + "journal_title", + "vol_no", + "issue_no", + "form_to_start", + "form_to_end", + "level_type", + "paper_type", + "total_pages", + "publication_date", + "isbn", + "abstract", + "language", + "url" + ] + @fields_to_show = @fields_to_show.map{|fs| [t("personal_journal.#{fs}"), fs]} + @default_fields_to_show = [ + "paper_title", + "journal_title", + "authors", + "year", + "issue_no", + "vol_no", + "level_type" + ] + render :layout => false + end + + def save_index_fields + page = Page.find(params[:page_id]) rescue nil + page.custom_array_field = params[:keys] + page.save + render :json => {"success" => true}.to_json + end end diff --git a/app/models/journal_paper.rb b/app/models/journal_paper.rb index d682197..b223334 100644 --- a/app/models/journal_paper.rb +++ b/app/models/journal_paper.rb @@ -73,15 +73,19 @@ class JournalPaper page = Page.where(:module => "personal_journal").first rescue nil if !page.nil? && page.custom_string_field == "table" - fields_to_show = [ - "paper_title", - "journal_title", - "authors", - "year", - "issue_no", - "vol_no", - "level_type" - ] + if !page.custom_array_field.blank? + fields_to_show = page.custom_array_field + else + fields_to_show = [ + "paper_title", + "journal_title", + "authors", + "year", + "issue_no", + "vol_no", + "level_type" + ] + end else fields_to_show = [ "year", @@ -116,6 +120,8 @@ class JournalPaper 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)} + when "publication_date" + pd_data << {"data_title" => (p.send(t).strftime("%Y/%m/%d") rescue "")} else pd_data << {"data_title" => p.send(t)} end @@ -183,6 +189,8 @@ class JournalPaper 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 = p.send(t).strftime("%Y/%m/%d") rescue "" when "author_name" value = [] ([I18n.locale]+(Site.first.in_use_locales-[I18n.locale])).each do |locale| diff --git a/app/views/personal_journals/get_fields_for_index.html.erb b/app/views/personal_journals/get_fields_for_index.html.erb new file mode 100644 index 0000000..7a3da03 --- /dev/null +++ b/app/views/personal_journals/get_fields_for_index.html.erb @@ -0,0 +1,48 @@ +<% if !@page.nil? %> +
+
+ +
+ +
+ +
+ +
+ <%= select_tag "fields_to_show_for_pp", options_for_select(@fields_to_show), prompt: "---Select something---" %> +
+
+ Add Field + + +
+
+ +<% else %> +

Page not found.

+<% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index cfd2b9b..e6262e3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -30,5 +30,7 @@ Rails.application.routes.draw do resources :journal_paper_types resources :journal_paper_intros end + get "/xhr/personal_journal/get_fields_for_index" => "personal_journals#get_fields_for_index" + post "/xhr/personal_journal/save_index_fields" => "personal_journals#save_index_fields" end end diff --git a/lib/personal_journal/engine.rb b/lib/personal_journal/engine.rb index ae24e7a..c864d94 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', :one_line_title => true + 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, :field_modifiable => true version "0.1" desktop_enabled true