aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-09-24 22:02:27 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-09-24 22:06:23 +0200
commit2be9d39965149fb5395e06c5036d79dab63447e4 (patch)
tree027b037451e44becc6b5a7e3f5803721d53e52bc /sonar-server/src
parent9eaf53b7e688de3a7c3cfff1e530a077ff7c6e75 (diff)
downloadsonarqube-2be9d39965149fb5395e06c5036d79dab63447e4.tar.gz
sonarqube-2be9d39965149fb5395e06c5036d79dab63447e4.zip
SONAR-3623 apply modal window to creation/restore Q profiles
Diffstat (limited to 'sonar-server/src')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb93
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb4
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb88
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_create_form.html.erb37
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_restore_form.html.erb22
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb56
-rw-r--r--sonar-server/src/main/webapp/stylesheets/style.css2
7 files changed, 173 insertions, 129 deletions
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 2e41cc0eab8..308a84a491c 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
@@ -46,6 +46,13 @@ class ProfilesController < ApplicationController
end
+ # GET /profiles/create_form?language=<language>
+ def create_form
+ language = params[:language]
+ bad_request 'Missing parameter: language' if language.blank?
+ profile = Profile.new(:language => language)
+ render :partial => 'profiles/create_form', :locals => {:language_key => language}
+ end
#
#
@@ -55,33 +62,25 @@ class ProfilesController < ApplicationController
def create
profile_name=params[:name]
language=params[:language]
- if profile_name.blank?|| language.blank?
- flash[:warning]=message('quality_profiles.please_type_profile_name')
- else
- profile=Profile.find_by_name_and_language(profile_name, language)
- if profile
- flash[:error]=message('quality_profiles.profile_x_already_exists', :params => profile_name)
- else
- profile = Profile.create(:name => profile_name, :language => language, :default_profile => false, :enabled => true)
- ok=profile.errors.empty?
- if ok && params[:backup]
- params[:backup].each_pair do |importer_key, file|
- if !file.blank? && ok
- messages = java_facade.importProfile(profile_name, language, importer_key, read_file_param(file))
- flash_validation_messages(messages)
- ok &= !messages.hasErrors()
- end
- end
- end
- if ok
- flash[:notice]=message('quality_profiles.profile_x_created', :params => profile.name)
- else
- profile.reload
- profile.destroy
+ profile = Profile.create(:name => profile_name, :language => language, :default_profile => false, :enabled => true)
+ ok = profile.errors.empty?
+ if ok && params[:backup]
+ params[:backup].each_pair do |importer_key, file|
+ if !file.blank? && ok
+ profile.import_configuration(importer_key, file)
+ ok &= profile.errors.empty?
end
end
end
+
+ flash_profile(profile)
+ if ok
+ flash[:notice]=message('quality_profiles.profile_x_created', :params => profile.name)
+ elsif profile.id
+ Profile.destroy(profile.id)
+ end
+
redirect_to :action => 'index'
end
@@ -155,18 +154,17 @@ class ProfilesController < ApplicationController
end
+ def restore_form
+ render :partial => 'profiles/restore_form'
+ end
- #
- #
# POST /profiles/restore/<id>
- #
- #
def restore
if params[:backup].blank?
flash[:warning]=message('quality_profiles.please_upload_backup_file')
else
- messages=java_facade.restoreProfile(read_file_param(params[:backup]), false)
- flash_validation_messages(messages)
+ messages=java_facade.restoreProfile(Api::Utils.read_post_request_param(params[:backup]), false)
+ flash_messages(messages)
end
redirect_to :action => 'index'
end
@@ -186,7 +184,7 @@ class ProfilesController < ApplicationController
profile = Profile.find_by_name_and_language(CGI::unescape(params[:name]), language)
end
not_found('Profile not found') unless profile
-
+
if (params[:format].blank?)
# standard sonar format
result = java_facade.backupProfile(profile.id)
@@ -205,7 +203,7 @@ class ProfilesController < ApplicationController
#
def inheritance
@profile = Profile.find(params[:id])
-
+
profiles=Profile.find(:all, :conditions => ['language=? and id<>? and (parent_name is null or parent_name<>?) and enabled=?', @profile.language, @profile.id, @profile.name, true], :order => 'name')
@select_parent = [[message('none'), nil]] + profiles.collect{ |profile| [profile.name, profile.name] }
end
@@ -256,7 +254,7 @@ class ProfilesController < ApplicationController
else
messages = java_facade.changeParentProfile(id, parent_name, current_user.name)
end
- flash_validation_messages(messages)
+ flash_messages(messages)
redirect_to :action => 'inheritance', :id => id
end
@@ -278,8 +276,8 @@ class ProfilesController < ApplicationController
#
def projects
@profile = Profile.find(params[:id])
- @available_projects=Project.find(:all,
- :include => ['profile','snapshots'],
+ @available_projects=Project.find(:all,
+ :include => ['profile','snapshots'],
:conditions => ['projects.qualifier=? AND projects.scope=? AND snapshots.islast=?', Project::QUALIFIER_PROJECT, Project::SCOPE_SET, true],
:order => 'projects.name asc')
@available_projects-=@profile.projects
@@ -326,7 +324,7 @@ class ProfilesController < ApplicationController
else
existing=Profile.find(:first, :conditions => {:name => name, :language => @profile.language, :enabled => true})
if existing
- @error=message('quality_profiles.profile_name_already_exists')
+ @error=message('quality_profiles.already_exists')
elsif !@profile.provided?
java_facade.renameProfile(@profile.id, name)
success=true
@@ -351,7 +349,7 @@ class ProfilesController < ApplicationController
if params[:id1].present? && params[:id2].present?
@profile1 = Profile.find(params[:id1])
@profile2 = Profile.find(params[:id2])
-
+
arules1 = ActiveRule.find(:all, :include => [{:active_rule_parameters => :rules_parameter}, :rule],
:conditions => ['active_rules.profile_id=?', @profile1.id])
arules2 = ActiveRule.find(:all, :order => 'rules.plugin_name, rules.plugin_rule_key', :include => [{:active_rule_parameters => :rules_parameter}, :rule],
@@ -385,7 +383,7 @@ class ProfilesController < ApplicationController
DIFF_IN2=2
DIFF_MODIFIED=3
DIFF_SAME=4
-
+
private
class RuleDiff
@@ -417,7 +415,7 @@ class ProfilesController < ApplicationController
end
else
@removed_params<<@arule1.parameter(param.name)
- end
+ end
elsif v2
@added_params<<@arule2.parameter(param.name)
end
@@ -435,7 +433,7 @@ class ProfilesController < ApplicationController
rule.name()<=>other.rule.name
end
end
-
+
#
# Remove active rules that are identical in both collections (same severity and same parameters)
# and return a map with results {:added => X, :removed => Y, :modified => Z,
@@ -497,19 +495,20 @@ class ProfilesController < ApplicationController
rules[rule] = [active_rule1, active_rule2]
end
end while !arules1.empty? || !arules2.empty?
- return {:same => same, :added => added, :removed => removed, :modified => modified, :rules => rules}
+ return {:same => same, :added => added, :removed => removed, :modified => modified, :rules => rules}
end
- def read_file_param(configuration_file)
- # configuration file is a StringIO
- if configuration_file.respond_to?(:read)
- return configuration_file.read
+ def flash_profile(profile)
+ # only 4 messages are kept each time to avoid cookie overflow.
+ if !profile.errors.empty?
+ flash[:error]=profile.errors.full_messages.to_a[0...4].join('<br/>')
+ end
+ if profile.warnings?
+ flash[:warning]=profile.warnings.full_messages.to_a[0...4].join('<br/>')
end
- # configuration file is not a readable object
- nil
end
- def flash_validation_messages(messages)
+ def flash_messages(messages)
# only 4 messages are kept each time to avoid cookie overflow.
if messages.hasErrors()
flash[:error]=messages.getErrors().to_a[0...4].join('<br/>')
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 1fe7ec88aa4..ddf214b88e2 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
@@ -165,4 +165,8 @@ class Api::Utils
nil
end
end
+
+ def self.java_facade
+ Java::OrgSonarServerUi::JRubyFacade.getInstance()
+ end
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb
index 72d5ee07cd5..079645ff6c6 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb
@@ -24,25 +24,41 @@ class Profile < ActiveRecord::Base
has_many :active_rules, :class_name => 'ActiveRule', :foreign_key => 'profile_id', :dependent => :destroy, :include => ['rule']
has_many :projects, :order => 'name asc'
has_many :active_rules_with_params, :class_name => 'ActiveRule', :foreign_key => 'profile_id',
- :include => ['active_rule_parameters', 'active_rule_note']
+ :include => ['active_rule_parameters', 'active_rule_note']
+
+ validates_uniqueness_of :name, :scope => :language, :case_sensitive => false, :message => Api::Utils.message('quality_profiles.already_exists')
+ validates_presence_of :name, :message => Api::Utils.message('quality_profiles.please_type_profile_name')
+
+ # The warnings that are set on this record, equivalent to normal ActiveRecord errors but does not prevent
+ # the record from saving.
+ def warnings
+ @warnings ||= ActiveRecord::Errors.new(self)
+ end
+
+ def warnings?
+ not warnings.empty?
+ end
+
+ def notices
+ @notices ||= ActiveRecord::Errors.new(self)
+ end
+
+ def notices?
+ not notices.empty?
+ end
- validates_uniqueness_of :name, :scope => :language, :case_sensitive => false
- validates_presence_of :name
-
- DEFAULT_PROFILE_NAME = 'Sun checks'
-
def active?
active
end
-
+
def key
"#{language}_#{name}"
end
-
+
def provided?
provided
end
-
+
def validate_copy(name)
new_rule_profile = Profile.new(:name => name, :provided => false, :default_profile => false, :language => language)
new_rule_profile.valid?
@@ -90,6 +106,7 @@ class Profile < ActiveRecord::Base
end
@active_hash_by_rule_id=nil
+
def active_hash_by_rule_id
if @active_hash_by_rule_id.nil?
@active_hash_by_rule_id={}
@@ -106,9 +123,9 @@ class Profile < ActiveRecord::Base
def count_overriding_rules
@count_overriding_rules||=
- begin
- active_rules.count(:conditions => ['inheritance=?', 'OVERRIDES'])
- end
+ begin
+ active_rules.count(:conditions => ['inheritance=?', 'OVERRIDES'])
+ end
end
def inherited?
@@ -117,35 +134,48 @@ class Profile < ActiveRecord::Base
def parent
@parent||=
- begin
- if parent_name.present?
- Profile.find(:first, :conditions => ['language=? and name=? and enabled=?', language, parent_name, true])
- else
- nil
+ begin
+ if parent_name.present?
+ Profile.find(:first, :conditions => ['language=? and name=? and enabled=?', language, parent_name, true])
+ else
+ nil
+ end
end
- end
end
def count_active_rules
- active_rules.select{|ar| ar.rule.enabled}.size
+ active_rules.select { |ar| ar.rule.enabled }.size
end
def ancestors
@ancestors ||=
- begin
- array=[]
- if parent
- array<<parent
- array.concat(parent.ancestors)
+ begin
+ array=[]
+ if parent
+ array<<parent
+ array.concat(parent.ancestors)
+ end
+ array
end
- array
- end
end
def children
@children ||=
- begin
- Profile.find(:all, :conditions => ['language=? and parent_name=? and enabled=?', language, name, true], :order => 'name')
- end
+ begin
+ Profile.find(:all, :conditions => ['language=? and parent_name=? and enabled=?', language, name, true], :order => 'name')
+ end
+ end
+
+ def import_configuration(importer_key, file)
+ messages = Api::Utils.java_facade.importProfile(name, language, importer_key, Api::Utils.read_post_request_param(file))
+ messages.getErrors().each do |msg|
+ errors.add_to_base msg
+ end
+ messages.getWarnings().each do |msg|
+ warnings.add_to_base msg
+ end
+ messages.getInfos().each do |msg|
+ notices.add_to_base msg
+ end
end
end \ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_create_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_create_form.html.erb
new file mode 100644
index 00000000000..f4e34e07c33
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_create_form.html.erb
@@ -0,0 +1,37 @@
+<%
+ language=controller.java_facade.getLanguages().find { |l| l.getKey()==language_key }
+ importers=controller.java_facade.getProfileImportersForLanguage(language_key)
+%>
+<form id="create-profile-form" action="profiles/create" enctype="multipart/form-data" method="POST">
+ <fieldset>
+ <input type="hidden" name="language" value="<%= language_key -%>"/>
+
+ <div class="form-head">
+ <h2><%= h message('quality_profiles.create_x_language_profile', :params => language.getName()) -%></h2>
+ </div>
+
+ <div class="form-body">
+
+ <div class="form-field">
+ <label for="name"><%= message('name') -%> <em>*</em></label>
+ <input id="create-profile-name" name="name" type="text" size="50" maxlength="100"/>
+ </div>
+
+ <% importers.to_a.sort { |x, y| x.getName() <=> y.getName() }.each do |importer| %>
+ <div class="form-field">
+ <label for="backup[<%= importer.getKey() -%>]"><%= h importer.getName() -%></label>
+ <%= file_field_tag "backup[#{importer.getKey()}]" %>
+ <div class="form-field-description"><%= h message('quality_profiles.optional_configuration_file') -%></div>
+ </div>
+ <% end %>
+ </div>
+
+ <div class="form-foot">
+ <input type="submit" value="<%= h message('create') -%>" id="create-profile-submit"/>
+ <a href="#" onclick="return closeModalWindow()" id="create-profile-cancel"><%= h message('cancel') -%></a>
+ </div>
+ </fieldset>
+</form>
+<script>
+ $j('#create-profile-name').focus();
+</script>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_restore_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_restore_form.html.erb
new file mode 100644
index 00000000000..a2274ec1d4f
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_restore_form.html.erb
@@ -0,0 +1,22 @@
+<form id="restore-profile-form" action="profiles/restore" enctype="multipart/form-data" method="POST">
+ <fieldset>
+
+ <div class="form-head">
+ <h2><%= h message('quality_profiles.restore_profile') -%></h2>
+ </div>
+
+ <div class="form-body">
+
+ <div class="form-field">
+ <label for="name"><%= message('backup_verb') -%> <em>*</em></label>
+ <%= file_field_tag 'backup' %>
+ </div>
+
+ </div>
+
+ <div class="form-foot">
+ <input type="submit" value="<%= h message('quality_profiles.restore_profile') -%>" id="restore-profile-submit"/>
+ <a href="#" onclick="return closeModalWindow()" id="restore-profile-cancel"><%= h message('cancel') -%></a>
+ </div>
+ </fieldset>
+</form> \ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb
index c193a57642f..59f703807f1 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb
@@ -3,79 +3,31 @@
<ul style="float: right" class="operations">
<li>
<%= image_tag 'compare.png' -%>
- <a href="<%= ApplicationController.root_context -%>/profiles/compare" id="compare-link"><%= message('quality_profiles.compare_profiles') -%></a>
+ <a href="profiles/compare" id="compare-link"><%= message('quality_profiles.compare_profiles') -%></a>
</li>
<li class="last">
<%= image_tag 'restore.gif' -%>
- <a href="#" onclick="$('restore-form').show();return false;" id="restore-link"><%= message('quality_profiles.restore_profile') -%></a>
+ <a href="profiles/restore_form" class="open-modal" id="restore-link"><%= message('quality_profiles.restore_profile') -%></a>
</li>
</ul>
<% end %>
<h1 class="marginbottom10"><%= message('quality_profiles.page') -%></h1>
</div>
-<% if administrator? %>
- <form class="admin marginbottom10" id="restore-form" action="<%= url_for :action => 'restore' -%>" enctype="multipart/form-data" style="display: none" method="post">
- <table class="spaced width100">
- <tr>
- <td width="1%" nowrap><%= message('backup_verb') -%>:</td>
- <td><%= file_field_tag 'backup' %></td>
- </tr>
-
- <tr>
- <td colspan="2">
- <input type="submit" value="<%= message('quality_profiles.restore_profile') -%>"/>
- <a href="#" onclick="$('restore-form').reset();$('restore-form').hide();return false;"><%= message('cancel') -%></a>
- </td>
- </tr>
- </table>
- </form>
-<% end %>
-
-
<%
languages.sort { |x, y| x.getName() <=> y.getName() }.each do |language|
- importers=controller.java_facade.getProfileImportersForLanguage(language.getKey())
%>
<div class="line-block">
<% if administrator? %>
<ul style="float: right" class="horizontal">
<li class="marginleft10 add">
- <a href="#" onClick="$('create-form-<%= language.getKey() -%>').show();$('create-form-<%= language.getKey() -%>-name').focus();return false;" id="create-link-<%= language.getKey() -%>"><%= message('create') -%></a>
- </li>
+ <a id="create-link-<%= language.getKey() -%>" href="profiles/create_form?language=<%= language.getKey() -%>" class="open-modal"><%= message('create') -%></a>
+ </li>
</ul>
<% end %>
<h2><%= message('quality_profiles.x_language_profiles', :params => language.getName()) -%></h2>
</div>
- <% if administrator? %>
- <form class="admin" id="create-form-<%= language.getKey() -%>" action="<%= url_for :action => 'create' -%>" style="display: none" enctype="multipart/form-data" method="post">
- <input type="hidden" name="language" value="<%= language.getKey() -%>"/>
- <table class="spaced width100">
- <tr>
- <td width="1%" nowrap><%= message('name') -%>:</td>
- <td><input type="text" name="name" id="create-form-<%= language.getKey() -%>-name"/></td>
- </tr>
- <% importers.to_a.sort { |x, y| x.getName() <=> y.getName() }.each do |importer| %>
- <tr>
- <td width="1%" nowrap><%= importer.getName() -%>:</td>
- <td>
- <%= file_field_tag "backup[#{importer.getKey()}]" %>
- <span class="note"><%= message('quality_profiles.optional_configuration_file') -%></span>
- </td>
- </tr>
- <% end %>
-
- <tr>
- <td colspan="2">
- <input type="submit" value="<%= message('quality_profiles.create_x_language_profile', :params => language.getName()) -%>" id="create-submit-<%= language.getKey() -%>"/>
- <a href="#" onclick="$('create-form-<%= language.getKey()-%>').reset();$('create-form-<%= language.getKey()-%>').hide();return false;"><%= message('cancel') -%></a>
- </td>
- </tr>
- </table>
- </form>
- <% end %>
-
<table class="data width100" id="profiles_<%= language.getKey() -%>">
<thead>
<tr>
diff --git a/sonar-server/src/main/webapp/stylesheets/style.css b/sonar-server/src/main/webapp/stylesheets/style.css
index eb256ea622d..dabef843723 100644
--- a/sonar-server/src/main/webapp/stylesheets/style.css
+++ b/sonar-server/src/main/webapp/stylesheets/style.css
@@ -2398,7 +2398,7 @@ select.medium-width {
.form-field-description {
clear: both;
- font-size: 11px;
+ font-size: 93%;
color: #777;
}