nodebb-plugin-poll 3.2.0 → 3.2.2

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/lib/poll.js CHANGED
@@ -101,7 +101,9 @@ Poll.getOptions = async function (pollId, withVotes = false) {
101
101
  Poll.getOption = async function (pollId, option, withVotes = false) {
102
102
  const [optionData, votes, voteCount] = await Promise.all([
103
103
  NodeBB.db.getObject(`poll:${pollId}:options:${option}`),
104
- withVotes ? NodeBB.db.getSortedSetRange(`poll:${pollId}:options:${option}:votes`, 0, -1) : null,
104
+ withVotes ?
105
+ NodeBB.db.getSortedSetRange(`poll:${pollId}:options:${option}:votes`, 0, -1) :
106
+ null,
105
107
  Poll.getOptionVoteCount(pollId, option),
106
108
  ]);
107
109
 
package/lib/sockets.js CHANGED
@@ -120,7 +120,7 @@ Sockets.removeVote = async function (socket, data) {
120
120
  }
121
121
 
122
122
  await Vote.remove(data);
123
- const pollData = Poll.get(data.pollId, socket.uid, false);
123
+ const pollData = await Poll.get(data.pollId, socket.uid, false);
124
124
  NodeBB.SocketIndex.server.sockets.emit('event:poll.voteChange', pollData);
125
125
  };
126
126
 
@@ -136,7 +136,9 @@ Sockets.getOptionDetails = async function (socket, data) {
136
136
  if (!option.votes || !option.votes.length) {
137
137
  return option;
138
138
  }
139
- const userData = await NodeBB.User.getUsersFields(option.votes, ['uid', 'username', 'userslug', 'picture']);
139
+ const userData = await NodeBB.User.getUsersFields(option.votes, [
140
+ 'uid', 'username', 'userslug', 'picture',
141
+ ]);
140
142
  option.votes = userData;
141
143
 
142
144
  const result = await NodeBB.Plugins.hooks.fire('filter:poll.getOptionDetails', {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-poll",
3
- "version": "3.2.0",
3
+ "version": "3.2.2",
4
4
  "description": "NodeBB Poll Plugin",
5
5
  "main": "library.js",
6
6
  "scripts": {
package/plugin.json CHANGED
@@ -20,16 +20,11 @@
20
20
  { "hook": "action:topic.delete", "method": "hooks.action.topicDelete" },
21
21
  { "hook": "action:topic.restore", "method": "hooks.action.topicRestore" }
22
22
  ],
23
- "staticDirs": {
24
- "public": "public",
25
- "vendor": "vendor"
26
- },
27
23
  "scss": [
28
24
  "public/scss/style.scss"
29
25
  ],
30
26
  "scripts": [
31
27
  "public/js/poll/main.js",
32
- "public/js/poll/sockets.js",
33
28
  "public/js/poll/creator.js",
34
29
  "public/js/poll/view.js"
35
30
  ],
@@ -70,17 +70,16 @@
70
70
  return alerts.error('[[error:category-not-selected]]');
71
71
  }
72
72
 
73
- Poll.sockets.canCreate({ cid: post.cid, pid: post.pid }, function (err, canCreate) {
73
+ socket.emit('plugins.poll.canCreate', { cid: post.cid, pid: post.pid }, function (err, canCreate) {
74
74
  if (err) {
75
75
  return alerts.error(err.message);
76
76
  }
77
77
  if (!canCreate) {
78
78
  return alerts.error('[[error:no-privileges]]');
79
79
  }
80
-
81
- Poll.sockets.getConfig(null, function (err, config) {
80
+ socket.emit('plugins.poll.getConfig', null, function (err, config) {
82
81
  if (err) {
83
- console.error(err);
82
+ return alerts.error(err);
84
83
  }
85
84
 
86
85
  var poll = {};
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ /* global Poll */
4
+
3
5
  window.Poll = {};
4
6
 
5
7
  (function () {
@@ -9,7 +11,9 @@ window.Poll = {};
9
11
  });
10
12
  };
11
13
 
14
+ // eslint-disable-next-line import/no-unresolved
12
15
  require('poll/serializer')(window.utils);
16
+
13
17
  $(window).on('action:topic.loading', function () {
14
18
  if (ajaxify.data.posts.length > 0 && ajaxify.data.posts[0].hasOwnProperty('pollId')) {
15
19
  getPoll(ajaxify.data.posts[0].pollId);
@@ -30,11 +34,15 @@ window.Poll = {};
30
34
  }
31
35
  });
32
36
 
37
+ socket.on('event:poll.voteChange', function (data) {
38
+ Poll.view.update(data);
39
+ });
40
+
33
41
  function getPoll(pollId) {
34
42
  pollId = parseInt(pollId, 10);
35
43
 
36
44
  if (!isNaN(pollId)) {
37
- Poll.sockets.getPoll({ pollId: pollId }, function (err, pollData) {
45
+ socket.emit('plugins.poll.get', { pollId }, function (err, pollData) {
38
46
  if (err) {
39
47
  return Poll.alertError(err.message);
40
48
  }
@@ -22,7 +22,7 @@
22
22
  options: votes,
23
23
  };
24
24
 
25
- Poll.sockets.vote(voteData, function (err) {
25
+ socket.emit('plugins.poll.vote', voteData, function (err) {
26
26
  if (!config.loggedIn) {
27
27
  $(window).trigger('action:poll.vote.notloggedin');
28
28
  }
@@ -55,8 +55,7 @@
55
55
  pollId: view.pollData.info.pollId,
56
56
  options: votes,
57
57
  };
58
-
59
- Poll.sockets.updateVote(voteData, function (err) {
58
+ socket.emit('plugins.poll.updateVote', voteData, function (err) {
60
59
  if (err) {
61
60
  return Poll.alertError(err.message);
62
61
  }
@@ -76,7 +75,7 @@
76
75
  handle: function (view) {
77
76
  var voteData = { pollId: view.pollData.info.pollId };
78
77
 
79
- Poll.sockets.removeVote(voteData, function (err) {
78
+ socket.emit('plugins.poll.removeVote', voteData, function (err) {
80
79
  if (err) {
81
80
  return Poll.alertError(err.message);
82
81
  }
@@ -119,7 +118,7 @@
119
118
  handle: function (view, e) {
120
119
  var optionId = $(e.currentTarget).parents('[data-poll-option-id]').data('poll-option-id');
121
120
 
122
- Poll.sockets.getOptionDetails({
121
+ socket.emit('plugins.poll.getOptionDetails', {
123
122
  pollId: view.pollData.info.pollId,
124
123
  optionId: optionId,
125
124
  }, function (err, details) {
@@ -140,7 +139,7 @@
140
139
  });
141
140
  },
142
141
  handle: function (view) {
143
- Poll.sockets.getConfig(null, function (err, config) {
142
+ socket.emit('plugins.poll.getConfig', null, function (err, config) {
144
143
  if (err) {
145
144
  console.error(err);
146
145
  }
@@ -250,15 +249,17 @@
250
249
  };
251
250
 
252
251
  View.prototype.showOptionDetails = function (details) {
253
- app.parseAndTranslate('poll/view/details', details, function (html) {
254
- bootbox.dialog({
255
- message: html,
256
- backdrop: true,
257
- buttons: {
258
- close: {
259
- label: 'Close',
252
+ require(['bootbox'], function (bootbox) {
253
+ app.parseAndTranslate('poll/view/details', details, function (html) {
254
+ bootbox.dialog({
255
+ message: html,
256
+ backdrop: true,
257
+ buttons: {
258
+ close: {
259
+ label: 'Close',
260
+ },
260
261
  },
261
- },
262
+ });
262
263
  });
263
264
  });
264
265
  };
@@ -2,28 +2,3 @@
2
2
  .composer.reply .poll, .composer.reply .ql-poll {
3
3
  display: none;
4
4
  }
5
-
6
- .poll-view {
7
- h2, h3 {
8
- margin-top: 0;
9
- }
10
-
11
- .card-title {
12
- display: inline-block;
13
- }
14
-
15
- .btn-group {
16
- display: block;
17
- a {
18
- color: inherit;
19
- }
20
- }
21
- }
22
-
23
- .poll-result-details:hover {
24
- text-decoration: none;
25
- }
26
-
27
- .poll-creator {
28
- z-index: 11000 !important;
29
- }
@@ -1,4 +1,4 @@
1
- <h2>{voteCount} [[poll:vote_count]]</h2>
1
+ <h4>{voteCount} [[poll:vote_count]]</h4>
2
2
  <!-- BEGIN votes -->
3
3
  <a href="{config.relative_path}/user/{votes.userslug}" class="poll-result-details">
4
4
  {buildAvatar(votes, "24px", true)}
@@ -1,12 +1,11 @@
1
1
  <div class="poll-view mb-3" data-poll-id="{poll.info.pollId}">
2
2
  <div class="card">
3
- <div class="card-header">
3
+ <div class="card-header d-flex justify-content-between align-items-center">
4
4
  <h5 class="card-title mb-0">{poll.settings.title}</h5>
5
- <div class="btn-group float-end hidden">
6
- <a href="#" class="poll-button-edit">
7
- <span class="fa fa-pencil"></span>
8
- </a>
9
- </div>
5
+
6
+ <a href="#" class="btn btn-sm btn-light border poll-button-edit hidden">
7
+ <span class="fa fa-pencil"></span>
8
+ </a>
10
9
  </div>
11
10
  <div class="card-body">
12
11
  <div class="poll-view-messages hidden"></div>
@@ -1,61 +0,0 @@
1
- 'use strict';
2
-
3
- (function (Poll) {
4
- var messages = [
5
- {
6
- method: 'getPoll',
7
- message: 'plugins.poll.get',
8
- },
9
- {
10
- method: 'vote',
11
- message: 'plugins.poll.vote',
12
- },
13
- {
14
- method: 'updateVote',
15
- message: 'plugins.poll.updateVote',
16
- },
17
- {
18
- method: 'removeVote',
19
- message: 'plugins.poll.removeVote',
20
- },
21
- {
22
- method: 'getOptionDetails',
23
- message: 'plugins.poll.getOptionDetails',
24
- },
25
- {
26
- method: 'getConfig',
27
- message: 'plugins.poll.getConfig',
28
- },
29
- {
30
- method: 'canCreate',
31
- message: 'plugins.poll.canCreate',
32
- },
33
- ];
34
-
35
- var handlers = [
36
- {
37
- event: 'event:poll.voteChange',
38
- handle: function (data) {
39
- Poll.view.update(data);
40
- },
41
- },
42
- ];
43
-
44
- function init() {
45
- handlers.forEach(function (handler) {
46
- if (socket.listeners(handler.event).length === 0) {
47
- socket.on(handler.event, handler.handle);
48
- }
49
- });
50
-
51
- messages.forEach(function (message) {
52
- Poll.sockets[message.method] = function (data, callback) {
53
- socket.emit(message.message, data, callback);
54
- };
55
- });
56
- }
57
-
58
- Poll.sockets = {};
59
-
60
- init();
61
- }(window.Poll));