ask/config/routes.rb

102 lines
3.5 KiB
Ruby
Raw Normal View History

2014-10-02 06:00:35 +00:00
Rails.application.routes.draw do
locales = Site.first.in_use_locales rescue I18n.available_locales
if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console')
Thread.new do
AskPrintSetting.create() if AskPrintSetting.count == 0
2022-08-18 03:07:45 +00:00
s = OrbitHelper::SharedHash['current_site']['site'] rescue Site.first
update_flag = s.respond_to?(:tmp_flags)
need_update = !update_flag || !(s.tmp_flags.include?('askf1'))
need_update2 = !update_flag || !(s.tmp_flags.include?('askf2'))
2022-08-18 03:07:45 +00:00
if need_update
ask_setting = AskSetting.first
check_custom_fields = {}
if ask_setting.nil?
ask_setting = AskSetting.create
else
ask_setting.sort_number = ask_setting.sort_number.map{|k,v| [k, v.to_i]}.sort_by{|k,v| v}.to_h
AskSetting::No_required.each do |f|
ask_setting.default_setting_required.delete(f)
end
ask_setting.save
check_custom_fields = ask_setting.custom_fields.map{|k,v| [k, v["field"][I18n.default_locale.to_s]]}.to_h
end
default_setting_field_name = ask_setting.default_setting_field_name
AskCategorySetting.all.each do |ask_setting|
ask_setting.sort_number = ask_setting.sort_number.map{|k,v| [k, v.to_i]}.sort_by{|k,v| v}.to_h
AskSetting::No_required.each do |f|
ask_setting.default_setting_required.delete(f)
end
2022-08-18 03:07:45 +00:00
ask_setting.default_setting_field_name = default_setting_field_name
ask_setting.update_need_check_customs(check_custom_fields, true, true)
ask_setting.save
end
default_keys = AskTicketStatus::DefaultKeys
if AskTicketStatus.count < default_keys.count
default_keys.each do |k|
ticket_status = AskTicketStatus.where(:is_default=>true,:key=>k).first
if ticket_status.nil?
AskTicketStatus.create(:is_default=>true,:key=>k, :title_translations=>locales.map{|l| [l.to_s, I18n.with_locale(l){I18n.t("ask.#{k}")}]}.to_h )
end
end
end
AskQuestion.where(:serial_number=>nil).asc(:id).each do |a|
last_serial_number = AskSetting.update_last_serial_number
a.serial_number = last_serial_number
a.save
end
if update_flag
Site.update_all("$push"=>{"tmp_flags"=>'askf1'})
end
elsif need_update2
([AskSetting.first] + AskCategorySetting.all.to_a).each do |a|
a.migrate_old
end
if update_flag
Site.update_all("$push"=>{"tmp_flags"=>'askf2'})
end
end
end
end
2014-10-02 06:00:35 +00:00
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
namespace :admin do #backend
resources :asks do
collection do
delete 'delete'
post 'batch_modify_status'
2020-07-04 13:36:32 +00:00
get ':id/print', to: 'asks#print'
2014-10-02 06:00:35 +00:00
get 'export'
get 'setting'
get 'backend_table_setting'
2020-07-04 13:36:32 +00:00
get 'category_setting'
post 'get_category_setting_field'
post 'category_setting_save'
get 'category_setting_delete'
get 'category_print_setting_delete'
post 'category_print_setting_save'
get 'category_print_setting_save'
post 'switch_to_default_setting'
2020-07-04 13:36:32 +00:00
get 'get_new_category_setting_index'
get 'print_setting'
get 'ticket_status'
post 'get_ticket_status'
post 'update_ticket_status'
delete 'delete_ticket_status'
2020-07-04 13:36:32 +00:00
post 'print_setting_save'
post 'setting_save'
post 'ask_list_setting_save'
post 'get_new_setting_index'
2020-07-04 13:36:32 +00:00
post 'get_new_category_setting_index'
2014-10-02 06:00:35 +00:00
post 'export', to: 'asks#do_export'
get 'order_fields'
post 'update_order_fields'
2022-08-18 03:07:45 +00:00
post 'apply_default_custom_fields'
2014-10-02 06:00:35 +00:00
end
end
resources :ask_acknowledgements
resources :ask_admins
end
2020-04-30 05:18:02 +00:00
resources :asks #fronted
2014-10-02 06:00:35 +00:00
end
end