fix the problem of creating multiple authors

This commit is contained in:
chiu 2019-11-16 13:43:37 +08:00
parent 741fa0a136
commit d79398896b
11 changed files with 236 additions and 34 deletions

View File

@ -9,12 +9,51 @@ class Admin::PatentsController < 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['patent_id'].each do |patent_id|
patent_ids = patent_id.split('/')
patents = Patent.find(patent_ids)
member_ids = patents.collect(&:member_profile_id).uniq
patents.each_with_index do |patent,index1|
if index1== 0
patent.member_profile_id = member_ids
patent.save!
else
patent.delete
end
end
end
redirect_to :action=> 'index'
end
def merge
@patents=Patent.order_by(:year=>'desc').map{|value| value}.group_by{|v| [v[:patent_title],v[:patent_no]]}
@patents.each do |key,value|
if value.length<=1
@patents.delete key
end
end
if params['mode']!='simple'
@patents.each do |key,value|
@patents[key] = value.group_by{|v| [get_year(v),get_patent_organization(v),get_patent_category(v),get_patent_country(v)]}
@patents[key].each do |key1,value1|
if value1.length<=1
@patents[key].delete key1
end
end
if @patents[key].length==0
@patents.delete key
end
end
end
end
def index def index
@patents = Patent.order_by(:year=>'desc').page(params[:page]).per(10) @patents = Patent.order_by(: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
@patent = Patent.new @patent = Patent.new
if params[:desktop] if params[:desktop]
@ -60,9 +99,9 @@ class Admin::PatentsController < 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|
patent_params['member_profile_id'] = author_member patent_params['member_profile_id'] = params[:author_members]
@patent = Patent.new(patent_params) @patent = Patent.new(patent_params)
@patent.save @patent.save
@ -70,7 +109,7 @@ class Admin::PatentsController < 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']
@ -92,14 +131,15 @@ class Admin::PatentsController < OrbitMemberController
end end
def edit def edit
@member = @patent.member_profile rescue nil @member = get_member(@patent)
if params[:desktop] if params[:desktop]
render :layout => false render :layout => false
end end
end end
def update def update
@member = @patent.member_profile rescue nil @member = get_member(@patent)
patent_params['member_profile_id'] = params[:author_members]
@patent.update_attributes(patent_params) @patent.update_attributes(patent_params)
@patent.save @patent.save
if params[:desktop] == "true" if params[:desktop] == "true"

View File

@ -1,4 +1,5 @@
class PersonalPatentsController < ApplicationController class PersonalPatentsController < ApplicationController
include Admin::PersonalPatentsHelper
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,12 @@ class PersonalPatentsController < ApplicationController
patents_show = patents_temp.select { |value| search_all_words(value.patent_author_types.collect(&:title).join(', '), params[:keywords]) } patents_show = patents_temp.select { |value| search_all_words(value.patent_author_types.collect(&:title).join(', '), params[:keywords]) }
when 'language' when 'language'
patents_show = patents_temp.select { |value| search_all_words((!value.language.nil? ? t(value.language.to_s) : ''), params[:keywords]) } patents_show = patents_temp.select { |value| search_all_words((!value.language.nil? ? t(value.language.to_s) : ''), params[:keywords]) }
when 'authors'
patents_show = patents_temp.select { |value| search_all_words(get_authors_text(value), params[:keywords]) }
when 'keywords'
patents_show = patents_temp.select { |value| search_all_words(Nokogiri::HTML(value.keywords).text, params[:keywords]) }
when 'note'
patents_show = patents_temp.select { |value| search_all_words(Nokogiri::HTML(value.note).text, params[:keywords]) }
else else
patents_show = patents_temp.select { |value| search_all_words((value.send(params[:selectbox]).to_s rescue ''), params[:keywords]) } patents_show = patents_temp.select { |value| search_all_words((value.send(params[:selectbox]).to_s rescue ''), params[:keywords]) }
end end
@ -54,6 +61,10 @@ class PersonalPatentsController < ApplicationController
t << { 'value' => (patent.patent_author_types.collect(&:title).join(', ') rescue '') } t << { 'value' => (patent.patent_author_types.collect(&:title).join(', ') rescue '') }
when 'language' when 'language'
t << { 'value' => (!patent.language.nil? ? t(patent.language.to_s) : '') } t << { 'value' => (!patent.language.nil? ? t(patent.language.to_s) : '') }
when 'url'
t << { 'value' => patent.url.to_s.blank? ? "" : "<a href='#{patent.url}'>#{patent.url}</a>"}
when 'authors'
t << { 'value' => get_authors_show(patent) }
else else
t << { 'value' => patent.send(fs) } t << { 'value' => patent.send(fs) }
end end
@ -65,7 +76,7 @@ class PersonalPatentsController < ApplicationController
fields_to_show.each do |fs| fields_to_show.each do |fs|
col = 2 col = 2
col = 3 if fs == 'patent_title' col = 3 if fs == 'patent_title'
header = fs == 'authors' ? t('users.name') : t("personal_patent.#{fs}") header = t("personal_patent.#{fs}")
headers << { headers << {
'head-title' => header, 'head-title' => header,
'col' => col 'col' => col
@ -144,7 +155,7 @@ class PersonalPatentsController < ApplicationController
keywords keywords
note note
] ]
@fields_to_show = @fields_to_show.map { |fs| [(fs == 'authors' ? t('users.name') : t("personal_patent.#{fs}")), fs] } @fields_to_show = @fields_to_show.map { |fs| t("personal_patent.#{fs}") }
@default_fields_to_show = %w[ @default_fields_to_show = %w[
publish_date publish_date
patent_title patent_title

View File

@ -1,7 +1,30 @@
module Admin::PersonalPatentsHelper module Admin::PersonalPatentsHelper
def get_authors_text(patent)
(patent.authors.to_s.blank? ? get_member(patent).collect(&:name).join('/') : Nokogiri::HTML(patent.authors.to_s).text rescue '')
end
def get_authors_show(patent)
(patent.authors.to_s.blank? ? get_type_authors_show(patent) : patent.authors.to_s rescue '')
end
def get_type_authors_show(patent)
get_member(patent).collect{|member| "<a href='#{OrbitHelper.url_to_plugin_show(member.to_param,'member')}' title='#{member.name}'>#{member.name}</a>"}.join('/')
end
def get_member(patent)
Array(MemberProfile.find(Array(patent).collect(&:member_profile_id)))
end
def get_year(patent)
patent.year
end
def get_patent_organization(patent)
patent[:patent_organization].collect{|key,value| value.to_s.blank? ? t('personal_patent.no_input') : value}.join('/') rescue ''
end
def get_patent_category(patent)
patent.patent_types.collect(&:title).join(', ') rescue ''
end
def get_patent_country(patent)
patent[:patent_country].collect{|key,value| value.to_s.blank? ? t('personal_patent.no_input') : value}.join('/') 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
patents = Patent.where(:member_profile_id => user_profile.id) patents = Patent.where(:member_profile_id => user_profile.id)
patents = patents.collect do |p| patents = patents.collect do |p|

View File

@ -3,7 +3,7 @@ class Patent
include Mongoid::Timestamps include Mongoid::Timestamps
include OrbitModel::Status include OrbitModel::Status
include Slug include Slug
include Admin::PersonalPatentsHelper
has_and_belongs_to_many :patent_types has_and_belongs_to_many :patent_types
has_and_belongs_to_many :patent_author_types has_and_belongs_to_many :patent_author_types
belongs_to :member_profile belongs_to :member_profile
@ -136,6 +136,8 @@ class Patent
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 "authors"
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_patent.authors") %></label> <label class="control-label muted"><%= t("personal_patent.authors") %></label>
<div class="controls"> <div class="controls">
<%= f.fields_for :authors_translations do |f| %> <%= f.fields_for :authors_translations do |f| %>
<%= f.text_field locale, placeholder: t("personal_patent.authors"), value: (@patent.authors_translations[locale] rescue nil) %> <%= f.text_area locale, placeholder: t("personal_patent.authors"), value: (@patent.authors_translations[locale] rescue nil), class: "ckeditor input-block-level" %>
<% end %> <% end %>
</div> </div>
</div> </div>
@ -128,27 +128,17 @@
<!-- Basic Module --> <!-- Basic Module -->
<div class="tab-pane fade in active" id="basic"> <div class="tab-pane fade in active" id="basic">
<% if !@member.nil? %>
<div class="control-group big-group"> <div class="control-group big-group">
<label class="control-label muted"><%= t("personal_plugins.author") %></label> <label class="control-label muted"><%= t("personal_plugins.author") %></label>
<div class="controls"> <div class="controls">
<%= @member.name rescue ''%> <% if !@member.nil? %>
<%= f.hidden_field :member_profile_id, :value => @member.id %> <%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'author_members[]', email_members:@member} %>
</div> <% else %>
</div> <%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'author_members[]', email_members:[]} %>
<% end %>
<% 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:[]} %>
</div> </div>
</div> </div>
<% end %>
<!-- year --> <!-- year -->
<div class="control-group"> <div class="control-group">
<label class="control-label muted"><%= t("personal_patent.year") %></label> <label class="control-label muted"><%= t("personal_patent.year") %></label>
@ -244,7 +234,7 @@
<div class="control-group big-group"> <div class="control-group big-group">
<label class="control-label muted"><%= t("personal_patent.keywords") %></label> <label class="control-label muted"><%= t("personal_patent.keywords") %></label>
<div class="controls"> <div class="controls">
<%= f.text_field :keywords %> <%= f.text_area :keywords, class: "ckeditor input-block-level" %>
</div> </div>
</div> </div>
@ -252,7 +242,7 @@
<div class="control-group big-group"> <div class="control-group big-group">
<label class="control-label muted"><%= t("personal_patent.note") %></label> <label class="control-label muted"><%= t("personal_patent.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

@ -12,6 +12,6 @@
</td> </td>
<td><%= patent.patent_no %></td> <td><%= patent.patent_no %></td>
<td><%= patent.patent_country %></td> <td><%= patent.patent_country %></td>
<td><%= patent.member_profile.name rescue "" %></td> <td><%= get_type_authors_show(patent).html_safe %></td>
</tr> </tr>
<% end %> <% end %>

View File

@ -1,3 +1,9 @@
<script src="https://kit.fontawesome.com/1fa49cfdc9.js" crossorigin="anonymous"></script>
<script>
function MergeUrl(){
location.href = '<%= merge_admin_patents_path %>'
}
</script>
<table class="table main-list"> <table class="table main-list">
<thead> <thead>
<tr> <tr>
@ -16,8 +22,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_patent.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_patent.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_patent.merge') %></button>
</form>
</nobr>
<form method="post" action='/admin/patents/merge_process?' name='merge_form'>
<%= token_tag(nil) %>
<table class="table main-list">
<thead>
<tr>
<th><%= t('personal_patent.patent_title') %></th>
<th><%= t('personal_patent.patent_no') %></th>
<% if params['mode']!='simple' %>
<th><%= t('personal_patent.year') %></th>
<th><%= t('personal_patent.patent_organization') %></th>
<th><%= t('personal_patent.patent_category') %></th>
<th><%= t('personal_patent.patent_country') %></th>
<% end %>
<th><%= t("personal_patent.merge") %></th>
<th><%= t("personal_patent.authors") %></th>
</tr>
</thead>
<tbody>
<% @patents.each do |key,patents| %>
<tr>
<% if params['mode']=='simple'
len = patents.length
else
len = patents.values.reduce(0){|sum,num| sum+num.length}
end
%>
<td rowspan="<%= len %>">
<%= key[0].values.map{|v| v=="" ? t('personal_patent.no_input') : v}.join('/') %>
</td>
<td rowspan="<%= len %>">
<%= key[1] %>
</td>
<% if params['mode']=='simple' %>
<td rowspan="<%= len %>">
<input type="checkbox" class="checkbox" name="patent_id[]" value="<%= patents.collect(&:id).join('/') %>">
</td>
<% patents.each_with_index do |patent,i| %>
<td>
<a href="<%= edit_admin_patent_path(patent) %>" target="_blank">
<%= get_member(patent).collect(&:name).join(' / ') rescue t('personal_patent.no_input') %>
</a>
</td>
<% if len!=(i+1) %>
</tr>
<tr>
<% end %>
<% end %>
<% else %>
<% i=0 %>
<% patents.each do |k,v| %>
<% len1 = v.length %>
<% k.each do |keychild| %>
<td rowspan="<%= len1 %>">
<%= keychild.to_s.blank? ? t('personal_patent.no_input') : keychild %>
</td>
<% end %>
<td rowspan="<%= len1 %>">
<input type="checkbox" class="checkbox" name="patent_id[]" value="<%= v.collect(&:id).join('/') %>">
</td>
<% v.each_with_index do |patent_child,index1| %>
<td>
<a href="<%= edit_admin_patent_path(patent_child) %>" target="_blank">
<%= get_member(patent_child).collect(&:name).join(' / ') rescue t('personal_patent.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_patent: Patent personal_patent: Patent
personal_patent: personal_patent:
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:"
@ -45,7 +48,7 @@ en:
graph_by : "Graph By" graph_by : "Graph By"
frontend: frontend:
writing_patents: "Patent Frontend" writing_patents: "Patent 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_patent: 專利 personal_patent: 專利
personal_patent: personal_patent:
merge: "合併"
upload: "上傳"
no_input: "未輸入"
select_class: "——選取分類——" select_class: "——選取分類——"
search_class: "搜尋類別:" search_class: "搜尋類別:"
word_to_search: "關鍵字搜尋:" word_to_search: "關鍵字搜尋:"
@ -12,7 +15,7 @@ zh_tw:
patent_country : "專利國別" patent_country : "專利國別"
patent_category : "專利類別" patent_category : "專利類別"
publishers : "Publishers" publishers : "Publishers"
authors : "作者" authors : "著作人"
tags : "領域" tags : "領域"
year : "年度" year : "年度"
language : "語言" language : "語言"
@ -43,7 +46,7 @@ zh_tw:
graph_by : "Graph By" graph_by : "Graph By"
frontend: frontend:
writing_patents: "專利前台" writing_patents: "專利前台"
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 :patents do resources :patents do
collection do collection do
post 'merge_process' => 'patents#merge_process'
get 'merge' => 'patents#merge'
get 'toggle_hide' => 'patents#toggle_hide' get 'toggle_hide' => 'patents#toggle_hide'
get 'analysis' get 'analysis'
get 'analysis_report' get 'analysis_report'