venue_management/app/controllers/admin/venue_managements_controlle...

414 lines
17 KiB
Ruby
Raw Normal View History

2020-05-07 15:26:34 +00:00
# encoding: utf-8
2020-08-04 09:04:04 +00:00
class Admin::VenueManagementsController < Admin::VenueAdminController
2020-05-07 15:26:34 +00:00
require 'axlsx'
helper Admin::VenueManagementsFieldHelper
before_action ->(module_app = @app_title) { set_variables module_app }
2020-07-30 17:30:14 +00:00
before_action :set_venue_management, only: [:edit, :set_write_off, :venue_management_signup, :destroy, :venue_management_invitings, :venue_management_memorabilias, :venue_management_contracts]
2020-05-07 15:26:34 +00:00
def initialize
super
@app_title = "venue_management"
end
def filter_fields(categories)
{
:category=>categories.map{|c| {:title=>(c.title.blank? ? " " : c.title), :id=>c.id}}
}
end
def index
@categories = @module_app.categories.enabled
@filter_fields = filter_fields(@categories)
2020-07-30 17:30:14 +00:00
@table_fields = [ :category,
'vm_inviting.type',
2020-07-30 17:30:14 +00:00
'venue_management.title',
"venue_management.contractor",
2020-07-30 17:30:14 +00:00
'venue_management.event_during',
'venue_management.signup_during',
'venue_management.contract_history',
'venue_management.inviting_history',
'venue_management.memorabilia',
'venue_management.export'
]
@filter_fields["vm_inviting.type"] = @module_app.tags.map{|t| {:title => t.name,:id => t.id} }
2020-07-27 16:34:33 +00:00
if !params[:sort].blank?
2020-05-07 15:26:34 +00:00
if params[:sort] == 'event_during'
2020-07-27 16:34:33 +00:00
sort = {:venue_management_start_date.to_sym=>params[:order]}
2020-05-07 15:26:34 +00:00
elsif params[:sort] == 'signup_during'
2020-07-27 16:34:33 +00:00
sort = {:signup_start_date.to_sym=>params[:order]}
2020-05-07 15:26:34 +00:00
else
2020-07-27 16:34:33 +00:00
sort = {params[:sort].to_sym=>params[:order]}
2020-05-07 15:26:34 +00:00
end
else
sort = {:signup_start_date=>"desc"}
end
filter_tags = params[:filters][:type].to_a rescue []
if filter_tags.empty?
@venue_managements = VenueManagementMain.all.order_by(sort).with_categories(filters("category"))
@venue_managements = search_data(@venue_managements,[:title]).page(params[:page]).per(10)
else
@venue_managements = VenueManagementMain.all.order_by(sort).with_categories(filters("category"))
@venue_managements = search_data(@venue_managements,[:title])
@venue_management_inviting_ids = @venue_managements.map{|v| v.venue_management_invitings.desc(:id).first.id rescue ""}
@venue_management_ids = VenueManagementInviting.where(:id.in=>@venue_management_inviting_ids).with_tags(filter_tags).map{|v| v.venue_management_main_id}
@venue_managements = VenueManagementMain.where(:id.in=>@venue_management_ids).page(params[:page]).per(10)
end
2020-07-27 16:34:33 +00:00
2020-05-07 15:26:34 +00:00
if request.xhr?
render :partial => "index"
end
end
def export
@venue_management = VenueManagementMain.find(params[:id])
@venue_management_signups = VenueManagementSignup.where(:venue_management_main_id => params[:id])
@site_in_use_locales = Site.first.in_use_locales
2020-05-07 15:26:34 +00:00
filename = @venue_management.title.parameterize.underscore + "_export.xlsx"
respond_to do |format|
format.xlsx {
response.headers['Content-Disposition'] = 'attachment; filename="' + filename + '"'
}
end
end
def new
@member = nil
@managers = nil
@contractors = nil
@coordinators = nil
@venue_management = VenueManagementMain.new
create_set (false)
@signup_sets = @venue_management.venue_management_signup_field_sets
@submission_set = @venue_management.venue_management_submission_field_sets
@custom_set = @venue_management.venue_management_signup_field_customs
@venue_management_items = VenueManagementItem.all
@review = @venue_management.venue_management_reviews.new()
end
def create
2020-07-27 16:34:33 +00:00
2020-08-02 13:33:41 +00:00
venue_management_main_params = venue_management_params
if !venue_management_main_params['venue_management_links_attributes'].nil?
venue_management_main_params['venue_management_links_attributes'].each do |idx,link|
venue_management_main_params['venue_management_links_attributes'].delete(idx.to_s) if link['url'].blank?
2020-05-07 15:26:34 +00:00
end
end
venue_management_signup_set_params = venue_management_main_params['venue_management_signup_field_sets']
venue_management_submission_set_params = venue_management_main_params['venue_management_submission_field_sets']
venue_management_email_sets_params = venue_management_main_params['venue_management_email_sets']
venue_management_main_params.delete(:venue_management_signup_field_sets)
venue_management_main_params.delete(:venue_management_submission_field_sets)
venue_management_main_params.delete(:venue_management_email_sets)
venue_management = VenueManagementMain.new(venue_management_main_params)
venue_management.create_user_id = current_user.id
venue_management.update_user_id = current_user.id
venue_management.save
#venue_management_signup_set_params.each do |key,value|
# venue_management.venue_management_signup_field_sets.create(value)
#end
#venue_management_submission_set_params.each do |key,value|
# venue_management.venue_management_submission_field_sets.create(value)
#end
venue_management_email_sets_params.each do |key,value|
venue_management.venue_management_email_sets.create(value)
end
redirect_to params['referer_url']
end
def edit
@venue_management_items = VenueManagementItem.all
@venue_management = VenueManagementMain.where(id: params[:id]).first
@venue_management.venue_management_signup_field_sets.each do |signup_field_set|
if !(VenueManagementSignup.attribute_names.include? signup_field_set.field_name) && signup_field_set.field_name != 'recaptcha'
signup_field_set.delete
end
end
@venue_management.venue_management_submission_field_sets.each do |submission_field_set|
if !(VenueManagementSignupContribute.attribute_names.include? submission_field_set.field_name)
submission_field_set.delete
end
end
@venue_management.venue_management_signup_field_customs.each do |custom_set|
if !(@venue_management.venue_management_signup_fields.collect(&:id).include? custom_set.venue_management_signup_field_id)
custom_set.delete
end
end
create_set (true)
@signup_sets = @venue_management.venue_management_signup_field_sets
@submission_set = @venue_management.venue_management_submission_field_sets
@custom_set = @venue_management.venue_management_signup_field_customs
if @venue_management.venue_management_reviews.first.nil?
@review = @venue_management.venue_management_reviews.new()
else
@review = @venue_management.venue_management_reviews.first
end
@member = MemberProfile.find(@review.reviewer_id) rescue nil
@managers = MemberProfile.find(@venue_management.manager_ids) rescue nil
@contractors = MemberProfile.find(@venue_management.contractor_ids) rescue nil
@coordinators = MemberProfile.find(@venue_management.coordinator_ids) rescue nil
end
def update
params[:venue_management_main][:registration_status] = (params[:venue_management_main][:registration_status] ? params[:venue_management_main][:registration_status] : [])
2020-07-27 16:34:33 +00:00
2020-05-07 15:26:34 +00:00
uid = params[:id].split('-').last
@venue_management = VenueManagementMain.find_by(:uid=>uid)
if params[:venue_management_main][:venue_management_signup_fields]
venue_management_params[:venue_management_signup_fields].each do |a|
@field_name = 'venue_management_main'
field_status = a.last[:id].present?
@attribute_field = VenueManagementSignupField.add_venue_management_signup_field(@venue_management, a.last, a.last[:id], field_status)
@attribute = @venue_management
end
flash.now[:notice] = "Updated Fields"
@venue_management.venue_management_signup_fields.each{|t| t.destroy if t["to_delete"] == true}
redirect_to admin_venue_managements_path
elsif params[:venue_management_main][:venue_management_submission_fields]
params[:venue_management_main][:venue_management_submission_fields].each do |a|
@field_name = 'venue_management_main'
field_status = a.last[:id].present?
@attribute_field = VenueManagementSubmissionField.add_venue_management_signup_field(@venue_management, a.last, a.last[:id], field_status)
@attribute = @venue_management
end
flash.now[:notice] = "Updated Fields"
@venue_management.venue_management_submission_fields.each{|t| t.destroy if t["to_delete"] == true}
redirect_to admin_venue_managements_path
else
2020-08-02 13:33:41 +00:00
venue_management_main_params = venue_management_params
if !venue_management_main_params['venue_management_links_attributes'].nil?
venue_management_main_params['venue_management_links_attributes'].each do |idx,link|
venue_management_main_params['venue_management_links_attributes'].delete(idx.to_s) if link['url'].blank?
2020-05-07 15:26:34 +00:00
end
end
2020-07-27 16:34:33 +00:00
2020-05-07 15:26:34 +00:00
@venue_management.update_user_id = current_user.id
2020-08-02 13:33:41 +00:00
if @venue_management.update_attributes(venue_management_main_params)
2020-05-07 15:26:34 +00:00
@venue_management.venue_management_signup_fields.each{|t| t.destroy if t["to_delete"] == true}
redirect_to params['referer_url']
else
flash.now[:error] = t('update.error.category')
2020-08-02 13:33:41 +00:00
flash.keep
redirect_to action: :edit, :id =>@venue_management.id.to_s
2020-05-07 15:26:34 +00:00
end
end
end
2020-07-27 16:34:33 +00:00
2020-05-07 15:26:34 +00:00
def set_write_off
@venue_management.donation_write_off_status = true
@venue_management.save
redirect_to "/admin/venue_managements?page=#{params['page']}"
end
def destroy
@venue_management.destroy
redirect_to "/admin/venue_managements"
end
def venue_management_signup_field
@field_name = 'venue_management_main'
2020-07-27 16:34:33 +00:00
@attribute = VenueManagementMain.find(params[:id])
2020-05-07 15:26:34 +00:00
@attribute_type = 'venue_management'
@class = 'venue_managements'
end
def venue_management_submission_field
@field_name = 'venue_management_main'
2020-07-27 16:34:33 +00:00
@attribute = VenueManagementMain.find(params[:id])
2020-05-07 15:26:34 +00:00
@attribute_type = 'venue_management'
@class = 'venue_managements'
end
def venue_management_signup
if !params[:search].blank?
@venue_management_signups = VenueManagementSignup.where(:venue_management_main_id => @venue_management.id, :name=>params[:search]).page(params[:page]).per(10)
else
@venue_management_signups = VenueManagementSignup.where(:venue_management_main_id => @venue_management.id).page(params[:page]).per(10)
end
2020-07-27 16:34:33 +00:00
2020-05-07 15:26:34 +00:00
end
def edit_venue_management_signup
@venue_management_signup = VenueManagementSignup.find(params[:id])
@venue_management = VenueManagementMain.find(@venue_management_signup.venue_management_main_id)
end
def delete_venue_management_signup
2020-07-27 16:34:33 +00:00
2020-05-07 15:26:34 +00:00
@venue_management_signup = VenueManagementSignup.find(params[:id])
@venue_management_id = @venue_management_signup.venue_management_main_id
@venue_management_signup.destroy
redirect_to "/admin/venue_managements/@venue_management_id.to_s/venue_management_signup"
end
2020-07-27 16:34:33 +00:00
def venue_management_invitings
@table_fields = [
'vm_inviting.case_no',
'vm_inviting.type',
2020-07-27 16:34:33 +00:00
'vm_inviting.publish_times',
'vm_inviting.start_end',
2020-07-27 16:34:33 +00:00
'vm_inviting.rents',
'vm_inviting.royalty',
'vm_inviting.house_land_tax_payer',
2020-07-27 16:34:33 +00:00
'vm_inviting.contractor_manager',
'vm_inviting.bid_result',
]
filter_tags = params[:filters]["type"].to_a rescue []
@invitings = @venue_management.venue_management_invitings.with_tags(filter_tags).page(params[:page]).per(10)
2020-08-09 03:28:13 +00:00
@tags = @module_app.tags
@filter_fields = {}
@filter_fields['vm_inviting.type'] = @tags.map{|t| {:title => t.name,:id => t.id} }
@venue_management_page_url = Page.where(:module =>"venue_management").last.url rescue ""
if request.xhr?
render :partial => 'admin/venue_management_invitings/index'
end
2020-07-27 16:34:33 +00:00
end
2020-07-30 14:28:57 +00:00
def venue_management_memorabilias
@table_fields = [
'vm_memorabilia.case_no',
'vm_memorabilia.event_date',
'vm_memorabilia.details',
]
@memorabilias = @venue_management.venue_management_memorabilias.page(params[:page]).per(10)
@venue_management_page_url = Page.where(:module =>"venue_management").last.url rescue ""
2020-07-30 14:28:57 +00:00
end
2020-07-30 17:30:14 +00:00
def venue_management_contracts
@table_fields = [
'vm_contract.case_no',
'vm_inviting.type',
2020-07-30 17:30:14 +00:00
'vm_contract.vendor',
'vm_inviting.rents',
'vm_inviting.royalty',
2020-07-30 17:30:14 +00:00
'vm_contract.start_end',
'vm_contract.renewal_permission',
'vm_contract.note',
]
@contracts = @venue_management.venue_management_contracts.page(params[:page]).per(10)
2020-08-09 03:28:13 +00:00
@venue_management_page_url = Page.where(:module =>"venue_management").last.url rescue ""
2020-07-30 17:30:14 +00:00
end
2020-05-07 15:26:34 +00:00
private
def set_venue_management
@venue_management = VenueManagementMain.find(params[:id])
end
def venue_management_params
params.require(:venue_management_main).permit!
end
def create_set (save_flag)
VenueManagementSignup.attribute_names.each do |attr_signup|
2020-07-27 16:34:33 +00:00
if !(['_id', 'created_at', 'updated_at','venue_management_main_id'].include? attr_signup)
2020-05-07 15:26:34 +00:00
signup_set = @venue_management.venue_management_signup_field_sets.select{|v| v.field_name==attr_signup }
if signup_set.length==0
if ['status','name','tel','phone','email','password'].include? attr_signup
disabled = false
else
disabled = true
end
if ['status','name','tel'].include? attr_signup
hidden = false
else
hidden = true
end
name1 = Hash.new
now_locale = I18n.locale
I18n.available_locales.each do |locale|
I18n.locale = locale
name1[locale] = t("venue_management_signup.#{attr_signup}")
end
I18n.locale = now_locale
if save_flag
@venue_management.venue_management_signup_field_sets.create(field_name:attr_signup,disabled:disabled,hidden:hidden,name:name1,placeholder:name1)
else
@venue_management.venue_management_signup_field_sets.new(field_name:attr_signup,disabled:disabled,hidden:hidden,name:name1,placeholder:name1)
end
end
end
end
signup_set = @venue_management.venue_management_signup_field_sets.select{|v| v.field_name== 'recaptcha' }
if signup_set.length==0
name1 = Hash.new
now_locale = I18n.locale
I18n.available_locales.each do |locale|
I18n.locale = locale
name1[locale] = t("venue_management_signup.recaptcha")
end
I18n.locale = now_locale
if save_flag
@venue_management.venue_management_signup_field_sets.create(field_name:'recaptcha',name:name1,placeholder:name1,hidden:true)
else
@venue_management.venue_management_signup_field_sets.new(field_name:'recaptcha',name:name1,placeholder:name1,hidden:true)
end
end
VenueManagementSignupContribute.attribute_names.each do |attr_submission|
2020-07-27 16:34:33 +00:00
if !(['_id', 'created_at', 'updated_at','venue_management_signup_id'].include? attr_submission)
2020-05-07 15:26:34 +00:00
signup_set = @venue_management.venue_management_submission_field_sets.select{|v| v.field_name==attr_submission }
if signup_set.length==0
name1 = Hash.new
now_locale = I18n.locale
I18n.available_locales.each do |locale|
I18n.locale = locale
name1[locale] = t("venue_management_signup.#{attr_submission}")
end
I18n.locale = now_locale
if save_flag
@venue_management.venue_management_submission_field_sets.create(field_name:attr_submission,name:name1,placeholder:name1)
else
@venue_management.venue_management_submission_field_sets.new(field_name:attr_submission,name:name1,placeholder:name1)
end
end
end
end
@venue_management.venue_management_signup_fields.all.map{|v| v}.each do |field|
set = @venue_management.venue_management_signup_field_customs.select{|v| v.venue_management_signup_field_id==field.id}
if set.length == 0
@venue_management.venue_management_signup_field_customs.create(venue_management_signup_field_id:field.id)
end
end
@email_set = []
['signup','submission','add_file','edit_file'].each do |field_name|
email_set = @venue_management.venue_management_email_sets.select{|v| v.field_name==field_name}
if email_set.length==0
title = Hash.new
content = Hash.new
now_locale = I18n.locale
I18n.available_locales.each do |locale|
I18n.locale = locale
title[locale] = t("venue_management.email_#{field_name}_success")
content[locale] = t("venue_management.email_#{field_name}_content")
end
I18n.locale = now_locale
if save_flag
email_set = @venue_management.venue_management_email_sets.create(field_name:field_name,title:title,content:content)
else
email_set = @venue_management.venue_management_email_sets.new(field_name:field_name,title:title,content:content)
end
else
email_set = email_set[0]
end
@email_set << email_set
end
end
end