]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5851 update copy action
authorStas Vilchik <vilchiks@gmail.com>
Fri, 10 Apr 2015 13:02:04 +0000 (15:02 +0200)
committerStas Vilchik <vilchiks@gmail.com>
Fri, 10 Apr 2015 14:53:56 +0000 (16:53 +0200)
server/sonar-web/src/main/js/quality-profiles/controller.js
server/sonar-web/src/main/js/quality-profiles/copy-profile-view.js
server/sonar-web/src/test/js/quality-profiles.js
server/sonar-web/src/test/json/quality-profiles/copy.json [new file with mode: 0644]

index 041ad87096086c2b672638f9e95ead05a7c3d0d1..ed58081869ebf12cd9a49a0d5a8f869c9ec373b4 100644 (file)
@@ -28,7 +28,6 @@ define([
 
     initialize: function () {
       this.listenTo(this.options.app.profiles, 'select', this.onProfileSelect);
-      this.listenTo(this.options.app.profiles, 'copy', this.onProfileCopy);
       this.listenTo(this.options.app.profiles, 'setAsDefault', this.onProfileSetAsDefault);
       this.listenTo(this.options.app.profiles, 'destroy', this.onProfileDestroy);
     },
@@ -62,17 +61,6 @@ define([
       });
     },
 
-    onProfileCopy: function (name, profile) {
-      var that = this,
-          lang = profile.get('language');
-      this.fetchProfiles().done(function () {
-        var newProfile = that.options.app.profiles.findWhere({ language: lang, name: name });
-        if (newProfile != null) {
-          newProfile.trigger('select', newProfile);
-        }
-      });
-    },
-
     onProfileSetAsDefault: function (profile) {
       var that = this,
           url = baseUrl + '/api/qualityprofiles/set_default',
index b46b3639eb288a0d5e1e4f764a938ae5e86e0bd7..376872436a19723200f30029fd4193ab9f9ee8df 100644 (file)
@@ -19,8 +19,9 @@
  */
 define([
   'common/modal-form',
+  'quality-profiles/profile',
   'templates/quality-profiles'
-], function (ModalFormView) {
+], function (ModalFormView, Profile) {
 
   var $ = jQuery;
 
@@ -48,13 +49,18 @@ define([
           // do not show global error
           400: null
         }
-      }).done(function () {
-        // TODO open new profile using key from response
-        that.model.trigger('copy', name, that.model);
+      }).done(function (r) {
+        that.addProfile(r);
         that.close();
       }).fail(function (jqXHR) {
         that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings);
       });
+    },
+
+    addProfile: function (profileData) {
+      var profile = new Profile(profileData);
+      this.model.collection.add([profile]);
+      profile.trigger('select', profile);
     }
   });
 
index 3b04b0b06f7b258cf5280ca46a03f882282262eb..51acd6ae1b696e7d6f260086bc164c9b400731e5 100644 (file)
@@ -165,9 +165,9 @@ casper.test.begin(testName('Copy Profile'), 5, function (test) {
       .start(lib.buildUrl('quality_profiles'), function () {
         lib.setDefaultViewport();
 
-        this.searchMock = lib.mockRequestFromFile('/api/qualityprofiles/search', 'search.json');
+        lib.mockRequestFromFile('/api/qualityprofiles/search', 'search.json');
         lib.mockRequestFromFile('/api/rules/search', 'rules.json');
-        lib.mockRequest('/api/qualityprofiles/copy', '{}');
+        lib.mockRequestFromFile('/api/qualityprofiles/copy', 'copy.json');
       })
 
       .then(function () {
@@ -193,9 +193,6 @@ casper.test.begin(testName('Copy Profile'), 5, function (test) {
       })
 
       .then(function () {
-        lib.clearRequestMock(this.searchMock);
-        lib.mockRequestFromFile('/api/qualityprofiles/search', 'search-with-copy.json');
-
         casper.evaluate(function () {
           jQuery('#copy-name').val('Copied Profile');
         });
diff --git a/server/sonar-web/src/test/json/quality-profiles/copy.json b/server/sonar-web/src/test/json/quality-profiles/copy.json
new file mode 100644 (file)
index 0000000..ba810f1
--- /dev/null
@@ -0,0 +1,8 @@
+{
+  "key": "java-copied-profile-11711",
+  "name": "Copied Profile",
+  "activeRuleCount": 161,
+  "language": "java",
+  "languageName": "Java",
+  "isInherited": false
+}