modified for index show fields

This commit is contained in:
Harry Bomrah 2016-03-19 02:06:06 +08:00
parent d28c7db5c4
commit 90342045db
5 changed files with 143 additions and 74 deletions

View File

@ -1,30 +1,49 @@
class PersonalProjectsController < ApplicationController class PersonalProjectsController < ApplicationController
def index 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) 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| fields_to_show = Page.where(:page_id => params[:page_id]).first.custom_array_field rescue []
{ if fields_to_show.blank?
"year" => project.year, fields_to_show = [
"duration" => project.duration, "project_type",
"project_title" => project.project_title, "year",
"job_title" => project.job_title, "project_title",
"participator" => project.participator, "participator",
"unit" => project.unit, "job_title",
"authors" => (project.member_profile.name rescue ""), "period",
"link_to_show" => OrbitHelper.url_to_show(project.to_param) "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" => "<a href='#{OrbitHelper.url_to_show(project.to_param)}'>" + (project.send(fs) rescue "") + "</a>"}
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 end
{ {
"projects" => project_list, "projects" => project_list,
"extras" => { "headers" => headers,
"widget-title" => t("module_name.personal_project"), "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')
},
"total_pages" => projects.total_pages "total_pages" => projects.total_pages
} }
end end
@ -47,48 +66,42 @@ class PersonalProjectsController < ApplicationController
] ]
{"plugin_datas"=>plugin.get_plugin_data(fields_to_show)} {"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
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 end

View File

@ -42,15 +42,21 @@ class Project
def self.get_plugin_datas_to_member(datas) def self.get_plugin_datas_to_member(datas)
fields_to_show = [ page = Page.where(:module => "personal_project").first rescue nil
"project_type",
"year", if !page.nil? && !page.custom_array_field.blank?
"project_title", fields_to_show = page.custom_array_field
"participator", else
"job_title", fields_to_show = [
"period", "project_type",
"unit" "year",
] "project_title",
"participator",
"job_title",
"period",
"unit"
]
end
fields_to_remove = [] fields_to_remove = []

View File

@ -0,0 +1,48 @@
<% if !@page.nil? %>
<form id="form_for_plugin_fields" action="">
<div class="form-inline">
<ul class="current-fields">
<% if @page.custom_array_field.blank? %>
<% @default_fields_to_show.each do |fs| %>
<li data-attrib-key="<%= fs %>" class="clearfix"><span class="field-value"><%= t("personal_project.#{fs}") %></span><span class="remove-field"><i class="icon-remove-sign"></i></span></li>
<% end %>
<% else %>
<% @page.custom_array_field.each do |fs| %>
<li data-attrib-key="<%= fs %>" class="clearfix"><span class="field-value"><%= t("personal_project.#{fs}") %></span><span class="remove-field"><i class="icon-remove-sign"></i></span></li>
<% end %>
<% end %>
</ul>
</div>
<div class="form-horizontal controls-row">
<div class="attr-type-wrap control-group">
<label class="attr control-label">Fields: </label>
<div class="attr controls">
<%= select_tag "fields_to_show_for_pp", options_for_select(@fields_to_show), prompt: "---Select something---" %>
</div>
</div>
<a href="#" class="add-pp-field btn btn-info">Add Field</a>
<input type="hidden" name="plugin_key" value="<%= @page.module %>">
<input type="hidden" name="plugin_page_frontend_id" value="<%= @page.id.to_s %>">
</div>
</form>
<script type="text/javascript">
$(".current-fields").sortable();
var select = $("select#fields_to_show_for_pp");
$(".add-pp-field").on("click",function(){
var val = select.val(),
text = select.find("option:selected").text(),
li = null;
if(val != ""){
li = '<li class="clearfix" data-attrib-key="' + val + '"><span class="field-value">' + text + '</span><span class="remove-field"><i class="icon-remove-sign"></i></span></li>';
}
$("#modify_plugin_fields ul.current-fields").append(li);
})
$(document).on("click",".remove-field",function(){
$(this).parent().remove();
})
</script>
<% else %>
<h3>Page not found.</h3>
<% end %>

View File

@ -28,5 +28,7 @@ Rails.application.routes.draw do
resources :project_types resources :project_types
post "project_types/update_order" => "project_types#update_order" post "project_types/update_order" => "project_types#update_order"
end 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
end end

View File

@ -4,7 +4,7 @@ module PersonalProject
OrbitApp.registration "PersonalProject",:type=> 'ModuleApp' do OrbitApp.registration "PersonalProject",:type=> 'ModuleApp' do
module_label 'module_name.personal_project' module_label 'module_name.personal_project'
base_url File.expand_path File.dirname(__FILE__) 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" version "0.1"
desktop_enabled true desktop_enabled true