From 7bf694f7175d3dec587fbe7e713a62fd2560bc5b Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Mon, 21 Mar 2016 16:39:54 +0800 Subject: [PATCH] fields modification implemented --- ...ersonal_technology_transfers_controller.rb | 101 ++++++++++++++++++ ...sersonal_technolgy_transfers_controller.rb | 47 -------- app/models/technology_transfer.rb | 35 +++--- .../get_fields_for_index.html.erb | 48 +++++++++ config/routes.rb | 2 + lib/personal_technology_transfer/engine.rb | 2 +- 6 files changed, 174 insertions(+), 61 deletions(-) create mode 100644 app/controllers/personal_technology_transfers_controller.rb delete mode 100644 app/controllers/psersonal_technolgy_transfers_controller.rb create mode 100644 app/views/personal_technology_transfers/get_fields_for_index.html.erb diff --git a/app/controllers/personal_technology_transfers_controller.rb b/app/controllers/personal_technology_transfers_controller.rb new file mode 100644 index 0000000..52eb9f3 --- /dev/null +++ b/app/controllers/personal_technology_transfers_controller.rb @@ -0,0 +1,101 @@ +class PersonalTechnologyTransfersController < ApplicationController + def index + params = OrbitHelper.params + tts = TechnologyTransfer.where(:is_hidden=>false).order_by(:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) + fields_to_show = Page.where(:page_id => params[:page_id]).first.custom_array_field rescue [] + + if fields_to_show.blank? + fields_to_show = [ + "year", + "title", + "patent_title", + "category", + "patent_granted", + "patent_number", + "authors" + ] + end + + tts_list = [] + + tts.each do |tt| + t = [] + fields_to_show.each do |fs| + case fs + when "title" + t << {"value" => "" + (tt.send(fs) rescue "") + ""} + when "category" + t << {"value" => (tt.send("technology_transfer_category").title rescue "")} + when "authors" + t << {"value" => (tt.send(:member_profile).name rescue "")} + else + t << {"value" => (tt.send(fs) rescue "")} + end + end + tts_list << {"technology_transfers" => 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_technology_transfer.#{fs}") + headers << { + "head-title" => header, + "col" => col + } + end + { + "tts" => tts_list, + "extras" => { "widget-title" => t("module_name.personal_technology_transfer")}, + "headers" => headers, + "total_pages" => tts.total_pages + } + end + + def show + params = OrbitHelper.params + plugin = TechnologyTransfer.where(:is_hidden=>false).find_by(uid: params[:uid]) + fields_to_show = [ + "year", + "title", + "patent_title", + "category", + "patent_granted", + "patent_number", + "authors" + ] + + {"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", + "title", + "patent_title", + "category", + "patent_granted", + "patent_number", + "authors" + ] + @fields_to_show = @fields_to_show.map{|fs| [(fs == "authors" ? t("users.name") : t("personal_technology_transfer.#{fs}")), fs]} + @default_fields_to_show = [ + "category", + "year", + "title", + "patent_granted", + "patent_title", + "patent_number" + ] + 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/controllers/psersonal_technolgy_transfers_controller.rb b/app/controllers/psersonal_technolgy_transfers_controller.rb deleted file mode 100644 index 9ac4e71..0000000 --- a/app/controllers/psersonal_technolgy_transfers_controller.rb +++ /dev/null @@ -1,47 +0,0 @@ -class PersonalTechnologyTransfersController < ApplicationController - def index - tts = TechnologyTransfer.where(:is_hidden=>false).order_by(:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) - tts_list = tts.collect do |tt| - { - "year" => tt.year, - "title" => tt.title, - "patent_title" => tt.patent_title, - "category" => (tt.technology_transfer_category.title rescue ""), - "patent_granted" => (tt.patent_granted ? "Yes" : "No"), - "patent_number" => tt.patent_number, - "authors" => (tt.member_profile.name rescue ""), - "link_to_show" => OrbitHelper.url_to_show(tt.to_param) - } - end - { - "tts" => tts_list, - "extras" => { - "widget-title" => t("module_name.personal_technology_transfer"), - "th_year" => t('personal_technology_transfer.year'), - "th_title" => t("personal_technology_transfer.title"), - "th_category" => t("personal_technology_transfer.category"), - "th_patent_title" => t("personal_technology_transfer.patent_title"), - "th_patent_granted" => t("personal_technology_transfer.patent_granted"), - "th_patent_number" => t("personal_technology_transfer.patent_number"), - "th_authors" => t('users.name') - }, - "total_pages" => tts.total_pages - } - end - - def show - params = OrbitHelper.params - plugin = TechnologyTransfer.where(:is_hidden=>false).find_by(uid: params[:uid]) - fields_to_show = [ - "year", - "title", - "patent_title", - "technology_transfer_category", - "patent_granted", - "patent_number", - "authors" - ] - - {"plugin_datas"=>plugin.get_plugin_data(fields_to_show)} - end -end \ No newline at end of file diff --git a/app/models/technology_transfer.rb b/app/models/technology_transfer.rb index 5641b20..696ca47 100644 --- a/app/models/technology_transfer.rb +++ b/app/models/technology_transfer.rb @@ -18,21 +18,28 @@ class TechnologyTransfer scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year =>'desc') } def self.get_plugin_datas_to_member(datas) - - fields_to_show = [ - "technology_transfer_category", - "year", - "title", - "patent_granted", - "patent_title", - "patent_number" - ] + page = Page.where(:module => "personal_technology_transfer").first rescue nil + + if !page.nil? && !page.custom_array_field.blank? + fields_to_show = page.custom_array_field + else + fields_to_show = [ + "category", + "year", + "title", + "patent_granted", + "patent_title", + "patent_number", + "authors" + ] + end fields_to_remove = [] pd_title = [] fields_to_show.each do |t| + t = "technology_transfer_category" if t == "category" if (self.fields[t].type.to_s == "String" || self.fields[t].type.to_s == "Object" rescue false) fields_to_remove << t if (datas.where(t.to_sym.ne => nil, t.to_sym.ne => "").count == 0 rescue false) else @@ -50,11 +57,13 @@ class TechnologyTransfer pd_data = [] fields_to_show.collect do |t| if t == "title" - pd_data << { "data_title" => "#{p.send(t)}" } - elsif t == "technology_transfer_category" - pd_data << {"data_title" => (p.technology_transfer_category.title rescue "")} + pd_data << { "data_title" => "#{p.send(t)}" } + elsif t == "category" + pd_data << {"data_title" => (p.technology_transfer_category.title rescue "")} elsif t == "patent_granted" - pd_data << {"data_title" => (p.patent_granted ? "Yes" : "No")} + pd_data << {"data_title" => (p.patent_granted ? "Yes" : "No")} + elsif t == "authors" + pd_data << {"data_title" => (p.member_profile.name rescue "")} else pd_data << { "data_title" => p.send(t) } end diff --git a/app/views/personal_technology_transfers/get_fields_for_index.html.erb b/app/views/personal_technology_transfers/get_fields_for_index.html.erb new file mode 100644 index 0000000..5ca9e0e --- /dev/null +++ b/app/views/personal_technology_transfers/get_fields_for_index.html.erb @@ -0,0 +1,48 @@ +<% if !@page.nil? %> +
+
+
    + <% if @page.custom_array_field.blank? %> + <% @default_fields_to_show.each do |fs| %> +
  • <%= t("personal_technology_transfer.#{fs}") %>
  • + <% end %> + <% else %> + <% @page.custom_array_field.each do |fs| %> +
  • <%= t("personal_technology_transfer.#{fs}") %>
  • + <% end %> + <% end %> +
+
+ +
+
+ +<% else %> +

Page not found.

+<% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 00581b5..91ec309 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,5 +24,7 @@ Rails.application.routes.draw do resources :technology_transfer_categories post "technology_transfer_categories/update_order" => "technology_transfer_categories#update_order" end + get "/xhr/personal_technology_transfer/get_fields_for_index" => "personal_technology_transfers#get_fields_for_index" + post "/xhr/personal_technology_transfer/save_index_fields" => "personal_technology_transfers#save_index_fields" end end diff --git a/lib/personal_technology_transfer/engine.rb b/lib/personal_technology_transfer/engine.rb index 81d68a5..b2da652 100644 --- a/lib/personal_technology_transfer/engine.rb +++ b/lib/personal_technology_transfer/engine.rb @@ -4,7 +4,7 @@ module PersonalTechnologyTransfer OrbitApp.registration "PersonalTechnologyTransfer",:type=> 'ModuleApp' do module_label 'module_name.technology_transfers' base_url File.expand_path File.dirname(__FILE__) - personal_plugin :enable => true, :sort_number => '35', :app_name=>"TechnologyTransfer", :intro_app_name=>"TechnologyTransferIntro",:path=>"/plugin/personal_technology_transfer/profile",:front_path=>"/profile",:admin_path=>"/admin/technology_transfers/",:i18n=>'module_name.technology_transfers', :module_app_name=>'TechnologyTransfer' + personal_plugin :enable => true, :sort_number => '35', :app_name=>"TechnologyTransfer", :intro_app_name=>"TechnologyTransferIntro",:path=>"/plugin/personal_technology_transfer/profile",:front_path=>"/profile",:admin_path=>"/admin/technology_transfers/",:i18n=>'module_name.technology_transfers', :module_app_name=>'TechnologyTransfer', :field_modifiable => true version "0.1" desktop_enabled true