diff --git a/plugins/top_bar/README.rdoc b/plugins/top_bar/README.rdoc new file mode 100644 index 00000000000..9ea0380dcad --- /dev/null +++ b/plugins/top_bar/README.rdoc @@ -0,0 +1,3 @@ += top_bar + +Description goes here diff --git a/plugins/top_bar/app/helpers/menu_generator_helper.rb b/plugins/top_bar/app/helpers/menu_generator_helper.rb new file mode 100755 index 00000000000..c2e708bafa4 --- /dev/null +++ b/plugins/top_bar/app/helpers/menu_generator_helper.rb @@ -0,0 +1,131 @@ +module MenuGeneratorHelper + def left_menu_tabs + tabs = [ { :name => 'menu', :label => 'Menu', :partial => 'left_menu/menu.rhtml' }, + { :name => 'actions', :label => 'Actions', :partial => 'left_menu/actions.rhtml' } ] + return tabs + end + def render_header_image (project) + out = "" + if project + if project.try(:topbarbackgroundcolor) + out += 'background-color:'+project.topbarbackgroundcolor+';' + end + if FileTest.exist?("#{Rails.root}/public/headerimages/"+project.id.to_s+'.jpg') + out += 'background-image:url(/headerimages/'+project.id.to_s+'.jpg);' + end + out = ' style="' + out + '"' + end + return out + end + + + def render_header_textcolor (project) + out = "" + if project then + if project.try(:topbartextcolor) then + out += 'color:'+project.topbartextcolor + end + end + return out + end + + def render_header_menu (project) + out = "" + ### HEADER MENU ### + # Highlight current top menu item + identifier = 'start' + if (project) then + identifier = get_parent_project_identifiers(project).last + end + + # Display START + htmlOptions = { + :class => 'start' + } + if (identifier == 'start') + htmlOptions[:class] += ' current' + end + #out += link_to "Start", {:controller => 'start', :action => 'index'}, htmlOptions + + # todo + # Display Subprojects + # Project.find(:all, :conditions => 'parent_id IS NULL', :order => :sorting).each { |prj| + # out += generate_link_to_project(prj, (identifier == prj.identifier), 0) + # } + return out + end + + def render_left_menu (project) + out = '' + if project and project.id + @projectidentifier = project.identifier + rootline = get_parent_project_identifiers(project) + firstLevelProject = Project.find(rootline.last) + out += outputProjectsRecursively(firstLevelProject, rootline, 1) + else # No project selected + out += link_to "Register project", "/" + end + return out; + end +private + + def get_parent_project_identifiers (project) + parentProjects = Array.new + parentProjects << project.identifier + while (project.parent != nil) do + project = project.parent + parentProjects << project.identifier + end + return parentProjects + end + + def generate_link_to_project (project, active, level) +# if (! project.visible_by(User.current)) then +# return "" +# end + htmlOptions = { + :class => 'level-'+level.to_s + } + if (active) then + htmlOptions[:class] += ' current' + end + + htmlOptions[:class] += ' sorting-'+project.sorting.to_s + + return link_to project.name, {:controller => 'projects', :action => 'show', :id => project.identifier }, htmlOptions + end + + def outputProjectsRecursively (project, rootline, level, inSelectTag = false) + out = '' + + projects = Project.find(:all, :order => "sorting, name", :conditions => [Project.visible_condition(User.current) + " AND parent_id = ?", project.id]) + + if (inSelectTag || ( level == 2 && projects.length > 20 ) ) then + if (level == 2) then + out += '' + end + else + projects.each { |prj| + if (rootline.include? prj.identifier) then # Selected menu item + out += generate_link_to_project(prj, true, level) + out += outputProjectsRecursively(prj, rootline, level + 1) + else # Not selected menu item + out += generate_link_to_project(prj, false, level) + end + } + end + return out + end +end diff --git a/plugins/top_bar/app/views/layouts/base.html.erb b/plugins/top_bar/app/views/layouts/base.html.erb new file mode 100644 index 00000000000..c4c965ec9c3 --- /dev/null +++ b/plugins/top_bar/app/views/layouts/base.html.erb @@ -0,0 +1,147 @@ + + + + + + <%= html_title %> + + + + <%= csrf_meta_tag %> + <%= favicon %> + <%= stylesheet_link_tag 'jquery/jquery-ui-1.11.0', 'application', 'responsive', :media => 'all' %> + <%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %> + <%= javascript_heads %> + <%= heads_for_theme %> + <%= call_hook :view_layouts_base_html_head %> + + <%= yield :header_tags -%> + + + +
+ +
+ + + <% if User.current.logged? || !Setting.login_required? %> + + <% end %> + + <% if User.current.logged? %> +
+ <% if Setting.gravatar_enabled? %> + <%= link_to(avatar(User.current, :size => "80"), user_path(User.current)) %> + <% end %> + <%= link_to_user(User.current, :format => :username) %> +
+ <% end %> + + <% if display_main_menu?(@project) %> +

<%= l(:label_project) %>

+ + <% end %> + +

<%= l(:label_general) %>

+ + + + +

<%= l(:label_profile) %>

+ + +
+ +
+
+
+
+ <%= render_menu :account_menu -%> +
+ <%= content_tag('div', "#{l(:label_logged_as)} #{link_to_user(User.current, :format => :username)}".html_safe, :id => 'loggedas') if User.current.logged? %> + <%= render_menu :top_menu if User.current.logged? || !Setting.login_required? -%> +
+ + + + +
+ + + + + +
+
+<%= call_hook :view_layouts_base_body_bottom %> + + diff --git a/plugins/top_bar/config/locales/en.yml b/plugins/top_bar/config/locales/en.yml new file mode 100644 index 00000000000..642b07f8211 --- /dev/null +++ b/plugins/top_bar/config/locales/en.yml @@ -0,0 +1,3 @@ +# English strings go here for Rails i18n +en: + # my_label: "My label" diff --git a/plugins/top_bar/config/routes.rb b/plugins/top_bar/config/routes.rb new file mode 100644 index 00000000000..1803173d04b --- /dev/null +++ b/plugins/top_bar/config/routes.rb @@ -0,0 +1,2 @@ +# Plugin's routes +# See: http://guides.rubyonrails.org/routing.html diff --git a/plugins/top_bar/init.rb b/plugins/top_bar/init.rb new file mode 100644 index 00000000000..fe45a15cde3 --- /dev/null +++ b/plugins/top_bar/init.rb @@ -0,0 +1,11 @@ +Redmine::Plugin.register :top_bar do + name 'Top Bar plugin' + author 'Matthias Hennemeyer' + description 'This is a plugin for Redmine' + version '0.0.1' + url 'http://example.com/path/to/plugin' + author_url 'http://example.com/about' +end + +ActionView::Base.send(:include, MenuGeneratorHelper) + diff --git a/plugins/top_bar/test/test_helper.rb b/plugins/top_bar/test/test_helper.rb new file mode 100644 index 00000000000..54685d33ca5 --- /dev/null +++ b/plugins/top_bar/test/test_helper.rb @@ -0,0 +1,2 @@ +# Load the Redmine helper +require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper')