From 90342045db02e3fa5784cb832f1ca78af9157152 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Sat, 19 Mar 2016 02:06:06 +0800 Subject: [PATCH] modified for index show fields --- .../personal_projects_controller.rb | 141 ++++++++++-------- app/models/project.rb | 24 +-- .../get_fields_for_index.html.erb | 48 ++++++ config/routes.rb | 2 + lib/personal_project/engine.rb | 2 +- 5 files changed, 143 insertions(+), 74 deletions(-) create mode 100644 app/views/personal_projects/get_fields_for_index.html.erb diff --git a/app/controllers/personal_projects_controller.rb b/app/controllers/personal_projects_controller.rb index 8a25308..c3a1b5b 100644 --- a/app/controllers/personal_projects_controller.rb +++ b/app/controllers/personal_projects_controller.rb @@ -1,30 +1,49 @@ class PersonalProjectsController < ApplicationController def index + params = OrbitHelper.params projects = Project.where(:is_hidden=>false).order_by(:period_start_date=>'desc',:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) - project_list = projects.collect do |project| - { - "year" => project.year, - "duration" => project.duration, - "project_title" => project.project_title, - "job_title" => project.job_title, - "participator" => project.participator, - "unit" => project.unit, - "authors" => (project.member_profile.name rescue ""), - "link_to_show" => OrbitHelper.url_to_show(project.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 = [ + "project_type", + "year", + "project_title", + "participator", + "job_title", + "period", + "unit" + ] + end + + project_list = [] + projects.each do |project| + t = [] + fields_to_show.each do |fs| + case fs + when "project_type" + t << {"value" => (project.send(fs).title rescue "")} + when "project_title" + t << {"value" => "" + (project.send(fs) rescue "") + ""} + else + t << {"value" => (project.send(fs) rescue "")} + end + end + project_list << {"project" => t} + end + + headers = [] + fields_to_show.each do |fs| + col = 2 + col = 3 if fs == "project_title" + headers << { + "head-title" => t("personal_project.#{fs}"), + "col" => col } end { "projects" => project_list, - "extras" => { - "widget-title" => t("module_name.personal_project"), - "th_year" => t('personal_project.year'), - "th_duration" => t('personal_project.period'), - "th_project_title" => t("personal_project.project_title"), - "th_job_title" => t('personal_project.job_title'), - "th_participator" => t("personal_project.participator"), - "th_unit" => t("personal_project.unit"), - "th_authors" => t('users.name') - }, + "headers" => headers, + "extras" => {"widget-title" => t("module_name.personal_project")}, "total_pages" => projects.total_pages } end @@ -47,48 +66,42 @@ class PersonalProjectsController < ApplicationController ] {"plugin_datas"=>plugin.get_plugin_data(fields_to_show)} - - # files = project.project_files.map do |file| - # { - # "file_url" => file.file.url, - # "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title), - # "file_ext" => File.extname(file.file.path).sub('.',''), - # "file_description" => file.description - # } - # end - - # { - # "files" => files, - - # "data" => { - # "project_title" => project.project_title, - # "project_type" => project.project_type.title, - # "job_title" => project.job_title, - # "participator" => project.participator, - # "unit" => project.unit, - # "year" => project.year, - # "language" => project.language, - # "keywords" => project.keywords, - # "abstract" => project.abstract, - # "duration" => project.duration, - # "url" => project.url, - # "note" => project.note, - - # "th_project_title" => t("personal_project.project_title"), - # "th_job_title" => t("personal_project.job_title"), - # "th_participator" => t("personal_project.participator"), - # "th_unit" => t("personal_project.unit"), - # "th_year" => t("personal_project.year"), - # "th_language" => t("personal_project.language"), - # "th_keywords" => t("personal_project.keywords"), - # "th_abstract" => t("personal_project.abstract"), - # "th_duration" => t("personal_project.period"), - # "th_url" => t("personal_project.url"), - # "th_note" => t("personal_project.note"), - - # "th_project_type" => t("personal_project.project_category"), - # "th_files" => t(:file_) - # } - # } end -end \ No newline at end of file + + def get_fields_for_index + @page = Page.find(params[:page_id]) rescue nil + @fields_to_show = [ + "year", + "project_type", + "project_title", + "participator", + "job_title", + "period", + "unit", + "abstract", + "url", + "file", + "language", + ] + @fields_to_show = @fields_to_show.map{|fs| [t("personal_project.#{fs}"), fs]} + @default_fields_to_show = [ + "project_type", + "year", + "project_title", + "participator", + "job_title", + "period", + "unit" + ] + 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/project.rb b/app/models/project.rb index 8a538ea..d1c8af3 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -42,15 +42,21 @@ class Project def self.get_plugin_datas_to_member(datas) - fields_to_show = [ - "project_type", - "year", - "project_title", - "participator", - "job_title", - "period", - "unit" - ] + page = Page.where(:module => "personal_project").first rescue nil + + if !page.nil? && !page.custom_array_field.blank? + fields_to_show = page.custom_array_field + else + fields_to_show = [ + "project_type", + "year", + "project_title", + "participator", + "job_title", + "period", + "unit" + ] + end fields_to_remove = [] diff --git a/app/views/personal_projects/get_fields_for_index.html.erb b/app/views/personal_projects/get_fields_for_index.html.erb new file mode 100644 index 0000000..0183116 --- /dev/null +++ b/app/views/personal_projects/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_project.#{fs}") %>
  • + <% end %> + <% else %> + <% @page.custom_array_field.each do |fs| %> +
  • <%= t("personal_project.#{fs}") %>
  • + <% end %> + <% end %> +
+
+ +
+ +
+ +
+ <%= 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 96a9368..1742c24 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -28,5 +28,7 @@ Rails.application.routes.draw do resources :project_types post "project_types/update_order" => "project_types#update_order" end + get "/xhr/personal_project/get_fields_for_index" => "personal_projects#get_fields_for_index" + post "/xhr/personal_project/save_index_fields" => "personal_projects#save_index_fields" end end diff --git a/lib/personal_project/engine.rb b/lib/personal_project/engine.rb index cb40854..5eff0c3 100644 --- a/lib/personal_project/engine.rb +++ b/lib/personal_project/engine.rb @@ -4,7 +4,7 @@ module PersonalProject OrbitApp.registration "PersonalProject",:type=> 'ModuleApp' do module_label 'module_name.personal_project' base_url File.expand_path File.dirname(__FILE__) - personal_plugin :enable => true, :sort_number => '15', :app_name=>"Project", :intro_app_name=>"PersonalProjectIntro",:path=>"/plugin/personal_project/profile",:front_path=>"/profile",:admin_path=>"/admin/projects",:i18n=>'module_name.personal_project', :module_app_name=>"PersonalProject" + personal_plugin :enable => true, :sort_number => '15', :app_name=>"Project", :intro_app_name=>"PersonalProjectIntro",:path=>"/plugin/personal_project/profile",:front_path=>"/profile",:admin_path=>"/admin/projects",:i18n=>'module_name.personal_project', :module_app_name=>"PersonalProject", :field_modifiable => true version "0.1" desktop_enabled true