aboutsummaryrefslogtreecommitdiff
path: root/client/js/controllers/snapshots_controller.js
blob: 0e9b773ce0de13cc89eff0e92a09bc6fea1e0ef7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'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,
            defaultLimit: 25,
            getClientUrlForPage: (offset, limit) => {
                const parameters = Object.assign(
                    {}, ctx.parameters, {offset: offset, limit: limit});
                return uri.formatClientLink('history', parameters);
            },
            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'],
        (ctx, next) => {
            ctx.controller = new SnapshotsController(ctx);
        });
};

© 2015 - 2026 Jakob L. Kreuze