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? %> +
+ +<% else %> +