From 35cff4a29be35026b038afcd1767811fac3794c9 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 28 Nov 2012 21:04:38 +0100 Subject: [PATCH] Add breadcrumb to profiles console --- .../resources/org/sonar/l10n/core.properties | 9 +++--- .../app/controllers/alerts_controller.rb | 2 ++ .../app/controllers/application_controller.rb | 9 +++++- .../app/controllers/measures_controller.rb | 2 +- .../app/controllers/profiles_controller.rb | 23 +++++++------ .../rules_configuration_controller.rb | 14 +++----- .../webapp/WEB-INF/app/models/api/utils.rb | 3 +- .../WEB-INF/app/views/alerts/index.html.erb | 1 - .../app/views/layouts/_breadcrumb.html.erb | 32 +++++++++++++++++-- .../app/views/layouts/_layout.html.erb | 4 +-- .../app/views/profiles/changelog.html.erb | 1 - .../app/views/profiles/compare.html.erb | 3 -- .../WEB-INF/app/views/profiles/index.html.erb | 1 - .../app/views/profiles/inheritance.html.erb | 1 - .../app/views/profiles/permalinks.html.erb | 1 - .../app/views/profiles/projects.html.erb | 1 - .../WEB-INF/app/views/profiles/show.html.erb | 13 -------- .../views/rules_configuration/index.html.erb | 2 -- .../src/main/webapp/stylesheets/layout.css | 2 +- 19 files changed, 67 insertions(+), 57 deletions(-) delete mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/profiles/show.html.erb diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties index 95436a19e3b..c882eef8435 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -297,7 +297,6 @@ layout.evaluation=Embedded database should be used for evaluation purpose only layout.ie6_warn=Your web browser is outdated. This website may not display correctly. layout.dashboards=Dashboards layout.tools=Tools -layout.tools.quality_profiles=Quality Profiles layout.user_panel.my_profile=My profile layout.user_panel.recent_history.title=Recent history layout.user_panel.recent_history.clear=Clear @@ -1226,10 +1225,10 @@ cloud.top_risk=Top risk # #------------------------------------------------------------------------------ -quality_profiles.quality_profiles=Quality profiles -quality_profiles.new_profile=New profile -quality_profiles.compare_profiles=Compare profiles -quality_profiles.restore_profile=Restore profile +quality_profiles.quality_profiles=Quality Profiles +quality_profiles.new_profile=New Profile +quality_profiles.compare_profiles=Compare Profiles +quality_profiles.restore_profile=Restore Profile quality_profiles.restore_submit=Restore quality_profiles.x_language_profiles={0} Profiles quality_profiles.optional_configuration_file=Optional configuration file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/alerts_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/alerts_controller.rb index c27ca5a90eb..586e91dca1f 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/alerts_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/alerts_controller.rb @@ -29,9 +29,11 @@ class AlertsController < ApplicationController # # def index + require_parameters :id @profile = Profile.find(params[:id]) @alerts = @profile.alerts.sort @alert=Alert.new + add_breadcrumbs ProfilesController::ROOT_BREADCRUMB, Api::Utils.language_name(@profile.language), @profile.name end # diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb index fa0dc0a07a5..0c6084981ac 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb @@ -174,7 +174,7 @@ class ApplicationController < ActionController::Base # - # FILTERS + # RAILS FILTERS # def init_resource_for_user_role init_resource_for_role :user @@ -194,4 +194,11 @@ class ApplicationController < ActionController::Base access_denied unless has_role?(role, @resource) end + + + # BREADCRUMBS + def add_breadcrumbs(*breadcrumbs) + @breadcrumbs ||= [] + @breadcrumbs.concat(breadcrumbs) + end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb index 53fc617c245..7475ad4e401 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb @@ -19,6 +19,7 @@ # class MeasuresController < ApplicationController + # GET /measures/index def index @filter = MeasureFilter.new @@ -191,5 +192,4 @@ class MeasuresController < ApplicationController def owner?(filter) current_user && (filter.user_id==current_user.id || (filter.user_id==nil && has_role?(:admin))) end - end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb index 821b6313b56..f05ebdaa0d0 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb @@ -22,20 +22,16 @@ class ProfilesController < ApplicationController # the backup action is allow to non-admin users : see http://jira.codehaus.org/browse/SONAR-2039 before_filter :admin_required, :only => ['create', 'delete', 'set_as_default', 'copy', 'restore', 'change_parent', 'set_projects', 'rename_form', 'rename'] + ROOT_BREADCRUMB = {:name => Api::Utils.message('quality_profiles.page'), :url => {:controller => 'profiles', :action => 'index'}} + # GET /profiles/index def index + add_breadcrumbs ROOT_BREADCRUMB @profiles = Profile.find(:all) Api::Utils.insensitive_sort!(@profiles){|profile| profile.name} end - # GET /profiles/show/ - def show - require_parameters 'id' - @profile = Profile.find(params[:id]) - end - - # GET /profiles/create_form?language= def create_form require_parameters 'language' @@ -124,7 +120,6 @@ class ProfilesController < ApplicationController end end - # POST /profiles/backup?id= def backup verify_post_request @@ -185,6 +180,8 @@ class ProfilesController < ApplicationController profiles=Profile.find(:all, :conditions => ['language=? and id<>? and (parent_name is null or parent_name<>?)', @profile.language, @profile.id, @profile.name], :order => 'name') @select_parent = [[message('none'), nil]] + profiles.collect { |profile| [profile.name, profile.name] } + + set_profile_breadcrumbs end # GET /profiles/changelog?id= @@ -214,6 +211,8 @@ class ProfilesController < ApplicationController @select_versions = versions.map { |u| [message(u.profile_version == last_version ? 'quality_profiles.last_version_x_with_date' : 'quality_profiles.version_x_with_date', :params => [u.profile_version.to_s, l(u.change_date)]), u.profile_version] } | [[message('quality_profiles.no_version'), 0]]; end + + set_profile_breadcrumbs end @@ -242,6 +241,7 @@ class ProfilesController < ApplicationController def permalinks require_parameters 'id' @profile = Profile.find(params[:id]) + set_profile_breadcrumbs end @@ -253,6 +253,7 @@ class ProfilesController < ApplicationController def projects require_parameters 'id' @profile = Profile.find(params[:id]) + set_profile_breadcrumbs end @@ -321,7 +322,6 @@ class ProfilesController < ApplicationController end end - # GET /profiles/compare?id1=&id2= def compare @profiles = Profile.find(:all, :order => 'language asc, name') @@ -363,6 +363,7 @@ class ProfilesController < ApplicationController end end end + add_breadcrumbs ROOT_BREADCRUMB, Api::Utils.message('compare') end DIFF_IN1=1 @@ -506,4 +507,8 @@ class ProfilesController < ApplicationController flash[:notice]=messages.getInfos().to_a[0...4].join('
') end end + + def set_profile_breadcrumbs + add_breadcrumbs ROOT_BREADCRUMB, Api::Utils.language_name(@profile.language), @profile.name + end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb index 5d0ad9c1b68..3282b6192ce 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb @@ -34,16 +34,10 @@ class RulesConfigurationController < ApplicationController before_filter :admin_required, :except => ['index', 'export'] def index - if params[:id].to_i<=0 - redirect_to :controller => 'profiles' - return - end - begin - @profile = Profile.find(params[:id].to_i) - rescue - redirect_to :controller => 'profiles' - return - end + require_parameters :id + + @profile = Profile.find(params[:id]) + add_breadcrumbs ProfilesController::ROOT_BREADCRUMB, Api::Utils.language_name(@profile.language), @profile.name init_params() diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb index e7419d5d511..b96e859c9ac 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb @@ -176,7 +176,8 @@ class Api::Utils end def self.language_name(key) - language(key) ? language(key).name : key + l = language(key) + l ? l.name : key end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/alerts/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/alerts/index.html.erb index dbab2ebbca1..2b8b029a0f9 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/alerts/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/alerts/index.html.erb @@ -1,4 +1,3 @@ -

<%= link_to message('quality_profiles.quality_profiles'), :controller => 'profiles', :action => 'index' -%> / <%= h @profile.language -%> / <%= h @profile.name %>

<%= render :partial => 'profiles/tabs', :locals => {:selected_tab=>'Alerts'} %> <% if is_admin? %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_breadcrumb.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_breadcrumb.html.erb index cac01887b8f..2a5ee916434 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_breadcrumb.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_breadcrumb.html.erb @@ -3,9 +3,11 @@ %>
<% if !@review %> -
    -
  • -
+
    +
  • + +
  • +
<% end %>
    <% @@ -50,4 +52,28 @@ %>
+<% elsif @breadcrumbs %> +
+
    + <% + @breadcrumbs.each_with_index do |breadcrumb, index| + %> + > + <% if breadcrumb.is_a?(String) %> + <%= h breadcrumb -%> + <% + elsif breadcrumb.is_a?(Hash) + name = breadcrumb[:name] + url = breadcrumb[:url] + icon = breadcrumb[:icon] + %> + <%= image_tag icon if icon %> + <%= link_to_if url, name, url -%> + <% elsif breadcrumb.respond_to?(:html) %> + <%= breadcrumb.html -%> + <% end %> + + <% end %> +
+
<% end %> \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb index 90b62d1f25c..9fb3b7bb9cb 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb @@ -18,7 +18,7 @@ <%= message('layout.measures') -%>
  • - <%= message('layout.tools.quality_profiles') -%> + <%= message('quality_profiles.page') -%>
  • <%= render 'layouts/tools' -%> @@ -43,7 +43,7 @@ -<%= render 'layouts/breadcrumb' if selected_section==Navigation::SECTION_RESOURCE -%> +<%= render 'layouts/breadcrumb' if @breadcrumbs || selected_section==Navigation::SECTION_RESOURCE -%>
    <% if selected_section || @sidebar %>
    diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/changelog.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/changelog.html.erb index 38521ea84a6..af89534c49d 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/changelog.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/changelog.html.erb @@ -1,4 +1,3 @@ -

    <%= link_to message('quality_profiles.quality_profiles'), :controller => 'profiles', :action => 'index' -%> / <%= h @profile.language -%> / <%= h @profile.name %>

    <%= render :partial => 'profiles/tabs', :locals => {:selected_tab=>'changelog'} %>
    diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/compare.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/compare.html.erb index 7cda38ad0c0..012cb6a341f 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/compare.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/compare.html.erb @@ -1,6 +1,3 @@ -

    <%= link_to message('quality_profiles.quality_profiles'), :controller => 'profiles', :action => 'index' -%> / - <%= message('compare') -%>

    -