add frontend pages and render page in olympiamanagementscontroller

This commit is contained in:
BOHUNG 2020-02-02 00:37:59 +08:00
parent ba7713b761
commit 4e461d47f1
10 changed files with 201 additions and 15 deletions

View File

@ -1,15 +1,29 @@
class OlympiamanagementsController < ApplicationController
class OlympiamanagementsController < PagesController
include ActionView::Context #vary important (only add this can access @@session from view)
include ApplicationHelper
before_action :set_sign_up_setting
#include "#{Rails.root}/app/helpers/application_helper.rb"
def initialize
super
@app_title = "olympiamanagement"
end
def set_sign_up_setting
@sign_up_setting = SignUpSetting.last
data_arr = [{:url=>'/olympiamanagements/school_connection_data',:name=>t('olympiamanagement.school_connection_data')},
{:url=>'/olympiamanagements/add_sign_up_student_data',:name=>t('olympiamanagement.add_sign_up_student_data')},
{:url=>'/olympiamanagements/sign_up_student_data_list',:name=>t('olympiamanagement.sign_up_student_data_list')},
{:url=>'/olympiamanagements/edit_password',:name=>t('olympiamanagement.edit_password')},
{:url=>'/olympiamanagements/print_registration_form',:name=>t('olympiamanagement.print_registration_form')},
{:url=>'/olympiamanagements/logout',:name=>t('olympiamanagement.logout')}]
@breadcumb = render_to_string(:formats=> [:html] ,:partial=>'breadcumb',:locals=>{:data_arr=>data_arr})
end
def index
uid = OrbitHelper.params[:uid] rescue ""
tags = OrbitHelper.widget_tags
categories = OrbitHelper.widget_categories || []
@sign_up_setting = SignUpSetting.last
case OrbitHelper.params[:layout_type]
when "olympia_managements_instructions_index"
@sign_up_setting = SignUpSetting.last
@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)
@ -25,12 +39,106 @@ class OlympiamanagementsController < ApplicationController
"extras"=>{"instructions"=> @olympiamanagement_instruction}
}
when "olympia_managements_index"
{
"olympiamanagement" => [],
"extras"=>{"instructions"=> '<h3 style="margin: 20px 0px 10px; padding: 0px; color: rgb(0, 153, 153); font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: bold; font-stretch: normal; font-size: 0.9375em; line-height: 20px; font-family: 微軟正黑體, sans-serif;">'+t('olympiamanagement.sign_up_hint')+'</h3>'}
}
@time_arr = ["year","month","day","o_clock","minute"]
start_time_str = @time_arr.map{|t| @sign_up_setting["start_"+t]}.join(' ')
end_time_str = @time_arr.map{|t| @sign_up_setting["end_"+t]}.join(' ')
time_now_str = Time.now.strftime("%Y %m %d %H %M")
if time_now_str <= end_time_str && time_now_str >= start_time_str
@error = nil
@page_content
if !OrbitHelper.params[:login_id].to_s.blank?
if OlympiaSchoolDataFields.where(:account_number=>OrbitHelper.params[:login_id]).length == 0
@error = "no_account"
else
if OlympiaSchoolDataFields.where(:account_number=>OrbitHelper.params[:login_id]).first.password != OrbitHelper.params[:login_pw]
@error = "password_error"
else
@@session[:olympia_login_id] = OrbitHelper.params[:login_id]
end
end
end
if @@session[:olympia_login_id].to_s.blank?
@page_content = render_to_string(:formats=> [:html] ,:partial=>'login')
else
@page_content = @breadcumb
end
{
"olympiamanagement" => [],
"extras"=>{"instructions"=> @page_content}
}
else
#@page_content = '<h3 style="margin: 20px 0px 10px; padding: 0px; color: rgb(0, 153, 153); font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: bold; font-stretch: normal; font-size: 0.9375em; line-height: 20px; font-family: 微軟正黑體, sans-serif;">'+t('olympiamanagement.sign_up_hint')+'</h3>'
@error = nil
@page_content
if !OrbitHelper.params[:login_id].to_s.blank?
if OlympiaSchoolDataFields.where(:account_number=>OrbitHelper.params[:login_id]).length == 0
@error = "no_account"
else
if OlympiaSchoolDataFields.where(:account_number=>OrbitHelper.params[:login_id]).first.password != OrbitHelper.params[:login_pw]
@error = "password_error"
else
@@session[:olympia_login_id] = OrbitHelper.params[:login_id]
end
end
end
if @@session[:olympia_login_id].to_s.blank?
@page_content = render_to_string(:formats=> [:html] ,:partial=>'login')
else
@page_content = @breadcumb
end
{
"olympiamanagement" => [],
"extras"=>{"page_content"=> @page_content}
}
end
end
end
def school_connection_data
@time_arr = ["year","month","day","o_clock","minute"]
start_time_str = @time_arr.map{|t| @sign_up_setting["start_"+t]}.join(' ')
end_time_str = @time_arr.map{|t| @sign_up_setting["end_"+t]}.join(' ')
time_now_str = Time.now.strftime("%Y %m %d %H %M")
if !(time_now_str <= end_time_str && time_now_str >= start_time_str) || session[:olympia_login_id].to_s.blank?
render_contents_in_index_page#redirect_to :back
else
if params[:type].to_s == "update_school_data"
redirect_to :back
end
end
end
def add_sign_up_student_data
@time_arr = ["year","month","day","o_clock","minute"]
start_time_str = @time_arr.map{|t| @sign_up_setting["start_"+t]}.join(' ')
end_time_str = @time_arr.map{|t| @sign_up_setting["end_"+t]}.join(' ')
time_now_str = Time.now.strftime("%Y %m %d %H %M")
if !(time_now_str <= end_time_str && time_now_str >= start_time_str) || @@session[:olympia_login_id].to_s.blank?
redirect_to :back
else
@olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>@@session[:olympia_login_id]).first
redirect_to :back if @olympia_school_data_field.nil?
@required_fields = [:school_contact_person_name,:department_job_title,:office_tel_number,:fax,:mobile_number,:email]
@flag = true
@required_fields.each do |field|
if @olympia_school_data_field[field].to_s.blank?
@flag = false
break
end
end
#if @flag = false
end
end
def sign_up_student_data_list
end
def edit_password
end
def print_registration_form
end
def logout
session[:olympia_login_id] = ""
redirect_to :back
end
def widget
uid = OrbitHelper.params[:uid] rescue ""
tags = OrbitHelper.widget_tags
@ -59,8 +167,18 @@ class OlympiamanagementsController < ApplicationController
tmp_filename_data = File.read(dir_path +@filename)
send_data(tmp_filename_data, type: 'application/xlsx', disposition: 'attachment', filename: "#{Time.now.year}#{Time.now.month}#{Time.now.day}_download_school_code.xlsx")
end
def render_contents_in_index_page(contents=@breadcumb)
doc = Nokogiri::HTML(render_final_page("page",Page.where(:layout=>"olympia_managements_index").first,true), nil, "UTF-8")
viewarea = doc.css("*[data-content='true']")[0]
viewarea.inner_html = @breadcumb
render :html => doc.to_html.html_safe
end
def updata_school_data
#render :html => '123'
# doc = Nokogiri::HTML(render_final_page("page",Page.where(:layout=>"olympia_managements_index").first,true), nil, "UTF-8")
# viewarea = doc.css("*[data-content='true']")[0]
# viewarea.inner_html = "123"
# render :html => doc.to_html.html_safe
render_contents_in_index_page('123')
end
def updata_student_data
#render :html => '123'

View File

View File

@ -0,0 +1,10 @@
<div class="sitemenu-wrap sitemenu-horizontal">
<ul data-list="pages" class="sitemenu-list level-1 list-unstyled" data-level="0">
<% data_arr.each do |data|%>
<li class="sitemenu-item level-1">
<a class="sitemenu-link level-1" href="<%=data[:url]%>" title=""><%=data[:name]%></a>
<ul class="sitemenu-list level-2" data-list="children" data-level="1"></ul>
</li>
<% end %>
</ul>
</div>

View File

@ -0,0 +1,23 @@
<div id="loginstyle">
<form name="login_form" id="login_form" method="get">
<p align="center">
<label for="login_id"><%=t('olympiamanagement.account_number')%>:</label><input name="login_id" type="text" id="login_id" size="12" value="">
<br>
<label for="login_pw"><%=t('olympiamanagement.password')%>:</label><input name="login_pw" type="password" id="login_pw" size="12">
</p>
<p align="center">
<input class="loginbutton" type="submit" name="login_Submit" value="<%=t('olympiamanagement.submit')%>">
<input type="hidden" name="PreviousPage" value="<%= OrbitHelper.request.original_url.split(OrbitHelper.request.env["HTTP_HOST"]).last.split('?').first rescue "/"%>">
</p>
</form>
</div>
<%if !@error.nil?%>
<script>
<%if @error == "no_account"%>
alert('<%=(I18n.locale.to_s=="zh_tw") ? "無此帳號!" : "No such account!"%>')
<%elsif @error == "password_error"%>
alert('<%=(I18n.locale.to_s=="zh_tw") ? "密碼錯誤!" : "Password error!"%>')
<%end%>
</script>
<%end%>

View File

@ -1 +1,3 @@
<% @@session = session %>
<%#=render :partial=>'login'%>
<%= render_view %>

View File

@ -6,6 +6,11 @@ en:
school_data_list: School data list
class_setting: Class setting
sign_up_setting: Sign up setting
logout: Logout
edit_password: Edit password
sign_up_student_data_list: Sign up student data list
add_sign_up_student_data: Add sign up student data
school_connection_data: School connection data
export_school_connection_data: Export school connection data
export_sign_up_student_data: Export sign up student data
download_scan_file_of_certificate: Download scan file of certificate

View File

@ -6,6 +6,11 @@ zh_tw:
school_data_list: 學校資料列表
class_setting: 班級設定
sign_up_setting: 報名設定
logout: 登出
edit_password: 修改密碼
sign_up_student_data_list: 報名學生資料列表
add_sign_up_student_data: 新增報名學生資料
school_connection_data: 學校聯絡資料
export_school_connection_data: 匯出學校聯絡資料
export_sign_up_student_data: 匯出報名學生資料
download_scan_file_of_certificate: 下載獎狀掃描檔

View File

@ -22,5 +22,20 @@ Rails.application.routes.draw do
get 'olympiamanagements/download_import_file' , to: 'olympiamanagements#download_import_file'
resources :olympiamanagements
end
resource 'olympiamanagements' do
get 'updata_school_data'
post 'updata_school_data'
patch 'updata_school_data'
get 'updata_student_data'
post 'updata_student_data'
patch 'updata_student_data'
get 'download_school_code'
get 'school_connection_data'
get 'add_sign_up_student_data'
get 'sign_up_student_data_list'
get 'edit_password'
get 'print_registration_form'
get 'logout'
end
end
end

View File

@ -1,7 +1,15 @@
get 'olympiamanagements/updata_school_data' , to: 'olympiamanagements#updata_school_data'
post 'olympiamanagements/updata_school_data' , to: 'olympiamanagements#updata_school_data'
patch 'olympiamanagements/updata_school_data' , to: 'olympiamanagements#updata_school_data'
get 'olympiamanagements/updata_student_data' , to: 'olympiamanagements#updata_student_data'
post 'olympiamanagements/updata_student_data' , to: 'olympiamanagements#updata_student_data'
patch 'olympiamanagements/updata_student_data' , to: 'olympiamanagements#updata_student_data'
get 'olympiamanagements/download_school_code' , to: 'olympiamanagements#download_school_code'
resources :olympiamanagements do
get 'updata_school_data'
post 'updata_school_data'
patch 'updata_school_data'
get 'updata_student_data'
post 'updata_student_data'
patch 'updata_student_data'
get 'download_school_code'
get 'school_connection_data'
get 'add_sign_up_student_data'
get 'sign_up_student_data_list'
get 'edit_password'
get 'print_registration_form'
get 'logout'
end

View File

@ -1,5 +1,5 @@
<script type="text/javascript" src="/assets/olympiamanagement.js"></script>
{{instructions}}
{{page_content}}
<link href="/assets/olympiamanagement.scss" media="screen" rel="stylesheet">
<link href="/assets/bootstrap.min.print.css" media="print" rel="stylesheet">
<link href="/assets/olympiamanagement.scss" media="print" rel="stylesheet">