]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5901 Allow to bulk add tags on issues from UI
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Tue, 16 Dec 2014 13:55:47 +0000 (14:55 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Tue, 16 Dec 2014 13:55:54 +0000 (14:55 +0100)
server/sonar-server/src/main/java/org/sonar/server/issue/AddTagsAction.java
server/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java
server/sonar-server/src/test/java/org/sonar/server/issue/AddTagsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/InternalRubyIssueServiceTest.java
server/sonar-web/src/main/webapp/WEB-INF/app/controllers/issues_controller.rb
server/sonar-web/src/main/webapp/WEB-INF/app/views/issues/_bulk_change_form.html.erb

index d52568f50ce17508e296b9beee94581a06ee2dff..ec10eaecdab57bf02cecb48b39a58e168e294c69 100644 (file)
@@ -67,7 +67,7 @@ public class AddTagsAction extends Action implements ServerComponent {
 
   private Set<String> parseTags(Map<String, Object> properties) {
     Set<String> result = Sets.newHashSet();
-    String tagsString = (String) properties.get("add_tags.tags");
+    String tagsString = (String) properties.get("tags");
     if (!Strings.isNullOrEmpty(tagsString)) {
       for(String tag: TAGS_SPLITTER.split(tagsString)) {
         RuleTagFormat.validate(tag);
index a686986824b5332571de69059dee50af8d8cf8a0..f4aea94df7420720c01785ec8b8dd12c7c545895 100644 (file)
@@ -648,4 +648,8 @@ public class InternalRubyIssueService implements ServerComponent {
     return context;
   }
 
+  public Collection<String> listTags() {
+    return issueService.listTags(null, 0);
+  }
+
 }
index ac07dc61d5aac1bb5cc538181e17bd22a4a14014..d92f272fc196bd18ea78ca39014c51e6424f3bc6 100644 (file)
 
 package org.sonar.server.issue;
 
-import org.mockito.Matchers;
 import com.google.common.collect.ImmutableSet;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+import org.mockito.Matchers;
 import org.sonar.api.issue.internal.DefaultIssue;
 import org.sonar.api.issue.internal.IssueChangeContext;
 import org.sonar.core.issue.IssueUpdater;
@@ -58,7 +58,7 @@ public class AddTagsActionTest {
   @SuppressWarnings("unchecked")
   public void should_execute() {
     Map<String, Object> properties = newHashMap();
-    properties.put("add_tags.tags", "tag2,tag3");
+    properties.put("tags", "tag2,tag3");
 
     DefaultIssue issue = mock(DefaultIssue.class);
     when(issue.tags()).thenReturn(ImmutableSet.of("tag1", "tag3"));
@@ -78,7 +78,7 @@ public class AddTagsActionTest {
     throwable.expectMessage("Tag 'th ag' is invalid. Rule tags accept only the characters: a-z, 0-9, '+', '-', '#', '.'");
 
     Map<String, Object> properties = newHashMap();
-    properties.put("add_tags.tags", "th ag");
+    properties.put("tags", "th ag");
 
     DefaultIssue issue = mock(DefaultIssue.class);
     when(issue.tags()).thenReturn(ImmutableSet.of("tag1", "tag3"));
index 914077f14203396b40c222cb6bd067dc3c550d2d..135abb515ee673033d4475e3690e3e0dcbfa8f0f 100644 (file)
@@ -21,6 +21,7 @@
 package org.sonar.server.issue;
 
 import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Maps;
 import org.junit.Before;
 import org.junit.Test;
@@ -56,7 +57,10 @@ import static org.fest.assertions.Fail.fail;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 @RunWith(MockitoJUnitRunner.class)
 public class InternalRubyIssueServiceTest {
@@ -699,6 +703,13 @@ public class InternalRubyIssueServiceTest {
     assertThat(context.getPage()).isEqualTo(1);
   }
 
+  @Test
+  public void list_tags() throws Exception {
+    ImmutableSet<String> tags = ImmutableSet.of("tag1", "tag2", "tag3");
+    when(issueService.listTags(null, 0)).thenReturn(tags);
+    assertThat(service.listTags()).isEqualTo(tags);
+  }
+
   private void checkBadRequestException(Exception e, String key, Object... params) {
     BadRequestException exception = (BadRequestException) e;
     Message msg = exception.errors().messages().get(0);
index 7d0474c8e00b00d3ed16121971b28daf2e248550..27d98b4c50ca1b6a9f6448f3734aeb087e5c5993 100644 (file)
@@ -140,6 +140,7 @@ class IssuesController < ApplicationController
     end
 
     @projectUuids = Set.new(@issues.map {|issue| issue.projectUuid()})
+    @tags = Internal.issues.listTags()
 
     render :partial => 'issues/bulk_change_form'
   end
index cf5e32c71b844fed4de68e3c3f11498317bc0f63..3c27f7531cc995ca7b7b5dd6cac69f8f4aeb754d 100644 (file)
@@ -97,8 +97,8 @@
         </label>
         <input id="add-tags-action" name="actions[]" type="checkbox" value="add_tags"/>
 
-        <%# TODO Here, select2 box with tags to add %>
-        <span style="float:right" class="note">(<%= message('issue_bulk_change.x_issues', :params => unresolved_issues_user_can_admin.to_s) -%>)</span>
+        <input id="add_tags" name="add_tags.tags" type="text"/>
+        <span style="float:right" class="note">(<%= message('issue_bulk_change.x_issues', :params => unresolved_issues.to_s) -%>)</span>
       </div>
 
       <% end %>
   $j('#assignee').click(function() { check('assign-action'); });
   $j('#plan').click(function() { check('plan-action'); });
   $j('#severity').click(function() { check('set-severity-action'); });
+  $j('#add_tags').select2({tags: [ '<%= @tags.join("', '") -%>' ], width: '250px' });
+  $j('#add_tags').click(function() { check('add-tags-action'); });
 </script>