Update sort.
This commit is contained in:
BoHung Chiu 2022-07-26 19:15:16 +08:00
parent 6987ad0b4a
commit 919bb6eca3
8 changed files with 70 additions and 68 deletions

View File

@ -301,11 +301,14 @@ class Admin::PersonalPluginFieldsController < OrbitMemberController
before_save_codes = ""#time_fields.map{|f| "self.#{f} = parse_time(self.#{f}.strftime('%H:%M'))"}.join("\r\n")
plugin_template_sort_hash = {}
@personal_plugin_field.backend_fields[:sort_asc].to_a.each do |f|
plugin_template_sort_hash[f] = 1
plugin_template_sort_hash[f.to_sym] = 1
end rescue nil
@personal_plugin_field.backend_fields[:sort_desc].to_a.each do |f|
plugin_template_sort_hash[f] = -1
plugin_template_sort_hash[f.to_sym] = -1
end rescue nil
if @personal_plugin_field.backend_fields[:sort_desc].to_a.count != 0
plugin_template_sort_hash[:id] = -1
end
@match_pattern = {"personal_plugin_template" => personal_plugin_template,
"plugin_template" => plugin_template,
"plugin_template_related" => plugin_template_related,

View File

@ -5,66 +5,38 @@
<button type="button" class="select_all btn"><%=t("select_all")%></button>
<button type="button" class="de_select_all btn"><%=t("de_select_all")%></button>
<table class="table table-bordered" id="<%="#{root_name}_#{page_name}"%>">
<thead>
<tbody>
<tr>
<% ths = [] %>
<% tds = [] %>
<% ii = -1 %>
<% object.primary_modal_fields.each do |field_value| %>
<% next if (!access_field_types.include?(field_value[:field_type]) rescue false) %>
<% ths << "<th data-index=\"#{ii+=1}\">#{field_value[:translation_name][I18n.locale] rescue ""}-#{field_value[:field_name]}</th>" %>
<% content = check_box_tag("#{f.object_name}[]", field_value[:field_name] , (object.send(root_name)[page_name].include?(field_value[:field_name]) rescue false),:id=>nil,:class=>"#{page_name}_fields") %>
<% tds << "<td data-index=\"#{ii+=1}\">#{field_value[:translation_name][I18n.locale] rescue ""}-#{field_value[:field_name]}<hr class=\"border-hr\">#{content}</td>" %>
<% end %>
<% if !defined?(access_field_types) %>
<% f.object.related_modal_name.each_with_index do |related_modal_name,i| %>
<% field_values = f.object.related_modal_fields[i].to_a %>
<% field_values.each do |field_value| %>
<% ths << "<th data-index=\"#{ii+=1}\">#{related_modal_name}-#{field_value[:translation_name][I18n.locale] rescue ""}-#{field_value[:field_name]}</th>" %>
<% content = check_box_tag("#{f.object_name}[]", "#{related_modal_name+'.'+field_value[:field_name]}" , (object.send(root_name)[page_name].include?(related_modal_name+'.'+field_value[:field_name]) rescue false),:id=>nil,:class=>"#{page_name}_fields") %>
<% tds << "<td data-index=\"#{ii+=1}\">#{related_modal_name}-#{field_value[:translation_name][I18n.locale] rescue ""}-#{field_value[:field_name]}<hr class=\"border-hr\">#{content}</td>" %>
<% end %>
<% end %>
<% author_name_translation = @personal_plugin_field.author_name_translations[locale] rescue ""
author_name_translation = I18n.t("personal_plugins.author") if author_name_translation.blank? %>
<% ths << "<th data-index=\"#{ii+=1}\">#{author_name_translation}</th>" %>
<% content = check_box_tag("#{f.object_name}[]", "member_profile" , (object.send(root_name)[page_name].include?("member_profile") rescue false),:id=>nil) %>
<% tds << "<td data-index=\"#{ii+=1}\">#{author_name_translation}<hr class=\"border-hr\">#{content}</td>" %>
<% end %>
<% fields_order = (0...ths.count).to_a
<% fields_order = (0...tds.count).to_a
if (object.fields_order["#{root_name}_#{page_name}"].present? rescue false)
object.fields_order["#{root_name}_#{page_name}"].to_a.each_with_index do |order,i|
fields_order[i] = order.to_i
end
end
%>
<% ths = ths.sort_by.with_index{|th,i| fields_order[i]}%>
<% ths.each do |th| %>
<%= th.html_safe %>
<% end %>
</tr>
</thead>
<tbody>
<tr>
<% tds = [] %>
<%= f.fields_for root_name do |f| %>
<%= f.fields_for page_name do |f| %>
<% object.primary_modal_fields.each do |field_value| %>
<% next if (!access_field_types.include?(field_value[:field_type]) rescue false) %>
<% tds << check_box_tag("#{f.object_name}[]", field_value[:field_name] , (object.send(root_name)[page_name].include?(field_value[:field_name]) rescue false),:id=>nil) %>
<% end %>
<% if !defined?(access_field_types) %>
<% object.related_modal_name.each_with_index do |related_modal_name,i| %>
<% field_values = object.related_modal_fields[i].to_a %>
<% field_values.each do |field_value| %>
<% tds << check_box_tag("#{f.object_name}[]", "#{related_modal_name+'.'+field_value[:field_name]}" , (object.send(root_name)[page_name].include?(related_modal_name+'.'+field_value[:field_name]) rescue false),:id=>nil) %>
<% end %>
<% end %>
<% tds << check_box_tag("#{f.object_name}[]", "member_profile" , (object.send(root_name)[page_name].include?("member_profile") rescue false),:id=>nil) %>
<% end %>
<% end %>
<% end %>
<% tds = tds.sort_by.with_index{|td,i| fields_order[i]}%>
<% tds.each do |td| %>
<td><%= td.html_safe %></td>
<% end %>
</tr>
<tr>
<% fields_order.each do |order| %>
<%= hidden_field_tag "#{f.object_name}[fields_order][#{root_name}_#{page_name}][]",order,:id=>nil %>
<%= td.html_safe %>
<% end %>
</tr>
</tbody>

View File

@ -50,6 +50,17 @@
.icons-list-2{
cursor: all-scroll;
}
hr.border-hr{
border-top: 1px solid #dddddd;
margin-top: 8px;
padding-bottom: 8px;
margin-left: -8px;
margin-right: -8px;
margin-bottom: 0;
}
.table tbody td {
font-weight: bold;
}
</style>
<script type="text/javascript">
$(".select_all").click(function(){
@ -76,11 +87,11 @@
$('#backend_fields_analysis').css( 'border','');
}
})
$( ".table thead th" ).each(function(i,v){
$( ".table tbody td" ).each(function(i,v){
$(v).attr("index",$(v).index());
$(v).html("<span class=\"brand ui-sortable-handle\"><i class=\"icons-list-2\"></i></span>" + $(v).html());
})
$( ".table thead >" ).sortable({
$( ".table tbody >" ).sortable({
axis: "x",
revert: true,
handle: ".brand",
@ -94,14 +105,23 @@
ui.item.parent().find(">").eq(new_i).attr("index",new_i);
ui.item.parent().parent().siblings("tbody").find("tr:eq(1) >").eq(org_i).val(new_i);
}
var tds = ui.item.parent().parent().siblings("tbody").find("tr:eq(0) >")
if(new_index > old_index){ //向後移動
tds.eq(new_index).after(tds.eq(old_index))
}
else if(new_index < old_index){ //向前移動
tds.eq(new_index).before(tds.eq(old_index))
var tds = ui.item.parent().parent().siblings("tbody").find("tr:eq(0) >");
if(tds.length){
if(new_index > old_index){ //向後移動
tds.eq(new_index).after(tds.eq(old_index))
}
else if(new_index < old_index){ //向前移動
tds.eq(new_index).before(tds.eq(old_index))
}
}
}
});
$( ".sort_asc_fields, .sort_desc_fields" ).on("click", function(){
var _this = $(this);
if(_this.prop('checked')){
var other_field_class = _this.hasClass('sort_asc_fields') ? '.sort_desc_fields' : '.sort_asc_fields';
$(other_field_class).filter('[value="' + _this.attr('value') + '"]').prop('checked', false);
}
})
}
</script>

View File

@ -34,8 +34,8 @@ zh_tw:
index: Index 頁面
show: Show 頁面
member_show: 會員show頁面
slug_title: 頭銜標題
please_choose_one_slug_title: 至少選擇一個頭銜標題!
slug_title: "頭銜標題(show頁面會顯示於網址)"
please_choose_one_slug_title: 選擇一個頭銜標題!
slug_title_can_only_choose_one: 頭銜標題只能選擇一個!
please_choose_one_analysis_field: 請至少選擇一個分析欄位!
analysis_field_can_only_choose_one: 分析欄位只能選擇一個!

View File

@ -9,24 +9,30 @@ class Admin::PluginTemplatesController < OrbitMemberController
before_action :allow_admin_only, :only => [:index, :setting]
def index
@plugin_templates = PluginTemplate.order_by(sort).page(params[:page]).per(10)
if params[:sort].present?
@plugin_templates = PluginTemplate.order_by(sort).page(params[:page]).per(10)
else
@plugin_templates = PluginTemplate.sort_hash.page(params[:page]).per(10)
end
end
def sort
unless params[:sort].blank?
case params[:sort]
when "status"
@sort = [[:is_top, params[:order]],
[:is_hot, params[:order]],
[:is_hidden,params[:order]]]
when "category"
@sort = {:category_id=>params[:order]}
else
s = Sanitize.clean(params[:sort]).to_sym
@sort = {s=>params[:order]}
end
else
@sort = {:created_at=>'desc'}
case params[:sort]
when "status"
@sort = [[:is_top, params[:order]],
[:is_hot, params[:order]],
[:is_hidden,params[:order]],
[:id,params[:order]]]
when "category"
@sort = {:category_id=>params[:order]}.merge({:id=>params[:order]})
else
if params[:sort].present?
s = Sanitize.clean(params[:sort]).to_sym
@sort = {s=>params[:order]}.merge({:id=>params[:order]})
else
@sort = {}
end
end
@sort
end
def new
@member = MemberProfile.find_by(:uid=>params['uid']) rescue nil

View File

@ -1,7 +1,7 @@
class PersonalPluginTemplatesController < ApplicationController
def index
params = OrbitHelper.params
plugin_templates = PluginTemplate.where(:is_hidden=>false).order_by(plugin_template_sort_hash)
plugin_templates = PluginTemplate.sort_for_frontend
fields_to_show = col_name_to_show_in_index_page
if params[:keywords].present?
plugin_templates = filter_keywords(plugin_templates,params[:selectbox],params[:keywords])

View File

@ -17,6 +17,7 @@ parse_again_end
field :rss2_id
belongs_to :member_profile
scope :sort_hash, ->{ order_by(plugin_template_sort_hash) }
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(plugin_template_sort_hash) }
parse_again_start

View File

@ -7,9 +7,9 @@
<%
if has_access?
@plugin_templates = PluginTemplate.where(member_profile_id: @member.id).order_by(plugin_template_sort_hash).page(params[:page]).per(10)
@plugin_templates = PluginTemplate.where(member_profile_id: @member.id).sort_hash.page(params[:page]).per(10)
else
@plugin_templates = PluginTemplate.where(is_hidden: false, member_profile_id: @member.id).order_by(plugin_template_sort_hash).page(params[:page]).per(10)
@plugin_templates = PluginTemplate.where(is_hidden: false, member_profile_id: @member.id).sort_hash.page(params[:page]).per(10)
end
%>