Vulcan/packages/telescope-search/lib/client/routes.js

75 lines
1.9 KiB
JavaScript
Raw Normal View History

Meteor.startup(function () {
Posts.controllers.search = Posts.controllers.list.extend({
view: 'search',
showViewsNav: false,
getTitle: function() {
return i18n.t("Search") + ' - ' + Settings.get('title', "Telescope");
},
getDescription: function() {
return Settings.get('description');
},
onBeforeAction: function() {
var query = this.params.query;
if ('q' in query) {
// if search box has 'empty' class, that means user just deleted last character in search keyword
// but router hasn't updated url, so params.query still has '?q=<LAST CHARACTER>'
// if we set searchQuery in this case, user will see last character pops up again unexpectedly
// so add this check to fix the bug. issue #825
if (!$('.search').hasClass('empty')) {
Session.set('searchQuery', query.q);
}
if (query.q) {
Meteor.call('logSearch', query.q);
}
}
this.next();
},
data: function () {
var terms = {
view: "search",
limit: this.params.query.limit || Settings.get('postsPerPage', 10),
query: this.params.query.q
};
return {searchQuery: this.params.query.q, terms: terms};
}
});
Router.onBeforeAction(Router._filters.isAdmin, {only: ['logs']});
// Search
Router.route('/search', {
name: 'search',
controller: Posts.controllers.search
});
// Search Logs
Router.route('/logs/:limit?', {
2015-04-22 08:47:23 +09:00
controller: Telescope.controllers.admin,
name: 'searchLogs',
2015-05-18 10:36:39 +09:00
template: 'search_logs',
waitOn: function () {
var limit = this.params.limit || 100;
if(Meteor.isClient) {
Session.set('logsLimit', limit);
}
return Meteor.subscribe('searches', limit);
},
data: function () {
return Searches.find({}, {sort: {timestamp: -1}});
},
fastRender: true
});
});