fix the problem of creating multiple authors

This commit is contained in:
chiu 2019-11-11 00:13:52 +08:00
parent 0e2ba7ab1b
commit 45d49bc290
11 changed files with 239 additions and 28 deletions

View File

@ -8,6 +8,44 @@ class Admin::BooksController < OrbitMemberController
before_action :need_access_right
before_action :allow_admin_only, :only => [:index, :setting]
def merge_process
params['book_id'].each do |book_id|
book_ids = book_id.split('/')
books = Book.find(book_ids)
member_ids = books.collect(&:member_profile_id).uniq
books.each_with_index do |book,index1|
if index1== 0
book.member_profile_id = member_ids
book.save!
else
book.delete
end
end
end
redirect_to :action=> 'index'
end
def merge
@books=Book.order_by(:year=>'desc').map{|value| value}.group_by{|v| [v[:book_title],v[:isbn]]}
@books.each do |key,value|
if value.length<=1
@books.delete key
end
end
if params['mode']!='simple'
@books.each do |key,value|
@books[key] = value.group_by{|v| [get_publisher(v),get_author_type(v),get_paper_type(v),get_publication_date(v)]}
@books[key].each do |key1,value1|
if value1.length<=1
@books[key].delete key1
end
end
if @books[key].length==0
@books.delete key
end
end
end
end
def index
@writing_books = Book.order_by(:year=>'desc').page(params[:page]).per(10)
@ -49,14 +87,15 @@ class Admin::BooksController < OrbitMemberController
end
def edit
@member = @book.member_profile
@member = get_member(@book)
if params[:desktop]
render :layout => false
end
end
def update
@member = @book.member_profile
@member = get_member(@book)
book_params['member_profile_id'] = params[:author_members]
@book.update_attributes(book_params)
@book.save
if params[:desktop] == "true"
@ -68,7 +107,7 @@ class Admin::BooksController < OrbitMemberController
def new
@book = Book.new
@member = MemberProfile.find_by(:uid=>params['uid']) rescue nil
@member = Array(MemberProfile.find_by(:uid=>params['uid'])) rescue nil
if params[:desktop]
render :layout => false
end
@ -90,9 +129,9 @@ class Admin::BooksController < OrbitMemberController
elsif !params[:author_members].blank?
params[:author_members].each do |author_member|
#params[:author_members].each do |author_member|
book_params['member_profile_id'] = author_member
book_params['member_profile_id'] = params[:author_members]
@book = Book.new(book_params)
@book.save
@ -100,7 +139,7 @@ class Admin::BooksController < OrbitMemberController
render json: {"data" => get_paper_list}.to_json
end
end
#end
redirect_to params['referer_url']

View File

@ -1,4 +1,5 @@
class PersonalBooksController < ApplicationController
include Admin::PersonalBooksHelper
def index
params = OrbitHelper.params
page_data_count = OrbitHelper.page_data_count
@ -45,6 +46,10 @@ class PersonalBooksController < ApplicationController
books_show = books_temp.select { |value| search_all_words((value.book_type.title rescue ''), params[:keywords]) }
when 'language'
books_show = books_temp.select { |value| search_all_words((!value.language.nil? ? t(value.language.to_s) : ''), params[:keywords]) }
when 'authors'
books_show = books_temp.select { |value| search_all_words(get_authors_text(value), params[:keywords]) }
when 'note'
books_show = books_temp.select { |value| search_all_words(Nokogiri::HTML(value.note).text, params[:keywords]) }
else
books_show = books_temp.select { |value| search_all_words(value.send(params[:selectbox]).to_s, params[:keywords]) }
end
@ -73,6 +78,10 @@ class PersonalBooksController < ApplicationController
t << { 'value' => (!book.language.nil? ? t(book.language.to_s) : '') }
when 'book_paper_type'
t << { 'value' => (book.book_type.title rescue '') }
when 'url'
t << { 'value' => book.url.to_s.blank? ? "" : "<a href='#{book.url}'>#{book.url}</a>"}
when 'authors'
t << { 'value' => get_authors_show(book) }
else
t << { 'value' => (book.send(fs) rescue '') }
end
@ -135,6 +144,7 @@ class PersonalBooksController < ApplicationController
file
publication_date
language
note
]
{ 'plugin_datas' => plugin.get_plugin_data(fields_to_show) }
@ -158,6 +168,7 @@ class PersonalBooksController < ApplicationController
url
publication_date
language
note
]
@fields_to_show = @fields_to_show.map { |fs| [t("personal_book.#{fs}"), fs] }
@default_fields_to_show = %w[

View File

@ -1,5 +1,25 @@
module Admin::PersonalBooksHelper
def get_authors_text(book)
(book.authors.to_s.blank? ? get_member(book).collect(&:name).join('/') : Nokogiri::HTML(book.authors.to_s).text rescue '')
end
def get_authors_show(book)
(book.authors.to_s.blank? ? get_member(book).collect{|member| "<a href='#{OrbitHelper.url_to_plugin_show(member.to_param,'member')}' title='#{member.name}'>#{member.name}</a>"}.join('/') : book.authors.to_s rescue '')
end
def get_member(book)
Array(MemberProfile.find(Array(book).collect(&:member_profile_id)))
end
def get_publisher(book)
book.publisher
end
def get_author_type(book)
book.book_author_types.collect(&:title).join(', ') rescue ''
end
def get_paper_type(book)
!book.book_type.blank? ? book.book_type.title : nil
end
def get_publication_date(book)
book.publication_date.strftime('%Y/%m/%d') rescue ''
end
def get_paper_list
user = current_user.nil? ? OrbitHelper.current_user : current_user
user_profile = user.member_profile

View File

@ -2,7 +2,7 @@ class Book
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Attributes::Dynamic
include Admin::PersonalBooksHelper
include OrbitModel::Status
include MemberHelper
include Slug
@ -175,6 +175,10 @@ class Book
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)
else
value = self.send(field) rescue ""
end

View File

@ -87,7 +87,7 @@
<label class="control-label muted"><%= t("personal_book.authors") %></label>
<div class="controls">
<%= f.fields_for :authors_translations do |f| %>
<%= f.text_area locale, class: "input-block-level", placeholder: t("personal_book.authors"), value: (@book.authors_translations[locale] rescue nil) %>
<%= f.text_area locale, class: "ckeditor input-block-level", placeholder: t("personal_book.authors"), value: (@book.authors_translations[locale] rescue nil) %>
<% end %>
</div>
</div>
@ -141,26 +141,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">
@ -263,7 +254,7 @@
<div class="control-group big-group">
<label class="control-label muted"><%= t("personal_book.note") %></label>
<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>

View File

@ -2,7 +2,7 @@
<tr id="<%= dom_id writing_book %>" class="with_action">
<td class="span1"><%= writing_book.year %></td>
<td class="span1">
<%= link_to writing_book.create_link, OrbitHelper.url_to_plugin_show(writing_book.to_param,'personal_book'), target: "blank" %>
<%= link_to Nokogiri::HTML(writing_book.create_link).text, OrbitHelper.url_to_plugin_show(writing_book.to_param,'personal_book'), target: "blank" %>
<div class="quick-edit">
<ul class="nav nav-pills hide">
<% if current_user.is_admin? %>

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_book.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_book.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_conference.merge') %></button>
</form>
</nobr>
<form method="post" action='/admin/books/merge_process?' name='merge_form'>
<%= token_tag(nil) %>
<table class="table main-list">
<thead>
<tr>
<th><%= t('personal_book.book_title') %></th>
<th><%= t('personal_book.isbn') %></th>
<% if params['mode']!='simple' %>
<th><%= t('personal_book.publisher') %></th>
<th><%= t('personal_book.author_type') %></th>
<th><%= t('personal_book.book_paper_type') %></th>
<th><%= t('personal_book.publication_date') %></th>
<% end %>
<th><%= t("personal_book.merge") %></th>
<th><%= t("personal_book.author") %></th>
</tr>
</thead>
<tbody>
<% @books.each do |key,books| %>
<tr>
<% if params['mode']=='simple'
len = books.length
else
len = books.values.reduce(0){|sum,num| sum+num.length}
end
%>
<td rowspan="<%= len %>">
<%= key[0].values.map{|v| v=="" ? t('personal_book.no_input') : v}.join('/') %>
</td>
<td rowspan="<%= len %>">
<%= key[1] %>
</td>
<% if params['mode']=='simple' %>
<td rowspan="<%= len %>">
<input type="checkbox" class="checkbox" name="books_id[]" value="<%= books.collect(&:id).join('/') %>">
</td>
<% books.each_with_index do |book,i| %>
<td>
<a href="<%= edit_admin_book_path(book) %>" target="_blank">
<%= get_member(book).collect(&:name).join(' / ') rescue t('personal_book.no_input') %>
</a>
</td>
<% if len!=(i+1) %>
</tr>
<tr>
<% end %>
<% end %>
<% else %>
<% i=0 %>
<% books.each do |k,v| %>
<% len1 = v.length %>
<% k.each do |keychild| %>
<td rowspan="<%= len1 %>">
<%= keychild.to_s.blank? ? t('personal_book.no_input') : keychild %>
</td>
<% end %>
<td rowspan="<%= len1 %>">
<input type="checkbox" class="checkbox" name="book_id[]" value="<%= v.collect(&:id).join('/') %>">
</td>
<% v.each_with_index do |book_child,index1| %>
<td>
<a href="<%= edit_admin_book_path(book_child) %>" target="_blank">
<%= get_member(book_child).collect(&:name).join(' / ') rescue t('personal_book.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,6 +4,9 @@ en:
book_paper: "Book / Book Chapter"
personal_book: "Book / Book Chapter"
personal_book:
merge: Merge
upload: Upload
no_input: No Input
select_class: "——select class——"
search_class: "search class:"
word_to_search: "word to search:"
@ -43,7 +46,7 @@ en:
graph_by : "Graph By"
frontend:
writing_books: "Book Frontend"
strict_compare_mode: Strict Compare mode
create_success : "Successfully Create"
update_success : "Successfully Update"
delete_success : "Successfully Delete"

View File

@ -4,6 +4,9 @@ zh_tw:
book_paper: "專書 / 專書章節"
personal_book : "專書 / 專書章節"
personal_book:
merge: "合併"
upload: "上傳"
no_input: "未輸入"
select_class: "——選取分類——"
search_class: "搜尋類別:"
word_to_search: "關鍵字搜尋:"
@ -43,7 +46,7 @@ zh_tw:
graph_by : "Graph By"
frontend:
writing_books: "專書前台"
strict_compare_mode: "嚴格比較模式"
create_success : "新增完成!!"
update_success : "更新完成!!"
delete_success : "刪除成功!!"

View File

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