-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathlibrary.js
executable file
·97 lines (79 loc) · 2.28 KB
/
library.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
'use strict';
const nconf = require.main.require('nconf');
const NodeBB = require('./lib/nodebb');
const Config = require('./lib/config');
const Sockets = require('./lib/sockets');
const Hooks = require('./lib/hooks');
const Scheduler = require('./lib/scheduler');
const Plugin = module.exports;
Plugin.hooks = Hooks;
Plugin.load = async function (params) {
const routeHelpers = require.main.require('./src/routes/helpers');
const { router } = params;
routeHelpers.setupAdminPageRoute(router, `/admin/plugins/${Config.plugin.id}`, (req, res) => {
res.render(`admin/plugins/${Config.plugin.id}`, {
title: 'Poll',
});
});
NodeBB.PluginSockets[Config.plugin.id] = Sockets;
NodeBB.AdminSockets[Config.plugin.id] = Config.adminSockets;
NodeBB.app = params.app;
if (nconf.get('runJobs')) {
Scheduler.start();
}
await Config.init();
};
Plugin.addAdminNavigation = function (adminHeader) {
adminHeader.plugins.push({
route: `/plugins/${Config.plugin.id}`,
icon: Config.plugin.icon,
name: Config.plugin.name,
});
return adminHeader;
};
Plugin.registerFormatting = function (payload) {
payload.options.push({
name: 'poll',
className: `fa ${Config.plugin.icon}`,
title: '[[poll:creator_title]]',
});
return payload;
};
Plugin.addPrivilege = function (hookData) {
hookData.privileges.set(
'poll:create', { label: '[[poll:admin.create-poll]]' },
);
};
Plugin.copyPrivilegesFrom = function (data) {
if (data.privileges.indexOf('poll:create') === -1) {
data.privileges.push('poll:create');
}
if (data.privileges.indexOf('groups:poll:create') === -1) {
data.privileges.push('groups:poll:create');
}
return data;
};
Plugin.defineWidgets = async function (widgets) {
const widget = {
widget: 'poll',
name: 'Poll',
description: 'Display a poll',
content: await NodeBB.app.renderAsync('admin/partials/widgets/poll', {}),
};
widgets.push(widget);
return widgets;
};
Plugin.renderPollWidget = async function (widget) {
const { tid } = widget.data;
const Poll = require('./lib/poll');
const pollId = await Poll.getPollIdByTid(tid);
if (!pollId) {
return null;
}
const pollData = await Poll.get(pollId, widget.uid, widget.req.loggedIn);
if (!pollData) {
return null;
}
widget.html = await NodeBB.app.renderAsync('poll/widget.tpl', { pollId });
return widget;
};