From 8e3e83f54819576523d7dfc403ff3ba293a9b5cc Mon Sep 17 00:00:00 2001 From: Bohung Date: Mon, 5 Apr 2021 11:08:58 +0800 Subject: [PATCH] change invitings sort. --- .../venue_management_invitings_controller.rb | 12 +++++++-- ...enue_management_memorabilias_controller.rb | 4 +-- .../admin/venue_managements_controller.rb | 27 ++++++++++++++++++- app/models/venue_management_contract.rb | 14 ++++++++++ app/models/venue_management_inviting.rb | 14 ++++++++++ app/models/venue_management_main.rb | 26 +++++++++++++++++- app/models/venue_management_memorabilia.rb | 14 ++++++++++ 7 files changed, 105 insertions(+), 6 deletions(-) diff --git a/app/controllers/admin/venue_management_invitings_controller.rb b/app/controllers/admin/venue_management_invitings_controller.rb index 5b943f5..7853045 100644 --- a/app/controllers/admin/venue_management_invitings_controller.rb +++ b/app/controllers/admin/venue_management_invitings_controller.rb @@ -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? diff --git a/app/controllers/admin/venue_management_memorabilias_controller.rb b/app/controllers/admin/venue_management_memorabilias_controller.rb index 5cf32fc..7845893 100644 --- a/app/controllers/admin/venue_management_memorabilias_controller.rb +++ b/app/controllers/admin/venue_management_memorabilias_controller.rb @@ -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 diff --git a/app/controllers/admin/venue_managements_controller.rb b/app/controllers/admin/venue_managements_controller.rb index 300ea56..f1ebab2 100644 --- a/app/controllers/admin/venue_managements_controller.rb +++ b/app/controllers/admin/venue_managements_controller.rb @@ -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 = [ diff --git a/app/models/venue_management_contract.rb b/app/models/venue_management_contract.rb index a1ee64e..9404000 100644 --- a/app/models/venue_management_contract.rb +++ b/app/models/venue_management_contract.rb @@ -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 diff --git a/app/models/venue_management_inviting.rb b/app/models/venue_management_inviting.rb index 56c71cd..a81b581 100644 --- a/app/models/venue_management_inviting.rb +++ b/app/models/venue_management_inviting.rb @@ -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","
").html_safe end diff --git a/app/models/venue_management_main.rb b/app/models/venue_management_main.rb index 5d049ba..8c45852 100644 --- a/app/models/venue_management_main.rb +++ b/app/models/venue_management_main.rb @@ -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')}" diff --git a/app/models/venue_management_memorabilia.rb b/app/models/venue_management_memorabilia.rb index ae72add..7d7541f 100644 --- a/app/models/venue_management_memorabilia.rb +++ b/app/models/venue_management_memorabilia.rb @@ -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