diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,6 +1,39 @@ # Methods added to this helper will be available to all templates in the application. module ApplicationHelper + #new bootstrap header + 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 + + 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'}}) + if GraderConfiguration['system.user_setting_enabled'] + right_menu << add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-cog')}".html_safe, 'users', 'index', {title: I18n.t('menu.settings'), data: {toggle: 'tooltip'}}) + end + 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'}}) + + + 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 + + def add_menu(title, controller, action,html_option = {}) + 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 + def user_header menu_items = '' user = User.find(session[:user_id]) @@ -75,6 +108,34 @@ end end + def toggle_button(on,toggle_url,id, option={}) + btn_size = option[:size] || 'btn-xs' + link_to (on ? "Yes" : "No"), toggle_url, + {class: "btn btn-block #{btn_size} btn-#{on ? 'success' : 'default'} ajax-toggle", + id: id, + data: {remote: true, method: 'get'}} + end + + 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 + + def user_title_bar(user) header = '' time_left = ''