fix the problem of multiple creating data when multiple authors are add

This commit is contained in:
chiu 2019-11-05 21:39:46 +08:00
parent 295b6cbf0f
commit 0f1f7c7b90
12 changed files with 286 additions and 71 deletions

View File

@ -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? '-'

View File

@ -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? ? "" : "<a href='#{journal_paper.url}'>#{journal_paper.url}</a>"}
when 'authors'
t << { 'value' => get_authors_show(journal_paper) }
else
t << { 'value' => (journal_paper.send(fs) rescue '') }
end

View File

@ -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| "<a href='#{OrbitHelper.url_to_plugin_show(member.to_param,'member')}' title='#{member.name}'>#{member.name}</a>"}.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")

View File

@ -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? ? "" : "<li><a href='#{url}'' target='_blank'>#{title}</li>")
end
value = files.join("")
when "url"
value = self.url.to_s.blank? ? "" : "<a href='#{self.url}'>#{self.url}</a>"
when "authors"
value = get_authors_show(self)
puts ['author_here',value]
else
value = self.send(field) rescue ""
end

View File

@ -65,7 +65,7 @@
<label class="control-label muted"><%= t("personal_journal.authors") %></label>
<div class="controls">
<%= 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 %>
</div>
</div>
@ -120,27 +120,17 @@
<!-- Basic Module -->
<div class="tab-pane fade in active" id="basic">
<% if !@member.nil? %>
<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 %>
<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:[]} %>
<% 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 %>
</div>
</div>
<% end %>
<!-- year -->
<div class="control-group">
<label class="control-label muted"><%= t("personal_journal.year") %></label>

View File

@ -2,10 +2,14 @@
<tr id="<%= dom_id writing_journal %>" class="with_action">
<td class="span1"><%= writing_journal.year %></td>
<td class="span1">
<%= link_to writing_journal.create_link, OrbitHelper.url_to_plugin_show(writing_journal.to_param,'personal_journal').to_s, target: "blank"%>
<a href="<%= OrbitHelper.url_to_plugin_show(writing_journal.to_param,'personal_journal').to_s %>" target="blank">
<span>
<%= "#{Nokogiri::HTML(writing_journal.create_link).text}" %>
</span>
</a>
<div class="quick-edit">
<ul class="nav nav-pills hide">
<li><%= link_to t('edit'), edit_admin_journal_paper_path(writing_journal) %></li>
<li><%= link_to t('edit').to_s, edit_admin_journal_paper_path(writing_journal) %></li>
<li><%= link_to t(:delete_), admin_journal_paper_path(id: writing_journal.id), method: :delete, remote: true, data: { confirm: 'Are you sure?' } %></li>
</ul>
</div>

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">
<thead>
<tr>
@ -14,8 +30,12 @@
<div class="bottomnav clearfix">
<div class="action pull-right">
<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_journal.merge') %>
</button>
<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_journal.upload') %>
<span class="caret"></span>
</button>
<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_journal.merge') %></button>
</form>
</nobr>
<form method="post" action='/admin/journal_papers/merge_process?' name='merge_form'>
<%= token_tag(nil) %>
<table class="table main-list">
<thead>
<tr>
<th><%= t('personal_journal.paper_title') %></th>
<th><%= t('personal_journal.journal_title') %></th>
<% if params['mode']!='simple' %>
<th><%= t('personal_journal.level_type') %></th>
<th><%= t('personal_journal.author_type') %></th>
<th><%= t('personal_journal.paper_type') %></th>
<th><%= t('personal_journal.publication_date') %></th>
<% end %>
<th><%= t("personal_journal.merge") %></th>
<th><%= t("personal_plugins.author") %></th>
</tr>
</thead>
<tbody>
<% @journals.each do |key,journals| %>
<tr>
<% if params['mode']=='simple'
len = journals.length
else
len = journals.values.reduce(0){|sum,num| sum+num.length}
end
%>
<td rowspan="<%= len %>">
<%= key[0].values.map{|v| v=="" ? t('personal_journal.no_input') : v}.join('/') %>
</td>
<td rowspan="<%= len %>">
<%= key[1].values.map{|v| v=="" ? t('personal_journal.no_input') : v}.join('/') %>
</td>
<% if params['mode']=='simple' %>
<td rowspan="<%= len %>">
<input type="checkbox" class="checkbox" name="journal_id[]" value="<%= journals.collect(&:id).join('/') %>">
</td>
<% journals.each_with_index do |journal,i| %>
<td>
<a href="<%= edit_admin_journal_paper_path(journal) %>" target="_blank">
<%= get_member(journal).collect(&:name).join(' / ') rescue t('personal_journal.no_input') %>
</a>
</td>
<% if len!=(i+1) %>
</tr>
<tr>
<% end %>
<% end %>
<% else %>
<% i=0 %>
<% journals.each do |k,v| %>
<% len1 = v.length %>
<% k.each do |keychild| %>
<td rowspan="<%= len1 %>">
<%= keychild.to_s.blank? ? t('personal_journal.no_input') : keychild %>
</td>
<% end %>
<td rowspan="<%= len1 %>">
<input type="checkbox" class="checkbox" name="journal_id[]" value="<%= v.collect(&:id).join('/') %>">
</td>
<% v.each_with_index do |journal_child,index1| %>
<td>
<a href="<%= edit_admin_journal_paper_path(journal_child) %>" target="_blank">
<%= get_member(journal_child).collect(&:name).join(' / ') rescue t('personal_journal.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

@ -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? %>
<div class="list-active">
<div class="btn-group">
@ -21,7 +19,6 @@
</div>
</div>
<% end -%>
<table class="table table-condensed table-striped main-list">
<thead>
<tr>
@ -56,16 +53,13 @@
<% end %>
</ul>
</div>
</td>
<td><%= writing_journal.authors %></td>
</tr>
<% end %>
</tbody>
</table>
<div class="bottomnav clearfix">
<% if has_access? %>
<div class="action pull-right">
@ -78,7 +72,6 @@
<%= paginate @writing_journals, :params => {:direction => params[:direction], :sort => params[:sort] } %>
</div>
</div>
<div id="dialog" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="Delete item" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
@ -89,4 +82,3 @@
<button class="delete-item btn btn-danger"><%= t(:submit) %></button>
</div>
</div>

View File

@ -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 Frontend"
strict_compare_mode: Strict Compare mode
create_success : "Successfully Create"
update_success : "Successfully Update"
delete_success : "Successfully Delete"

View File

@ -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 : "刪除成功!!"

View File

@ -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