]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6138 Access favorites from user's menu of the top navbar
authorStas Vilchik <vilchiks@gmail.com>
Mon, 20 Apr 2015 12:35:07 +0000 (14:35 +0200)
committerStas Vilchik <vilchiks@gmail.com>
Mon, 20 Apr 2015 12:45:38 +0000 (14:45 +0200)
server/sonar-web/src/main/hbs/nav/nav-search-item.hbs
server/sonar-web/src/main/js/nav/search-view.js
server/sonar-web/src/test/js/nav-spec.js
server/sonar-web/src/test/json/nav-spec/favorite.json [new file with mode: 0644]
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index fe80ef05c582a5513b41d33c0ccb1cb05b50259d..855b51751873d85792be73544c53d18dbc302b48 100644 (file)
@@ -8,6 +8,7 @@
 {{/notNull}}
 
 <a href="{{url}}" title="{{name}}">
+  {{#if icon}}<i class="icon-{{icon}} text-text-bottom"></i>{{/if}}
   {{#if q}}{{qualifierIcon q}}{{/if}}
   {{#eq q 'FIL'}}
     {{collapsedDirFromPath name}}{{fileFromPath name}}
index 0a21ebf40947a596f621d4e10a310a13ee0059bc..8554a6d133b2b125ff28ea6b2fd713717c5aef31 100644 (file)
@@ -75,8 +75,16 @@ define([
     },
 
     initialize: function () {
+      var that = this;
       this.results = new Backbone.Collection();
-      this.resetResultsToDefault();
+      this.favorite = [];
+      if (window.SS.user) {
+        this.fetchFavorite().always(function () {
+          that.resetResultsToDefault();
+        });
+      } else {
+        this.resetResultsToDefault();
+      }
       this.resultsView = new SearchResultsView({ collection: this.results });
       this.debouncedOnKeyUp = _.debounce(this.onKeyUp, 400);
       this._bufferedValue = '';
@@ -125,6 +133,21 @@ define([
       return false;
     },
 
+    fetchFavorite: function () {
+      var that = this;
+      return $.get(baseUrl + '/api/favourites').done(function (r) {
+        that.favorite = r.map(function (f, index) {
+          var isFile = ['FIL', 'UTS'].indexOf(f.qualifier) !== -1;
+          return {
+            url: baseUrl + '/dashboard/index?id=' + encodeURIComponent(f.key) + dashboardParameters(true),
+            name: isFile ? window.collapsedDirFromPath(f.lname) + window.fileFromPath(f.lname) : f.name,
+            icon: 'favorite',
+            extra: index === 0 ? t('favorite') : null
+          };
+        });
+      });
+    },
+
     resetResultsToDefault: function () {
       var recentHistory = JSON.parse(localStorage.getItem('sonar_recent_history')),
           history = (recentHistory || []).map(function (historyItem, index) {
@@ -142,7 +165,7 @@ define([
               extra: index === 0 ? '' : null
             };
           });
-      this.results.reset(history.concat(qualifiers));
+      this.results.reset([].concat(history, this.favorite, qualifiers));
     },
 
     search: function (q) {
index 1174fc501cf2fc792628c2f555b627a8209acc57..15c4ee640587a02c712860768968c484c2fe2a0d 100644 (file)
@@ -228,16 +228,18 @@ casper.test.begin(testName('Login'), 3, function (test) {
 });
 
 
-casper.test.begin(testName('Search'), 16, function (test) {
+casper.test.begin(testName('Search'), 20, function (test) {
   casper
       .start(lib.buildUrl('nav'), function () {
         lib.setDefaultViewport();
 
         lib.mockRequestFromFile('/api/components/suggestions', 'search.json');
+        lib.mockRequestFromFile('/api/favourites', 'favorite.json');
       })
 
       .then(function () {
         casper.evaluate(function () {
+          window.SS.user = 'user';
           window.SS.isUserAdmin = false;
           window.navbarOptions = new Backbone.Model();
           window.navbarOptions.set({ qualifiers: ['TRK', 'VW', 'DEV'] });
@@ -259,6 +261,7 @@ casper.test.begin(testName('Search'), 16, function (test) {
       })
 
       .then(function () {
+        lib.capture();
         // for top-level qualifiers
         test.assertExists('.js-search-results a[href*="/all_projects?qualifier=TRK"]');
         test.assertExists('.js-search-results a[href*="/all_projects?qualifier=VW"]');
@@ -267,6 +270,12 @@ casper.test.begin(testName('Search'), 16, function (test) {
         // browsed recently
         test.assertExists('.js-search-results a[href*="localhistoryproject"]');
         test.assertSelectorContains('.js-search-results a[href*="localhistoryproject"]', 'Local History Project');
+
+        // favorite
+        test.assertExists('.js-search-results a[href*="favorite-project-key"]');
+        test.assertSelectorContains('.js-search-results a[href*="favorite-project-key"]', 'Favorite Project');
+        test.assertExists('.js-search-results a[href*="favorite-file-key"]');
+        test.assertSelectorContains('.js-search-results a[href*="favorite-file-key"]', 'FavoriteFile.java');
       })
 
       .then(function () {
diff --git a/server/sonar-web/src/test/json/nav-spec/favorite.json b/server/sonar-web/src/test/json/nav-spec/favorite.json
new file mode 100644 (file)
index 0000000..471a156
--- /dev/null
@@ -0,0 +1,14 @@
+[
+  {
+    "key": "favorite-project-key",
+    "name": "Favorite Project",
+    "lname": "SonarSource :: Rule API",
+    "qualifier": "TRK"
+  },
+  {
+    "key": "favorite-file-key",
+    "name": "FavoriteFile.java",
+    "lname": "src/main/java/com/example/FavoriteFile.java",
+    "qualifier": "FIL"
+  }
+]
index 42fec916b8d5f085cb178e769a2bdf70f7b0e3d0..b93c8a9663c4924bdf6059dd1b5ec008a260a99a 100644 (file)
@@ -65,6 +65,7 @@ duplications=Duplications
 edit=Edit
 events=Events
 false=False
+favorite=Favorite
 file=File
 files=Files
 filter_verb=Filter