From 2cad391fa72e7b72d7c92266d96badc74bb5de81 Mon Sep 17 00:00:00 2001 From: bohung Date: Tue, 10 Mar 2020 16:13:14 +0800 Subject: [PATCH] Remove instruction page will disapeared when the time not in the registation setting time. --- .../olympiamanagements_controller.rb | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/app/controllers/olympiamanagements_controller.rb b/app/controllers/olympiamanagements_controller.rb index 6fd4ffd..f2a89d4 100644 --- a/app/controllers/olympiamanagements_controller.rb +++ b/app/controllers/olympiamanagements_controller.rb @@ -84,29 +84,35 @@ class OlympiamanagementsController < ApplicationController end @page = Page.where(:layout=>"olympia_managements_index",:parent_page_id=>(Page.where(:name=> ((I18n.locale.to_s == "en") ? "Home" : "首頁")).first.id)).first @instructions_pages = Page.where(:parent_page_id=>@page.id).select{|page| page.name_translations==@instructions_name} + if @instructions_pages.count == 0 #auto create instruction page + @newpage = Page.create(:layout=> "olympia_managements_instructions_index",:data_count=>@page.data_count,:parent_page_id=>@page.id,:url=>"/olympia_instructions", + :menu_enabled_for=>@page.menu_enabled_for,:enabled_for_sitemap=>@page.enabled_for_sitemap,:enabled_for=>@page.enabled_for,:module=>@page[:module],:page_id=>'olympia_instructions') + @newpage.name_translations = @instructions_name + @newpage.save + end case OrbitHelper.params[:layout_type] when "olympia_managements_instructions_index" - if (time_now_str <= end_time_str && time_now_str >= start_time_str) - @olympiamanagement_instruction = @sign_up_setting.registration_instructions[I18n.locale.to_s].to_s - @sign_up_setting.attributes.to_h.each do |key,value| - @olympiamanagement_instruction = @olympiamanagement_instruction.gsub("{{#{key}}}",value.to_s) - end - if !OrbitHelper.current_user.nil? - @edit_link = '/admin/olympiamanagements/sign_up_setting#registration_instructions' - @edit_text = (I18n.locale.to_s == "zh_tw") ? "編輯" : "Edit" - if !OrbitHelper.current_user.nil? - @olympiamanagement_instruction += '

'+@edit_text+'

' - end - end - data_arr = @page.child_page.map{|page| {:url=>"/#{I18n.locale}#{page.url}",:name=>page.name}} - @breadcumb = render_to_string(:formats=> [:html] ,:partial=>'breadcumb',:locals=>{:data_arr=>data_arr,:@title=>I18n.t('olympiamanagement.sign_up_title')}) - @olympiamanagement_instruction = @breadcumb + @olympiamanagement_instruction.html_safe - else - if !@instructions_pages.empty? - @instructions_pages.each{|page| page.destroy} - end - @olympiamanagement_instruction = '

'+t('olympiamanagement.sign_up_hint')+'

' + #if (time_now_str <= end_time_str && time_now_str >= start_time_str) + @olympiamanagement_instruction = @sign_up_setting.registration_instructions[I18n.locale.to_s].to_s + @sign_up_setting.attributes.to_h.each do |key,value| + @olympiamanagement_instruction = @olympiamanagement_instruction.gsub("{{#{key}}}",value.to_s) end + if !OrbitHelper.current_user.nil? + @edit_link = '/admin/olympiamanagements/sign_up_setting#registration_instructions' + @edit_text = (I18n.locale.to_s == "zh_tw") ? "編輯" : "Edit" + if !OrbitHelper.current_user.nil? + @olympiamanagement_instruction += '

'+@edit_text+'

' + end + end + data_arr = @page.child_page.map{|page| {:url=>"/#{I18n.locale}#{page.url}",:name=>page.name}} + @breadcumb = render_to_string(:formats=> [:html] ,:partial=>'breadcumb',:locals=>{:data_arr=>data_arr,:@title=>I18n.t('olympiamanagement.sign_up_title')}) + @olympiamanagement_instruction = @breadcumb + @olympiamanagement_instruction.html_safe + #else + #if !@instructions_pages.empty? + # @instructions_pages.each{|page| page.destroy} + #end + #@olympiamanagement_instruction = '

'+t('olympiamanagement.sign_up_hint')+'

' + #end { "olympiamanagement" => [], "extras"=>{"instructions"=> @olympiamanagement_instruction}