summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2013-10-14 12:25:11 +0200
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2013-10-14 14:09:03 +0200
commit0b0735751e88ee196340d3de7f456a8120038575 (patch)
tree94d41be67211212264b7d88e165109cfa0d9ce99
parent2f58b5598d1e8f80b8586bb44bc88020e36fcaf6 (diff)
downloadsonarqube-0b0735751e88ee196340d3de7f456a8120038575.tar.gz
sonarqube-0b0735751e88ee196340d3de7f456a8120038575.zip
SONAR-3871 Fix error messages and confirm popup in provisioning
-rw-r--r--plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties10
-rw-r--r--sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java22
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/provisioning_controller.rb11
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/provisioning/_create_form.html.erb8
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/provisioning/_delete_form.html.erb25
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/provisioning/index.html.erb4
-rw-r--r--sonar-server/src/test/java/org/sonar/server/component/DefaultRubyComponentServiceTest.java5
7 files changed, 67 insertions, 18 deletions
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 7928916fbab..609a9071c14 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
@@ -276,6 +276,14 @@ qualifiers.new.TRK=New Project
qualifiers.new.VW=New View
qualifiers.new.DEV=New Developer
+qualifiers.delete.TRK=Delete Project
+qualifiers.delete.VW=Delete View
+qualifiers.delete.DEV=Delete Developer
+
+qualifiers.delete_confirm.TRK=Do you want to delete this project?
+qualifiers.delete_confirm.VW=Do you want to delete this view?
+qualifiers.delete_confirm.DEV=Do you want to delete this developer?
+
qualifiers.create.TRK=Create Project
qualifiers.create.VW=Create View
qualifiers.create.DEV=Create Developer
@@ -1726,7 +1734,7 @@ bulk_deletion.delete_all_ghosts=Delete all ghosts
#------------------------------------------------------------------------------
provisioning.missing.key=Key is missing
provisioning.missing.name=Name is missing
-provisioning.no_analysis=No analysis has been performed since creation. The only available section is configuration.
+provisioning.no_analysis=No analysis has been performed since creation. The only available section is Configuration.
#------------------------------------------------------------------------------
diff --git a/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java b/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java
index abee537dda9..3b72f1265e9 100644
--- a/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java
+++ b/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java
@@ -22,6 +22,7 @@ package org.sonar.server.component;
import com.google.common.base.Strings;
import org.sonar.api.component.Component;
import org.sonar.api.component.RubyComponentService;
+import org.sonar.api.i18n.I18n;
import org.sonar.core.component.ComponentDto;
import org.sonar.core.component.ComponentKeys;
import org.sonar.core.resource.ResourceDao;
@@ -33,6 +34,7 @@ import org.sonar.server.util.RubyUtils;
import java.util.Date;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
public class DefaultRubyComponentService implements RubyComponentService {
@@ -40,11 +42,13 @@ public class DefaultRubyComponentService implements RubyComponentService {
private final ResourceDao resourceDao;
private final DefaultComponentFinder finder;
private final ResourceIndexerDao resourceIndexerDao;
+ private final I18n i18n;
- public DefaultRubyComponentService(ResourceDao resourceDao, DefaultComponentFinder finder, ResourceIndexerDao resourceIndexerDao) {
+ public DefaultRubyComponentService(ResourceDao resourceDao, DefaultComponentFinder finder, ResourceIndexerDao resourceIndexerDao, I18n i18n) {
this.resourceDao = resourceDao;
this.finder = finder;
this.resourceIndexerDao = resourceIndexerDao;
+ this.i18n = i18n;
}
@Override
@@ -55,9 +59,9 @@ public class DefaultRubyComponentService implements RubyComponentService {
public void createComponent(String kee, String name, String scope, String qualifier) {
ComponentDto component = (ComponentDto)resourceDao.findByKey(kee);
if (component != null) {
- throw new BadRequestException("Could not create resource, key already exists: "+kee);
+ throw new BadRequestException(formatMessage("Could not create %s, key already exists: %s", qualifier, kee));
}
- checkKeyFormat(kee);
+ checkKeyFormat(qualifier, kee);
resourceDao.insertOrUpdate(
new ResourceDto()
@@ -69,7 +73,7 @@ public class DefaultRubyComponentService implements RubyComponentService {
.setCreatedAt(new Date()));
component = (ComponentDto)resourceDao.findByKey(kee);
if (component == null) {
- throw new BadRequestException("Resource not created: "+kee);
+ throw new BadRequestException(String.format("%s not created: %s", null, kee));
}
resourceIndexerDao.indexResource(component.getId());
}
@@ -79,7 +83,7 @@ public class DefaultRubyComponentService implements RubyComponentService {
if (resource == null) {
throw new NotFoundException();
}
- checkKeyFormat(key);
+ checkKeyFormat(resource.getQualifier(), key);
resourceDao.insertOrUpdate(resource.setKey(key).setName(name));
}
@@ -122,9 +126,13 @@ public class DefaultRubyComponentService implements RubyComponentService {
return builder.build();
}
- private static void checkKeyFormat(String kee) {
+ private void checkKeyFormat(String qualifier, String kee) {
if (!ComponentKeys.isValidModuleKey(kee)) {
- throw new BadRequestException("Could not create resource, malformed key: "+kee);
+ throw new BadRequestException(formatMessage("Malformed key for %s: %s", qualifier, kee));
}
}
+
+ private String formatMessage(String message, String qualifier, String key) {
+ return String.format(message, i18n.message(Locale.getDefault(), "qualifier."+qualifier, "Project"), key);
+ }
}
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/provisioning_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/provisioning_controller.rb
index 2d734e8afb0..b7dd96e8f23 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/provisioning_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/provisioning_controller.rb
@@ -51,8 +51,8 @@ class ProvisioningController < ApplicationController
redirect_to :action => 'index'
rescue Exception => e
- flash[:error]= Api::Utils.message(e.message)
- render :partial => 'create_form', :key => @key, :name => @name, :status => 400
+ flash.now[:error]= Api::Utils.message(e.message)
+ render :partial => 'create_form', :id => @id, :key => @key, :name => @name, :status => 400
end
end
@@ -63,12 +63,17 @@ class ProvisioningController < ApplicationController
render :partial => 'create_form'
end
+ def delete_form
+ @id = params[:id]
+ render :partial => 'delete_form'
+ end
+
def delete
access_denied unless has_role?("provisioning")
@id = params[:id].to_i
Java::OrgSonarServerUi::JRubyFacade.getInstance().deleteResourceTree(@id)
- flash[:notice]= Api::Utils.message('resource_viewer.resource_deleted')
+ flash.now[:notice]= Api::Utils.message('resource_viewer.resource_deleted')
redirect_to :action => 'index'
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/provisioning/_create_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/provisioning/_create_form.html.erb
index b6876ac6224..1156521fcda 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/provisioning/_create_form.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/provisioning/_create_form.html.erb
@@ -1,11 +1,11 @@
<form id="create-resource-form" method="post" action="<%= ApplicationController.root_context -%>/provisioning/create_or_update">
<input type="hidden" name="id" value="<%= @id -%>"/>
<fieldset>
- <% if flash[:error] %>
- <p class="error"><%= h flash[:error] -%></p>
+ <% if flash.now[:error] %>
+ <p class="error"><%= h flash.now[:error] -%></p>
<% end %>
<div class="modal-head">
- <h2><%= message('qualifiers.new.TRK') -%></h2>
+ <h2><%= message((@id.nil? or @id.empty?) ? 'qualifiers.new.TRK' : 'qualifiers.update.TRK') -%></h2>
</div>
<div class="modal-body">
<div class="modal-field">
@@ -18,7 +18,7 @@
</div>
</div>
<div class="modal-foot">
- <input type="submit" value="<%= h message(@id.nil? ? 'qualifiers.create.TRK' : 'qualifiers.update.TRK') -%>" id="save-submit"/>
+ <input type="submit" value="<%= h message((@id.nil? or @id.empty?) ? 'qualifiers.create.TRK' : 'qualifiers.update.TRK') -%>" id="save-submit"/>
<a href="#" onclick="return closeModalWindow()" id="save-cancel"><%= h message('cancel') -%></a>
</div>
</fieldset>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/provisioning/_delete_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/provisioning/_delete_form.html.erb
new file mode 100644
index 00000000000..477affddcae
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/provisioning/_delete_form.html.erb
@@ -0,0 +1,25 @@
+<form id="delete-project-form" method="DELETE" action="<%= ApplicationController.root_context -%>/provisioning/delete">
+ <input type="hidden" name="id" value="<%= @id -%>">
+ <input type="hidden" name="_method" value="delete">
+ <fieldset>
+ <div class="modal-head">
+ <h2><%= message 'qualifiers.delete.TRK' -%></h2>
+ </div>
+ <div class="modal-body">
+ <div class="info">
+ <img src="<%= ApplicationController.root_context -%>/images/information.png" style="vertical-align: text-bottom"/>
+ <%= message 'qualifiers.delete_confirm.TRK' -%>
+ </div>
+ </div>
+ <div class="modal-foot">
+ <input type="submit" value="<%= message 'qualifiers.delete.TRK' -%>" id="confirm-submit"/>
+ <a href="#" onclick="return closeModalWindow()" id="confirm-cancel"><%= h message('cancel') -%></a>
+ </div>
+ </fieldset>
+</form>
+
+<script>
+ $j("#delete-project-form").modalForm({success: function (data) {
+ window.location = baseUrl + '/provisioning';
+ }});
+</script>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/provisioning/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/provisioning/index.html.erb
index 881dbaa1207..0c85ec01dc2 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/provisioning/index.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/provisioning/index.html.erb
@@ -34,8 +34,8 @@
<td class="operations">
<%= link_to message('edit'), {:action => :create_form, :id => resource.id, :key => resource.key, :name => resource.name},
{:id => "edit-#{u resource.key}", :class => 'open-modal link-action'} %>
- <%= link_to message('delete'), {:action => :delete, :id => resource.id},
- {:id => "delete-#{u resource.key}", :confirm => message('are_you_sure'), :class => 'link-action link-red', :method => 'delete'} %>
+ <%= link_to message('delete'), {:action => :delete_form, :id => resource.id},
+ {:id => "delete-#{u resource.key}", :class => 'open-modal link-action link-red'} %>
</td>
</tr>
<% end %>
diff --git a/sonar-server/src/test/java/org/sonar/server/component/DefaultRubyComponentServiceTest.java b/sonar-server/src/test/java/org/sonar/server/component/DefaultRubyComponentServiceTest.java
index 890ab13bc95..022e922af68 100644
--- a/sonar-server/src/test/java/org/sonar/server/component/DefaultRubyComponentServiceTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/component/DefaultRubyComponentServiceTest.java
@@ -24,6 +24,7 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.sonar.api.component.Component;
+import org.sonar.api.i18n.I18n;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Scopes;
import org.sonar.core.component.ComponentDto;
@@ -51,6 +52,7 @@ public class DefaultRubyComponentServiceTest {
private ResourceDao resourceDao;
private DefaultComponentFinder finder;
private ResourceIndexerDao resourceIndexerDao;
+ private I18n i18n;
private DefaultRubyComponentService componentService;
@Before
@@ -58,7 +60,8 @@ public class DefaultRubyComponentServiceTest {
resourceDao = mock(ResourceDao.class);
finder = mock(DefaultComponentFinder.class);
resourceIndexerDao = mock(ResourceIndexerDao.class);
- componentService = new DefaultRubyComponentService(resourceDao, finder, resourceIndexerDao);
+ i18n = mock(I18n.class);
+ componentService = new DefaultRubyComponentService(resourceDao, finder, resourceIndexerDao, i18n);
}
@Test