calendar/config/routes.rb

54 lines
1.7 KiB
Ruby

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
s = Site.first
update_flag = s.respond_to?(:tmp_flags)
need_update = !update_flag || !(s.tmp_flags.include?('cf1'))
calendar_setting = CalendarSetting.first
calendar_setting = CalendarSetting.create if calendar_setting.nil?
if need_update
Event.where(:title_translations.in=>[nil,{}]).each do |e|
e.title_translations = locales.map{|l| [l.to_s, e[:title]]}.to_h
e.save
end
Event.where(:note_translations.in=>[nil,{}]).each do |e|
e.note_translations = locales.map{|l| [l.to_s, e[:note]]}.to_h
e.save
end
Event.where(:url_translations=>nil).each do |e|
e.url_translations = locales.map{|l| [l.to_s, e[:url].to_s]}.to_h
e.save
end
if update_flag
s = Site.first
s.tmp_flags << 'cf1'
s.save
end
puts "Calendar fix!"
end
end
end
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
namespace :admin do
get "/calendars/agenda" => "calendars#agenda"
resources :calendars do
collection do
get 'calendar_setting'
post 'update_calendar_setting'
patch 'update_calendar_setting'
end
end
resources :calendar_types
end
get "/xhr/calendars/events" => "calendars#events"
get "/xhr/calendars/agenda" => "calendars#agenda"
get "/xhr/calendars/index_agenda" => "calendars#index_agenda"
end
end