Show More
Commit Description:
added options to enable test-pair import
Commit Description:
added options to enable test-pair import
References:
File last commit:
Show/Diff file:
Action:
app/helpers/application_helper.rb
| 124 lines
| 3.4 KiB
| text/x-ruby
| RubyLexer
|
|
r0 | # Methods added to this helper will be available to all templates in the application. | ||
module ApplicationHelper | ||||
|
r13 | |||
|
r122 | SYSTEM_MODE_CONF_KEY = 'system.mode' | ||
|
r22 | def user_header | ||
|
r36 | menu_items = '' | ||
|
r13 | user = User.find(session[:user_id]) | ||
|
r25 | |||
|
r104 | if (user!=nil) and (session[:admin]) | ||
|
r77 | # admin menu | ||
menu_items << "<b>Administrative task:</b> " | ||||
|
r97 | append_to menu_items, '[Announcements]', 'announcements', 'index' | ||
|
r102 | append_to menu_items, '[Msg console]', 'messages', 'console' | ||
|
r77 | append_to menu_items, '[Problem admin]', 'problems', 'index' | ||
append_to menu_items, '[User admin]', 'user_admin', 'index' | ||||
|
r162 | append_to menu_items, '[Results]', 'user_admin', 'user_stat' | ||
|
r105 | append_to menu_items, '[Graders]', 'graders', 'list' | ||
|
r162 | append_to menu_items, '[Sites]', 'sites', 'index' | ||
append_to menu_items, '[System config]', 'configurations', 'index' | ||||
|
r77 | menu_items << "<br/>" | ||
end | ||||
|
r25 | # main page | ||
|
r162 | append_to menu_items, "[#{I18n.t 'menu.main'}]", 'main', 'list' | ||
append_to menu_items, "[#{I18n.t 'menu.messages'}]", 'messages', 'list' | ||||
|
r122 | |||
if (user!=nil) and (Configuration.show_tasks_to?(user)) | ||||
|
r162 | append_to menu_items, "[#{I18n.t 'menu.tasks'}]", 'tasks', 'list' | ||
append_to menu_items, "[#{I18n.t 'menu.submissions'}]", 'main', 'submission' | ||||
append_to menu_items, "[#{I18n.t 'menu.test'}]", 'test', 'index' | ||||
|
r122 | end | ||
|
r162 | append_to menu_items, "[#{I18n.t 'menu.help'}]", 'main', 'help' | ||
|
r156 | |||
if Configuration['system.user_setting_enabled'] | ||||
|
r162 | append_to menu_items, "[#{I18n.t 'menu.settings'}]", 'users', 'index' | ||
|
r156 | end | ||
|
r162 | append_to menu_items, "[#{I18n.t 'menu.log_out'}]", 'main', 'login' | ||
|
r36 | |||
menu_items | ||||
end | ||||
def append_to(option,label, controller, action) | ||||
option << ' ' if option!='' | ||||
option << link_to_unless_current(label, | ||||
:controller => controller, | ||||
:action => action) | ||||
|
r13 | end | ||
|
r65 | def format_short_time(time) | ||
|
r120 | now = Time.now.gmtime | ||
|
r65 | st = '' | ||
if (time.yday != now.yday) or | ||||
(time.year != now.year) | ||||
st = time.strftime("%x ") | ||||
end | ||||
st + time.strftime("%X") | ||||
end | ||||
|
r122 | def read_textfile(fname,max_size=2048) | ||
begin | ||||
File.open(fname).read(max_size) | ||||
rescue | ||||
nil | ||||
end | ||||
end | ||||
|
r78 | |||
def user_title_bar(user) | ||||
|
r122 | header = '' | ||
|
r123 | time_left = '' | ||
|
r122 | |||
# | ||||
# if the contest is over | ||||
|
r123 | if Configuration[SYSTEM_MODE_CONF_KEY]=='contest' | ||
if user.site!=nil and user.site.finished? | ||||
header = <<CONTEST_OVER | ||||
|
r85 | <tr><td colspan="2" align="center"> | ||
<span class="contest-over-msg">THE CONTEST IS OVER</span> | ||||
</td></tr> | ||||
CONTEST_OVER | ||||
|
r123 | end | ||
|
r162 | if !user.site.started | ||
time_left = " " + (t 'title_bar.contest_not_started') | ||||
else | ||||
if user.site!=nil | ||||
time_left = " " + (t 'title_bar.remaining_time') + | ||||
" #{Time.at(user.site.time_left).gmtime.strftime("%X")}" | ||||
end | ||||
|
r123 | end | ||
|
r85 | end | ||
|
r122 | |||
# | ||||
# if the contest is in the anaysis mode | ||||
if Configuration[SYSTEM_MODE_CONF_KEY]=='analysis' | ||||
header = <<ANALYSISMODE | ||||
<tr><td colspan="2" align="center"> | ||||
<span class="contest-over-msg">ANALYSIS MODE</span> | ||||
</td></tr> | ||||
ANALYSISMODE | ||||
end | ||||
|
r141 | contest_name = Configuration['contest.name'] | ||
|
r122 | # | ||
# build real title bar | ||||
|
r78 | <<TITLEBAR | ||
<div class="title"> | ||||
<table> | ||||
|
r122 | #{header} | ||
|
r78 | <tr> | ||
<td class="left-col"> | ||||
#{user.full_name}<br/> | ||||
|
r162 | #{t 'title_bar.current_time'} #{format_short_time(Time.new)} | ||
|
r123 | #{time_left} | ||
<br/> | ||||
|
r78 | </td> | ||
|
r141 | <td class="right-col">#{contest_name}</td> | ||
|
r78 | </tr> | ||
</table> | ||||
</div> | ||||
TITLEBAR | ||||
end | ||||
|
r0 | end | ||