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

58 lines
1.6 KiB
JavaScript
Raw Normal View History

2014-06-23 11:05:06 +09:00
Meteor.startup(function () {
PostsSearchController = PostsListController.extend({
view: 'search',
showViewsNav: false,
getTitle: function() {
2015-03-28 18:30:26 +09:00
return i18n.t("Search") + ' - ' + Settings.get('title', "Telescope");
},
getDescription: function() {
2015-03-28 18:30:26 +09:00
return Settings.get('description');
},
onBeforeAction: function() {
2014-11-28 17:26:06 -08:00
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);
}
2014-11-28 17:26:06 -08:00
if (query.q) {
Meteor.call('logSearch', query.q)
}
}
this.next();
}
});
2014-06-23 11:05:06 +09:00
Router.onBeforeAction(Router._filters.isAdmin, {only: ['logs']});
2014-11-17 14:53:42 +09:00
// Search
2014-06-23 11:05:06 +09:00
2014-11-17 14:53:42 +09:00
Router.route('/search/:limit?', {
name: 'search',
2014-11-28 17:26:06 -08:00
controller: PostsSearchController
2014-11-17 14:53:42 +09:00
});
// Search Logs
Router.route('/logs/:limit?', {
2015-03-23 10:32:56 +09:00
controller: AdminController,
2014-11-17 14:53:42 +09:00
name: 'searchLogs',
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
2014-06-23 11:05:06 +09:00
});
});