@@ -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}} |
@@ -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) { |
@@ -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 () { |
@@ -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" | |||
} | |||
] |
@@ -65,6 +65,7 @@ duplications=Duplications | |||
edit=Edit | |||
events=Events | |||
false=False | |||
favorite=Favorite | |||
file=File | |||
files=Files | |||
filter_verb=Filter |