From d79398896b8b71c74e0f8ba3c164487e6afd03ff Mon Sep 17 00:00:00 2001 From: chiu Date: Sat, 16 Nov 2019 13:43:37 +0800 Subject: [PATCH] fix the problem of creating multiple authors --- app/controllers/admin/patents_controller.rb | 52 +++++++- .../personal_patents_controller.rb | 15 ++- app/helpers/admin/personal_patents_helper.rb | 27 +++- app/models/patent.rb | 4 +- app/views/admin/patents/_form.html.erb | 26 ++-- app/views/admin/patents/_patent.html.erb | 2 +- app/views/admin/patents/index.html.erb | 12 +- app/views/admin/patents/merge.html.erb | 118 ++++++++++++++++++ config/locales/en.yml | 5 +- config/locales/zh_tw.yml | 7 +- config/routes.rb | 2 + 11 files changed, 236 insertions(+), 34 deletions(-) create mode 100644 app/views/admin/patents/merge.html.erb diff --git a/app/controllers/admin/patents_controller.rb b/app/controllers/admin/patents_controller.rb index eb3b7f8..42d7ea2 100644 --- a/app/controllers/admin/patents_controller.rb +++ b/app/controllers/admin/patents_controller.rb @@ -9,12 +9,51 @@ class Admin::PatentsController < OrbitMemberController before_action :need_access_right 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 @patents = Patent.order_by(: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 @patent = Patent.new if params[:desktop] @@ -60,9 +99,9 @@ class Admin::PatentsController < OrbitMemberController 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.save @@ -70,7 +109,7 @@ class Admin::PatentsController < OrbitMemberController render json: {"data" => get_paper_list}.to_json end - end + #end redirect_to params['referer_url'] @@ -92,14 +131,15 @@ class Admin::PatentsController < OrbitMemberController end def edit - @member = @patent.member_profile rescue nil + @member = get_member(@patent) if params[:desktop] render :layout => false end end 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.save if params[:desktop] == "true" diff --git a/app/controllers/personal_patents_controller.rb b/app/controllers/personal_patents_controller.rb index 7f9a3bc..984b618 100644 --- a/app/controllers/personal_patents_controller.rb +++ b/app/controllers/personal_patents_controller.rb @@ -1,4 +1,5 @@ class PersonalPatentsController < ApplicationController + include Admin::PersonalPatentsHelper def index params = OrbitHelper.params 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]) } when 'language' 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 patents_show = patents_temp.select { |value| search_all_words((value.send(params[:selectbox]).to_s rescue ''), params[:keywords]) } end @@ -54,6 +61,10 @@ class PersonalPatentsController < ApplicationController t << { 'value' => (patent.patent_author_types.collect(&:title).join(', ') rescue '') } when 'language' t << { 'value' => (!patent.language.nil? ? t(patent.language.to_s) : '') } + when 'url' + t << { 'value' => patent.url.to_s.blank? ? "" : "#{patent.url}"} + when 'authors' + t << { 'value' => get_authors_show(patent) } else t << { 'value' => patent.send(fs) } end @@ -65,7 +76,7 @@ class PersonalPatentsController < ApplicationController fields_to_show.each do |fs| col = 2 col = 3 if fs == 'patent_title' - header = fs == 'authors' ? t('users.name') : t("personal_patent.#{fs}") + header = t("personal_patent.#{fs}") headers << { 'head-title' => header, 'col' => col @@ -144,7 +155,7 @@ class PersonalPatentsController < ApplicationController keywords 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[ publish_date patent_title diff --git a/app/helpers/admin/personal_patents_helper.rb b/app/helpers/admin/personal_patents_helper.rb index e0af44f..7eafe8d 100644 --- a/app/helpers/admin/personal_patents_helper.rb +++ b/app/helpers/admin/personal_patents_helper.rb @@ -1,7 +1,30 @@ 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| "#{member.name}"}.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 - user = current_user.nil? ? OrbitHelper.current_user : current_user + user = current_user.nil? ? OrbitHelper.current_user : current_user user_profile = user.member_profile patents = Patent.where(:member_profile_id => user_profile.id) patents = patents.collect do |p| diff --git a/app/models/patent.rb b/app/models/patent.rb index dc807ef..1da5648 100644 --- a/app/models/patent.rb +++ b/app/models/patent.rb @@ -3,7 +3,7 @@ class Patent include Mongoid::Timestamps include OrbitModel::Status include Slug - + include Admin::PersonalPatentsHelper has_and_belongs_to_many :patent_types has_and_belongs_to_many :patent_author_types belongs_to :member_profile @@ -136,6 +136,8 @@ class Patent files << (url.nil? ? "" : "
  • #{title}
  • ") end value = files.join("") + when "authors" + value = get_authors_show(self) else value = self.send(field) rescue "" end diff --git a/app/views/admin/patents/_form.html.erb b/app/views/admin/patents/_form.html.erb index 0ca6e38..b91d74b 100644 --- a/app/views/admin/patents/_form.html.erb +++ b/app/views/admin/patents/_form.html.erb @@ -61,7 +61,7 @@
    <%= 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 %>
    @@ -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 %> -
    @@ -244,7 +234,7 @@
    - <%= f.text_field :keywords %> + <%= f.text_area :keywords, class: "ckeditor input-block-level" %>
    @@ -252,7 +242,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/patents/_patent.html.erb b/app/views/admin/patents/_patent.html.erb index a6df1c7..54aeae4 100644 --- a/app/views/admin/patents/_patent.html.erb +++ b/app/views/admin/patents/_patent.html.erb @@ -12,6 +12,6 @@ <%= patent.patent_no %> <%= patent.patent_country %> - <%= patent.member_profile.name rescue "" %> + <%= get_type_authors_show(patent).html_safe %> <% end %> \ No newline at end of file diff --git a/app/views/admin/patents/index.html.erb b/app/views/admin/patents/index.html.erb index bc6d465..586921a 100644 --- a/app/views/admin/patents/index.html.erb +++ b/app/views/admin/patents/index.html.erb @@ -1,3 +1,9 @@ + + @@ -16,8 +22,12 @@
    +
    + + + + +<% if params['mode']!='simple' %> + + + + +<% end %> + + + + + +<% @patents.each do |key,patents| %> + + <% if params['mode']=='simple' + len = patents.length + else + len = patents.values.reduce(0){|sum,num| sum+num.length} + end + %> + + + <% if params['mode']=='simple' %> + + <% patents.each_with_index do |patent,i| %> + + <% if len!=(i+1) %> + + + <% end %> + <% end %> + <% else %> + <% i=0 %> + <% patents.each do |k,v| %> + <% len1 = v.length %> + <% k.each do |keychild| %> + + <% end %> + + <% v.each_with_index do |patent_child,index1| %> + + <% if len1!=index1 %> + + + <% end %> + <% end %> + <% if len1!=(i+1) %> + + + <% end %> + <% i =i+1 %> + <% end %> + <% end %> + +<% end %> + +
    <%= t('personal_patent.patent_title') %><%= t('personal_patent.patent_no') %><%= t('personal_patent.year') %><%= t('personal_patent.patent_organization') %><%= t('personal_patent.patent_category') %><%= t('personal_patent.patent_country') %><%= t("personal_patent.merge") %><%= t("personal_patent.authors") %>
    + <%= key[0].values.map{|v| v=="" ? t('personal_patent.no_input') : v}.join('/') %> + + <%= key[1] %> + + + + + <%= get_member(patent).collect(&:name).join(' / ') rescue t('personal_patent.no_input') %> + +
    + <%= keychild.to_s.blank? ? t('personal_patent.no_input') : keychild %> + + + + + <%= get_member(patent_child).collect(&:name).join(' / ') rescue t('personal_patent.no_input') %> + +
    + \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 57f2e6b..61f60f3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2,6 +2,9 @@ en: module_name: personal_patent: Patent personal_patent: + merge: Merge + upload: Upload + no_input: No Input select_class: "——select class——" search_class: "search class:" word_to_search: "word to search:" @@ -45,7 +48,7 @@ en: graph_by : "Graph By" frontend: writing_patents: "Patent 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 15e5f3c..f183261 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -2,6 +2,9 @@ zh_tw: module_name: personal_patent: 專利 personal_patent: + merge: "合併" + upload: "上傳" + no_input: "未輸入" select_class: "——選取分類——" search_class: "搜尋類別:" word_to_search: "關鍵字搜尋:" @@ -12,7 +15,7 @@ zh_tw: patent_country : "專利國別" patent_category : "專利類別" publishers : "Publishers" - authors : "作者" + authors : "著作人" tags : "領域" year : "年度" language : "語言" @@ -43,7 +46,7 @@ zh_tw: graph_by : "Graph By" frontend: writing_patents: "專利前台" - + strict_compare_mode: "嚴格比較模式" create_success : "新增完成!!" update_success : "更新完成!!" delete_success : "刪除成功!!" diff --git a/config/routes.rb b/config/routes.rb index c7e5dde..2b98259 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,6 +8,8 @@ Rails.application.routes.draw do resources :patents do collection do + post 'merge_process' => 'patents#merge_process' + get 'merge' => 'patents#merge' get 'toggle_hide' => 'patents#toggle_hide' get 'analysis' get 'analysis_report'