fix the problem of creating multiple authors

This commit is contained in:
chiu 2019-11-12 22:48:52 +08:00
parent 17d94188ac
commit b4458dfd4b
11 changed files with 261 additions and 53 deletions

View File

@ -8,13 +8,51 @@ class Admin::ProjectsController < OrbitMemberController
before_action :need_access_right before_action :need_access_right
before_action :allow_admin_only, :only => [:index, :setting] 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 def index
@projects = Project.order_by(:period_start_date=>'desc',:year=>'desc').page(params[:page]).per(10) @projects = Project.order_by(:period_start_date=>'desc',:year=>'desc').page(params[:page]).per(10)
end end
def new def new
@member = MemberProfile.find_by(:uid=>params['uid']) rescue nil @member = Array(MemberProfile.find_by(:uid=>params['uid'])) rescue nil
@project = Project.new @project = Project.new
if params[:desktop] if params[:desktop]
render :layout => false render :layout => false
@ -62,9 +100,9 @@ class Admin::ProjectsController < OrbitMemberController
elsif !params[:author_members].blank? 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 = Project.new(project_params)
@project.save @project.save
@ -72,7 +110,7 @@ class Admin::ProjectsController < OrbitMemberController
render json: {"data" => get_paper_list}.to_json render json: {"data" => get_paper_list}.to_json
end end
end #end
redirect_to params['referer_url'] redirect_to params['referer_url']
@ -94,14 +132,15 @@ class Admin::ProjectsController < OrbitMemberController
end end
def edit def edit
@member = @project.member_profile rescue nil @member = get_member(@project)
if params[:desktop] if params[:desktop]
render :layout => false render :layout => false
end end
end end
def update 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.update_attributes(project_params)
@project.save @project.save
if params[:desktop] == "true" if params[:desktop] == "true"

View File

@ -1,4 +1,5 @@
class PersonalProjectsController < ApplicationController class PersonalProjectsController < ApplicationController
include Admin::PersonalProjectsHelper
def index def index
params = OrbitHelper.params params = OrbitHelper.params
page_data_count = OrbitHelper.page_data_count 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]) } projects_show = projects_temp.select { |value| search_all_words(value.send('duration').to_s, params[:keywords]) }
when 'language' when 'language'
projects_show = projects_temp.select { |value| search_all_words(t(value.send('language')), params[:keywords]) } 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 else
projects_show = projects_temp.select { |value| search_all_words(value.send(params[:selectbox]).to_s, params[:keywords]) } projects_show = projects_temp.select { |value| search_all_words(value.send(params[:selectbox]).to_s, params[:keywords]) }
end end
@ -48,6 +51,10 @@ class PersonalProjectsController < ApplicationController
t << { 'value' => (project.send('duration') rescue '') } t << { 'value' => (project.send('duration') rescue '') }
when 'language' when 'language'
t << { 'value' => (t(project.send('language')) rescue '') } t << { 'value' => (t(project.send('language')) rescue '') }
when 'url'
t << { 'value' => project.url.to_s.blank? ? "" : "<a href='#{project.url}'>#{project.url}</a>"}
when 'participator'
t << { 'value' => get_authors_show(project) }
else else
t << { 'value' => (project.send(fs) rescue '') } t << { 'value' => (project.send(fs) rescue '') }
end end
@ -102,6 +109,7 @@ class PersonalProjectsController < ApplicationController
period period
unit unit
abstract abstract
note
url url
file file
language language
@ -121,6 +129,7 @@ class PersonalProjectsController < ApplicationController
period period
unit unit
abstract abstract
note
url url
file file
language language

View File

@ -1,5 +1,25 @@
module Admin::PersonalProjectsHelper 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| "<a href='#{OrbitHelper.url_to_plugin_show(member.to_param,'member')}' title='#{member.name}'>#{member.name}</a>"}.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 def get_paper_list
user = current_user.nil? ? OrbitHelper.current_user : current_user user = current_user.nil? ? OrbitHelper.current_user : current_user
user_profile = user.member_profile user_profile = user.member_profile

View File

@ -4,7 +4,7 @@ class Project
include OrbitModel::Status include OrbitModel::Status
include MemberHelper include MemberHelper
include Slug include Slug
include Admin::PersonalProjectsHelper
belongs_to :project_type belongs_to :project_type
belongs_to :member_profile belongs_to :member_profile
@ -137,6 +137,10 @@ class Project
files << (url.nil? ? "" : "<li><a href='#{url}'' target='_blank'>#{title}</li>") files << (url.nil? ? "" : "<li><a href='#{url}'' target='_blank'>#{title}</li>")
end end
value = files.join("") value = files.join("")
when "url"
value = self.url.to_s.blank? ? "" : "<a href='#{self.url}'>#{self.url}</a>"
when "participator"
value = get_authors_show(self)
else else
value = self.send(field) rescue "" value = self.send(field) rescue ""
end end

View File

@ -61,7 +61,7 @@
<label class="control-label muted"><%= t("personal_project.participator") %></label> <label class="control-label muted"><%= t("personal_project.participator") %></label>
<div class="controls"> <div class="controls">
<%= f.fields_for :participator_translations do |f| %> <%= 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 %> <% end %>
</div> </div>
</div> </div>
@ -128,26 +128,16 @@
<!-- Basic Module --> <!-- Basic Module -->
<div class="tab-pane fade in active" id="basic"> <div class="tab-pane fade in active" id="basic">
<div class="control-group big-group">
<label class="control-label muted"><%= t("personal_plugins.author") %></label>
<div class="controls">
<% if !@member.nil? %> <% if !@member.nil? %>
<%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'author_members[]', email_members:@member} %>
<div class="control-group big-group">
<label class="control-label muted"><%= t("personal_plugins.author") %></label>
<div class="controls">
<%= @member.name rescue ''%>
<%= f.hidden_field :member_profile_id, :value => @member.id %>
</div>
</div>
<% else %> <% else %>
<div class="control-group big-group">
<label class="control-label muted"><%= t("personal_plugins.author") %></label>
<div class="controls">
<%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'author_members[]', email_members:[]} %> <%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'author_members[]', email_members:[]} %>
</div>
</div>
<% end %> <% end %>
</div>
</div>
<!-- year --> <!-- year -->
<div class="control-group"> <div class="control-group">
@ -213,7 +203,7 @@
<div class="control-group big-group"> <div class="control-group big-group">
<label class="control-label muted"><%= t("personal_project.abstract") %></label> <label class="control-label muted"><%= t("personal_project.abstract") %></label>
<div class="controls"> <div class="controls">
<%= f.text_area :abstract, rows: 2, class: "input-block-level" %> <%= f.text_area :abstract, rows: 2, class: "ckeditor input-block-level" %>
</div> </div>
</div> </div>
@ -221,7 +211,7 @@
<div class="control-group big-group"> <div class="control-group big-group">
<label class="control-label muted"><%= t("personal_project.note") %></label> <label class="control-label muted"><%= t("personal_project.note") %></label>
<div class="controls"> <div class="controls">
<%= f.text_area :note, rows: 2, class: "input-block-level" %> <%= f.text_area :note, rows: 2, class: "ckeditor input-block-level" %>
</div> </div>
</div> </div>

View File

@ -11,8 +11,8 @@
</div> </div>
</td> </td>
<td><%= project.job_title %></td> <td><%= project.job_title %></td>
<td><%= project.participator %></td> <td><%= project.participator.to_s.html_safe %></td>
<td><%= project.unit %></td> <td><%= project.unit %></td>
<td><%= project.member_profile.name rescue "" %></td> <td><%= get_participator_show(project).html_safe %></td>
</tr> </tr>
<% end %> <% end %>

View File

@ -1,3 +1,19 @@
<script src="https://kit.fontawesome.com/1fa49cfdc9.js" crossorigin="anonymous"></script>
<script>
function MergeUrl(){
var temp_url = location.href
if (temp_url.search("locale=")!=-1){
var tp=temp_url.lastIndexOf('/')
location.href = temp_url.substring(0,tp+1)+"merge/"+temp_url.substring(tp+1)
}
else if (temp_url.slice(-1)=='/'){
location.href = location.href + "merge"
}
else{
location.href = location.href + "/merge"
}
}
</script>
<table class="table main-list"> <table class="table main-list">
<thead> <thead>
<tr> <tr>
@ -17,8 +33,12 @@
<div class="bottomnav clearfix"> <div class="bottomnav clearfix">
<div class="action pull-right"> <div class="action pull-right">
<div class="dropup upload-button"> <div class="dropup upload-button">
<button class="btn btn-primary" type="button" onclick="MergeUrl()">
<i class="far fa-object-group"></i>
<span class="group"></span><%= t('personal_project.merge') %>
</button>
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown"> <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">
<i class="icon-upload-alt icon-white"></i>上傳 <i class="icon-upload-alt icon-white"></i><%= t('personal_project.upload') %>
<span class="caret"></span> <span class="caret"></span>
</button> </button>
<div class="dropdown-menu upload-box"> <div class="dropdown-menu upload-box">

View File

@ -0,0 +1,118 @@
<%= csrf_meta_tags %>
<% content_for :page_specific_css do %>
<%= stylesheet_link_tag "lib/main-forms" %>
<%= stylesheet_link_tag "lib/fileupload" %>
<%= stylesheet_link_tag "lib/main-list" %>
<%= stylesheet_link_tag "lib/main-form-col2" %>
<style>
table.table.main-list.tablet.footable-loaded td{
vertical-align: middle;
}
</style>
<% end %>
<script>
function change_mode(){
var value = $("form[name='mode_form']").find("input[type='checkbox']")[0].checked
if (value){
$("input[name='mode']").val("strict")
}
else{
$("input[name='mode']").val("simple")
}
document.mode_form.submit()
}
</script>
<nobr>
<form method="get" action='?' name='mode_form'>
<%= t('strict_compare_mode') +':' %>
<input type='hidden' name='mode' value=''>
<% if params['mode']!='simple' %>
<input type="checkbox" onchange='change_mode()' checked><span style="margin-right: 2em;"><%= t('yes_') %></span>
<% else %>
<input type="checkbox" onchange='change_mode()'><span style="margin-right: 2em;"><%= t('no_') %></span>
<% end %>
<button type="button" onclick="merge_form.submit()"><%= t('personal_project.merge') %></button>
</form>
</nobr>
<form method="post" action='/admin/projects/merge_process?' name='merge_form'>
<%= token_tag(nil) %>
<table class="table main-list">
<thead>
<tr>
<th><%= t('personal_project.project_title') %></th>
<th><%= t('personal_project.unit') %></th>
<% if params['mode']!='simple' %>
<th><%= t('personal_project.year') %></th>
<th><%= t('personal_project.participator') %></th>
<th><%= t('personal_project.project_type') %></th>
<th><%= t('personal_project.period') %></th>
<% end %>
<th><%= t("personal_project.merge") %></th>
<th><%= t("personal_plugins.author") %></th>
</tr>
</thead>
<tbody>
<% @projects.each do |key,projects| %>
<tr>
<% if params['mode']=='simple'
len = projects.length
else
len = projects.values.reduce(0){|sum,num| sum+num.length}
end
%>
<td rowspan="<%= len %>">
<%= key[0].values.map{|v| v=="" ? t('personal_project.no_input') : v}.join('/') %>
</td>
<td rowspan="<%= len %>">
<%= key[1].values.map{|v| v=="" ? t('personal_project.no_input') : v}.join('/') %>
</td>
<% if params['mode']=='simple' %>
<td rowspan="<%= len %>">
<input type="checkbox" class="checkbox" name="project_id[]" value="<%= projects.collect(&:id).join('/') %>">
</td>
<% projects.each_with_index do |project,i| %>
<td>
<a href="<%= edit_admin_project_path(project) %>" target="_blank">
<%= get_member(project).collect(&:name).join(' / ') rescue t('personal_project.no_input') %>
</a>
</td>
<% if len!=(i+1) %>
</tr>
<tr>
<% end %>
<% end %>
<% else %>
<% i=0 %>
<% projects.each do |k,v| %>
<% len1 = v.length %>
<% k.each do |keychild| %>
<td rowspan="<%= len1 %>">
<%= keychild.to_s.blank? ? t('personal_project.no_input') : keychild %>
</td>
<% end %>
<td rowspan="<%= len1 %>">
<input type="checkbox" class="checkbox" name="project_id[]" value="<%= v.collect(&:id).join('/') %>">
</td>
<% v.each_with_index do |project_child,index1| %>
<td>
<a href="<%= edit_admin_project_path(project_child) %>" target="_blank">
<%= get_member(project_child).collect(&:name).join(' / ') rescue t('personal_project.no_input') %>
</a>
</td>
<% if len1!=index1 %>
</tr>
<tr>
<% end %>
<% end %>
<% if len1!=(i+1) %>
</tr>
<tr>
<% end %>
<% i =i+1 %>
<% end %>
<% end %>
</tr>
<% end %>
</tbody>
</table>
</form>

View File

@ -2,6 +2,9 @@ en:
module_name: module_name:
personal_project: "Project" personal_project: "Project"
personal_project: personal_project:
merge: Merge
upload: Upload
no_input: No Input
select_class: "——select class——" select_class: "——select class——"
search_class: "search class:" search_class: "search class:"
word_to_search: "word to search:" word_to_search: "word to search:"
@ -43,7 +46,7 @@ en:
book_paper_type : "Book Paper Type" book_paper_type : "Book Paper Type"
frontend: frontend:
projects: "Project Frontend" projects: "Project Frontend"
strict_compare_mode: Strict Compare mode
create_success : "Successfully Create" create_success : "Successfully Create"
update_success : "Successfully Update" update_success : "Successfully Update"
delete_success : "Successfully Delete" delete_success : "Successfully Delete"

View File

@ -2,6 +2,9 @@ zh_tw:
module_name: module_name:
personal_project: 研究計畫 personal_project: 研究計畫
personal_project: personal_project:
merge: "合併"
upload: "上傳"
no_input: "未輸入"
select_class: "——選取分類——" select_class: "——選取分類——"
search_class: "搜尋類別:" search_class: "搜尋類別:"
word_to_search: "關鍵字搜尋:" word_to_search: "關鍵字搜尋:"
@ -43,7 +46,7 @@ zh_tw:
book_paper_type : "Book Paper Type" book_paper_type : "Book Paper Type"
frontend: frontend:
projects: "研究計畫前台" projects: "研究計畫前台"
strict_compare_mode: "嚴格比較模式"
create_success : "新增完成!!" create_success : "新增完成!!"
update_success : "更新完成!!" update_success : "更新完成!!"
delete_success : "刪除成功!!" delete_success : "刪除成功!!"

View File

@ -8,6 +8,8 @@ Rails.application.routes.draw do
resources :projects do resources :projects do
collection do collection do
post 'merge_process' => 'projects#merge_process'
get 'merge' => 'projects#merge'
get 'toggle_hide' => 'projects#toggle_hide' get 'toggle_hide' => 'projects#toggle_hide'
get 'analysis' get 'analysis'
get 'analysis_report' get 'analysis_report'