diff --git a/app/controllers/admin/projects_controller.rb b/app/controllers/admin/projects_controller.rb index c1e5e57..e80f8a2 100644 --- a/app/controllers/admin/projects_controller.rb +++ b/app/controllers/admin/projects_controller.rb @@ -8,13 +8,51 @@ class Admin::ProjectsController < OrbitMemberController before_action :need_access_right before_action :allow_admin_only, :only => [:index, :setting] + def merge_process + params['project_id'].each do |project_id| + project_ids = project_id.split('/') + projects = Project.find(project_ids) + member_ids = projects.collect(&:member_profile_id).uniq + projects.each_with_index do |project,index1| + if index1== 0 + project.member_profile_id = member_ids + project.save! + else + project.delete + end + end + end + redirect_to :action=> 'index' + end + def merge + @projects=Project.order_by(:year=>'desc').map{|value| value}.group_by{|v| [v[:project_title],v[:unit]]} + @projects.each do |key,value| + if value.length<=1 + @projects.delete key + end + end + if params['mode']!='simple' + @projects.each do |key,value| + @projects[key] = value.group_by{|v| [get_year(v),v.participator.to_s,get_project_type(v),get_period(v)]} + @projects[key].each do |key1,value1| + if value1.length<=1 + @projects[key].delete key1 + end + end + if @projects[key].length==0 + @projects.delete key + end + end + + end + end def index @projects = Project.order_by(:period_start_date=>'desc',:year=>'desc').page(params[:page]).per(10) end def new - @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil + @member = Array(MemberProfile.find_by(:uid=>params['uid'])) rescue nil @project = Project.new if params[:desktop] render :layout => false @@ -62,9 +100,9 @@ class Admin::ProjectsController < OrbitMemberController elsif !params[:author_members].blank? - params[:author_members].each do |author_member| + #params[:author_members].each do |author_member| - project_params['member_profile_id'] = author_member + project_params['member_profile_id'] = params[:author_members] @project = Project.new(project_params) @project.save @@ -72,7 +110,7 @@ class Admin::ProjectsController < OrbitMemberController render json: {"data" => get_paper_list}.to_json end - end + #end redirect_to params['referer_url'] @@ -94,14 +132,15 @@ class Admin::ProjectsController < OrbitMemberController end def edit - @member = @project.member_profile rescue nil + @member = get_member(@project) if params[:desktop] render :layout => false end end def update - @member = @project.member_profile rescue nil + @member = get_member(@project) + project_params['member_profile_id'] = params[:author_members] @project.update_attributes(project_params) @project.save if params[:desktop] == "true" diff --git a/app/controllers/personal_projects_controller.rb b/app/controllers/personal_projects_controller.rb index cfcda10..0ea41d8 100644 --- a/app/controllers/personal_projects_controller.rb +++ b/app/controllers/personal_projects_controller.rb @@ -1,4 +1,5 @@ class PersonalProjectsController < ApplicationController + include Admin::PersonalProjectsHelper def index params = OrbitHelper.params page_data_count = OrbitHelper.page_data_count @@ -26,6 +27,8 @@ class PersonalProjectsController < ApplicationController projects_show = projects_temp.select { |value| search_all_words(value.send('duration').to_s, params[:keywords]) } when 'language' projects_show = projects_temp.select { |value| search_all_words(t(value.send('language')), params[:keywords]) } + when 'participator' + projects_show = projects_temp.select { |value| search_all_words(get_authors_text(value), params[:keywords]) } else projects_show = projects_temp.select { |value| search_all_words(value.send(params[:selectbox]).to_s, params[:keywords]) } end @@ -48,6 +51,10 @@ class PersonalProjectsController < ApplicationController t << { 'value' => (project.send('duration') rescue '') } when 'language' t << { 'value' => (t(project.send('language')) rescue '') } + when 'url' + t << { 'value' => project.url.to_s.blank? ? "" : "#{project.url}"} + when 'participator' + t << { 'value' => get_authors_show(project) } else t << { 'value' => (project.send(fs) rescue '') } end @@ -102,6 +109,7 @@ class PersonalProjectsController < ApplicationController period unit abstract + note url file language @@ -121,6 +129,7 @@ class PersonalProjectsController < ApplicationController period unit abstract + note url file language diff --git a/app/helpers/admin/personal_projects_helper.rb b/app/helpers/admin/personal_projects_helper.rb index 05c1d66..f1b3bd9 100644 --- a/app/helpers/admin/personal_projects_helper.rb +++ b/app/helpers/admin/personal_projects_helper.rb @@ -1,30 +1,50 @@ module Admin::PersonalProjectsHelper - + def get_authors_text(project) + (project.participator.to_s.blank? ? get_member(project).collect(&:name).join('/') : Nokogiri::HTML(project.participator.to_s).text rescue '') + end + def get_authors_show(project) + (project.participator.to_s.blank? ? get_participator_show(project) : project.participator.to_s rescue '') + end + def get_participator_show(project) + get_member(project).collect{|member| "#{member.name}"}.join('/') + end + def get_member(project) + Array(MemberProfile.find(Array(project).collect(&:member_profile_id))) + end + def get_year(project) + project.year + end + def get_project_type(project) + project.project_type.title rescue '' + end + def get_period(project) + project.duration rescue '' + end def get_paper_list user = current_user.nil? ? OrbitHelper.current_user : current_user - user_profile = user.member_profile - projects = Project.where(:member_profile_id => user_profile.id) - projects = projects.collect do |p| - files = p.project_files.collect do |pf| - { - "title" => pf.title, - "description" => pf.description, - "link" => pf.file.url, - "extension" => (pf.file.url.split(".").last rescue "") - } - end + user_profile = user.member_profile + projects = Project.where(:member_profile_id => user_profile.id) + projects = projects.collect do |p| + files = p.project_files.collect do |pf| + { + "title" => pf.title, + "description" => pf.description, + "link" => pf.file.url, + "extension" => (pf.file.url.split(".").last rescue "") + } + end - { - "id" => p.id.to_s, - "edit_url" => "/#{I18n.locale.to_s}/admin/members/#{user_profile.to_param}/projects/#{p.to_param}/edit", - "delete_url" => "/#{I18n.locale.to_s}/admin/projects/#{p.id.to_s}", - "paper_title" => p.project_title, - "keywords" => p.keywords, - "abstract" => p.abstract, - "files" => files - } - end - projects + { + "id" => p.id.to_s, + "edit_url" => "/#{I18n.locale.to_s}/admin/members/#{user_profile.to_param}/projects/#{p.to_param}/edit", + "delete_url" => "/#{I18n.locale.to_s}/admin/projects/#{p.id.to_s}", + "paper_title" => p.project_title, + "keywords" => p.keywords, + "abstract" => p.abstract, + "files" => files + } + end + projects end def import_this_project(row, mp) diff --git a/app/models/project.rb b/app/models/project.rb index bec396e..4d292fe 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -4,7 +4,7 @@ class Project include OrbitModel::Status include MemberHelper include Slug - + include Admin::PersonalProjectsHelper belongs_to :project_type belongs_to :member_profile @@ -137,6 +137,10 @@ class Project files << (url.nil? ? "" : "