change invitings sort.

This commit is contained in:
BoHung Chiu 2021-04-05 11:10:29 +08:00
parent 96db4615fc
commit d490b2d0a3
7 changed files with 105 additions and 6 deletions

View File

@ -39,13 +39,21 @@ class Admin::VenueManagementInvitingsController < Admin::VenueAdminController
render :partial => 'index'
end
end
def sort_hash
if params[:sort].blank?
sort = {start_date: :desc}
elsif params[:sort] == "start_end"
sort = {start_date: params["order"]}
else
sort = {params[:sort]=>params["order"]}
end
end
def filter_inviting
@ext_filename = ""
filter_tags = params[:filters]["type"].to_a rescue []
start_date = DateTime.parse(params[:filters]["start_date"]) rescue 0
end_date = DateTime.parse(params[:filters]["end_date"]) rescue 0
@invitings = VenueManagementInviting.with_tags(filter_tags).order(updated_at: :desc).page(params[:page]).per(10)
@invitings = VenueManagementInviting.with_tags(filter_tags).order(sort_hash).page(params[:page]).per(10)
@ext_filename += (I18n.t("vm_inviting.type") + ": #{Tag.where(:id.in=>filter_tags).map{|t| t.name}.join(',')}") if !filter_tags.blank?
if start_date != 0 && end_date != 0
@ext_filename += (I18n.t("vm_inviting.start_end") + ": #{start_date}~#{end_date}") if @ext_filename.blank?

View File

@ -27,7 +27,7 @@ class Admin::VenueManagementMemorabiliasController < Admin::VenueAdminController
@filter_fields = {}
if params[:keywords].present?
@main_ids = @memorabilias.pluck(:venue_management_main_id)
@invintings = VenueManagementInviting.where(:id.in => VenueManagementMemorabilia.all.pluck(:venue_management_inviting_id))
@invintings = VenueManagementInviting.where(:id.in => @memorabilias.pluck(:venue_management_inviting_id))
@venue_managements = VenueManagementMain.where(:id.in=>@main_ids)
@main_ids = search_data(@venue_managements,[:title]).pluck(:id)
ids2 = []
@ -39,7 +39,7 @@ class Admin::VenueManagementMemorabiliasController < Admin::VenueAdminController
end
ids = VenueManagementMemorabilia.where(:venue_management_inviting_id.in=>@invintings.pluck(:id)).pluck(:id)
ids1 = VenueManagementMemorabilia.where(:venue_management_main_id.in=>@main_ids).pluck(:id)
@memorabilias = VenueManagementMemorabilia.where(:id.in=>(ids + ids1 + ids2))
@memorabilias = @memorabilias.where(:id.in=>(ids + ids1 + ids2))
end
end
def new

View File

@ -344,6 +344,14 @@ class Admin::VenueManagementsController < Admin::VenueAdminController
@invitings = @invitings.where(:end_date.lte=>end_date).page(params[:page]).per(10)
end
end
if params[:sort].blank?
sort = {start_date: :desc}
elsif params[:sort] == "start_end"
sort = {start_date: params["order"]}
else
sort = {params[:sort]=>params["order"]}
end
@invitings = @invitings.order_by(sort).page(params[:page]).per(10)
@venue_management_page_url = Page.where(:module =>"venue_management").last.url rescue ""
if request.xhr?
render :partial => 'admin/venue_management_invitings/index'
@ -357,8 +365,25 @@ class Admin::VenueManagementsController < Admin::VenueAdminController
'vm_memorabilia.details',
]
@filter_fields = {}
@memorabilias = @venue_management.venue_management_memorabilias.page(params[:page]).per(10)
@memorabilias = @venue_management.venue_management_memorabilias
@filter_fields = {}
if params[:keywords].present?
ids2 = []
@invintings = VenueManagementInviting.where(:id.in =>@memorabilias.pluck(:venue_management_inviting_id))
if params[:keywords] == I18n.t(:empty)
@invintings = @invintings.where(:case_no=>"")
ids2 = @venue_management.venue_management_memorabilias.where(:venue_management_inviting_id =>nil ).pluck(:id)
else
@invintings = search_data(@invintings,[:case_no])
end
ids = VenueManagementMemorabilia.where(:venue_management_inviting_id.in=>@invintings.pluck(:id)).pluck(:id)
@memorabilias = VenueManagementMemorabilia.where(:id.in=>(ids + ids2))
end
@memorabilias = @memorabilias.page(params[:page]).per(10)
@venue_management_page_url = Page.where(:module =>"venue_management").last.url rescue ""
if request.xhr?
render :partial => 'admin/venue_management_memorabilias/index'
end
end
def venue_management_bills
@table_fields = [

View File

@ -63,6 +63,20 @@ class VenueManagementContract
belongs_to :venue_management_main
belongs_to :venue_management_inviting
include VenueLinkFile
after_create do
venue_management = self.venue_management_main
if venue_management
venue_management.contract_history = venue_management.contract_history + 1
venue_management.save(:validate=>false)
end
end
after_destroy do
venue_management = self.venue_management_main
if venue_management
venue_management.contract_history = venue_management.contract_history - 1
venue_management.save(:validate=>false)
end
end
def deposit_amount_type_exp_date
return "#{self.deposit_amount}/#{self.deposit_type}/#{self.deposit_exp_date}"
end

View File

@ -31,6 +31,20 @@ class VenueManagementInviting
has_many :venue_management_memorabilias, :class_name => 'VenueManagementMemorabilia', :foreign_key => "venue_management_memorabilia_ids"
belongs_to :venue_management_main
include VenueLinkFile
after_create do
venue_management = self.venue_management_main
if venue_management
venue_management.inviting_history = venue_management.inviting_history + 1
venue_management.save(:validate=>false)
end
end
after_destroy do
venue_management = self.venue_management_main
if venue_management
venue_management.inviting_history = venue_management.inviting_history - 1
venue_management.save(:validate=>false)
end
end
def display_royalty
self.royalty.to_s.gsub("\r\n","<br>").html_safe
end

View File

@ -30,7 +30,9 @@ class VenueManagementMain
field :contribute_file_count, type: String
field :registration_status , :type => Array #C: 投稿者 G:一般
field :inviting_history , :type => Integer
field :contract_history , :type => Integer
field :memorabilia, :type => Integer
field :create_user_id
field :update_user_id
@ -60,6 +62,28 @@ class VenueManagementMain
accepts_nested_attributes_for :venue_management_email_sets, :allow_destroy => true
accepts_nested_attributes_for :venue_management_signup_field_customs, :allow_destroy => true
include VenueLinkFile
after_initialize do
unless self.new_record?
if self.inviting_history.nil?
self.inviting_history = self.venue_management_invitings.count rescue 0
self.save(:validate=>false)
self.class.all.each do |record|
record.inviting_history = record.venue_management_invitings.count rescue 0
record.contract_history = record.venue_management_contracts.count rescue 0
record.memorabilia = record.venue_management_memorabilias.count rescue 0
record.save(:validate=>false)
end
end
if self.contract_history.nil?
self.contract_history = self.venue_management_contracts.count rescue 0
self.save(:validate=>false)
end
if self.memorabilia.nil?
self.memorabilia = self.venue_management_memorabilias.count rescue 0
self.save(:validate=>false)
end
end
end
def self.time_range(date1 = null, date2 = null)
if !date1.blank?
r = "#{date1.strftime('%Y-%m-%d')}"

View File

@ -17,6 +17,20 @@ class VenueManagementMemorabilia
belongs_to :venue_management_inviting
belongs_to :venue_management_main
include VenueLinkFile
after_create do
venue_management = self.venue_management_main
if venue_management
venue_management.memorabilia = venue_management.memorabilia + 1
venue_management.save(:validate=>false)
end
end
after_destroy do
venue_management = self.venue_management_main
if venue_management
venue_management.memorabilia = venue_management.memorabilia - 1
venue_management.save(:validate=>false)
end
end
def display_details
html = self.details.to_s.split("\r\n").select{|s| !s.blank?}.first
return Nokogiri::HTML(html).css("body").text