diff --git a/app/controllers/personal_patents_controller.rb b/app/controllers/personal_patents_controller.rb index e6eb282..c171c25 100644 --- a/app/controllers/personal_patents_controller.rb +++ b/app/controllers/personal_patents_controller.rb @@ -1,26 +1,55 @@ class PersonalPatentsController < ApplicationController def index + params = OrbitHelper.params patents = Patent.where(:is_hidden=>false).order_by(:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) - patent_list = patents.collect do |patent| - { - "publication_date" => patent.publish_date, - "patent_title" => patent.patent_title, - "patent_no" => patent.patent_no, - "patent_country" => patent.patent_country, - "authors" => (patent.member_profile.name rescue ""), - "link_to_show" => OrbitHelper.url_to_show(patent.to_param) + fields_to_show = Page.where(:page_id => params[:page_id]).first.custom_array_field rescue [] + if fields_to_show.blank? + fields_to_show = [ + "publish_date", + "patent_title", + "patent_no", + "patent_country", + "authors" + ] + end + patent_list = [] + patents.each do |patent| + t = [] + fields_to_show.each do |fs| + case fs + when "title" + t << {"value" => "" + (patent.send(fs) rescue "") + ""} + when "publish_date" + t << {"value" => (patent.publish_date.strftime("%Y/%m/%d") rescue "")} + when "application_date" + t << {"value" => (patent.application_date.strftime("%Y/%m/%d") rescue "")} + when "end_date" + t << {"value" => (patent.end_date.strftime("%Y/%m/%d") rescue "")} + when "patent_category" + t << {"value" => (patent.patent_types.collect{|pt| pt.title}.join(", ") rescue "")} + when "author_type" + t << {"value" => (patent.patent_author_types.collect{|pt| pt.title}.join(", ") rescue "")} + else + t << {"value" => patent.send(fs)} + end + end + patent_list << {"patent_list" => t} + end + + headers = [] + fields_to_show.each do |fs| + col = 2 + col = 3 if fs == "patent_title" + header = fs == "authors" ? t("users.name") : t("personal_patent.#{fs}") + headers << { + "head-title" => header, + "col" => col } end { "patents" => patent_list, - "extras" => { - "widget-title" => t("module_name.personal_patent"), - "th_publication_date" => t('personal_patent.publication_date'), - "th_patent_title" => t("personal_patent.patent_title"), - "th_patent_no" => t('personal_patent.patent_no'), - "th_patent_country" => t("personal_patent.patent_country"), - "th_authors" => t('users.name') - }, + "extras" => { "widget-title" => t("module_name.personal_patent") }, + "headers" => headers, "total_pages" => patents.total_pages } end @@ -34,8 +63,14 @@ class PersonalPatentsController < ApplicationController "publish_date", "patent_title", "patent_no", + "patent_organization", + "progress_status", + "application_date", + "end_date", + "publish_date", "patent_country", "authors", + "author_type", "url", "language", "keywords", @@ -45,4 +80,44 @@ class PersonalPatentsController < 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 = [ + "patent_category", + "year", + "publish_date", + "patent_title", + "patent_no", + "patent_organization", + "progress_status", + "application_date", + "end_date", + "publish_date", + "author_type", + "patent_country", + "authors", + "url", + "language", + "keywords", + "note" + ] + @fields_to_show = @fields_to_show.map{|fs| [(fs == "authors" ? t("users.name") : t("personal_patent.#{fs}")), fs]} + @default_fields_to_show = [ + "publish_date", + "patent_title", + "patent_no", + "patent_country", + "authors" + ] + 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 \ No newline at end of file diff --git a/app/models/patent.rb b/app/models/patent.rb index b721d28..565dc18 100644 --- a/app/models/patent.rb +++ b/app/models/patent.rb @@ -47,14 +47,19 @@ class Patent end def self.get_plugin_datas_to_member(datas) - - fields_to_show = [ - "publish_date", - "patent_title", - "patent_no", - "patent_country", - "authors" - ] + page = Page.where(:module => "personal_patent").first rescue nil + + if !page.nil? && !page.custom_array_field.blank? + fields_to_show = page.custom_array_field + else + fields_to_show = [ + "publish_date", + "patent_title", + "patent_no", + "patent_country", + "authors" + ] + end fields_to_remove = [] @@ -64,7 +69,11 @@ class Patent if (self.fields[t].type.to_s == "String" rescue false) fields_to_remove << t if (datas.where(t.to_sym.ne => nil).or(t.to_sym.ne => "").count == 0 rescue false) else + t = "patent_types" if t == "patent_category" + t = "patent_author_types" if t == "author_type" fields_to_remove << t if (datas.where(t.to_sym.ne => nil).count == 0 rescue false) + t = "patent_category" if t == "patent_types" + t = "author_type" if t == "patent_author_types" end pd_title << { "plugin_data_title" => I18n.t("personal_patent.#{t}") @@ -77,10 +86,21 @@ class Patent pd_data = [] fields_to_show.collect do |t| - if t == "patent_title" - pd_data << { "data_title" => "#{p.send(t)}" } - else - pd_data << { "data_title" => p.send(t) } + case t + when "title" + pd_data << {"data_title" => "" + (p.send(fs) rescue "") + ""} + when "publish_date" + pd_data << {"data_title" => (p.publish_date.strftime("%Y/%m/%d") rescue "")} + when "application_date" + pd_data << {"data_title" => (p.application_date.strftime("%Y/%m/%d") rescue "")} + when "end_date" + pd_data << {"data_title" => (p.end_date.strftime("%Y/%m/%d") rescue "")} + when "patent_category" + pd_data << {"data_title" => (p.patent_types.collect{|pt| pt.title}.join(", ") rescue "")} + when "author_type" + pd_data << {"data_title" => (p.patent_author_types.collect{|pt| pt.title}.join(", ") rescue "")} + else + pd_data << {"data_title" => p.send(t)} end end @@ -100,6 +120,14 @@ class Patent value = self.patent_types.collect{|patent_type| patent_type.title}.join(',') rescue "" when "language" value = I18n.t(self.language) if !self.language.nil? rescue "" + when "publish_date" + value = self.publish_date.strftime("%Y/%m/%d") rescue "" + when "application_date" + value = self.application_date.strftime("%Y/%m/%d") rescue "" + when "end_date" + value = self.end_date.strftime("%Y/%m/%d") rescue "" + when "author_type" + value = self.patent_author_types.collect{|pt| pt.title}.join(", ") rescue "" when "file" files = [] self.patent_files.each do |patent_file| diff --git a/app/views/personal_patents/get_fields_for_index.html.erb b/app/views/personal_patents/get_fields_for_index.html.erb new file mode 100644 index 0000000..f1e46bb --- /dev/null +++ b/app/views/personal_patents/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 5ac5d3f..47d9bc5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -27,5 +27,7 @@ Rails.application.routes.draw do resources :patent_types end + get "/xhr/personal_patent/get_fields_for_index" => "personal_patents#get_fields_for_index" + post "/xhr/personal_patent/save_index_fields" => "personal_patents#save_index_fields" end end diff --git a/lib/personal_patent/engine.rb b/lib/personal_patent/engine.rb index 0192133..d99a86d 100644 --- a/lib/personal_patent/engine.rb +++ b/lib/personal_patent/engine.rb @@ -4,7 +4,7 @@ module PersonalPatent OrbitApp.registration "PersonalPatent",:type=> 'ModuleApp' do module_label 'module_name.personal_patent' base_url File.expand_path File.dirname(__FILE__) - personal_plugin :enable => true, :sort_number => '35', :app_name=>"Patent", :intro_app_name=>"PersonalPatentIntro",:path=>"/plugin/personal_patent/profile",:front_path=>"/profile",:admin_path=>"/admin/patents",:i18n=>'module_name.personal_patent', :module_app_name=>"PersonalPatent" + personal_plugin :enable => true, :sort_number => '35', :app_name=>"Patent", :intro_app_name=>"PersonalPatentIntro",:path=>"/plugin/personal_patent/profile",:front_path=>"/profile",:admin_path=>"/admin/patents",:i18n=>'module_name.personal_patent', :module_app_name=>"PersonalPatent", :field_modifiable => true version "0.1" desktop_enabled true @@ -13,9 +13,9 @@ module PersonalPatent intro "I am intro" update_info 'some update_info' - frontend_enabled - icon_class_no_sidebar "icons-user" - data_count 1..10 + frontend_enabled + icon_class_no_sidebar "icons-user" + data_count 1..10 end end end