Browse Source

SONAR-6138 Access favorites from user's menu of the top navbar

tags/5.2-RC1
Stas Vilchik 9 years ago
parent
commit
1cd940f928

+ 1
- 0
server/sonar-web/src/main/hbs/nav/nav-search-item.hbs View File

{{/notNull}} {{/notNull}}


<a href="{{url}}" title="{{name}}"> <a href="{{url}}" title="{{name}}">
{{#if icon}}<i class="icon-{{icon}} text-text-bottom"></i>{{/if}}
{{#if q}}{{qualifierIcon q}}{{/if}} {{#if q}}{{qualifierIcon q}}{{/if}}
{{#eq q 'FIL'}} {{#eq q 'FIL'}}
{{collapsedDirFromPath name}}{{fileFromPath name}} {{collapsedDirFromPath name}}{{fileFromPath name}}

+ 25
- 2
server/sonar-web/src/main/js/nav/search-view.js View File

}, },


initialize: function () { initialize: function () {
var that = this;
this.results = new Backbone.Collection(); 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.resultsView = new SearchResultsView({ collection: this.results });
this.debouncedOnKeyUp = _.debounce(this.onKeyUp, 400); this.debouncedOnKeyUp = _.debounce(this.onKeyUp, 400);
this._bufferedValue = ''; this._bufferedValue = '';
return false; 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 () { resetResultsToDefault: function () {
var recentHistory = JSON.parse(localStorage.getItem('sonar_recent_history')), var recentHistory = JSON.parse(localStorage.getItem('sonar_recent_history')),
history = (recentHistory || []).map(function (historyItem, index) { history = (recentHistory || []).map(function (historyItem, index) {
extra: index === 0 ? '' : null extra: index === 0 ? '' : null
}; };
}); });
this.results.reset(history.concat(qualifiers));
this.results.reset([].concat(history, this.favorite, qualifiers));
}, },


search: function (q) { search: function (q) {

+ 10
- 1
server/sonar-web/src/test/js/nav-spec.js View File

}); });




casper.test.begin(testName('Search'), 16, function (test) {
casper.test.begin(testName('Search'), 20, function (test) {
casper casper
.start(lib.buildUrl('nav'), function () { .start(lib.buildUrl('nav'), function () {
lib.setDefaultViewport(); lib.setDefaultViewport();


lib.mockRequestFromFile('/api/components/suggestions', 'search.json'); lib.mockRequestFromFile('/api/components/suggestions', 'search.json');
lib.mockRequestFromFile('/api/favourites', 'favorite.json');
}) })


.then(function () { .then(function () {
casper.evaluate(function () { casper.evaluate(function () {
window.SS.user = 'user';
window.SS.isUserAdmin = false; window.SS.isUserAdmin = false;
window.navbarOptions = new Backbone.Model(); window.navbarOptions = new Backbone.Model();
window.navbarOptions.set({ qualifiers: ['TRK', 'VW', 'DEV'] }); window.navbarOptions.set({ qualifiers: ['TRK', 'VW', 'DEV'] });
}) })


.then(function () { .then(function () {
lib.capture();
// for top-level qualifiers // 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=TRK"]');
test.assertExists('.js-search-results a[href*="/all_projects?qualifier=VW"]'); test.assertExists('.js-search-results a[href*="/all_projects?qualifier=VW"]');
// browsed recently // browsed recently
test.assertExists('.js-search-results a[href*="localhistoryproject"]'); test.assertExists('.js-search-results a[href*="localhistoryproject"]');
test.assertSelectorContains('.js-search-results a[href*="localhistoryproject"]', 'Local History Project'); 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 () { .then(function () {

+ 14
- 0
server/sonar-web/src/test/json/nav-spec/favorite.json View File

[
{
"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"
}
]

+ 1
- 0
sonar-core/src/main/resources/org/sonar/l10n/core.properties View File

edit=Edit edit=Edit
events=Events events=Events
false=False false=False
favorite=Favorite
file=File file=File
files=Files files=Files
filter_verb=Filter filter_verb=Filter

Loading…
Cancel
Save