From b4458dfd4bc49b30436c250846e4caa9c9be6a78 Mon Sep 17 00:00:00 2001 From: chiu Date: Tue, 12 Nov 2019 22:48:52 +0800 Subject: [PATCH] fix the problem of creating multiple authors --- app/controllers/admin/projects_controller.rb | 51 +++++++- .../personal_projects_controller.rb | 9 ++ app/helpers/admin/personal_projects_helper.rb | 66 ++++++---- app/models/project.rb | 6 +- app/views/admin/projects/_form.html.erb | 26 ++-- app/views/admin/projects/_project.html.erb | 4 +- app/views/admin/projects/index.html.erb | 22 +++- app/views/admin/projects/merge.html.erb | 118 ++++++++++++++++++ config/locales/en.yml | 5 +- config/locales/zh_tw.yml | 5 +- config/routes.rb | 2 + 11 files changed, 261 insertions(+), 53 deletions(-) create mode 100644 app/views/admin/projects/merge.html.erb 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? ? "" : "
  • #{title}
  • ") end value = files.join("") + when "url" + value = self.url.to_s.blank? ? "" : "#{self.url}" + when "participator" + value = get_authors_show(self) else value = self.send(field) rescue "" end diff --git a/app/views/admin/projects/_form.html.erb b/app/views/admin/projects/_form.html.erb index d287749..760fb1e 100644 --- a/app/views/admin/projects/_form.html.erb +++ b/app/views/admin/projects/_form.html.erb @@ -61,7 +61,7 @@
    <%= f.fields_for :participator_translations do |f| %> - <%= f.text_field locale, class: "input-block-level", placeholder: t("personal_project.participator"), value: (@project.participator_translations[locale] rescue nil) %> + <%= f.text_area locale, class: "ckeditor input-block-level", placeholder: t("personal_project.participator"), value: (@project.participator_translations[locale] rescue nil) %> <% end %>
    @@ -128,27 +128,17 @@
    - <% if !@member.nil? %> -
    - <%= @member.name rescue ''%> - <%= f.hidden_field :member_profile_id, :value => @member.id %> -
    -
    - - <% else %> - -
    - -
    - <%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'author_members[]', email_members:[]} %> + <% if !@member.nil? %> + <%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'author_members[]', email_members:@member} %> + <% else %> + <%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'author_members[]', email_members:[]} %> + <% end %>
    - <% end %> -
    @@ -213,7 +203,7 @@
    - <%= f.text_area :abstract, rows: 2, class: "input-block-level" %> + <%= f.text_area :abstract, rows: 2, class: "ckeditor input-block-level" %>
    @@ -221,7 +211,7 @@
    - <%= f.text_area :note, rows: 2, class: "input-block-level" %> + <%= f.text_area :note, rows: 2, class: "ckeditor input-block-level" %>
    diff --git a/app/views/admin/projects/_project.html.erb b/app/views/admin/projects/_project.html.erb index 3a0aaf0..0fb546a 100644 --- a/app/views/admin/projects/_project.html.erb +++ b/app/views/admin/projects/_project.html.erb @@ -11,8 +11,8 @@
    <%= project.job_title %> - <%= project.participator %> + <%= project.participator.to_s.html_safe %> <%= project.unit %> - <%= project.member_profile.name rescue "" %> + <%= get_participator_show(project).html_safe %> <% end %> \ No newline at end of file diff --git a/app/views/admin/projects/index.html.erb b/app/views/admin/projects/index.html.erb index e67d1c8..d55cc36 100644 --- a/app/views/admin/projects/index.html.erb +++ b/app/views/admin/projects/index.html.erb @@ -1,3 +1,19 @@ + + @@ -17,8 +33,12 @@
    +
    + + + + +<% if params['mode']!='simple' %> + + + + +<% end %> + + + + + +<% @projects.each do |key,projects| %> + + <% if params['mode']=='simple' + len = projects.length + else + len = projects.values.reduce(0){|sum,num| sum+num.length} + end + %> + + + <% if params['mode']=='simple' %> + + <% projects.each_with_index do |project,i| %> + + <% if len!=(i+1) %> + + + <% end %> + <% end %> + <% else %> + <% i=0 %> + <% projects.each do |k,v| %> + <% len1 = v.length %> + <% k.each do |keychild| %> + + <% end %> + + <% v.each_with_index do |project_child,index1| %> + + <% if len1!=index1 %> + + + <% end %> + <% end %> + <% if len1!=(i+1) %> + + + <% end %> + <% i =i+1 %> + <% end %> + <% end %> + +<% end %> + +
    <%= t('personal_project.project_title') %><%= t('personal_project.unit') %><%= t('personal_project.year') %><%= t('personal_project.participator') %><%= t('personal_project.project_type') %><%= t('personal_project.period') %><%= t("personal_project.merge") %><%= t("personal_plugins.author") %>
    + <%= key[0].values.map{|v| v=="" ? t('personal_project.no_input') : v}.join('/') %> + + <%= key[1].values.map{|v| v=="" ? t('personal_project.no_input') : v}.join('/') %> + + + + + <%= get_member(project).collect(&:name).join(' / ') rescue t('personal_project.no_input') %> + +
    + <%= keychild.to_s.blank? ? t('personal_project.no_input') : keychild %> + + + + + <%= get_member(project_child).collect(&:name).join(' / ') rescue t('personal_project.no_input') %> + +
    + \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index d4bd03b..929a457 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2,6 +2,9 @@ en: module_name: personal_project: "Project" personal_project: + merge: Merge + upload: Upload + no_input: No Input select_class: "——select class——" search_class: "search class:" word_to_search: "word to search:" @@ -43,7 +46,7 @@ en: book_paper_type : "Book Paper Type" frontend: projects: "Project Front-end" - + strict_compare_mode: Strict Compare mode create_success : "Successfully Create" update_success : "Successfully Update" delete_success : "Successfully Delete" diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 9266aac..28978a0 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -2,6 +2,9 @@ zh_tw: module_name: personal_project: 研究計畫 personal_project: + merge: "合併" + upload: "上傳" + no_input: "未輸入" select_class: "——選取分類——" search_class: "搜尋類別:" word_to_search: "關鍵字搜尋:" @@ -43,7 +46,7 @@ zh_tw: book_paper_type : "Book Paper Type" frontend: projects: "研究計畫前台" - + strict_compare_mode: "嚴格比較模式" create_success : "新增完成!!" update_success : "更新完成!!" delete_success : "刪除成功!!" diff --git a/config/routes.rb b/config/routes.rb index 0f65453..f1bae25 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,6 +8,8 @@ Rails.application.routes.draw do resources :projects do collection do + post 'merge_process' => 'projects#merge_process' + get 'merge' => 'projects#merge' get 'toggle_hide' => 'projects#toggle_hide' get 'analysis' get 'analysis_report'