# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
def user_header
menu_items = ''
user = User.find(session[:user_id])
if (user!=nil) and (session[:admin])
# admin menu
menu_items << "Administrative task: "
append_to menu_items, '[Announcements]', 'announcements', 'index'
append_to menu_items, '[Msg console]', 'messages', 'console'
append_to menu_items, '[Problems]', 'problems', 'index'
append_to menu_items, '[Users]', 'user_admin', 'index'
append_to menu_items, '[Results]', 'user_admin', 'user_stat'
append_to menu_items, '[Report]', 'report', 'login_stat'
append_to menu_items, '[Graders]', 'graders', 'list'
append_to menu_items, '[Contests]', 'contest_management', 'index'
append_to menu_items, '[Sites]', 'sites', 'index'
append_to menu_items, '[System config]', 'configurations', 'index'
menu_items << " "
end
# main page
append_to menu_items, "[#{I18n.t 'menu.main'}]", 'main', 'list'
append_to menu_items, "[#{I18n.t 'menu.messages'}]", 'messages', 'list'
if (user!=nil) and (GraderConfiguration.show_tasks_to?(user))
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'
end
if GraderConfiguration['right.user_hall_of_fame']
append_to menu_items, "[#{I18n.t 'menu.hall_of_fame'}]", 'report', 'problem_hof'
end
append_to menu_items, "[#{I18n.t 'menu.help'}]", 'main', 'help'
if GraderConfiguration['system.user_setting_enabled']
append_to menu_items, "[#{I18n.t 'menu.settings'}]", 'users', 'index'
end
append_to menu_items, "[#{I18n.t 'menu.log_out'}]", 'main', 'login'
menu_items.html_safe
end
def append_to(option,label, controller, action)
option << ' ' if option!=''
option << link_to_unless_current(label,
:controller => controller,
:action => action)
end
def format_short_time(time)
now = Time.now.gmtime
st = ''
if (time.yday != now.yday) or
(time.year != now.year)
st = time.strftime("%x ")
end
st + time.strftime("%X")
end
def format_short_duration(duration)
return '' if duration==nil
d = duration.to_f
return Time.at(d).gmtime.strftime("%X")
end
def read_textfile(fname,max_size=2048)
begin
File.open(fname).read(max_size)
rescue
nil
end
end
def user_title_bar(user)
header = ''
time_left = ''
#
# if the contest is over
if GraderConfiguration.time_limit_mode?
if user.contest_finished?
header = <
THE CONTEST IS OVER
CONTEST_OVER
end
if !user.contest_started?
time_left = " " + (t 'title_bar.contest_not_started')
else
time_left = " " + (t 'title_bar.remaining_time') +
" #{format_short_duration(user.contest_time_left)}"
end
end
#
# if the contest is in the anaysis mode
if GraderConfiguration.analysis_mode?
header = <
ANALYSIS MODE
ANALYSISMODE
end
contest_name = GraderConfiguration['contest.name']
#
# build real title bar
result = <