Show More
Commit Description:
modernize java-bm, merge with algo-bm,master
Commit Description:
modernize java-bm, merge with algo-bm,master
References:
File last commit:
Show/Diff file:
Action:
app/helpers/application_helper.rb
| 138 lines
| 3.9 KiB
| text/x-ruby
| RubyLexer
|
|
r0 | # Methods added to this helper will be available to all templates in the application. | ||
module ApplicationHelper | ||||
|
r13 | |||
|
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' | ||
|
r217 | append_to menu_items, '[Problems]', 'problems', 'index' | ||
append_to menu_items, '[Users]', 'user_admin', 'index' | ||||
|
r162 | append_to menu_items, '[Results]', 'user_admin', 'user_stat' | ||
r501 | append_to menu_items, '[Report]', 'report', 'multiple_login' | |||
|
r105 | append_to menu_items, '[Graders]', 'graders', 'list' | ||
|
r266 | append_to menu_items, '[Contests]', 'contest_management', 'index' | ||
|
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 | |||
|
r320 | if (user!=nil) and (GraderConfiguration.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 | ||
r424 | ||||
r425 | if GraderConfiguration['right.user_hall_of_fame'] | |||
r424 | append_to menu_items, "[#{I18n.t 'menu.hall_of_fame'}]", 'report', 'problem_hof' | |||
end | ||||
|
r162 | append_to menu_items, "[#{I18n.t 'menu.help'}]", 'main', 'help' | ||
|
r156 | |||
|
r320 | if GraderConfiguration['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 | |||
|
r320 | menu_items.html_safe | ||
|
r36 | 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 | ||||
|
r217 | def format_short_duration(duration) | ||
return '' if duration==nil | ||||
d = duration.to_f | ||||
return Time.at(d).gmtime.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 | ||||
|
r320 | if GraderConfiguration.time_limit_mode? | ||
|
r217 | if user.contest_finished? | ||
|
r123 | 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 | ||
|
r217 | if !user.contest_started? | ||
|
r162 | time_left = " " + (t 'title_bar.contest_not_started') | ||
else | ||||
|
r217 | time_left = " " + (t 'title_bar.remaining_time') + | ||
" #{format_short_duration(user.contest_time_left)}" | ||||
|
r123 | end | ||
|
r85 | end | ||
|
r122 | |||
# | ||||
# if the contest is in the anaysis mode | ||||
|
r320 | if GraderConfiguration.analysis_mode? | ||
|
r122 | header = <<ANALYSISMODE | ||
<tr><td colspan="2" align="center"> | ||||
<span class="contest-over-msg">ANALYSIS MODE</span> | ||||
</td></tr> | ||||
ANALYSISMODE | ||||
end | ||||
|
r320 | contest_name = GraderConfiguration['contest.name'] | ||
|
r141 | |||
|
r122 | # | ||
# build real title bar | ||||
|
r320 | result = <<TITLEBAR | ||
|
r78 | <div class="title"> | ||
<table> | ||||
|
r122 | #{header} | ||
|
r78 | <tr> | ||
<td class="left-col"> | ||||
#{user.full_name}<br/> | ||||
r351 | #{t 'title_bar.current_time'} #{format_short_time(Time.zone.now)} | |||
|
r123 | #{time_left} | ||
<br/> | ||||
|
r78 | </td> | ||
|
r141 | <td class="right-col">#{contest_name}</td> | ||
|
r78 | </tr> | ||
</table> | ||||
</div> | ||||
TITLEBAR | ||||
|
r320 | result.html_safe | ||
|
r78 | end | ||
|
r322 | def markdown(text) | ||
markdown = RDiscount.new(text) | ||||
markdown.to_html.html_safe | ||||
end | ||||
|
r0 | end | ||