From 0f1f7c7b90b70c6e961d5d15501211dab9f240f8 Mon Sep 17 00:00:00 2001 From: chiu Date: Tue, 5 Nov 2019 21:39:46 +0800 Subject: [PATCH 1/3] fix the problem of multiple creating data when multiple authors are add --- .../admin/journal_papers_controller.rb | 70 +++++++++-- .../personal_journals_controller.rb | 7 ++ app/helpers/admin/journal_papers_helper.rb | 21 ++++ app/models/journal_paper.rb | 7 +- app/views/admin/journal_papers/_form.html.erb | 22 +--- .../journal_papers/_writing_journal.html.erb | 8 +- app/views/admin/journal_papers/index.html.erb | 22 +++- app/views/admin/journal_papers/merge.html.erb | 118 ++++++++++++++++++ .../plugin/personal_journal/_profile.html.erb | 8 -- config/locales/en.yml | 5 +- config/locales/zh_tw.yml | 5 +- config/routes.rb | 64 +++++----- 12 files changed, 286 insertions(+), 71 deletions(-) create mode 100644 app/views/admin/journal_papers/merge.html.erb diff --git a/app/controllers/admin/journal_papers_controller.rb b/app/controllers/admin/journal_papers_controller.rb index 3073be8..fa41c6d 100644 --- a/app/controllers/admin/journal_papers_controller.rb +++ b/app/controllers/admin/journal_papers_controller.rb @@ -2,20 +2,70 @@ require 'rubyXL' class Admin::JournalPapersController < OrbitMemberController include Admin::JournalPapersHelper layout "member_plugin" - before_action :set_journal_paper, only: [:show, :edit , :update, :destroy] before_action :set_plugin before_action :get_settings,:only => [:new, :edit, :setting] before_action :need_access_right before_action :allow_admin_only, :only => [:index, :setting] - + def merge_process + params['journal_id'].each do |journal_id| + journal_ids = journal_id.split('/') + journals = JournalPaper.find(journal_ids) + member_ids = journals.collect(&:member_profile_id).uniq + journals.each_with_index do |journal,index1| + if index1== 0 + journal.member_profile_id = member_ids + journal.save! + else + journal.delete + end + end + end + redirect_to :action=> 'index' + end + def merge + @journals=JournalPaper.order_by(:year=>'desc').map{|value| value}.group_by{|v| [v[:paper_title],v[:journal_title]]} + @journals.each do |key,value| + if value.length<=1 + @journals.delete key + end + end + #journals = JournalPaper.order_by(:year=>'desc').map{|value| value} + #journals_name1 = journals.map{|value| value[:paper_title]} + #journals_name2 = journals.map{|value| value[:journal_title]} + #compare1 = journals_name1.map{|v1| journals_name1.select{|v2| v2==v1}.count>1} + #compare2 = journals_name2.map{|v1| journals_name2.select{|v2| v2==v1}.count>1} + #compare = compare1 and compare2 + #@journal = Hash.new + #compare.each_with_index do |b,i| + # if b && !(@journal.keys.include? [journals_name1[i],journals_name2[i]]) + # @journal[[journals_name1[i],journals_name2[i]]] = [journals[i]] + # elsif b + # @journal[[journals_name1[i],journals_name2[i]]] << journals[i] + # end + #end + if params['mode']!='simple' + @journals.each do |key,value| + @journals[key] = value.group_by{|v| [get_level_type(v),get_author_type(v),get_paper_type(v),get_publication_date(v)]} + @journals[key].each do |key1,value1| + if value1.length<=1 + @journals[key].delete key1 + end + end + if @journals[key].length==0 + @journals.delete key + end + end + + end + end def index @writing_journals = JournalPaper.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 @journal_paper = JournalPaper.new if params[:desktop] @@ -64,17 +114,17 @@ class Admin::JournalPapersController < OrbitMemberController elsif !params[:author_members].blank? - params[:author_members].each do |author_member| + #params[:author_members].each do |author_member| - journal_paper_params['member_profile_id'] = author_member + journal_paper_params['member_profile_id'] = params[:author_members] @journal_paper = JournalPaper.new(journal_paper_params) @journal_paper.save - + if params[:desktop] == "true" render json: {"data" => get_paper_list}.to_json end - end + #end redirect_to params['referer_url'] @@ -96,14 +146,15 @@ class Admin::JournalPapersController < OrbitMemberController end def edit - @member = @journal_paper.member_profile + @member = get_member(@journal_paper) if params[:desktop] render :layout => false end end def update - @member = @journal_paper.member_profile + @member = get_member(@journal_paper) + journal_paper_params['member_profile_id'] = params[:author_members] @journal_paper.update_attributes(journal_paper_params) @journal_paper.save if params[:desktop] == "true" @@ -192,7 +243,6 @@ class Admin::JournalPapersController < OrbitMemberController end private - def set_journal_paper path = request.path.split('/') if path.last.include? '-' diff --git a/app/controllers/personal_journals_controller.rb b/app/controllers/personal_journals_controller.rb index 8b3c826..4d156af 100644 --- a/app/controllers/personal_journals_controller.rb +++ b/app/controllers/personal_journals_controller.rb @@ -1,4 +1,5 @@ class PersonalJournalsController < ApplicationController + include Admin::JournalPapersHelper def index params = OrbitHelper.params page_data_count = OrbitHelper.page_data_count @@ -42,6 +43,8 @@ class PersonalJournalsController < ApplicationController journal_papers_show = journal_papers_temp.select { |value| search_all_words((value.journal_paper_type.title rescue ''), params[:keywords]) } when 'language' journal_papers_show = journal_papers_temp.select { |value| search_all_words((!value.language.nil? ? t(value.language.to_s) : ''), params[:keywords]) } + when 'authors' + journal_papers_show = journal_papers_temp.select { |value| search_all_words(get_authors_text(value), params[:keywords]) } else journal_papers_show = journal_papers_temp.select { |value| search_all_words(value.send(params[:selectbox]).to_s, params[:keywords]) } end @@ -72,6 +75,10 @@ class PersonalJournalsController < ApplicationController t << { 'value' => (journal_paper.journal_paper_type.title rescue '') } when 'language' t << { 'value' => (!journal_paper.language.nil? ? t(journal_paper.language.to_s) : '') } + when 'url' + t << { 'value' => journal_paper.url.to_s.blank? ? "" : "#{journal_paper.url}"} + when 'authors' + t << { 'value' => get_authors_show(journal_paper) } else t << { 'value' => (journal_paper.send(fs) rescue '') } end diff --git a/app/helpers/admin/journal_papers_helper.rb b/app/helpers/admin/journal_papers_helper.rb index a5abbbb..f5fa870 100644 --- a/app/helpers/admin/journal_papers_helper.rb +++ b/app/helpers/admin/journal_papers_helper.rb @@ -1,4 +1,25 @@ module Admin::JournalPapersHelper + def get_authors_text(journal) + (journal.authors.to_s.blank? ? get_member(journal).collect(&:name).join('/') : Nokogiri::HTML(journal.authors.to_s).text rescue "") + end + def get_authors_show(journal) + (journal.authors.to_s.blank? ? get_member(journal).collect{|member| "#{member.name}"}.join('/') : (journal.authors.to_s) rescue "") + end + def get_member(journal) + Array(MemberProfile.find(Array(journal).collect(&:member_profile_id))) + end + def get_level_type(journal) + !journal.journal_levels.blank? ? "(#{journal.journal_levels.collect(&:title).join(', ')})" : nil + end + def get_author_type(journal) + journal.journal_paper_author_types.collect(&:title).join(', ') rescue '' + end + def get_paper_type(journal) + journal.journal_paper_type.title rescue '' + end + def get_publication_date(journal) + journal.publication_date.strftime('%Y/%m/%d') rescue '' + end def page_for_journal_paper(journal_paper_object) journal_paper_page = nil pages = Page.where(:module=>"journal_paper") diff --git a/app/models/journal_paper.rb b/app/models/journal_paper.rb index 8ff8da1..9f82cf3 100644 --- a/app/models/journal_paper.rb +++ b/app/models/journal_paper.rb @@ -2,7 +2,7 @@ class JournalPaper include Mongoid::Document include Mongoid::Timestamps include Mongoid::Attributes::Dynamic - + include Admin::JournalPapersHelper include OrbitModel::Status include MemberHelper include Slug @@ -215,6 +215,11 @@ class JournalPaper files << (url.nil? ? "" : "
  • #{title}
  • ") end value = files.join("") + when "url" + value = self.url.to_s.blank? ? "" : "#{self.url}" + when "authors" + value = get_authors_show(self) + puts ['author_here',value] else value = self.send(field) rescue "" end diff --git a/app/views/admin/journal_papers/_form.html.erb b/app/views/admin/journal_papers/_form.html.erb index 3661f1f..59268a3 100644 --- a/app/views/admin/journal_papers/_form.html.erb +++ b/app/views/admin/journal_papers/_form.html.erb @@ -65,7 +65,7 @@
    <%= f.fields_for :authors_translations do |f| %> - <%= f.text_area locale, class: "input-block-level", placeholder: t("personal_journal.authors"), value: (@journal_paper.authors_translations[locale] rescue nil) %> + <%= f.text_area locale, class: "ckeditor input-block-level", placeholder: t("personal_journal.authors"), value: (@journal_paper.authors_translations[locale] rescue nil) %> <% end %>
    @@ -120,27 +120,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 %> -
    diff --git a/app/views/admin/journal_papers/_writing_journal.html.erb b/app/views/admin/journal_papers/_writing_journal.html.erb index 0670767..24acaac 100644 --- a/app/views/admin/journal_papers/_writing_journal.html.erb +++ b/app/views/admin/journal_papers/_writing_journal.html.erb @@ -2,10 +2,14 @@ <%= writing_journal.year %> - <%= link_to writing_journal.create_link, OrbitHelper.url_to_plugin_show(writing_journal.to_param,'personal_journal').to_s, target: "blank"%> + + + <%= "#{Nokogiri::HTML(writing_journal.create_link).text}" %> + +
    diff --git a/app/views/admin/journal_papers/index.html.erb b/app/views/admin/journal_papers/index.html.erb index 24eeed8..e59d4b1 100644 --- a/app/views/admin/journal_papers/index.html.erb +++ b/app/views/admin/journal_papers/index.html.erb @@ -1,3 +1,19 @@ + + @@ -14,8 +30,12 @@
    +
    + + + + +<% if params['mode']!='simple' %> + + + + +<% end %> + + + + + +<% @journals.each do |key,journals| %> + + <% if params['mode']=='simple' + len = journals.length + else + len = journals.values.reduce(0){|sum,num| sum+num.length} + end + %> + + + <% if params['mode']=='simple' %> + + <% journals.each_with_index do |journal,i| %> + + <% if len!=(i+1) %> + + + <% end %> + <% end %> + <% else %> + <% i=0 %> + <% journals.each do |k,v| %> + <% len1 = v.length %> + <% k.each do |keychild| %> + + <% end %> + + <% v.each_with_index do |journal_child,index1| %> + + <% if len1!=index1 %> + + + <% end %> + <% end %> + <% if len1!=(i+1) %> + + + <% end %> + <% i =i+1 %> + <% end %> + <% end %> + +<% end %> + +
    <%= t('personal_journal.paper_title') %><%= t('personal_journal.journal_title') %><%= t('personal_journal.level_type') %><%= t('personal_journal.author_type') %><%= t('personal_journal.paper_type') %><%= t('personal_journal.publication_date') %><%= t("personal_journal.merge") %><%= t("personal_plugins.author") %>
    + <%= key[0].values.map{|v| v=="" ? t('personal_journal.no_input') : v}.join('/') %> + + <%= key[1].values.map{|v| v=="" ? t('personal_journal.no_input') : v}.join('/') %> + + + + + <%= get_member(journal).collect(&:name).join(' / ') rescue t('personal_journal.no_input') %> + +
    + <%= keychild.to_s.blank? ? t('personal_journal.no_input') : keychild %> + + + + + <%= get_member(journal_child).collect(&:name).join(' / ') rescue t('personal_journal.no_input') %> + +
    + \ No newline at end of file diff --git a/app/views/plugin/personal_journal/_profile.html.erb b/app/views/plugin/personal_journal/_profile.html.erb index e4a16df..1af5d4f 100644 --- a/app/views/plugin/personal_journal/_profile.html.erb +++ b/app/views/plugin/personal_journal/_profile.html.erb @@ -4,7 +4,6 @@ <% content_for :page_specific_javascript do %> <%= javascript_include_tag "lib/list-check" %> <% end %> - <% if has_access? @writing_journals = JournalPaper.where(member_profile_id: @member.id).desc(:year).page(params[:page]).per(10) @@ -12,7 +11,6 @@ @writing_journals = JournalPaper.where(is_hidden: false, member_profile_id: @member.id).desc(:year).page(params[:page]).per(10) end %> - <% if has_access? %>
    @@ -21,7 +19,6 @@
    <% end -%> - @@ -56,16 +53,13 @@ <% end %> - <% end %> -
    <%= writing_journal.authors %>
    -
    <% if has_access? %>
    @@ -78,7 +72,6 @@ <%= paginate @writing_journals, :params => {:direction => params[:direction], :sort => params[:sort] } %>
    - - diff --git a/config/locales/en.yml b/config/locales/en.yml index 8e659ec..86bc349 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3,6 +3,9 @@ en: personal_journal: Journal Paper journal_paper: Journal Paper personal_journal: + merge: Merge + upload: Upload + no_input: No Input select_class: "——select class——" search_class: "search class:" word_to_search: "word to search:" @@ -41,7 +44,7 @@ en: graph_by : "Graph By" frontend: writing_journals: "Journal Paper 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 8d8b997..5e589d9 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -3,6 +3,9 @@ zh_tw: personal_journal: 期刊論文 journal_paper: 期刊論文 personal_journal: + merge: "合併" + upload: "上傳" + no_input: "未輸入" select_class: "——選取分類——" search_class: "搜尋類別:" word_to_search: "關鍵字搜尋:" @@ -40,7 +43,7 @@ zh_tw: graph_by : "Graph By" frontend: writing_journals: "期刊論文前台" - + strict_compare_mode: "嚴格比較模式" create_success : "新增完成!!" update_success : "更新完成!!" delete_success : "刪除成功!!" diff --git a/config/routes.rb b/config/routes.rb index ae2c340..caa0533 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,39 +1,41 @@ Rails.application.routes.draw do locales = Site.find_by(site_active: true).in_use_locales rescue I18n.available_locales scope "(:locale)", locale: Regexp.new(locales.join("|")) do - namespace :admin do - get 'writing_journal_setting' => "journal_papers#setting" - get 'journal_papers/download_excel_format' => 'journal_papers#excel_format' - post 'journal_papers/import_from_excel' => 'journal_papers#import_from_excel' - - resources :journal_papers do - collection do - get 'toggle_hide' => 'journal_papers#toggle_hide' - get 'analysis' - get 'analysis_report' - get "download_excel" - end - end - - resources :members do - collection do - scope '(:name-:uid)' do - resources :journal_papers do - collection do - get 'frontend_setting' => 'journal_papers#frontend_setting' - post 'update_frontend_setting' => 'journal_papers#update_frontend_setting' + namespace :admin do + get 'writing_journal_setting' => "journal_papers#setting" + get 'journal_papers/download_excel_format' => 'journal_papers#excel_format' + post 'journal_papers/import_from_excel' => 'journal_papers#import_from_excel' + + resources :journal_papers do + collection do + post 'merge_process' => 'journal_papers#merge_process' + get 'merge' => 'journal_papers#merge' + get 'toggle_hide' => 'journal_papers#toggle_hide' + get 'analysis' + get 'analysis_report' + get "download_excel" + end + end + + resources :members do + collection do + scope '(:name-:uid)' do + resources :journal_papers do + collection do + get 'frontend_setting' => 'journal_papers#frontend_setting' + post 'update_frontend_setting' => 'journal_papers#update_frontend_setting' + end + end end end end - end - end - - resources :journal_levels - resources :journal_paper_author_types - resources :journal_paper_types - resources :journal_paper_intros - end - get "/xhr/personal_journal/get_fields_for_index" => "personal_journals#get_fields_for_index" - post "/xhr/personal_journal/save_index_fields" => "personal_journals#save_index_fields" + + resources :journal_levels + resources :journal_paper_author_types + resources :journal_paper_types + resources :journal_paper_intros + end + get "/xhr/personal_journal/get_fields_for_index" => "personal_journals#get_fields_for_index" + post "/xhr/personal_journal/save_index_fields" => "personal_journals#save_index_fields" end end From 0a179503d6aa4e0c0a243507811d1f2bab958073 Mon Sep 17 00:00:00 2001 From: chiu Date: Tue, 5 Nov 2019 21:59:31 +0800 Subject: [PATCH 2/3] Update journal_papers_controller.rb --- app/controllers/admin/journal_papers_controller.rb | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/app/controllers/admin/journal_papers_controller.rb b/app/controllers/admin/journal_papers_controller.rb index fa41c6d..ffe8624 100644 --- a/app/controllers/admin/journal_papers_controller.rb +++ b/app/controllers/admin/journal_papers_controller.rb @@ -31,20 +31,6 @@ class Admin::JournalPapersController < OrbitMemberController @journals.delete key end end - #journals = JournalPaper.order_by(:year=>'desc').map{|value| value} - #journals_name1 = journals.map{|value| value[:paper_title]} - #journals_name2 = journals.map{|value| value[:journal_title]} - #compare1 = journals_name1.map{|v1| journals_name1.select{|v2| v2==v1}.count>1} - #compare2 = journals_name2.map{|v1| journals_name2.select{|v2| v2==v1}.count>1} - #compare = compare1 and compare2 - #@journal = Hash.new - #compare.each_with_index do |b,i| - # if b && !(@journal.keys.include? [journals_name1[i],journals_name2[i]]) - # @journal[[journals_name1[i],journals_name2[i]]] = [journals[i]] - # elsif b - # @journal[[journals_name1[i],journals_name2[i]]] << journals[i] - # end - #end if params['mode']!='simple' @journals.each do |key,value| @journals[key] = value.group_by{|v| [get_level_type(v),get_author_type(v),get_paper_type(v),get_publication_date(v)]} From 4a64893c59c1c2ca11c55c577b652183a455ab62 Mon Sep 17 00:00:00 2001 From: chiu Date: Tue, 5 Nov 2019 22:53:17 +0800 Subject: [PATCH 3/3] Update journal_paper.rb remove puts --- app/models/journal_paper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/models/journal_paper.rb b/app/models/journal_paper.rb index 9f82cf3..00faf85 100644 --- a/app/models/journal_paper.rb +++ b/app/models/journal_paper.rb @@ -219,7 +219,6 @@ class JournalPaper value = self.url.to_s.blank? ? "" : "#{self.url}" when "authors" value = get_authors_show(self) - puts ['author_here',value] else value = self.send(field) rescue "" end