2016-08-17 11:01:17 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const api = require('../api.js');
|
2017-01-20 20:51:04 +00:00
|
|
|
const uri = require('../util/uri.js');
|
2016-08-17 11:01:17 +00:00
|
|
|
const SnapshotList = require('../models/snapshot_list.js');
|
|
|
|
const PageController = require('../controllers/page_controller.js');
|
|
|
|
const topNavigation = require('../models/top_navigation.js');
|
|
|
|
const SnapshotsPageView = require('../views/snapshots_page_view.js');
|
2016-08-23 19:18:03 +00:00
|
|
|
const EmptyView = require('../views/empty_view.js');
|
2016-08-17 11:01:17 +00:00
|
|
|
|
|
|
|
class SnapshotsController {
|
|
|
|
constructor(ctx) {
|
2016-08-23 19:18:03 +00:00
|
|
|
if (!api.hasPrivilege('snapshots:list')) {
|
|
|
|
this._view = new EmptyView();
|
|
|
|
this._view.showError('You don\'t have privileges to view history.');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-17 11:01:17 +00:00
|
|
|
topNavigation.activate('');
|
|
|
|
topNavigation.setTitle('History');
|
|
|
|
|
2016-08-28 16:53:06 +00:00
|
|
|
this._pageController = new PageController();
|
|
|
|
this._pageController.run({
|
2016-08-17 11:01:17 +00:00
|
|
|
parameters: ctx.parameters,
|
2017-02-08 23:48:06 +00:00
|
|
|
defaultLimit: 25,
|
|
|
|
getClientUrlForPage: (offset, limit) => {
|
2016-08-17 11:01:17 +00:00
|
|
|
const parameters = Object.assign(
|
2017-02-08 23:48:06 +00:00
|
|
|
{}, ctx.parameters, {offset: offset, limit: limit});
|
2017-01-20 20:51:04 +00:00
|
|
|
return uri.formatClientLink('history', parameters);
|
2016-08-17 11:01:17 +00:00
|
|
|
},
|
2017-02-08 23:48:06 +00:00
|
|
|
requestPage: (offset, limit) => {
|
|
|
|
return SnapshotList.search('', offset, limit);
|
2016-08-17 11:01:17 +00:00
|
|
|
},
|
|
|
|
pageRenderer: pageCtx => {
|
|
|
|
Object.assign(pageCtx, {
|
|
|
|
canViewPosts: api.hasPrivilege('posts:view'),
|
|
|
|
canViewUsers: api.hasPrivilege('users:view'),
|
|
|
|
canViewTags: api.hasPrivilege('tags:view'),
|
|
|
|
});
|
|
|
|
return new SnapshotsPageView(pageCtx);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = router => {
|
2017-01-20 20:51:04 +00:00
|
|
|
router.enter(['history'],
|
2016-08-17 11:01:17 +00:00
|
|
|
(ctx, next) => { ctx.controller = new SnapshotsController(ctx); });
|
|
|
|
};
|