finish olympiamagement version -1

This commit is contained in:
BOHUNG 2020-02-06 14:28:16 +08:00
parent 42150a399e
commit de71f3b4eb
11 changed files with 283 additions and 35 deletions

View File

@ -0,0 +1,36 @@
table.print_contest1, .print_contest2, .print_contest3 {
width: 100%;
margin: 0 0 1em 0;
border-spacing: 0;
border-top: 0.0625em solid black;
border-right: 0.0625em solid black;
}
table.print_contest1 th, table.print_contest1 td{
border-collapse:collapse;
border-bottom: 0.0625em solid black;
border-left: 0.0625em solid black;
height:2.5em;
font-size: 1em;
text-align: center;
}
table.print_contest2 th, table.print_contest2 td{
border-collapse:collapse;
border-left: 0.0625em solid black;
border-bottom: 0.0625em solid black;
height:2.5em;
font-size: 1em;
}
table.print_contest3 th, table.print_contest3 td{
border-collapse:collapse;
border-left: 0.0625em solid black;
border-bottom: 0.0625em solid black;
height:2.5em;
font-size: 1em;
text-align: center;
}
h2{
margin: 0;
}

View File

@ -1,6 +1,163 @@
.fieldset_title{
margin: 0 15px 20px 15px;
padding: 5px;
margin: 0 0.9375em 1.25em 0.9375em;
padding: 0.3125em;
font-size: 1.2em;
font-weight: bold;
border: 0em;
width: auto;
}
.errMsg {
color: #CC3333;
display: block;
margin: 10px;
padding-left: 20px;
background-image: url(/assets/warning.gif);
background-repeat: no-repeat;
background-position: left center;
}
.fieldset_block{
padding: 1.25em 0.625em 1.25em 3%;
border-width: 0.125em;
border-style: groove;
border-color: threedface;
border-image: initial;
}
.col {
float: left;
clear: both;
width: 9.125em;
margin: 0 0.625em 0em 0;
padding: 0.0625em 0 0.0625em 0;
}
.col_r {
float: left;
display: inline;
padding-bottom: 0.1875em;
}
.col_input{
padding: 0;
width: auto;
}
.ts_styled, .ts_rowsonly{
border-collapse: collapse;
clear: both;
margin: 0 0 10px;
width: 100%;
font-size: 12px;
}
.ts_styled caption, .ts_rowsonly caption{
color: #009999;
font: bold 15px/20px '微軟正黑體',sans-serif;
margin: 10px 0 10px;
text-align: left;
width: 500px;
}
.ts_styled th, .ts_rowsonly th{
border-top: 2px solid #999;
border-bottom: 1px solid #999;
color: #666;
padding: 10px 5px;
text-align: left;
white-space: nowrap;
font-size: 13px;
font-family: "微軟正黑體";
}
.ts_styled td, .ts_rowsonly td{
border-bottom: 1px solid #e3e3e3;
padding: 6px 5px;
color: #333;
}
.ts_styled a, .ts_rowsonly a{
color: #333;
}
.ts_styled a:hover, .ts_rowsonly a:hover{
color: #467cb2;
}
.ts_styled .even, .ts_rowsonly .even{}
.ts_styled tr:hover, .ts_styled tr:hover a {
background: #f5f5f5;
transition: background 0.3s;
}
.ts_vstyled{}
.ts_vstyled caption{
color: #1db2dd;
font: bold 15px/20px '微軟正黑體',sans-serif;
margin: 0 0 10px;
text-align: left;
width: 500px;
}
.ts_vstyled th{
border-right: 2px solid #1db2dd;
color: #1db2dd;
padding: 1%;
text-align: left;
width: 13%;
}
.ts_vstyled td{
padding: 1% 2%;
text-align: left;
width: 81%;
}
.ts_vstyled a{}
.ts_vstyled a:hover{}
.PageDetails {
padding-top: 0.1875em;
padding-bottom: 0.1875em;
font-weight: bold;
font-size: 0.875em;
border-bottom: 0.0625em solid #ddd;
overflow: hidden;
text-align: right;
color: black;
font-size: 1.3em;
}
.PageList {
margin: 0em 0em 0 0.5em;
font-weight: bold;
font-size: 0.875em;
overflow: hidden;
list-style: none;
display: inline;
background: none;
color: #999;
}
ol {
margin: 0 0 0.5em 0;
min-height: 0.625em;
height: auto !important;
height: 0.625em;
padding: 0;
clear: both;
float: right;
}
.PageList li {
display: inline;
}
.wrap-inner{
font-size: 1.1em;
}
.field-hint-inactive {
color: #999;
margin-left: 0.3125em;
padding-left: 1em;
padding-right: 0.5em;
background-image: url(/assets/fhi.png);
background-repeat: no-repeat;
background-position: left center;
float: left;
}
.required {
font-weight: bold;
}
.lleft{
float: left;
}
.red_text{
color: red;
}
.layout-content-inner.container{
min-height: 38em;
}
li{
display: block;
}

View File

@ -7,6 +7,7 @@ class Admin::OlympiamanagementsController < OrbitAdminController
helper Admin::OlympiamanagementsHelper
load File.expand_path(__dir__)+'/zipgenerator.rb'
def index
session[:sign_up_setting_id] = ""
page_num = params[:page] || 1
@sign_up_settings = SignUpSetting.all.desc(:id)
@sign_up_settings = @sign_up_settings.page(page_num).per(10)
@ -44,6 +45,16 @@ class Admin::OlympiamanagementsController < OrbitAdminController
@error_msg << ((I18n.locale.to_s == "zh_tw") ? "查無資料" : "Not found.")
render 'error_message'
end
elsif params[:type] == "delete_sign_up_setting"
@sign_up_setting = SignUpSetting.find(params[:id]) rescue nil
if !@sign_up_setting.nil?
@sign_up_setting.destroy
redirect_to :back
else
@error_msg = []
@error_msg << ((I18n.locale.to_s == "zh_tw") ? "查無資料" : "Not found.")
render 'error_message'
end
else
render :html => '404' and return
end
@ -74,10 +85,27 @@ class Admin::OlympiamanagementsController < OrbitAdminController
redirect_to :back
end
elsif params[:type] == 'add_school_data'
@olympia_school_data_field = (params[:id].nil? ? OlympiaSchoolDataFields.new : ((OlympiaSchoolDataFields.find(params[:id]).nil? rescue true) ? OlympiaSchoolDataFields.new : OlympiaSchoolDataFields.find(params[:id])))
@olympia_school_data_field = OlympiaSchoolDataFields.find(params[:id]) rescue nil
if @olympia_school_data_field.nil?
if OlympiaSchoolDataFields.where(:account_number => params['add_school_data']['account_number'],:sign_up_setting_id=>@sign_up_setting.id).length != 0
@error_msg = []
@error_msg << ((I18n.locale.to_s == "zh_tw") ? "帳號:#{params['add_school_data']['account_number']}已存在(帳號不可重複建立)" : "Account number: #{params['add_school_data']['account_number']} already exist.(Account name can not be created repeatedly.)")
render "error_message" and return
end
@olympia_school_data_field = OlympiaSchoolDataFields.new
else
if @olympia_school_data_field.account_number != params['add_school_data']['account_number']
if OlympiaSchoolDataFields.where(:account_number => params['add_school_data']['account_number'],:sign_up_setting_id=>@sign_up_setting.id).length != 0
@error_msg = []
@error_msg << ((I18n.locale.to_s == "zh_tw") ? "帳號:#{params['add_school_data']['account_number']}已存在(帳號不可重複建立)" : "Account number: #{params['add_school_data']['account_number']} already exist.(Account name can not be created repeatedly.)")
render "error_message" and return
end
end
end
params['add_school_data'].keys.each do |field|
@olympia_school_data_field[field] = params['add_school_data'][field]
end
@olympia_school_data_field.sign_up_setting_id = @sign_up_setting.id
@olympia_school_data_field.save
redirect_to admin_olympiamanagements_school_data_list_path
elsif params[:type] == 'import_class_setting'
@ -131,7 +159,7 @@ class Admin::OlympiamanagementsController < OrbitAdminController
@SchoolDataname = @SchoolDataField.school_data_fields.map{|field| field.keys[0]}
page_num = params[:page] || 1
@OlympiaSchoolDataFields = OlympiaSchoolDataFields.where(:sign_up_setting_id=>@sign_up_setting.id).asc(:id)
@OlympiaSchoolDataFields = @OlympiaSchoolDataFields.where("school_name" => /#{params[:school_name]}/) if !params[:school_name].to_s.blank?
@OlympiaSchoolDataFields = @OlympiaSchoolDataFields.where("school_name" => /#{params[:school_name].gsub('(','\(').gsub(')','\)').gsub('[','\[').gsub(']','\]')}/) if !params[:school_name].to_s.blank?
@OlympiaSchoolDataFields = @OlympiaSchoolDataFields.where("school_code" => /#{params[:school_code]}/) if !params[:school_code].to_s.blank?
@OlympiaSchoolDataFields = @OlympiaSchoolDataFields.page(page_num).per(10)
end

View File

@ -1,6 +1,6 @@
class OlympiamanagementsController < ApplicationController
include ActionView::Context #vary important (only add this can access @@session from view)
before_action :set_sign_up_setting,:create_first_fields
before_action :set_sign_up_setting,:create_first_fields,:check_time
prepend_view_path "app/templates" #for_render_pages
layout :get_layout #for_render_pages
helper Admin::OlympiamanagementsHelper
@ -13,7 +13,16 @@ class OlympiamanagementsController < ApplicationController
StudentDataField.create if StudentDataField.all.length == 0
SchoolDataFields.create if SchoolDataFields.all.length == 0
SignUpSetting.create if SignUpSetting.all.length == 0
@sign_up_setting = SignUpSetting.where(:active=>true).last
end
def check_time
@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")
@page = Page.where(:layout=>"olympia_managements_index",:parent_page_id=>(Page.where(:name=> ((I18n.locale.to_s == "en") ? "Home" : "首頁")).first.id)).first
if !(time_now_str <= end_time_str && time_now_str >= start_time_str)
redirect_to "/#{I18n.locale}#{@page.url}"
end
end
def check_login
begin
@ -21,7 +30,7 @@ class OlympiamanagementsController < ApplicationController
rescue
@@error = nil
end
@school = OlympiaSchoolDataFields.where(:account_number=>request.session[:olympia_login_id],:approved=>true).first rescue nil
@school = OlympiaSchoolDataFields.where(:sign_up_setting_id=>@sign_up_setting.id,:account_number=>request.session[:olympia_login_id],:approved=>true).first rescue nil
if @school.nil?
render_contents_in_index_page(render_to_string(:formats=> [:html] ,:partial=>'login',:locals=>{:@error=>@@error})) and return
end
@ -29,10 +38,12 @@ class OlympiamanagementsController < ApplicationController
def login
@@error = nil
if !params[:login_id].to_s.blank?
if OlympiaSchoolDataFields.where(:account_number=>params[:login_id],:approved=>true).length == 0
if OlympiaSchoolDataFields.where(:sign_up_setting_id=>@sign_up_setting.id,:account_number=>params[:login_id],:approved=>true).length == 0
@@error = "no_account"
else
if OlympiaSchoolDataFields.where(:account_number=>params[:login_id]).first.password != params[:login_pw]
@correct_password = OlympiaSchoolDataFields.where(:sign_up_setting_id=>@sign_up_setting.id,:account_number=>params[:login_id]).first.password
@correct_password = @sign_up_setting.default_password if @correct_password.blank?
if params[:login_pw] != @correct_password
@@error = "password_error"
else
session[:olympia_login_id] = params[:login_id]
@ -219,7 +230,7 @@ class OlympiamanagementsController < ApplicationController
def sign_up_student_data_list
page_num = params[:page] || 1
@field_infos = StudentDataField.first.student_data_fields
@olympia_school_data_fields_id = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id]).first.id
@olympia_school_data_fields_id = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id],:sign_up_setting_id=>@sign_up_setting.id).first.id
@sign_up_setting_id = @sign_up_setting.id
@student_fields = OlympiaStudentDataField.where(:olympia_school_data_fields_id=>@olympia_school_data_fields_id,:sign_up_setting_id=>@sign_up_setting_id).asc(:id).page(page_num).per(10)
@page_content = render_to_string(:formats=> [:html] ,:partial=>'student_data_list.html',:locals=>{:@student_fields=>(@student_fields rescue [])}).html_safe
@ -260,13 +271,14 @@ class OlympiamanagementsController < ApplicationController
@sign_up_setting.attributes.to_h.each do |key,value|
@remark_texts = @remark_texts.gsub("{{#{key}}}",value.to_s)
end
@record_form_title = ((I18n.locale.to_s == "zh_tw") ? "#{Time.now.year}年國中科學奧林匹亞競賽國家代表隊選拔初選報名表" : "#{Time.now.year} Year International Junior Science Olympiad National Team Selection First Stage Sign up Form")
@remark_texts = @remark_texts.html_safe
@record_form_title = ((I18n.locale.to_s == "zh_tw") ? "#{@sign_up_setting.end_year}年國中科學奧林匹亞競賽國家代表隊選拔初選報名表" : "#{Time.now.year} Year International Junior Science Olympiad National Team Selection First Stage Sign up Form")
@school_data = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id]).first
@record_fields = [['school_name','school_code'],['school_address'],['class_number','enrollment_limited'],
['office_tel_number','fax'],['mobile_number','email'],['principal_signature','dean_signature']]
@student_fields = ['serial_number','StudentName','StudentSex','StudentClass','StudentIDNO','birth_date','StudentArea','StudentIdentity']
@field_infos = StudentDataField.first.student_data_fields
@olympia_school_data_fields_id = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id]).first.id
@olympia_school_data_fields_id = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id],:sign_up_setting_id=>@sign_up_setting.id).first.id
@sign_up_setting_id = @sign_up_setting.id
@student_data_list = OlympiaStudentDataField.where(:olympia_school_data_fields_id=>@olympia_school_data_fields_id,:sign_up_setting_id=>@sign_up_setting_id)
@head = render_to_string(:formats=>[:html],:file=>"#{Rails.root}/app/templates/#{@key}/partial/_head.html")
@ -668,9 +680,9 @@ class OlympiamanagementsController < ApplicationController
if @student_params['StudentIdentity'] == '1' && (@student_params['olympia_student_images']['0']['StudentFile'].nil? rescue true)
@error_msg << I18n.t('olympiamanagement.StudentFile')
end
@olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id]).first
@olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id],:sign_up_setting_id=>@sign_up_setting.id).first
@enrollment_limited = ((@olympia_school_data_field.enrollment_limited.nil? || @olympia_school_data_field.enrollment_limited == 0) ? ClassSettingFields.all.select{|class_setting_field| class_setting_field.class_number_range[0] <= @olympia_school_data_field.class_number.to_i && class_setting_field.class_number_range[1] >= @olympia_school_data_field.class_number.to_i}.first.enrollment_available.to_i : @olympia_school_data_field.enrollment_limited.to_i)
@student_fields = OlympiaStudentDataField.where(:olympia_school_data_fields_id=>@olympia_school_data_field.id,:sign_up_setting_id=>@sign_up_setting_id)
@student_fields = OlympiaStudentDataField.where(:olympia_school_data_fields_id=>@olympia_school_data_field.id,:sign_up_setting_id=>@sign_up_setting.id)
if @student_fields.length > @enrollment_limited
@error_msg << ((I18n.locale.to_s == "zh_tw") ? ("一般身分報名人數上限為 #{@enrollment_limited} 人。") : ("Enrollment limited of General identity is #{@enrollment_limited} people."))
@error_msg << I18n.t('olympiamanagement.already_exceed_enrollment_limited')

View File

@ -1,7 +1,7 @@
<link rel="stylesheet" media="screen" type="text/css" href="/assets/admin/olympiamanagement.scss">
<link rel="stylesheet" media="print" type="text/css" href="/assets/admin/olympiamanagement.scss">
<script src="/assets/admin/olympiamanagement.js"></script>
<% th_name_list = ['sign_up_start_time','sign_up_end_time','enrollment','status','action']%>
<% th_name_list = ['sign_up_start_time','sign_up_end_time','school_number','enrollment','status','action']%>
<% time = ['year','month','day'] %>
<h3><%=t('olympiamanagement.history_contest')%></h3>
<table class="ts_rowsonly" width="100%">
@ -15,6 +15,7 @@
<tr>
<td><%= time.map{|td| sign_up_setting["start_#{td}"]}.join('-') %></td>
<td><%= time.map{|td| sign_up_setting["end_#{td}"]}.join('-') %></td>
<td><%= @school_number = OlympiaSchoolDataFields.where(:sign_up_setting_id=>sign_up_setting.id).length %></td>
<td><%= @student_number = OlympiaStudentDataField.where(:sign_up_setting_id=>sign_up_setting.id).length %></td>
<td>
<% if sign_up_setting.active%>
@ -31,9 +32,10 @@
</td>
<td>
<% if !sign_up_setting.active%>
<a href='<%= admin_olympiamanagements_update_sign_up_data_path + "?type=active&id=#{sign_up_setting.id}"%>'><%=t('olympiamanagement.active')%></a>
<a class="btn" href='<%= admin_olympiamanagements_update_sign_up_data_path + "?type=active&id=#{sign_up_setting.id}"%>'><%=t('olympiamanagement.active')%></a>
<% end %>
<a href='<%= admin_olympiamanagements_update_sign_up_data_path + "?type=view&id=#{sign_up_setting.id}"%>'><%=t('olympiamanagement.view')%></a>
<a class="btn" href='<%= admin_olympiamanagements_update_sign_up_data_path + "?type=view&id=#{sign_up_setting.id}"%>'><%=t('olympiamanagement.view')%></a>
<a class="btn" href="#" onclick="if( window.confirm('<%=t('olympiamanagement.please_confirm_delete')%>') ) { window.location='<%=admin_olympiamanagements_update_sign_up_data_path + "?type=delete_sign_up_setting&id=#{sign_up_setting.id}"%>'; }" onkeypress="if( window.confirm('<%=t('olympiamanagement.please_confirm_delete')%>') ) { window.location='<%=admin_olympiamanagements_update_sign_up_data_path + "?type=delete_sign_up_setting&id=#{sign_up_setting.id}"%>'; }"><%=t('olympiamanagement.delete')%></a>
</td>
</tr>
<% end %>

View File

@ -3,7 +3,8 @@
<script src="/assets/admin/olympiamanagement.js"></script>
<fieldset class="fieldset_block">
<legend class="fieldset_title"><%=t('olympiamanagement.school_connection_data')%></legend>
<%=form_for @olympia_school_data_field ,:url=>{:controller=>"olympiamanagements" ,:action=>"update_school_data",:olympia_user_name=>(session[:olympia_login_id] rescue "")} do |form|%>
<%=form_for @olympia_school_data_field ,:url=>{:controller=>"olympiamanagements" ,:action=>"update_school_data"} do |form|%>
<input name="olympia_user_name" type="hidden" value="<%=session[:olympia_login_id] rescue "" %>">
<% @school_data_fields.each do |field| %>
<div class="col_text">
<% @extra_class = ((field.values[0]["required"] == "true")? " required" : "")%>

View File

@ -1,5 +1,5 @@
<link rel="stylesheet" media="screen" type="text/css" href="/assets/admin/olympiamanagement.scss">
<link rel="stylesheet" media="print" type="text/css" href="/assets/admin/olympiamanagement.scss">
<link rel="stylesheet" media="screen" type="text/css" href="/assets/olympiamanagement.scss">
<link rel="stylesheet" media="print" type="text/css" href="/assets/olympiamanagement.scss">
<script src="/assets/admin/olympiamanagement.js"></script>
<% th_name_list = ['StudentIdentity','StudentName','StudentClass','StudentArea','StudentPhone','action']%>
<table cellspacing="0" class="ts_rowsonly" width="100%" id="RSS_Table_page_contest_admin_1">

View File

@ -2,17 +2,28 @@
<html>
<head>
<%=@head%>
<link href="/assets/contest.css" rel="stylesheet" type="text/css">
<%= stylesheet_link_tag "template/template" , :media=>'print' %>
</head>
<body>
<body style="background-color: white;margin: 0.8em;">
<div id="main1"><div id="main2"><div id="main">
<%=@breadcumb%>
<table class="print_contest1"><tbody>
<tr><th colspan="4"><font face="標楷體, cursive"><font size="6" style="font-size: 1.67em;"><%=@record_form_title%></font></font></th></tr>
<% @record_fields.each_with_index do |record_block,i| %>
<tr>
<% record_block.each do |record_item| %>
<% record_block.each_with_index do |record_item,td_index| %>
<td <%=((i==@record_fields.count-1) ? "style=line-height:80px;" : "")%>><%=t('olympiamanagement.'+record_item.to_s)%></td>
<td <%=((i==@record_fields.count-1) ? "style=line-height:80px;" : "")%>><%=(@school_data[record_item.to_s].nil? ? '&nbsp;'.html_safe : @school_data[record_item.to_s]) %></td>
<% if record_item == "enrollment_limited"%>
<% @olympia_school_data_field = OlympiaSchoolDataFields.find(@olympia_school_data_fields_id)%>
<% if(@olympia_school_data_field.enrollment_limited.to_i == 0) %>
<td><%= ClassSettingFields.all.select{|class_setting_field| class_setting_field.class_number_range[0] <= @olympia_school_data_field.class_number && class_setting_field.class_number_range[1] >= @olympia_school_data_field.class_number}.first.enrollment_available.to_s %></td>
<% else %>
<td><%= @olympia_school_data_field.enrollment_limited %></td>
<% end %>
<% else %>
<td <%= ((td_index == record_block.count-1) ? "colspan=#{3-td_index*2}" : "") %> <%=((i==@record_fields.count-1) ? "style=line-height:80px;" : "")%>><%=(@school_data[record_item.to_s].nil? ? '&nbsp;'.html_safe : @school_data[record_item.to_s]) %></td>
<% end %>
<% end %>
</tr>
<% end %>
@ -51,12 +62,11 @@
</tbody></table>
<script type="text/javascript">
window.onload = function ()
{
text=document
print(text)
}
window.onload = function (){
text = document;
print(text);
};
</script>
</div></div></div></div></div></div></div>
</body>
</html>>
</html>

View File

@ -1,5 +1,6 @@
en:
olympiamanagement:
school_number: School number
new_sign_up: Create new Sign up
view: View
history_contest: History Contest

View File

@ -1,5 +1,6 @@
zh_tw:
olympiamanagement:
school_number: 學校數量
new_sign_up: 建立新的報名
view: 查看
add_sign_up_setting: 增加報名設定

View File

@ -28,12 +28,12 @@ Rails.application.routes.draw do
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 'update_school_data'
post 'update_school_data'
patch 'update_school_data'
get 'update_student_data'
post 'update_student_data'
patch 'update_student_data'
get 'download_school_code'
get 'school_connection_data'
get 'add_sign_up_student_data'