nodebb-plugin-poll 3.2.4 → 3.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/eslint.config.mjs +10 -0
- package/languages/zh_CN/poll.json +8 -2
- package/lib/sockets.js +3 -3
- package/library.js +33 -1
- package/package.json +3 -4
- package/plugin.json +4 -1
- package/public/js/poll/main.js +19 -7
- package/public/js/poll/serializer.js +2 -2
- package/public/js/poll/view.js +41 -36
- package/templates/admin/partials/widgets/poll.tpl +5 -0
- package/templates/poll/view/messages.tpl +1 -1
- package/templates/poll/widget.tpl +1 -0
- package/.eslintrc +0 -3
- package/public/js/.eslintrc +0 -3
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"default_title": "默认投票标题",
|
|
9
9
|
"max_votes": "每个用户最多选几项",
|
|
10
10
|
"disallow_vote_update": "不允许用户更改投票",
|
|
11
|
+
"allow_anon_voting": "允许匿名投票",
|
|
11
12
|
"info_choices": "如果数字大于1,那么就是多选投票",
|
|
12
13
|
"settings": "设置",
|
|
13
14
|
"save": "保存",
|
|
@@ -29,10 +30,12 @@
|
|
|
29
30
|
|
|
30
31
|
"error.not_main": "只能在帖子主体中添加投票",
|
|
31
32
|
"error.privilege.create": "你不被允许创建投票",
|
|
33
|
+
"error.anon-voting-not-allowed": "不允许匿名投票",
|
|
32
34
|
|
|
33
35
|
"warning.redactor": "你正在使用编辑器。<strong>请不要</strong>手动编辑投票模块。 可以重新使用投票创建工具。",
|
|
34
36
|
|
|
35
37
|
"vote": "投票",
|
|
38
|
+
"vote_anonymously": "匿名投票",
|
|
36
39
|
"update_vote": "更改投票",
|
|
37
40
|
"remove_vote": "删除投票",
|
|
38
41
|
"to_voting": "去投票",
|
|
@@ -43,5 +46,8 @@
|
|
|
43
46
|
"vote_is_final": "投票已结束,无法更改",
|
|
44
47
|
|
|
45
48
|
"vote_count": "名用户投了此票",
|
|
46
|
-
"votes": "票"
|
|
47
|
-
|
|
49
|
+
"votes": "票",
|
|
50
|
+
"x-votes": "%1 票",
|
|
51
|
+
"total-votes-x": "总票数: %1",
|
|
52
|
+
"admin.create-poll": "创建投票"
|
|
53
|
+
}
|
package/lib/sockets.js
CHANGED
|
@@ -75,7 +75,7 @@ Sockets.vote = async function (socket, data) {
|
|
|
75
75
|
await Vote.add(data);
|
|
76
76
|
|
|
77
77
|
const pollData = await Poll.get(data.pollId, socket.uid, false);
|
|
78
|
-
NodeBB.SocketIndex.server.sockets.emit('event:poll.voteChange', pollData);
|
|
78
|
+
NodeBB.SocketIndex.server.sockets.emit('event:poll.voteChange', { pollData, uid: socket.uid });
|
|
79
79
|
};
|
|
80
80
|
|
|
81
81
|
Sockets.updateVote = async function (socket, data) {
|
|
@@ -111,7 +111,7 @@ Sockets.updateVote = async function (socket, data) {
|
|
|
111
111
|
|
|
112
112
|
await Vote.update(data);
|
|
113
113
|
const pollData = await Poll.get(data.pollId, socket.uid, false);
|
|
114
|
-
NodeBB.SocketIndex.server.sockets.emit('event:poll.voteChange', pollData);
|
|
114
|
+
NodeBB.SocketIndex.server.sockets.emit('event:poll.voteChange', { pollData, uid: socket.uid });
|
|
115
115
|
};
|
|
116
116
|
|
|
117
117
|
Sockets.removeVote = async function (socket, data) {
|
|
@@ -130,7 +130,7 @@ Sockets.removeVote = async function (socket, data) {
|
|
|
130
130
|
|
|
131
131
|
await Vote.remove(data);
|
|
132
132
|
const pollData = await Poll.get(data.pollId, socket.uid, false);
|
|
133
|
-
NodeBB.SocketIndex.server.sockets.emit('event:poll.voteChange', pollData);
|
|
133
|
+
NodeBB.SocketIndex.server.sockets.emit('event:poll.voteChange', { pollData, uid: socket.uid });
|
|
134
134
|
};
|
|
135
135
|
|
|
136
136
|
Sockets.getOptionDetails = async function (socket, data) {
|
package/library.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const nconf = require.main.require('nconf');
|
|
4
|
+
|
|
3
5
|
const NodeBB = require('./lib/nodebb');
|
|
4
6
|
const Config = require('./lib/config');
|
|
5
7
|
const Sockets = require('./lib/sockets');
|
|
@@ -24,7 +26,10 @@ Plugin.load = async function (params) {
|
|
|
24
26
|
NodeBB.AdminSockets[Config.plugin.id] = Config.adminSockets;
|
|
25
27
|
|
|
26
28
|
NodeBB.app = params.app;
|
|
27
|
-
|
|
29
|
+
|
|
30
|
+
if (nconf.get('runJobs')) {
|
|
31
|
+
Scheduler.start();
|
|
32
|
+
}
|
|
28
33
|
|
|
29
34
|
await Config.init();
|
|
30
35
|
};
|
|
@@ -63,3 +68,30 @@ Plugin.copyPrivilegesFrom = function (data) {
|
|
|
63
68
|
}
|
|
64
69
|
return data;
|
|
65
70
|
};
|
|
71
|
+
|
|
72
|
+
Plugin.defineWidgets = async function (widgets) {
|
|
73
|
+
const widget = {
|
|
74
|
+
widget: 'poll',
|
|
75
|
+
name: 'Poll',
|
|
76
|
+
description: 'Display a poll',
|
|
77
|
+
content: await NodeBB.app.renderAsync('admin/partials/widgets/poll', {}),
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
widgets.push(widget);
|
|
81
|
+
return widgets;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
Plugin.renderPollWidget = async function (widget) {
|
|
85
|
+
const { tid } = widget.data;
|
|
86
|
+
const Poll = require('./lib/poll');
|
|
87
|
+
const pollId = await Poll.getPollIdByTid(tid);
|
|
88
|
+
if (!pollId) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
const pollData = await Poll.get(pollId, widget.uid, widget.req.loggedIn);
|
|
92
|
+
if (!pollData) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
widget.html = await NodeBB.app.renderAsync('poll/widget.tpl', { pollId });
|
|
96
|
+
return widget;
|
|
97
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nodebb-plugin-poll",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.6",
|
|
4
4
|
"description": "NodeBB Poll Plugin",
|
|
5
5
|
"main": "library.js",
|
|
6
6
|
"scripts": {
|
|
@@ -29,8 +29,7 @@
|
|
|
29
29
|
"compatibility": "^4.0.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"eslint": "
|
|
33
|
-
"eslint-config-nodebb": "
|
|
34
|
-
"eslint-plugin-import": "2.29.1"
|
|
32
|
+
"eslint": "9.28.0",
|
|
33
|
+
"eslint-config-nodebb": "1.1.7"
|
|
35
34
|
}
|
|
36
35
|
}
|
package/plugin.json
CHANGED
|
@@ -18,7 +18,10 @@
|
|
|
18
18
|
{ "hook": "action:post.delete", "method": "hooks.action.postDelete" },
|
|
19
19
|
{ "hook": "action:post.restore", "method": "hooks.action.postRestore" },
|
|
20
20
|
{ "hook": "action:topic.delete", "method": "hooks.action.topicDelete" },
|
|
21
|
-
{ "hook": "action:topic.restore", "method": "hooks.action.topicRestore" }
|
|
21
|
+
{ "hook": "action:topic.restore", "method": "hooks.action.topicRestore" },
|
|
22
|
+
|
|
23
|
+
{ "hook": "filter:widgets.getWidgets", "method": "defineWidgets" },
|
|
24
|
+
{ "hook": "filter:widget.render:poll", "method": "renderPollWidget" }
|
|
22
25
|
],
|
|
23
26
|
"scss": [
|
|
24
27
|
"public/scss/style.scss"
|
package/public/js/poll/main.js
CHANGED
|
@@ -11,41 +11,53 @@ window.Poll = {};
|
|
|
11
11
|
});
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
// eslint-disable-next-line import/no-unresolved
|
|
15
14
|
require('poll/serializer')(window.utils);
|
|
16
15
|
|
|
17
16
|
$(window).on('action:topic.loading', function () {
|
|
18
17
|
if (ajaxify.data.posts.length > 0 && ajaxify.data.posts[0].hasOwnProperty('pollId')) {
|
|
19
|
-
|
|
18
|
+
getPollByPost(ajaxify.data.posts[0]);
|
|
20
19
|
}
|
|
21
20
|
});
|
|
22
21
|
|
|
23
22
|
$(window).on('action:posts.loaded', function (ev, data) {
|
|
24
23
|
data.posts.forEach((post) => {
|
|
25
24
|
if (post.hasOwnProperty('pollId')) {
|
|
26
|
-
|
|
25
|
+
getPollByPost(post);
|
|
27
26
|
}
|
|
28
27
|
});
|
|
29
28
|
});
|
|
30
29
|
|
|
31
30
|
$(window).on('action:posts.edited', function (ev, data) {
|
|
32
31
|
if (data.post.hasOwnProperty('pollId')) {
|
|
33
|
-
|
|
32
|
+
getPollByPost(data.post);
|
|
34
33
|
}
|
|
35
34
|
});
|
|
36
35
|
|
|
36
|
+
$(window).on('action:ajaxify.end', function () {
|
|
37
|
+
$('[data-widget-poll-id]').each(function () {
|
|
38
|
+
getPoll($(this).attr('data-widget-poll-id'), $(this));
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
37
42
|
socket.on('event:poll.voteChange', function (data) {
|
|
38
|
-
Poll.view.update(data);
|
|
43
|
+
Poll.view.update(data.pollData, data.uid);
|
|
39
44
|
});
|
|
40
45
|
|
|
41
|
-
function
|
|
42
|
-
|
|
46
|
+
function getPollByPost(post) {
|
|
47
|
+
const postEl = $('[component="post"][data-pid="' + post.pid + '"]');
|
|
48
|
+
if (postEl.length && post.pollId) {
|
|
49
|
+
getPoll(post.pollId, postEl.find('[component="post/content"]'));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
43
52
|
|
|
53
|
+
function getPoll(pollId, container) {
|
|
54
|
+
pollId = parseInt(pollId, 10);
|
|
44
55
|
if (!isNaN(pollId)) {
|
|
45
56
|
socket.emit('plugins.poll.get', { pollId }, function (err, pollData) {
|
|
46
57
|
if (err) {
|
|
47
58
|
return Poll.alertError(err.message);
|
|
48
59
|
}
|
|
60
|
+
pollData.container = container;
|
|
49
61
|
Poll.view.load(pollData);
|
|
50
62
|
});
|
|
51
63
|
}
|
|
@@ -133,7 +133,7 @@ module.exports = function (utils) {
|
|
|
133
133
|
|
|
134
134
|
const stripped = utils.stripHTMLTags(raw).replace(/\\/g, '\');
|
|
135
135
|
let match;
|
|
136
|
-
while ((match = settingsRegex.exec(stripped)) !== null) {
|
|
136
|
+
while ((match = settingsRegex.exec(stripped)) !== null) {
|
|
137
137
|
var key = match.groups.key.trim();
|
|
138
138
|
var value = match.groups.value.trim();
|
|
139
139
|
|
|
@@ -150,7 +150,7 @@ module.exports = function (utils) {
|
|
|
150
150
|
function deserializeSettings(settings, config) {
|
|
151
151
|
var deserialized = '';
|
|
152
152
|
|
|
153
|
-
for (var k
|
|
153
|
+
for (var k of Object.keys(settings)) {
|
|
154
154
|
if (settings.hasOwnProperty(k) && config.defaults.hasOwnProperty(k)) {
|
|
155
155
|
var key = utils.stripHTMLTags(k).trim();
|
|
156
156
|
var value = utils.stripHTMLTags(settings[k]).trim();
|
package/public/js/poll/view.js
CHANGED
|
@@ -176,44 +176,41 @@
|
|
|
176
176
|
|
|
177
177
|
View.prototype.load = function () {
|
|
178
178
|
var self = this;
|
|
179
|
+
if (!self.pollData.container.length) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
179
182
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
votingPanelButton: panel.find('.poll-button-voting'),
|
|
197
|
-
resultsPanelButton: panel.find('.poll-button-results'),
|
|
198
|
-
editButton: panel.find('.poll-button-edit'),
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
self.hideMessage();
|
|
183
|
+
app.parseAndTranslate('poll/view', { poll: self.pollData }, function (panel) {
|
|
184
|
+
self.pollData.container.prepend(panel);
|
|
185
|
+
self.dom = {
|
|
186
|
+
panel: panel,
|
|
187
|
+
votingForm: panel.find('.poll-voting-form'),
|
|
188
|
+
messages: panel.find('.poll-view-messages'),
|
|
189
|
+
votingPanel: panel.find('.poll-view-voting'),
|
|
190
|
+
resultsPanel: panel.find('.poll-view-results'),
|
|
191
|
+
voteButton: panel.find('.poll-button-vote'),
|
|
192
|
+
voteAnonButton: panel.find('.poll-button-vote-anon'),
|
|
193
|
+
updateVoteButton: panel.find('.poll-button-update-vote'),
|
|
194
|
+
removeVoteButton: panel.find('.poll-button-remove-vote'),
|
|
195
|
+
votingPanelButton: panel.find('.poll-button-voting'),
|
|
196
|
+
resultsPanelButton: panel.find('.poll-button-results'),
|
|
197
|
+
editButton: panel.find('.poll-button-edit'),
|
|
198
|
+
};
|
|
202
199
|
|
|
203
|
-
|
|
204
|
-
self.hasVotedAndVotingUpdateDisallowed();
|
|
200
|
+
self.hideMessage();
|
|
205
201
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
} else {
|
|
209
|
-
self.showVotingPanel();
|
|
210
|
-
}
|
|
202
|
+
self.pollEndedOrDeleted();
|
|
203
|
+
self.hasVotedAndVotingUpdateDisallowed();
|
|
211
204
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
205
|
+
if (!app.user.uid || self.pollData.hasVoted) {
|
|
206
|
+
self.showResultsPanel();
|
|
207
|
+
} else {
|
|
208
|
+
self.showVotingPanel();
|
|
216
209
|
}
|
|
210
|
+
|
|
211
|
+
Actions.forEach(function (action) {
|
|
212
|
+
action.register(self);
|
|
213
|
+
});
|
|
217
214
|
});
|
|
218
215
|
};
|
|
219
216
|
|
|
@@ -241,8 +238,16 @@
|
|
|
241
238
|
}
|
|
242
239
|
};
|
|
243
240
|
|
|
244
|
-
View.prototype.update = function (pollData) {
|
|
241
|
+
View.prototype.update = function (pollData, uid) {
|
|
242
|
+
const isSelf = String(uid) === String(app.user.uid);
|
|
243
|
+
const hasVoted = this.pollData.hasVoted;
|
|
244
|
+
const vote = this.pollData.vote;
|
|
245
245
|
this.pollData = pollData;
|
|
246
|
+
if (!isSelf) {
|
|
247
|
+
// restore user specific data if update is not self
|
|
248
|
+
this.pollData.hasVoted = hasVoted;
|
|
249
|
+
this.pollData.vote = vote;
|
|
250
|
+
}
|
|
246
251
|
|
|
247
252
|
this.pollEndedOrDeleted();
|
|
248
253
|
|
|
@@ -401,10 +406,10 @@
|
|
|
401
406
|
|
|
402
407
|
view.load();
|
|
403
408
|
},
|
|
404
|
-
update: function (pollData) {
|
|
409
|
+
update: function (pollData, uid) {
|
|
405
410
|
var pollId = pollData.info.pollId;
|
|
406
411
|
if (this.polls.hasOwnProperty(pollId)) {
|
|
407
|
-
this.polls[pollId].update(pollData);
|
|
412
|
+
this.polls[pollId].update(pollData, uid);
|
|
408
413
|
}
|
|
409
414
|
},
|
|
410
415
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<div data-widget-poll-id="{./pollId}"></div>
|
package/.eslintrc
DELETED
package/public/js/.eslintrc
DELETED