Merge branch 'master' into 'master'

Master

fix the problem of creating multiple authors

See merge request !4
This commit is contained in:
wmcheng 2019-11-05 23:51:42 +08:00
commit 2f91ead395
11 changed files with 234 additions and 27 deletions

View File

@ -8,13 +8,51 @@ class Admin::WritingConferencesController < 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['writing_conference_id'].each do |writing_conference_id|
writing_conference_ids = writing_conference_id.split('/')
writing_conferences = WritingConference.find(writing_conference_ids)
member_ids = writing_conferences.collect(&:member_profile_id).uniq
writing_conferences.each_with_index do |writing_conference,index1|
if index1== 0
writing_conference.member_profile_id = member_ids
writing_conference.save!
else
writing_conference.delete
end
end
end
redirect_to :action=> 'index'
end
def merge
@writing_conferences=WritingConference.order_by(:year=>'desc').map{|value| value}.group_by{|v| [v[:paper_title],v[:conference_title]]}
@writing_conferences.each do |key,value|
if value.length<=1
@writing_conferences.delete key
end
end
if params['mode']!='simple'
@writing_conferences.each do |key,value|
@writing_conferences[key] = value.group_by{|v| [get_sponsor(v),get_author_type(v),get_paper_type(v),get_publication_date(v)]}
@writing_conferences[key].each do |key1,value1|
if value1.length<=1
@writing_conferences[key].delete key1
end
end
if @writing_conferences[key].length==0
@writing_conferences.delete key
end
end
end
end
def index def index
@writing_conferences = WritingConference.order_by(:year=>'desc').page(params[:page]).per(10) @writing_conferences = WritingConference.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
@writing_conference = WritingConference.new @writing_conference = WritingConference.new
if params[:desktop] if params[:desktop]
@ -60,9 +98,9 @@ class Admin::WritingConferencesController < 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|
conference_params['member_profile_id'] = author_member conference_params['member_profile_id'] = params[:author_members]
@writing_conference = WritingConference.new(conference_params) @writing_conference = WritingConference.new(conference_params)
@writing_conference.save @writing_conference.save
@ -70,7 +108,7 @@ class Admin::WritingConferencesController < 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 +130,15 @@ class Admin::WritingConferencesController < OrbitMemberController
end end
def edit def edit
@member = @writing_conference.member_profile @member = get_member(@writing_conference)
if params[:desktop] if params[:desktop]
render :layout => false render :layout => false
end end
end end
def update def update
@member = @writing_conference.member_profile @member = get_member(@writing_conference)
conference_params['member_profile_id'] = params[:author_members]
@writing_conference.update_attributes(conference_params) @writing_conference.update_attributes(conference_params)
@writing_conference.save @writing_conference.save
if params[:desktop] == "true" if params[:desktop] == "true"

View File

@ -1,4 +1,5 @@
class PersonalConferencesController < ApplicationController class PersonalConferencesController < ApplicationController
include Admin::PersonalConferencesHelper
def index def index
params = OrbitHelper.params params = OrbitHelper.params
page_data_count = OrbitHelper.page_data_count page_data_count = OrbitHelper.page_data_count
@ -43,6 +44,8 @@ class PersonalConferencesController < ApplicationController
writing_conferences_show = writing_conferences_temp.select { |value| search_all_words(value.conference_author_types.collect(&:title).join(', '), params[:keywords]) } writing_conferences_show = writing_conferences_temp.select { |value| search_all_words(value.conference_author_types.collect(&:title).join(', '), params[:keywords]) }
when 'language' when 'language'
writing_conferences_show = writing_conferences_temp.select { |value| search_all_words((!value.language.nil? ? t(value.language.to_s) : ''), params[:keywords]) } writing_conferences_show = writing_conferences_temp.select { |value| search_all_words((!value.language.nil? ? t(value.language.to_s) : ''), params[:keywords]) }
when 'authors'
writing_conferences_show = writing_conferences_temp.select { |value| search_all_words(get_authors_text(value), params[:keywords]) }
else else
writing_conferences_show = writing_conferences_temp.select { |value| search_all_words(value.send(params[:selectbox]).to_s, params[:keywords]) } writing_conferences_show = writing_conferences_temp.select { |value| search_all_words(value.send(params[:selectbox]).to_s, params[:keywords]) }
end end
@ -75,6 +78,10 @@ class PersonalConferencesController < ApplicationController
t << { 'value' => writing_conference.duration } t << { 'value' => writing_conference.duration }
when 'language' when 'language'
t << { 'value' => (!writing_conference.language.nil? ? t(writing_conference.language.to_s) : '') } t << { 'value' => (!writing_conference.language.nil? ? t(writing_conference.language.to_s) : '') }
when 'url'
t << { 'value' => writing_conference.url.to_s.blank? ? "" : "<a href='#{writing_conference.url}'>#{writing_conference.url}</a>"}
when 'authors'
t << { 'value' => get_authors_show(writing_conference) }
else else
t << { 'value' => writing_conference.send(fs) } t << { 'value' => writing_conference.send(fs) }
end end

View File

@ -1,5 +1,25 @@
module Admin::PersonalConferencesHelper module Admin::PersonalConferencesHelper
def get_authors_text(writing_conference)
(writing_conference.authors.to_s.blank? ? get_member(writing_conference).collect(&:name).join('/') : Nokogiri::HTML(writing_conference.authors.to_s).text rescue '')
end
def get_authors_show(writing_conference)
(writing_conference.authors.to_s.blank? ? get_member(writing_conference).collect{|member| "<a href='#{OrbitHelper.url_to_plugin_show(member.to_param,'member')}' title='#{member.name}'>#{member.name}</a>"}.join('/') : writing_conference.authors.to_s rescue '')
end
def get_member(writing_conference)
Array(MemberProfile.find(Array(writing_conference).collect(&:member_profile_id)))
end
def get_sponsor(writing_conference)
writing_conference.sponsor
end
def get_author_type(writing_conference)
writing_conference.conference_author_types.collect(&:title).join(', ') rescue ''
end
def get_paper_type(writing_conference)
!writing_conference.conference_paper_types.blank? ? writing_conference.conference_paper_types.collect(&:title).join(', ').to_s : nil
end
def get_publication_date(writing_conference)
writing_conference.publication_date.strftime('%Y/%m/%d') 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

View File

@ -1,7 +1,7 @@
class WritingConference class WritingConference
include Mongoid::Document include Mongoid::Document
include Mongoid::Timestamps include Mongoid::Timestamps
include Admin::PersonalConferencesHelper
include OrbitModel::Status include OrbitModel::Status
include OrbitTag::Taggable include OrbitTag::Taggable
include MemberHelper include MemberHelper
@ -196,6 +196,10 @@ class WritingConference
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 "url"
value = self.url.to_s.blank? ? "" : "<a href='#{self.url}'>#{self.url}</a>"
when "authors"
value = get_authors_show(self)
else else
value = self.send(field) rescue "" value = self.send(field) rescue ""
end end

View File

@ -81,7 +81,7 @@
<label class="control-label muted"><%= t("personal_conference.authors") %></label> <label class="control-label muted"><%= t("personal_conference.authors") %></label>
<div class="controls"> <div class="controls">
<%= f.fields_for :authors_translations do |f| %> <%= f.fields_for :authors_translations do |f| %>
<%= f.text_area locale, class: "input-block-level", placeholder: t("personal_conference.authors"), value: (@writing_conference.authors_translations[locale] rescue nil) %> <%= f.text_area locale, class: "ckeditor input-block-level", placeholder: t("personal_conference.authors"), value: (@writing_conference.authors_translations[locale] rescue nil) %>
<% end %> <% end %>
</div> </div>
</div> </div>
@ -138,26 +138,17 @@
<!-- Basic Module --> <!-- Basic Module -->
<div class="tab-pane fade in active" id="basic"> <div class="tab-pane fade in active" id="basic">
<div class="control-group big-group">
<label class="control-label muted"><%= t("personal_plugins.author") %></label>
<div class="controls">
<% if !@member.nil? %> <% if !@member.nil? %>
<%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'author_members[]', email_members:@member} %>
<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 %> <% 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:[]} %> <%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'author_members[]', email_members:[]} %>
<% end %>
</div> </div>
</div> </div>
<% end %>
<!-- year --> <!-- year -->
<div class="control-group"> <div class="control-group">

View File

@ -2,7 +2,7 @@
<tr id="<%= dom_id writing_conference %>" class="<%= writing_conference.is_hidden ? "checkHide" : "" %>"> <tr id="<%= dom_id writing_conference %>" class="<%= writing_conference.is_hidden ? "checkHide" : "" %>">
<td><%= writing_conference.year %></td> <td><%= writing_conference.year %></td>
<td> <td>
<%= link_to writing_conference.create_link, OrbitHelper.url_to_plugin_show(writing_conference.to_param,'personal_conference'), target: "blank"%> <%= link_to Nokogiri::HTML(writing_conference.create_link).text, OrbitHelper.url_to_plugin_show(writing_conference.to_param,'personal_conference'), target: "blank"%>
<div class="quick-edit"> <div class="quick-edit">
<ul class="nav nav-pills hide"> <ul class="nav nav-pills hide">
<li><%= link_to t('edit'), edit_admin_writing_conference_path(writing_conference) %></li> <li><%= link_to t('edit'), edit_admin_writing_conference_path(writing_conference) %></li>

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"> <table class="table main-list">
<thead> <thead>
<tr> <tr>
@ -14,8 +30,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_conference.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_conference.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_conference.merge') %></button>
</form>
</nobr>
<form method="post" action='/admin/writing_conferences/merge_process?' name='merge_form'>
<%= token_tag(nil) %>
<table class="table main-list">
<thead>
<tr>
<th><%= t('personal_conference.paper_title') %></th>
<th><%= t('personal_conference.conference_title') %></th>
<% if params['mode']!='simple' %>
<th><%= t('personal_conference.sponsor') %></th>
<th><%= t('personal_conference.author_type') %></th>
<th><%= t('personal_conference.paper_type') %></th>
<th><%= t('personal_conference.publication_date') %></th>
<% end %>
<th><%= t("personal_conference.merge") %></th>
<th><%= t("personal_plugins.author") %></th>
</tr>
</thead>
<tbody>
<% @writing_conferences.each do |key,writing_conferences| %>
<tr>
<% if params['mode']=='simple'
len = writing_conferences.length
else
len = writing_conferences.values.reduce(0){|sum,num| sum+num.length}
end
%>
<td rowspan="<%= len %>">
<%= key[0].values.map{|v| v=="" ? t('personal_conference.no_input') : v}.join('/') %>
</td>
<td rowspan="<%= len %>">
<%= key[1].values.map{|v| v=="" ? t('personal_conference.no_input') : v}.join('/') %>
</td>
<% if params['mode']=='simple' %>
<td rowspan="<%= len %>">
<input type="checkbox" class="checkbox" name="writing_conference_id[]" value="<%= writing_conferences.collect(&:id).join('/') %>">
</td>
<% writing_conferences.each_with_index do |writing_conference,i| %>
<td>
<a href="<%= edit_admin_writing_conference_path(writing_conference) %>" target="_blank">
<%= get_member(writing_conference).collect(&:name).join(' / ') rescue t('personal_conference.no_input') %>
</a>
</td>
<% if len!=(i+1) %>
</tr>
<tr>
<% end %>
<% end %>
<% else %>
<% i=0 %>
<% writing_conferences.each do |k,v| %>
<% len1 = v.length %>
<% k.each do |keychild| %>
<td rowspan="<%= len1 %>">
<%= keychild.to_s.blank? ? t('personal_conference.no_input') : keychild %>
</td>
<% end %>
<td rowspan="<%= len1 %>">
<input type="checkbox" class="checkbox" name="writing_conference_id[]" value="<%= v.collect(&:id).join('/') %>">
</td>
<% v.each_with_index do |writing_conference_child,index1| %>
<td>
<a href="<%= edit_admin_writing_conference_path(writing_conference_child) %>" target="_blank">
<%= get_member(writing_conference_child).collect(&:name).join(' / ') rescue t('personal_conference.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:
personal_conference: Conference Paper personal_conference: Conference Paper
personal_conference: personal_conference:
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_conferences: "Conference Paper Frontend" writing_conferences: "Conference Paper Frontend"
strict_compare_mode: Strict Compare mode
frontend_setting: "Frontend Setting" frontend_setting: "Frontend Setting"
create_success : "Successfully Create" create_success : "Successfully Create"
update_success : "Successfully Update" update_success : "Successfully Update"

View File

@ -3,6 +3,9 @@ zh_tw:
module_name: module_name:
personal_conference: 研討會論文 personal_conference: 研討會論文
personal_conference: personal_conference:
merge: "合併"
upload: "上傳"
no_input: "未輸入"
select_class: "——選取分類——" select_class: "——選取分類——"
search_class: "搜尋類別:" search_class: "搜尋類別:"
word_to_search: "關鍵字搜尋:" word_to_search: "關鍵字搜尋:"
@ -44,7 +47,7 @@ zh_tw:
graph_by : "Graph by" graph_by : "Graph by"
frontend: frontend:
writing_conferences: "研討會論文前台" writing_conferences: "研討會論文前台"
strict_compare_mode: "嚴格比較模式"
frontend_setting: "前台設定" frontend_setting: "前台設定"
create_success : "新增完成!!" create_success : "新增完成!!"
update_success : "更新完成!!" update_success : "更新完成!!"

View File

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