nodebb-plugin-poll 3.1.4 → 3.1.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/languages/en_GB/poll.json +2 -0
- package/languages/en_US/poll.json +4 -1
- package/lib/nodebb.js +1 -0
- package/lib/poll.js +4 -5
- package/lib/sockets.js +21 -10
- package/package.json +1 -1
- package/public/js/poll/main.js +8 -0
- package/public/js/poll/view.js +5 -1
- package/templates/poll/view/results.tpl +1 -1
- package/templates/poll/view.tpl +1 -0
|
@@ -43,5 +43,8 @@
|
|
|
43
43
|
"vote_is_final": "Changing your vote is not allowed for this poll so your vote is final",
|
|
44
44
|
|
|
45
45
|
"vote_count": "users voted for this option",
|
|
46
|
-
"votes": "votes"
|
|
46
|
+
"votes": "votes",
|
|
47
|
+
"x-votes": "%1 votes",
|
|
48
|
+
"total-votes-x": "Total Votes: %1",
|
|
49
|
+
"admin.create-poll": "Create Poll"
|
|
47
50
|
}
|
package/lib/nodebb.js
CHANGED
|
@@ -8,6 +8,7 @@ module.exports = {
|
|
|
8
8
|
Posts: require.main.require('./src/posts'),
|
|
9
9
|
Topics: require.main.require('./src/topics'),
|
|
10
10
|
Privileges: require.main.require('./src/privileges'),
|
|
11
|
+
Plugins: require.main.require('./src/plugins'),
|
|
11
12
|
PluginSockets: require.main.require('./src/socket.io/plugins'),
|
|
12
13
|
AdminSockets: require.main.require('./src/socket.io/admin').plugins,
|
|
13
14
|
SocketIndex: require.main.require('./src/socket.io/index'),
|
package/lib/poll.js
CHANGED
|
@@ -37,17 +37,17 @@ const Scheduler = require('./scheduler');
|
|
|
37
37
|
async.apply(async.series, [
|
|
38
38
|
// Save poll options in parallel
|
|
39
39
|
async.apply(
|
|
40
|
-
async.parallel,
|
|
40
|
+
async.parallel,
|
|
41
41
|
pollData.options.map(
|
|
42
|
-
|
|
42
|
+
option => async.apply(NodeBB.db.setObject, `poll:${pollId}:options:${option.id}`, option)
|
|
43
43
|
),
|
|
44
44
|
),
|
|
45
|
-
// Add poll option id to option list synchronously
|
|
45
|
+
// Add poll option id to option list synchronously
|
|
46
46
|
// To avoid race condition causing duplicate error
|
|
47
47
|
async.apply(
|
|
48
48
|
async.series,
|
|
49
49
|
pollData.options.map(
|
|
50
|
-
|
|
50
|
+
option => async.apply(NodeBB.db.setAdd, `poll:${pollId}:options`, option.id)
|
|
51
51
|
),
|
|
52
52
|
),
|
|
53
53
|
]),
|
|
@@ -56,7 +56,6 @@ const Scheduler = require('./scheduler');
|
|
|
56
56
|
async.apply(NodeBB.db.listAppend, 'polls', pollId),
|
|
57
57
|
async.apply(NodeBB.db.setObjectField, `topic:${poll.tid}`, 'pollId', pollId),
|
|
58
58
|
], (err) => {
|
|
59
|
-
|
|
60
59
|
if (err) {
|
|
61
60
|
return callback(err);
|
|
62
61
|
}
|
package/lib/sockets.js
CHANGED
|
@@ -36,8 +36,7 @@ const Vote = require('./vote');
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
pollData.optionType = parseInt(pollData.settings.maxvotes, 10) > 1 ? 'checkbox' : 'radio';
|
|
39
|
-
|
|
40
|
-
return callback(null, pollData);
|
|
39
|
+
callback(null, pollData);
|
|
41
40
|
});
|
|
42
41
|
};
|
|
43
42
|
|
|
@@ -188,22 +187,34 @@ const Vote = require('./vote');
|
|
|
188
187
|
if (!socket.uid || !data || isNaN(parseInt(data.pollId, 10)) || isNaN(parseInt(data.optionId, 10))) {
|
|
189
188
|
return callback(new Error('Invalid request'));
|
|
190
189
|
}
|
|
191
|
-
|
|
192
|
-
|
|
190
|
+
async.parallel({
|
|
191
|
+
poll: function (next) {
|
|
192
|
+
Poll.getInfo(data.pollId, next);
|
|
193
|
+
},
|
|
194
|
+
option: function (next) {
|
|
195
|
+
Poll.getOption(data.pollId, data.optionId, true, next);
|
|
196
|
+
},
|
|
197
|
+
}, (err, result) => {
|
|
193
198
|
if (err) {
|
|
194
199
|
return callback(new Error('Something went wrong!'));
|
|
195
200
|
}
|
|
196
|
-
|
|
197
|
-
if (!
|
|
198
|
-
return callback(null,
|
|
201
|
+
const { poll, option } = result;
|
|
202
|
+
if (!option.votes || !option.votes.length) {
|
|
203
|
+
return callback(null, option);
|
|
199
204
|
}
|
|
200
205
|
|
|
201
|
-
NodeBB.User.getUsersFields(
|
|
206
|
+
NodeBB.User.getUsersFields(option.votes, ['uid', 'username', 'userslug', 'picture'], (err, userData) => {
|
|
202
207
|
if (err) {
|
|
203
208
|
console.error(err);
|
|
209
|
+
return callback(err);
|
|
204
210
|
}
|
|
205
|
-
|
|
206
|
-
|
|
211
|
+
option.votes = userData;
|
|
212
|
+
NodeBB.Plugins.hooks.fire('filter:poll.getOptionDetails', {
|
|
213
|
+
poll,
|
|
214
|
+
option,
|
|
215
|
+
}, (err, result) => {
|
|
216
|
+
callback(err, result.option);
|
|
217
|
+
});
|
|
207
218
|
});
|
|
208
219
|
});
|
|
209
220
|
};
|
package/package.json
CHANGED
package/public/js/poll/main.js
CHANGED
|
@@ -16,6 +16,14 @@ window.Poll = {};
|
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
+
$(window).on('action:posts.loaded', function (ev, data) {
|
|
20
|
+
data.posts.forEach((post) => {
|
|
21
|
+
if (post.hasOwnProperty('pollId')) {
|
|
22
|
+
getPoll(post.pollId);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
19
27
|
$(window).on('action:posts.edited', function (ev, data) {
|
|
20
28
|
if (data.post.hasOwnProperty('pollId')) {
|
|
21
29
|
getPoll(data.post.pollId);
|
package/public/js/poll/view.js
CHANGED
|
@@ -227,10 +227,14 @@
|
|
|
227
227
|
|
|
228
228
|
this.pollData.options.forEach(function (option) {
|
|
229
229
|
var el = this.dom.resultsPanel.find('[data-poll-option-id=' + option.id + ']');
|
|
230
|
-
el.find('.poll-result-votecount span').
|
|
230
|
+
el.find('.poll-result-votecount span').translateText(`[[poll:x-votes, ${option.voteCount}]]`);
|
|
231
231
|
el.find('.poll-result-progressbar').css('width', option.percentage + '%')
|
|
232
232
|
.find('span.percent').text(option.percentage);
|
|
233
233
|
}, this);
|
|
234
|
+
|
|
235
|
+
this.dom.resultsPanel
|
|
236
|
+
.find('.poll-result-total-votecount')
|
|
237
|
+
.translateText(`[[poll:total-votes-x, ${pollData.info.voteCount}]]`);
|
|
234
238
|
};
|
|
235
239
|
|
|
236
240
|
View.prototype.showMessage = function (title, content) {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<div class="d-flex justify-content-between mb-1">
|
|
4
4
|
<strong>{poll.options.title}</strong>
|
|
5
5
|
<a class="poll-result-votecount small" href="#">
|
|
6
|
-
<span>{poll.options.voteCount}</span>
|
|
6
|
+
<span>[[poll:x-votes, {poll.options.voteCount}]]</span>
|
|
7
7
|
</a>
|
|
8
8
|
</div>
|
|
9
9
|
<div class="progress">
|
package/templates/poll/view.tpl
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
</div>
|
|
16
16
|
<div class="poll-view-results d-flex flex-column gap-3 mb-3 <!-- IF !poll.hasVoted -->hidden<!-- ENDIF !poll.hasVoted -->">
|
|
17
17
|
<!-- IMPORT poll/view/results.tpl -->
|
|
18
|
+
<div class="text-end text-sm text-secondary poll-result-total-votecount">[[poll:total-votes-x, {poll.info.voteCount}]]</div>
|
|
18
19
|
</div>
|
|
19
20
|
|
|
20
21
|
<div class="poll-view-buttons">
|