gallery.accords-library.com/client/js/controllers/snapshots_controller.js

52 lines
1.8 KiB
JavaScript
Raw Normal View History

'use strict';
const api = require('../api.js');
const uri = require('../util/uri.js');
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');
const EmptyView = require('../views/empty_view.js');
class SnapshotsController {
constructor(ctx) {
if (!api.hasPrivilege('snapshots:list')) {
this._view = new EmptyView();
this._view.showError('You don\'t have privileges to view history.');
return;
}
topNavigation.activate('');
topNavigation.setTitle('History');
this._pageController = new PageController();
this._pageController.run({
parameters: ctx.parameters,
2017-02-08 23:48:06 +00:00
defaultLimit: 25,
getClientUrlForPage: (offset, limit) => {
const parameters = Object.assign(
2017-02-08 23:48:06 +00:00
{}, ctx.parameters, {offset: offset, limit: limit});
return uri.formatClientLink('history', parameters);
},
2017-02-08 23:48:06 +00:00
requestPage: (offset, limit) => {
return SnapshotList.search('', offset, limit);
},
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 => {
router.enter(['history'],
2020-06-04 18:09:35 +00:00
(ctx, next) => {
ctx.controller = new SnapshotsController(ctx);
});
};