From: Stas Vilchik Date: Mon, 20 Apr 2015 12:35:07 +0000 (+0200) Subject: SONAR-6138 Access favorites from user's menu of the top navbar X-Git-Tag: 5.2-RC1~2186 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1cd940f9280516025f92539311de16e932c71308;p=sonarqube.git SONAR-6138 Access favorites from user's menu of the top navbar --- diff --git a/server/sonar-web/src/main/hbs/nav/nav-search-item.hbs b/server/sonar-web/src/main/hbs/nav/nav-search-item.hbs index fe80ef05c58..855b5175187 100644 --- a/server/sonar-web/src/main/hbs/nav/nav-search-item.hbs +++ b/server/sonar-web/src/main/hbs/nav/nav-search-item.hbs @@ -8,6 +8,7 @@ {{/notNull}} + {{#if icon}}{{/if}} {{#if q}}{{qualifierIcon q}}{{/if}} {{#eq q 'FIL'}} {{collapsedDirFromPath name}}{{fileFromPath name}} diff --git a/server/sonar-web/src/main/js/nav/search-view.js b/server/sonar-web/src/main/js/nav/search-view.js index 0a21ebf4094..8554a6d133b 100644 --- a/server/sonar-web/src/main/js/nav/search-view.js +++ b/server/sonar-web/src/main/js/nav/search-view.js @@ -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) { diff --git a/server/sonar-web/src/test/js/nav-spec.js b/server/sonar-web/src/test/js/nav-spec.js index 1174fc501cf..15c4ee64058 100644 --- a/server/sonar-web/src/test/js/nav-spec.js +++ b/server/sonar-web/src/test/js/nav-spec.js @@ -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 index 00000000000..471a15610ae --- /dev/null +++ b/server/sonar-web/src/test/json/nav-spec/favorite.json @@ -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" + } +] diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 42fec916b8d..b93c8a9663c 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -65,6 +65,7 @@ duplications=Duplications edit=Edit events=Events false=False +favorite=Favorite file=File files=Files filter_verb=Filter