2016-03-19 20:37:04 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-06-12 12:04:42 +00:00
|
|
|
const api = require('../api.js');
|
2016-06-12 18:11:43 +00:00
|
|
|
const router = require('../router.js');
|
2016-06-12 12:04:42 +00:00
|
|
|
const misc = require('../util/misc.js');
|
|
|
|
const pageController = require('../controllers/page_controller.js');
|
2016-06-13 20:34:39 +00:00
|
|
|
const TopNavigation = require('../models/top_navigation.js');
|
2016-06-12 12:04:42 +00:00
|
|
|
const CommentsPageView = require('../views/comments_page_view.js');
|
2016-05-29 10:21:25 +00:00
|
|
|
const EmptyView = require('../views/empty_view.js');
|
2016-03-19 20:37:04 +00:00
|
|
|
|
2016-03-31 22:20:34 +00:00
|
|
|
class CommentsController {
|
2016-04-06 19:49:26 +00:00
|
|
|
registerRoutes() {
|
2016-06-12 18:11:43 +00:00
|
|
|
router.enter('/comments/:query?',
|
2016-06-12 12:04:42 +00:00
|
|
|
(ctx, next) => { misc.parseSearchQueryRoute(ctx, next); },
|
|
|
|
(ctx, next) => { this._listCommentsRoute(ctx); });
|
|
|
|
this._commentsPageView = new CommentsPageView();
|
2016-05-29 10:21:25 +00:00
|
|
|
this._emptyView = new EmptyView();
|
2016-04-06 19:49:26 +00:00
|
|
|
}
|
|
|
|
|
2016-06-12 12:04:42 +00:00
|
|
|
_listCommentsRoute(ctx) {
|
2016-06-13 20:34:39 +00:00
|
|
|
TopNavigation.activate('comments');
|
2016-06-12 12:04:42 +00:00
|
|
|
|
|
|
|
pageController.run({
|
|
|
|
searchQuery: ctx.searchQuery,
|
|
|
|
clientUrl: '/comments/' + misc.formatSearchQuery({page: '{page}'}),
|
2016-06-12 20:02:15 +00:00
|
|
|
requestPage: pageController.createHistoryCacheProxy(
|
|
|
|
ctx,
|
|
|
|
page => {
|
|
|
|
return api.get(
|
|
|
|
'/posts/?query=sort:comment-date+comment-count-min:1' +
|
|
|
|
`&page=${page}&pageSize=10&fields=` +
|
|
|
|
'id,comments,commentCount,thumbnailUrl');
|
|
|
|
}),
|
2016-06-12 12:04:42 +00:00
|
|
|
pageRenderer: this._commentsPageView,
|
|
|
|
pageContext: {
|
|
|
|
canViewPosts: api.hasPrivilege('posts:view'),
|
|
|
|
}
|
|
|
|
});
|
2016-03-19 20:37:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-31 22:20:34 +00:00
|
|
|
module.exports = new CommentsController();
|