mirror of
https://hk.gh-proxy.com/https://github.com/NodeBB/nodebb-plugin-poll.git
synced 2025-10-03 04:31:04 +08:00
feat(eslint): manually fix eslint errors (not auto-fixable)
This commit is contained in:
parent
4fe1031712
commit
7e0ee094c0
14 changed files with 225 additions and 175 deletions
16
lib/hooks.js
16
lib/hooks.js
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
const util = require('util');
|
||||
const NodeBB = require('./nodebb');
|
||||
|
||||
|
@ -54,7 +56,7 @@ const Serializer = require('./serializer');
|
|||
return obj;
|
||||
};
|
||||
|
||||
Hooks.filter.topicPost = async function (data, callback) {
|
||||
Hooks.filter.topicPost = async function (data) {
|
||||
if (Serializer.hasMarkup(data.content)) {
|
||||
await canCreate(data.cid, data.uid);
|
||||
return data;
|
||||
|
@ -64,6 +66,9 @@ const Serializer = require('./serializer');
|
|||
|
||||
Hooks.action.postDelete = function (data) {
|
||||
Poll.getPollIdByPid(data.post.pid, (err, pollId) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
if (pollId) {
|
||||
Poll.delete(pollId);
|
||||
}
|
||||
|
@ -72,6 +77,9 @@ const Serializer = require('./serializer');
|
|||
|
||||
Hooks.action.postRestore = function (data) {
|
||||
Poll.getPollIdByPid(data.post.pid, (err, pollId) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
if (pollId) {
|
||||
Poll.restore(pollId);
|
||||
}
|
||||
|
@ -80,6 +88,9 @@ const Serializer = require('./serializer');
|
|||
|
||||
Hooks.action.topicDelete = function (data) {
|
||||
Poll.getPollIdByTid(data.topic.tid, (err, pollId) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
if (pollId) {
|
||||
Poll.delete(pollId);
|
||||
}
|
||||
|
@ -88,6 +99,9 @@ const Serializer = require('./serializer');
|
|||
|
||||
Hooks.action.topicRestore = function (data) {
|
||||
Poll.getPollIdByTid(data.topic.tid, (err, pollId) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
if (pollId) {
|
||||
Poll.restore(pollId);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
db: require.main.require('./src/database'),
|
||||
|
|
|
@ -172,6 +172,10 @@ const Scheduler = require('./scheduler');
|
|||
|
||||
Poll.getVoteCount = function (pollId, callback) {
|
||||
NodeBB.db.getSetMembers(`poll:${pollId}:options`, (err, options) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
async.map(options, (option, next) => {
|
||||
Poll.getOptionVoteCount(pollId, option, next);
|
||||
}, (err, results) => {
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
'use strict';
|
||||
|
||||
const cron = require('cron').CronJob;
|
||||
const NodeBB = require('./nodebb');
|
||||
|
||||
const Poll = require('./poll');
|
||||
const cron = require('cron').CronJob;
|
||||
|
||||
(function (Scheduler) {
|
||||
const jobs = {};
|
||||
|
||||
Scheduler.start = function () {
|
||||
Poll.getScheduled((err, pollIds) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
pollIds.forEach((pollId) => {
|
||||
Scheduler.add(pollId);
|
||||
});
|
||||
|
|
|
@ -28,6 +28,9 @@ const Vote = require('./vote');
|
|||
|
||||
const pollId = parseInt(data.pollId, 10);
|
||||
Poll.get(pollId, socket.uid, !!socket.uid, (err, pollData) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
if (!pollData.info.version) {
|
||||
return callback(new Error('Legacy polls are not supported'));
|
||||
}
|
||||
|
@ -77,6 +80,10 @@ const Vote = require('./vote');
|
|||
}
|
||||
|
||||
Poll.get(data.pollId, socket.uid, false, (err, pollData) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
NodeBB.SocketIndex.server.sockets.emit('event:poll.voteChange', pollData);
|
||||
|
||||
callback();
|
||||
|
@ -116,7 +123,9 @@ const Vote = require('./vote');
|
|||
return callback(new Error('Can\'t update vote'));
|
||||
}
|
||||
if (err || !data.options.length) {
|
||||
err && console.error(err);
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
return callback(new Error('Invalid option'));
|
||||
}
|
||||
|
||||
|
@ -126,6 +135,10 @@ const Vote = require('./vote');
|
|||
}
|
||||
|
||||
Poll.get(data.pollId, socket.uid, false, (err, pollData) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
NodeBB.SocketIndex.server.sockets.emit('event:poll.voteChange', pollData);
|
||||
|
||||
callback();
|
||||
|
@ -160,6 +173,10 @@ const Vote = require('./vote');
|
|||
return callback(new Error('Error during removing vote'));
|
||||
}
|
||||
Poll.get(data.pollId, socket.uid, false, (err, pollData) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
NodeBB.SocketIndex.server.sockets.emit('event:poll.voteChange', pollData);
|
||||
callback();
|
||||
});
|
||||
|
@ -182,6 +199,9 @@ const Vote = require('./vote');
|
|||
}
|
||||
|
||||
NodeBB.User.getUsersFields(result.votes, ['uid', 'username', 'userslug', 'picture'], (err, userData) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
result.votes = userData;
|
||||
callback(null, result);
|
||||
});
|
||||
|
@ -207,7 +227,7 @@ const Vote = require('./vote');
|
|||
next(null, cid);
|
||||
});
|
||||
},
|
||||
function (cid, next) {
|
||||
function (cid) {
|
||||
checkPrivs(cid, socket.uid, callback);
|
||||
},
|
||||
]);
|
||||
|
|
|
@ -40,6 +40,10 @@ const Poll = require('./poll');
|
|||
|
||||
Vote.removeUidVote = function (uid, pollId, callback) {
|
||||
Vote.getUidVote(uid, pollId, (err, vote) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
async.parallel([
|
||||
function (next) {
|
||||
async.each(vote.options || [], (option, next) => {
|
||||
|
@ -65,7 +69,7 @@ const Poll = require('./poll');
|
|||
pollId: pollId,
|
||||
uid: uid,
|
||||
options: options
|
||||
.filter(option => option.votes.some(_uid => _uid == uid))
|
||||
.filter(option => option.votes.some(_uid => _uid === uid))
|
||||
.map(option => option.id),
|
||||
});
|
||||
});
|
||||
|
|
|
@ -10,7 +10,7 @@ const Scheduler = require('./lib/scheduler');
|
|||
Plugin.hooks = Hooks;
|
||||
|
||||
Plugin.load = function (params, callback) {
|
||||
function renderAdmin(req, res, next) {
|
||||
function renderAdmin(req, res) {
|
||||
res.render(`admin/plugins/${Config.plugin.id}`, {});
|
||||
}
|
||||
|
||||
|
@ -62,11 +62,11 @@ const Scheduler = require('./lib/scheduler');
|
|||
};
|
||||
|
||||
Plugin.copyPrivilegesFrom = function (data, callback) {
|
||||
if (data.privileges.indexOf('poll:create') == -1) {
|
||||
if (data.privileges.indexOf('poll:create') === -1) {
|
||||
data.privileges.push('poll:create');
|
||||
}
|
||||
|
||||
if (data.privileges.indexOf('groups:poll:create') == -1) {
|
||||
if (data.privileges.indexOf('groups:poll:create') === -1) {
|
||||
data.privileges.push('groups:poll:create');
|
||||
}
|
||||
callback(null, data);
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/* globals $, app, socket, define, bootbox */
|
||||
|
||||
define('admin/plugins/poll', ['settings'], function (Settings) {
|
||||
var wrapper;
|
||||
|
||||
|
@ -31,6 +29,9 @@ define('admin/plugins/poll', ['settings'], function (Settings) {
|
|||
bootbox.confirm('Are you sure you wish to reset the settings?', function (sure) {
|
||||
if (sure) {
|
||||
socket.emit('admin.plugins.poll.getDefaults', null, function (err, data) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
Settings.set('poll', data, wrapper, function () {
|
||||
socket.emit('admin.plugins.poll.sync');
|
||||
});
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/* globals $, app, templates, define */
|
||||
|
||||
(function (Poll) {
|
||||
var Creator = {};
|
||||
|
||||
|
@ -78,6 +76,10 @@
|
|||
}
|
||||
|
||||
Poll.sockets.getConfig(null, function (err, config) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
var poll = {};
|
||||
|
||||
// If there's already a poll in the post, serialize it for editing
|
||||
|
@ -147,7 +149,7 @@
|
|||
return obj.length;
|
||||
});
|
||||
|
||||
if (obj.options.length == 0) {
|
||||
if (obj.options.length === 0) {
|
||||
return error('[[poll:error.no_options]]');
|
||||
}
|
||||
|
||||
|
@ -173,13 +175,15 @@
|
|||
|
||||
if (config.limits.maxOptions <= el.prevAll('input').length) {
|
||||
clearErrors();
|
||||
translator.translate('[[poll:error.max_options]]', function (text) {
|
||||
error(text.replace('%d', config.limits.maxOptions));
|
||||
require(['translator'], function (translator) {
|
||||
translator.translate('[[poll:error.max_options]]', function (text) {
|
||||
error(text.replace('%d', config.limits.maxOptions));
|
||||
});
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
if (prevOption.val().length != 0) {
|
||||
if (prevOption.val().length !== 0) {
|
||||
prevOption.clone().val('').insertBefore(el).focus();
|
||||
}
|
||||
});
|
||||
|
@ -220,16 +224,15 @@
|
|||
}
|
||||
|
||||
function serializeObjectFromForm(form) {
|
||||
|
||||
var obj = form.serializeObject();
|
||||
var result = {
|
||||
options: obj.options,
|
||||
settings: {
|
||||
title: obj['settings.title'],
|
||||
maxvotes: obj['settings.maxvotes'],
|
||||
disallowVoteUpdate: obj['settings.disallowVoteUpdate'] === "on" ? "true" : "false",
|
||||
disallowVoteUpdate: obj['settings.disallowVoteUpdate'] === 'on' ? 'true' : 'false',
|
||||
end: obj['settings.end'],
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
return result;
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/* globals require, utils */
|
||||
|
||||
(function (module) {
|
||||
var utils;
|
||||
var Serializer = {};
|
||||
|
@ -134,7 +132,7 @@
|
|||
|
||||
const stripped = utils.stripHTMLTags(raw).replace(/\\/g, '\');
|
||||
let match;
|
||||
while ((match = settingsRegex.exec(stripped)) !== null) {
|
||||
while ((match = settingsRegex.exec(stripped)) !== null) { // eslint-disable-line no-cond-assign
|
||||
var key = match.groups.key.trim();
|
||||
var value = match.groups.value.trim();
|
||||
|
||||
|
@ -170,7 +168,7 @@
|
|||
module.exports = Serializer;
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
Poll.serializer = module.exports;
|
||||
window.Poll.serializer = module.exports;
|
||||
}
|
||||
}(typeof module === 'undefined' ? {
|
||||
module: {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
/* globals socket */
|
||||
|
||||
(function (Poll) {
|
||||
var messages = [
|
||||
{
|
||||
|
|
|
@ -1,8 +1,155 @@
|
|||
'use strict';
|
||||
|
||||
/* globals $, app,config */
|
||||
|
||||
(function (Poll) {
|
||||
var Actions = [
|
||||
{
|
||||
// Voting
|
||||
register: function (view) {
|
||||
var self = this;
|
||||
view.dom.voteButton.off('click').on('click', function () {
|
||||
self.handle(view);
|
||||
});
|
||||
},
|
||||
handle: function (view) {
|
||||
var form = view.dom.votingPanel.find('form');
|
||||
var votes = form.serializeArray().map(function (option) {
|
||||
return parseInt(option.value, 10);
|
||||
});
|
||||
|
||||
if (votes.length > 0) {
|
||||
var voteData = {
|
||||
pollId: view.pollData.info.pollId,
|
||||
options: votes,
|
||||
};
|
||||
|
||||
Poll.sockets.vote(voteData, function (err) {
|
||||
if (!config.loggedIn) {
|
||||
$(window).trigger('action:poll.vote.notloggedin');
|
||||
}
|
||||
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
|
||||
view.showResultsPanel();
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
// Voting
|
||||
register: function (view) {
|
||||
var self = this;
|
||||
view.dom.updateVoteButton.off('click').on('click', function () {
|
||||
self.handle(view);
|
||||
});
|
||||
},
|
||||
handle: function (view) {
|
||||
var form = view.dom.votingPanel.find('form');
|
||||
var votes = form.serializeArray().map(function (option) {
|
||||
return parseInt(option.value, 10);
|
||||
});
|
||||
|
||||
if (votes.length > 0) {
|
||||
var voteData = {
|
||||
pollId: view.pollData.info.pollId,
|
||||
options: votes,
|
||||
};
|
||||
|
||||
Poll.sockets.updateVote(voteData, function (err) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
view.showResultsPanel();
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
// Remove vote
|
||||
register: function (view) {
|
||||
var self = this;
|
||||
view.dom.removeVoteButton.off('click').on('click', function () {
|
||||
self.handle(view);
|
||||
});
|
||||
},
|
||||
handle: function (view) {
|
||||
var voteData = { pollId: view.pollData.info.pollId };
|
||||
|
||||
Poll.sockets.removeVote(voteData, function (err) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
view.showResultsPanel();
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
// Results button
|
||||
register: function (view) {
|
||||
var self = this;
|
||||
view.dom.resultsPanelButton.off('click').on('click', function () {
|
||||
self.handle(view);
|
||||
});
|
||||
},
|
||||
handle: function (view) {
|
||||
view.showResultsPanel();
|
||||
},
|
||||
},
|
||||
{
|
||||
// To Voting button
|
||||
register: function (view) {
|
||||
var self = this;
|
||||
view.dom.votingPanelButton.off('click').on('click', function () {
|
||||
self.handle(view);
|
||||
});
|
||||
},
|
||||
handle: function (view) {
|
||||
view.showVotingPanel();
|
||||
},
|
||||
},
|
||||
{
|
||||
// Option details
|
||||
register: function (view) {
|
||||
var self = this;
|
||||
view.dom.resultsPanel.off('click').on('click', '.poll-result-votecount', function (e) {
|
||||
self.handle(view, e);
|
||||
});
|
||||
},
|
||||
handle: function (view, e) {
|
||||
var optionId = $(e.currentTarget).parents('[data-poll-option-id]').data('poll-option-id');
|
||||
|
||||
Poll.sockets.getOptionDetails({
|
||||
pollId: view.pollData.info.pollId,
|
||||
optionId: optionId,
|
||||
}, function (err, details) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
|
||||
view.showOptionDetails(details);
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
// Editing
|
||||
register: function (view) {
|
||||
var self = this;
|
||||
view.dom.editButton.off('click').on('click', function () {
|
||||
self.handle(view);
|
||||
});
|
||||
},
|
||||
handle: function (view) {
|
||||
Poll.sockets.getConfig(null, function (err, config) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
Poll.creator.show(view.pollData, config, function () {});
|
||||
});
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
var View = function (pollData) {
|
||||
this.pollData = pollData;
|
||||
};
|
||||
|
@ -206,153 +353,6 @@
|
|||
this.dom.resultsPanelButton.addClass('hidden');
|
||||
};
|
||||
|
||||
var Actions = [
|
||||
{
|
||||
// Voting
|
||||
register: function (view) {
|
||||
var self = this;
|
||||
view.dom.voteButton.off('click').on('click', function () {
|
||||
self.handle(view);
|
||||
});
|
||||
},
|
||||
handle: function (view) {
|
||||
var form = view.dom.votingPanel.find('form');
|
||||
var votes = form.serializeArray().map(function (option) {
|
||||
return parseInt(option.value, 10);
|
||||
});
|
||||
|
||||
if (votes.length > 0) {
|
||||
var voteData = {
|
||||
pollId: view.pollData.info.pollId,
|
||||
options: votes,
|
||||
};
|
||||
|
||||
Poll.sockets.vote(voteData, function (err, result) {
|
||||
if (!config.loggedIn) {
|
||||
$(window).trigger('action:poll.vote.notloggedin');
|
||||
}
|
||||
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
|
||||
view.showResultsPanel();
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
// Voting
|
||||
register: function (view) {
|
||||
var self = this;
|
||||
view.dom.updateVoteButton.off('click').on('click', function () {
|
||||
self.handle(view);
|
||||
});
|
||||
},
|
||||
handle: function (view) {
|
||||
var form = view.dom.votingPanel.find('form');
|
||||
var votes = form.serializeArray().map(function (option) {
|
||||
return parseInt(option.value, 10);
|
||||
});
|
||||
|
||||
if (votes.length > 0) {
|
||||
var voteData = {
|
||||
pollId: view.pollData.info.pollId,
|
||||
options: votes,
|
||||
};
|
||||
|
||||
Poll.sockets.updateVote(voteData, function (err, result) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
view.showResultsPanel();
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
// Remove vote
|
||||
register: function (view) {
|
||||
var self = this;
|
||||
view.dom.removeVoteButton.off('click').on('click', function () {
|
||||
self.handle(view);
|
||||
});
|
||||
},
|
||||
handle: function (view) {
|
||||
var voteData = { pollId: view.pollData.info.pollId };
|
||||
|
||||
Poll.sockets.removeVote(voteData, function (err, result) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
view.showResultsPanel();
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
// Results button
|
||||
register: function (view) {
|
||||
var self = this;
|
||||
view.dom.resultsPanelButton.off('click').on('click', function () {
|
||||
self.handle(view);
|
||||
});
|
||||
},
|
||||
handle: function (view) {
|
||||
view.showResultsPanel();
|
||||
},
|
||||
},
|
||||
{
|
||||
// To Voting button
|
||||
register: function (view) {
|
||||
var self = this;
|
||||
view.dom.votingPanelButton.off('click').on('click', function () {
|
||||
self.handle(view);
|
||||
});
|
||||
},
|
||||
handle: function (view) {
|
||||
view.showVotingPanel();
|
||||
},
|
||||
},
|
||||
{
|
||||
// Option details
|
||||
register: function (view) {
|
||||
var self = this;
|
||||
view.dom.resultsPanel.off('click').on('click', '.poll-result-votecount', function (e) {
|
||||
self.handle(view, e);
|
||||
});
|
||||
},
|
||||
handle: function (view, e) {
|
||||
var optionId = $(e.currentTarget).parents('[data-poll-option-id]').data('poll-option-id');
|
||||
|
||||
Poll.sockets.getOptionDetails({
|
||||
pollId: view.pollData.info.pollId,
|
||||
optionId: optionId,
|
||||
}, function (err, details) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
|
||||
view.showOptionDetails(details);
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
// Editing
|
||||
register: function (view) {
|
||||
var self = this;
|
||||
view.dom.editButton.off('click').on('click', function () {
|
||||
self.handle(view);
|
||||
});
|
||||
},
|
||||
handle: function (view) {
|
||||
Poll.sockets.getConfig(null, function (err, config) {
|
||||
Poll.creator.show(view.pollData, config, function (data) {
|
||||
});
|
||||
});
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
Poll.view = {
|
||||
polls: {},
|
||||
load: function (pollData) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const async = require.main.require('async');
|
||||
const NodeBB = require('../lib/nodebb');
|
||||
const Poll = require('../lib/poll');
|
||||
|
||||
const timestamp = Date.UTC(2019, 3, 1);
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
'use strict';
|
||||
|
||||
const async = require.main.require('async');
|
||||
const NodeBB = require('../lib/nodebb');
|
||||
|
@ -7,6 +8,9 @@ module.exports = {
|
|||
timestamp: Date.UTC(2019, 2, 8),
|
||||
method: function (callback) {
|
||||
NodeBB.db.getSortedSetRange('categories:cid', 0, -1, (err, cids) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
async.some(cids, (cid, next) => {
|
||||
// if any category already had a poll:create privilege, then this has ran before
|
||||
// todo: weak check?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue