{{/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}} |
}, | }, | ||||
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) { |
}); | }); | ||||
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 () { |
[ | |||||
{ | |||||
"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" | |||||
} | |||||
] |
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 |