From 44b95974c7d3b066250941289425adc7b51889c5 Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Mon, 2 Jul 2012 12:24:04 +0200 Subject: [PATCH] SONAR-3517 Ability to update profile in project configuration section --- .../resources/org/sonar/l10n/core.properties | 12 ++++++++++ .../app/controllers/project_controller.rb | 23 ++++++++++++++++++- .../app/views/layouts/_layout.html.erb | 4 ++++ .../views/project/quality_profile.html.erb | 19 +++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/project/quality_profile.html.erb diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties index 755f6f02243..73c224d5077 100644 --- a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -330,6 +330,7 @@ lcom4_viewer.page=LCOM4 dependencies.page=Dependencies resource_deletion.page={0} Deletion update_key.page=Update Key +project_quality_profile.page=Quality Profile # GWT pages @@ -972,6 +973,17 @@ update_key.current_key_for_project_x_is_x=The key of the "{0}" project is curren update_key.are_you_sure_to_rename_x=Are you sure you want to rename "{0}", as well as all its modules and resources ? update_key.are_you_sure_to_bulk_rename_x_into_x=Are you sure you want to rename "{0}{1}" into "{2}{1}", as well as all its modules and resources ? + +#------------------------------------------------------------------------------ +# +# PROJECT QUALITY PROFILE PAGE +# +#------------------------------------------------------------------------------ +project_quality_profile.current_profile_for_x=Current quality profile for "{0}": +project_quality_profile.project_cannot_be_update_with_profile_x=The current project can not be updated with the following profile: "{0}". +project_quality_profile.profile_successfully_updated=Quality profile successfully updated. + + #------------------------------------------------------------------------------ # # PROJECT (RESOURCE) DELETION PAGE diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb index dbe65bc7a5f..9a91912b815 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb @@ -18,7 +18,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 # class ProjectController < ApplicationController - verify :method => :post, :only => [:set_links, :set_exclusions, :delete_exclusions, :update_key, :perform_key_bulk_update], + verify :method => :post, :only => [:set_links, :set_exclusions, :delete_exclusions, :update_key, :perform_key_bulk_update, :update_quality_profile], :redirect_to => {:action => :index} verify :method => :delete, :only => [:delete], :redirect_to => {:action => :index} @@ -48,6 +48,27 @@ class ProjectController < ApplicationController redirect_to_default end + def quality_profile + @project = get_current_project(params[:id]) + @profiles = Profile.find(:all, :conditions => {:language => @project.language, :enabled => true}) + end + + def update_quality_profile + project = get_current_project(params[:id]) + + selected_profile = Profile.find(:first, :conditions => {:id => params[:quality_profile]}) + if selected_profile && selected_profile.language == project.language + project.profile = selected_profile + project.save! + flash[:notice] = message('project_quality_profile.profile_successfully_updated') + else + selected_profile_name = selected_profile ? selected_profile.name + "(" + selected_profile.language + ")" : "Unknown profile" + flash[:error] = message('project_quality_profile.project_cannot_be_update_with_profile_x', :params => selected_profile_name) + end + + redirect_to :action => 'quality_profile', :id => project.id + end + def key @project = get_current_project(params[:id]) 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 67cb894ef68..37a9379ace6 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 @@ -75,6 +75,10 @@ <% end %> <% if has_role?(:admin, @project) %>
  • <%= message('sidebar.project_settings') -%>
  • + <% if (@project.project?) %> +
  • + <%= message('project_quality_profile.page') -%>
  • + <% end %>
  • <%= message('manual_measures.page') -%>
  • <% if (@project.project?) %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/project/quality_profile.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/project/quality_profile.html.erb new file mode 100644 index 00000000000..078956f8bb4 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/project/quality_profile.html.erb @@ -0,0 +1,19 @@ +

    <%= message('project_quality_profile.page') -%>

    +
    +<% + form_tag( {:action => 'update_quality_profile', :id => @project.id }) do + project_profile = @project.profile +%> + + <%= message('project_quality_profile.current_profile_for_x', :params => @project.name) -%> + + + + <%= submit_tag message('update_verb'), :id => 'update_profile' %> + +<% end %> -- 2.39.5