2016-03-19 21:37:04 +01:00
|
|
|
'use strict';
|
|
|
|
|
2016-06-12 14:04:42 +02:00
|
|
|
const api = require('../api.js');
|
|
|
|
const misc = require('../util/misc.js');
|
2016-06-14 10:31:48 +02:00
|
|
|
const topNavigation = require('../models/top_navigation.js');
|
|
|
|
const PageController = require('../controllers/page_controller.js');
|
2016-06-12 14:04:42 +02:00
|
|
|
const CommentsPageView = require('../views/comments_page_view.js');
|
2016-03-19 21:37:04 +01:00
|
|
|
|
2016-04-01 00:20:34 +02:00
|
|
|
class CommentsController {
|
2016-06-14 10:31:48 +02:00
|
|
|
constructor(ctx) {
|
|
|
|
topNavigation.activate('comments');
|
2016-06-12 14:04:42 +02:00
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
this._pageController = new PageController({
|
2016-06-12 14:04:42 +02:00
|
|
|
searchQuery: ctx.searchQuery,
|
|
|
|
clientUrl: '/comments/' + misc.formatSearchQuery({page: '{page}'}),
|
2016-06-14 10:31:48 +02:00
|
|
|
requestPage: PageController.createHistoryCacheProxy(
|
2016-06-12 22:02:15 +02:00
|
|
|
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-14 10:31:48 +02:00
|
|
|
pageRenderer: pageCtx => {
|
|
|
|
Object.assign(pageCtx, {
|
|
|
|
canViewPosts: api.hasPrivilege('posts:view'),
|
|
|
|
});
|
|
|
|
return new CommentsPageView(pageCtx);
|
|
|
|
},
|
2016-06-12 14:04:42 +02:00
|
|
|
});
|
2016-03-19 21:37:04 +01:00
|
|
|
}
|
2016-06-14 10:31:48 +02:00
|
|
|
};
|
2016-03-19 21:37:04 +01:00
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
module.exports = router => {
|
|
|
|
router.enter('/comments/:query?',
|
|
|
|
(ctx, next) => { misc.parseSearchQueryRoute(ctx, next); },
|
|
|
|
(ctx, next) => { new CommentsController(ctx); });
|
|
|
|
};
|