Show More
Commit Description:
fig bugs in login report
Commit Description:
fig bugs in login report
References:
File last commit:
Show/Diff file:
Action:
app/helpers/application_helper.rb
| 222 lines
| 6.9 KiB
| text/x-ruby
| RubyLexer
|
|
r0 | # Methods added to this helper will be available to all templates in the application. | ||
module ApplicationHelper | ||||
|
r13 | |||
r588 | #new bootstrap header | |||
r553 | def navbar_user_header | |||
left_menu = '' | ||||
right_menu = '' | ||||
user = User.find(session[:user_id]) | ||||
if (user!=nil) and (GraderConfiguration.show_tasks_to?(user)) | ||||
left_menu << add_menu("#{I18n.t 'menu.tasks'}", 'tasks', 'list') | ||||
left_menu << add_menu("#{I18n.t 'menu.submissions'}", 'main', 'submission') | ||||
left_menu << add_menu("#{I18n.t 'menu.test'}", 'test', 'index') | ||||
end | ||||
if GraderConfiguration['right.user_hall_of_fame'] | ||||
left_menu << add_menu("#{I18n.t 'menu.hall_of_fame'}", 'report', 'problem_hof') | ||||
end | ||||
r554 | right_menu << add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-question-sign')}".html_safe, 'main', 'help') | |||
right_menu << add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-comment')}".html_safe, 'messages', 'list', {title: I18n.t('menu.messages'), data: {toggle: 'tooltip'}}) | ||||
r553 | if GraderConfiguration['system.user_setting_enabled'] | |||
r554 | right_menu << add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-cog')}".html_safe, 'users', 'index', {title: I18n.t('menu.settings'), data: {toggle: 'tooltip'}}) | |||
r553 | end | |||
r554 | right_menu << add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-log-out')} #{user.full_name}".html_safe, 'main', 'login', {title: I18n.t('menu.log_out'), data: {toggle: 'tooltip'}}) | |||
r553 | ||||
result = content_tag(:ul,left_menu.html_safe,class: 'nav navbar-nav') + content_tag(:ul,right_menu.html_safe,class: 'nav navbar-nav navbar-right') | ||||
end | ||||
r644 | def add_menu(title, controller, action, html_option = {}) | |||
r553 | link_option = {controller: controller, action: action} | |||
html_option[:class] = (html_option[:class] || '') + " active" if current_page?(link_option) | ||||
content_tag(:li, link_to(title,link_option),html_option) | ||||
end | ||||
|
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) | ||
r696 | now = Time.zone.now | |||
|
r65 | st = '' | ||
r696 | if (time.yday != now.yday) or (time.year != now.year) | |||
st = time.strftime("%d/%m/%y ") | ||||
|
r65 | 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 | ||||
r696 | def format_full_time_ago(time) | |||
st = time_ago_in_words(time) + ' ago (' + format_short_time(time) + ')' | ||||
end | ||||
|
r122 | def read_textfile(fname,max_size=2048) | ||
begin | ||||
File.open(fname).read(max_size) | ||||
rescue | ||||
nil | ||||
end | ||||
end | ||||
|
r78 | |||
r563 | def toggle_button(on,toggle_url,id, option={}) | |||
btn_size = option[:size] || 'btn-xs' | ||||
r795 | btn_block = option[:block] || 'btn-block' | |||
r563 | link_to (on ? "Yes" : "No"), toggle_url, | |||
r795 | {class: "btn #{btn_block} #{btn_size} btn-#{on ? 'success' : 'default'} ajax-toggle", | |||
r563 | id: id, | |||
data: {remote: true, method: 'get'}} | ||||
r559 | end | |||
r566 | def get_ace_mode(language) | |||
# return ace mode string from Language | ||||
case language.pretty_name | ||||
when 'Pascal' | ||||
'ace/mode/pascal' | ||||
when 'C++','C' | ||||
'ace/mode/c_cpp' | ||||
when 'Ruby' | ||||
'ace/mode/ruby' | ||||
when 'Python' | ||||
'ace/mode/python' | ||||
when 'Java' | ||||
'ace/mode/java' | ||||
else | ||||
'ace/mode/c_cpp' | ||||
end | ||||
end | ||||
r572 | ||||
|
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"> | ||||
|
r123 | <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 | ||||
r632 | ||||
BOOTSTRAP_FLASH_MSG = { | ||||
success: 'alert-success', | ||||
error: 'alert-danger', | ||||
r678 | alert: 'alert-danger', | |||
r632 | notice: 'alert-info' | |||
} | ||||
def bootstrap_class_for(flash_type) | ||||
BOOTSTRAP_FLASH_MSG.fetch(flash_type.to_sym, flash_type.to_s) | ||||
end | ||||
def flash_messages | ||||
flash.each do |msg_type, message| | ||||
concat(content_tag(:div, message, class: "alert #{bootstrap_class_for(msg_type)} fade in") do | ||||
concat content_tag(:button, 'x', class: "close", data: { dismiss: 'alert' }) | ||||
concat message | ||||
end) | ||||
end | ||||
nil | ||||
end | ||||
|
r0 | end | ||