DEV: apply coding standards to plugins (#10594)

This commit is contained in:
Joffrey JAFFEUX
2020-09-04 13:51:53 +02:00
committed by GitHub
parent 034a59a69d
commit bf88410126
27 changed files with 269 additions and 277 deletions

View File

@@ -86,9 +86,9 @@ export default Component.extend({
// TODO: It's a workaround for Chart.js' terrible hover styling.
// It will break on non-white backgrounds.
// Should be updated after #10341 lands
hoverBorderColor: "#fff"
}
]
hoverBorderColor: "#fff",
},
],
},
options: {
plugins: {
@@ -98,13 +98,13 @@ export default Component.extend({
borderRadius: 2,
font: {
family: getComputedStyle(document.body).fontFamily,
size: 16
size: 16,
},
padding: {
top: 2,
right: 6,
bottom: 2,
left: 6
left: 6,
},
formatter(votes) {
if (displayMode !== "percentage") {
@@ -112,12 +112,12 @@ export default Component.extend({
}
const percent = I18n.toNumber((votes / totalVotes) * 100.0, {
precision: 1
precision: 1,
});
return `${percent}%`;
}
}
},
},
},
responsive: true,
aspectRatio: 1.1,
@@ -131,15 +131,15 @@ export default Component.extend({
const sliceIndex = activeElements[0]._index;
const optionIndex = Object.keys(this._optionToSlice).find(
option => this._optionToSlice[option] === sliceIndex
(option) => this._optionToSlice[option] === sliceIndex
);
// Clear the array to avoid issues in Chart.js
activeElements.length = 0;
this.setHighlightedOption(Number(optionIndex));
}
}
},
},
};
},
@@ -178,5 +178,5 @@ export default Component.extend({
this._previousHighlightedSliceIndex = sliceIndex;
meta.controller.setHoverStyle(slice);
this._chart.draw();
}
},
});

View File

@@ -57,5 +57,5 @@ export default Component.extend({
} else {
this.onMouseOut();
}
}
},
});

View File

@@ -17,7 +17,7 @@ export default Controller.extend(ModalFunctionality, {
@discourseComputed("model.groupableUserFields")
groupableUserFields(fields) {
return fields.map(field => {
return fields.map((field) => {
const transformed = field.split("_").filter(Boolean);
if (transformed.length > 1) {
@@ -51,17 +51,17 @@ export default Controller.extend(ModalFunctionality, {
data: {
post_id: this.model.post.id,
poll_name: this.model.poll.name,
user_field_name: this.groupedBy
}
user_field_name: this.groupedBy,
},
})
.catch(error => {
.catch((error) => {
if (error) {
popupAjaxError(error);
} else {
bootbox.alert(I18n.t("poll.error_while_fetching_voters"));
}
})
.then(result => {
.then((result) => {
if (this.isDestroying || this.isDestroyed) {
return;
}
@@ -79,5 +79,5 @@ export default Controller.extend(ModalFunctionality, {
@action
onSelectPanel(panel) {
this.set("displayMode", panel.id);
}
},
});

View File

@@ -18,12 +18,12 @@ export default Controller.extend({
pollChartTypes: [
{
name: I18n.t("poll.ui_builder.poll_chart_type.bar"),
value: BAR_CHART_TYPE
value: BAR_CHART_TYPE,
},
{
name: I18n.t("poll.ui_builder.poll_chart_type.pie"),
value: PIE_CHART_TYPE
}
value: PIE_CHART_TYPE,
},
],
pollType: null,
@@ -39,16 +39,16 @@ export default Controller.extend({
return [
{
name: I18n.t("poll.ui_builder.poll_type.regular"),
value: regularPollType
value: regularPollType,
},
{
name: I18n.t("poll.ui_builder.poll_type.number"),
value: numberPollType
value: numberPollType,
},
{
name: I18n.t("poll.ui_builder.poll_type.multiple"),
value: multiplePollType
}
value: multiplePollType,
},
];
},
@@ -72,21 +72,21 @@ export default Controller.extend({
let options = [
{
name: I18n.t("poll.ui_builder.poll_result.always"),
value: alwaysPollResult
value: alwaysPollResult,
},
{
name: I18n.t("poll.ui_builder.poll_result.vote"),
value: votePollResult
value: votePollResult,
},
{
name: I18n.t("poll.ui_builder.poll_result.closed"),
value: closedPollResult
}
value: closedPollResult,
},
];
if (this.get("currentUser.staff")) {
options.push({
name: I18n.t("poll.ui_builder.poll_result.staff"),
value: staffPollResult
value: staffPollResult,
});
}
return options;
@@ -95,7 +95,7 @@ export default Controller.extend({
@discourseComputed("site.groups")
siteGroups(groups) {
return groups
.map(g => {
.map((g) => {
// prevents group "everyone" to be listed
if (g.id !== 0) {
return { name: g.name };
@@ -130,7 +130,7 @@ export default Controller.extend({
let length = 0;
pollOptions.split("\n").forEach(option => {
pollOptions.split("\n").forEach((option) => {
if (option.length !== 0) length += 1;
});
@@ -267,7 +267,7 @@ export default Controller.extend({
output += `${pollHeader}\n`;
if (pollOptions.length > 0 && !isNumber) {
pollOptions.split("\n").forEach(option => {
pollOptions.split("\n").forEach((option) => {
if (option.length !== 0) output += `* ${option}\n`;
});
}
@@ -299,7 +299,7 @@ export default Controller.extend({
if (pollMin >= pollMax) {
options = {
failed: true,
reason: I18n.t("poll.ui_builder.help.invalid_values")
reason: I18n.t("poll.ui_builder.help.invalid_values"),
};
}
@@ -313,7 +313,7 @@ export default Controller.extend({
if (pollStep < 1) {
options = {
failed: true,
reason: I18n.t("poll.ui_builder.help.min_step_value")
reason: I18n.t("poll.ui_builder.help.min_step_value"),
};
}
@@ -327,7 +327,7 @@ export default Controller.extend({
if (disableInsert) {
options = {
failed: true,
reason: I18n.t("poll.ui_builder.help.options_count")
reason: I18n.t("poll.ui_builder.help.options_count"),
};
}
@@ -335,9 +335,9 @@ export default Controller.extend({
},
_comboboxOptions(startIndex, endIndex) {
return [...Array(endIndex - startIndex).keys()].map(number => ({
return [...Array(endIndex - startIndex).keys()].map((number) => ({
value: number + startIndex,
name: number + startIndex
name: number + startIndex,
}));
},
@@ -353,12 +353,8 @@ export default Controller.extend({
chartType: BAR_CHART_TYPE,
pollResult: this.alwaysPollResult,
pollGroups: null,
date: moment()
.add(1, "day")
.format("YYYY-MM-DD"),
time: moment()
.add(1, "hour")
.format("HH:mm")
date: moment().add(1, "day").format("YYYY-MM-DD"),
time: moment().add(1, "hour").format("HH:mm"),
});
},
@@ -367,6 +363,6 @@ export default Controller.extend({
this.toolbarEvent.addText(this.pollOutput);
this.send("closeModal");
this._setupPoll();
}
}
},
},
});

View File

@@ -22,8 +22,8 @@ function initializePollUIBuilder(api) {
actions: {
showPollBuilder() {
showModal("poll-ui-builder").set("toolbarEvent", this.toolbarEvent);
}
}
},
},
});
api.addToolbarPopupMenuOptionsCallback(() => {
@@ -31,7 +31,7 @@ function initializePollUIBuilder(api) {
action: "showPollBuilder",
icon: "chart-bar",
label: "poll.ui_builder.title",
condition: "canBuildPoll"
condition: "canBuildPoll",
};
});
}
@@ -41,5 +41,5 @@ export default {
initialize() {
withPluginApi("0.8.7", initializePollUIBuilder);
}
},
};

View File

@@ -10,7 +10,7 @@ function initializePolls(api) {
api.modifyClass("controller:topic", {
subscribe() {
this._super(...arguments);
this.messageBus.subscribe("/polls/" + this.get("model.id"), msg => {
this.messageBus.subscribe("/polls/" + this.get("model.id"), (msg) => {
const post = this.get("model.postStream").findLoadedPost(msg.post_id);
if (post) {
post.set("polls", msg.polls);
@@ -20,14 +20,14 @@ function initializePolls(api) {
unsubscribe() {
this.messageBus.unsubscribe("/polls/*");
this._super(...arguments);
}
},
});
let _glued = [];
let _interval = null;
function rerender() {
_glued.forEach(g => g.queueRerender());
_glued.forEach((g) => g.queueRerender());
}
api.modifyClass("model:post", {
@@ -40,7 +40,7 @@ function initializePolls(api) {
const polls = this.polls;
if (polls) {
this._polls = this._polls || {};
polls.forEach(p => {
polls.forEach((p) => {
const existing = this._polls[p.name];
if (existing) {
this._polls[p.name].setProperties(p);
@@ -51,7 +51,7 @@ function initializePolls(api) {
this.set("pollsObject", this._polls);
rerender();
}
}
},
});
function attachPolls($elem, helper) {
@@ -81,7 +81,7 @@ function initializePolls(api) {
pollPost = post.quoted[quotedId];
pollPost = EmberObject.create(pollPost);
poll = EmberObject.create(
pollPost.polls.find(p => p.name === pollName)
pollPost.polls.find((p) => p.name === pollName)
);
vote = pollPost.polls_votes || {};
vote = vote[pollName] || [];
@@ -98,7 +98,7 @@ function initializePolls(api) {
.poll_groupable_user_fields || ""
)
.split("|")
.filter(Boolean)
.filter(Boolean),
};
const glue = new WidgetGlue("discourse-poll", register, attrs);
glue.appendTo(pollElem);
@@ -113,7 +113,7 @@ function initializePolls(api) {
_interval = null;
}
_glued.forEach(g => g.cleanUp());
_glued.forEach((g) => g.cleanUp());
_glued = [];
}
@@ -127,5 +127,5 @@ export default {
initialize() {
withPluginApi("0.8.7", initializePolls);
}
},
};

View File

@@ -9,7 +9,7 @@ export function getColors(count, palette) {
25: [220, 237, 200],
50: [66, 179, 213],
75: [26, 39, 62],
100: [0, 0, 0]
100: [0, 0, 0],
};
break;
case "warm":
@@ -18,7 +18,7 @@ export function getColors(count, palette) {
25: [254, 235, 101],
50: [228, 82, 27],
75: [77, 52, 47],
100: [0, 0, 0]
100: [0, 0, 0],
};
break;
}

View File

@@ -15,7 +15,7 @@ const WHITELISTED_ATTRIBUTES = [
"groups",
"status",
"step",
"type"
"type",
];
function replaceToken(tokens, target, list) {
@@ -84,14 +84,14 @@ function invalidPoll(state, tag) {
const rule = {
tag: "poll",
before: function(state, tagInfo, raw) {
before: function (state, tagInfo, raw) {
let token = state.push("text", "", 0);
token.content = raw;
token.bbcode_attrs = tagInfo.attrs;
token.bbcode_type = "poll_open";
},
after: function(state, openToken, raw) {
after: function (state, openToken, raw) {
let items = getListItems(state.tokens, openToken);
if (!items) {
return invalidPoll(state, raw);
@@ -106,7 +106,7 @@ const rule = {
attributes.push([DATA_PREFIX + "status", "open"]);
}
WHITELISTED_ATTRIBUTES.forEach(name => {
WHITELISTED_ATTRIBUTES.forEach((name) => {
if (attrs[name]) {
attributes.push([DATA_PREFIX + name, attrs[name]]);
}
@@ -221,7 +221,7 @@ const rule = {
state.push("poll_close", "div", -1);
state.push("poll_close", "div", -1);
state.push("poll_close", "div", -1);
}
},
};
function newApiInit(helper) {
@@ -230,7 +230,7 @@ function newApiInit(helper) {
opts.pollMaximumOptions = siteSettings.poll_maximum_options;
});
helper.registerPlugin(md => {
helper.registerPlugin((md) => {
md.block.bbcode.ruler.push("poll", rule);
});
}
@@ -247,7 +247,7 @@ export function setup(helper) {
"span.info-label",
"a.button.cast-votes",
"a.button.toggle-results",
"li[data-*]"
"li[data-*]",
]);
newApiInit(helper);

View File

@@ -1,10 +1,10 @@
// works as described on http://stackoverflow.com/a/13483710
function sumsUpTo100(percentages) {
return percentages.map(p => Math.floor(p)).reduce((a, b) => a + b) === 100;
return percentages.map((p) => Math.floor(p)).reduce((a, b) => a + b) === 100;
}
export default function(percentages) {
var decimals = percentages.map(a => a % 1);
export default function (percentages) {
var decimals = percentages.map((a) => a % 1);
const sumOfDecimals = Math.ceil(decimals.reduce((a, b) => a + b));
// compensate error by adding 1 to n items with the greatest decimal part
for (let i = 0, max = decimals.length; i < sumOfDecimals && i < max; i++) {
@@ -24,5 +24,5 @@ export default function(percentages) {
if (sumsUpTo100(percentages)) break;
}
return percentages.map(p => Math.floor(p));
return percentages.map((p) => Math.floor(p));
}

View File

@@ -26,12 +26,12 @@ function optionHtml(option) {
function infoTextHtml(text) {
return new RawHtml({
html: `<span class="info-text">${text}</span>`
html: `<span class="info-text">${text}</span>`,
});
}
function _fetchVoters(data) {
return ajax("/polls/voters.json", { data }).catch(error => {
return ajax("/polls/voters.json", { data }).catch((error) => {
if (error) {
popupAjaxError(error);
} else {
@@ -42,16 +42,16 @@ function _fetchVoters(data) {
function checkUserGroups(user, poll) {
const pollGroups =
poll && poll.groups && poll.groups.split(",").map(g => g.toLowerCase());
poll && poll.groups && poll.groups.split(",").map((g) => g.toLowerCase());
if (!pollGroups) {
return true;
}
const userGroups =
user && user.groups && user.groups.map(g => g.name.toLowerCase());
user && user.groups && user.groups.map((g) => g.name.toLowerCase());
return userGroups && pollGroups.some(g => userGroups.includes(g));
return userGroups && pollGroups.some((g) => userGroups.includes(g));
}
createWidget("discourse-poll-option", {
@@ -82,12 +82,12 @@ createWidget("discourse-poll-option", {
if ($(e.target).closest("a").length === 0) {
this.sendWidgetAction("toggleOption", this.attrs.option);
}
}
},
});
createWidget("discourse-poll-load-more", {
tagName: "div.poll-voters-toggle-expand",
buildKey: attrs => `load-more-${attrs.optionId}`,
buildKey: (attrs) => `load-more-${attrs.optionId}`,
defaultState() {
return { loading: false };
@@ -108,18 +108,18 @@ createWidget("discourse-poll-load-more", {
return this.sendWidgetAction("loadMore").finally(
() => (state.loading = false)
);
}
},
});
createWidget("discourse-poll-voters", {
tagName: "ul.poll-voters-list",
buildKey: attrs => `poll-voters-${attrs.optionId}`,
buildKey: (attrs) => `poll-voters-${attrs.optionId}`,
defaultState() {
return {
loaded: "new",
voters: [],
page: 1
page: 1,
};
},
@@ -133,8 +133,8 @@ createWidget("discourse-poll-voters", {
post_id: attrs.postId,
poll_name: attrs.pollName,
option_id: attrs.optionId,
page: state.page
}).then(result => {
page: state.page,
}).then((result) => {
state.loaded = "loaded";
state.page += 1;
@@ -143,9 +143,11 @@ createWidget("discourse-poll-voters", {
? result.voters
: result.voters[attrs.optionId];
const existingVoters = new Set(state.voters.map(voter => voter.username));
const existingVoters = new Set(
state.voters.map((voter) => voter.username)
);
newVoters.forEach(voter => {
newVoters.forEach((voter) => {
if (!existingVoters.has(voter.username)) {
existingVoters.add(voter.username);
state.voters.push(voter);
@@ -165,13 +167,13 @@ createWidget("discourse-poll-voters", {
state.voters = attrs.voters;
}
const contents = state.voters.map(user => {
const contents = state.voters.map((user) => {
return h("li", [
avatarFor("tiny", {
username: user.username,
template: user.avatar_template
template: user.avatar_template,
}),
" "
" ",
]);
});
@@ -180,12 +182,12 @@ createWidget("discourse-poll-voters", {
}
return h("div.poll-voters", contents);
}
},
});
createWidget("discourse-poll-standard-results", {
tagName: "ul.results",
buildKey: attrs => `poll-standard-results-${attrs.id}`,
buildKey: (attrs) => `poll-standard-results-${attrs.id}`,
defaultState() {
return { loaded: false };
@@ -196,8 +198,8 @@ createWidget("discourse-poll-standard-results", {
return _fetchVoters({
post_id: attrs.post.id,
poll_name: attrs.poll.get("name")
}).then(result => {
poll_name: attrs.poll.get("name"),
}).then((result) => {
state.voters = result.voters;
this.scheduleRerender();
});
@@ -233,7 +235,7 @@ createWidget("discourse-poll-standard-results", {
const percentages =
voters === 0
? Array(ordered.length).fill(0)
: ordered.map(o => (100 * o.votes) / voters);
: ordered.map((o) => (100 * o.votes) / voters);
const rounded = attrs.isMultiple
? percentages.map(Math.floor)
@@ -265,7 +267,7 @@ createWidget("discourse-poll-standard-results", {
optionId: option.id,
pollName: poll.get("name"),
totalVotes: option.votes,
voters: (state.voters && state.voters[option.id]) || []
voters: (state.voters && state.voters[option.id]) || [],
})
);
}
@@ -273,11 +275,11 @@ createWidget("discourse-poll-standard-results", {
return h("li", { className: `${chosen ? "chosen" : ""}` }, contents);
});
}
}
},
});
createWidget("discourse-poll-number-results", {
buildKey: attrs => `poll-number-results-${attrs.id}`,
buildKey: (attrs) => `poll-number-results-${attrs.id}`,
defaultState() {
return { loaded: false };
@@ -288,8 +290,8 @@ createWidget("discourse-poll-number-results", {
return _fetchVoters({
post_id: attrs.post.id,
poll_name: attrs.poll.get("name")
}).then(result => {
poll_name: attrs.poll.get("name"),
}).then((result) => {
state.voters = result.voters;
this.scheduleRerender();
});
@@ -309,7 +311,7 @@ createWidget("discourse-poll-number-results", {
h(
"div.poll-results-number-rating",
new RawHtml({ html: `<span>${averageRating}</span>` })
)
),
];
if (poll.get("public")) {
@@ -324,13 +326,13 @@ createWidget("discourse-poll-number-results", {
voters: state.voters || [],
postId: attrs.post.id,
pollName: poll.get("name"),
pollType: poll.get("type")
pollType: poll.get("type"),
})
);
}
return contents;
}
},
});
createWidget("discourse-poll-container", {
@@ -362,11 +364,11 @@ createWidget("discourse-poll-container", {
contents.push(
h(
"ul",
options.map(option => {
options.map((option) => {
return this.attach("discourse-poll-option", {
option,
isMultiple: attrs.isMultiple,
vote: attrs.vote
vote: attrs.vote,
});
})
)
@@ -374,7 +376,7 @@ createWidget("discourse-poll-container", {
return contents;
}
}
},
});
createWidget("discourse-poll-info", {
@@ -390,11 +392,11 @@ createWidget("discourse-poll-info", {
if (max < options) {
return I18n.t("poll.multiple.help.between_min_and_max_options", {
min,
max
max,
});
} else {
return I18n.t("poll.multiple.help.at_least_min_options", {
count: min
count: min,
});
}
} else if (max <= options) {
@@ -409,8 +411,8 @@ createWidget("discourse-poll-info", {
const contents = [
h("p", [
h("span.info-number", count.toString()),
h("span.info-label", I18n.t("poll.voters", { count }))
])
h("span.info-label", I18n.t("poll.voters", { count })),
]),
];
if (attrs.isMultiple) {
@@ -425,7 +427,7 @@ createWidget("discourse-poll-info", {
h(
"span.info-label",
I18n.t("poll.total_votes", { count: totalVotes })
)
),
])
);
} else {
@@ -450,7 +452,7 @@ createWidget("discourse-poll-info", {
}
return contents;
}
},
});
function clearPieChart(id) {
@@ -478,9 +480,9 @@ createWidget("discourse-poll-pie-canvas", {
buildAttributes(attrs) {
return {
id: `poll-results-chart-${attrs.id}`
id: `poll-results-chart-${attrs.id}`,
};
}
},
});
createWidget("discourse-poll-pie-chart", {
@@ -499,7 +501,7 @@ createWidget("discourse-poll-pie-chart", {
label: "poll.group-results.label",
title: "poll.group-results.title",
icon: "far-eye",
action: "showBreakdown"
action: "showBreakdown",
});
contents.push(button);
@@ -511,37 +513,37 @@ createWidget("discourse-poll-pie-chart", {
contents.push(h(`div#poll-results-legend-${attrs.id}.pie-chart-legends`));
return contents;
}
},
});
function pieChartConfig(data, labels, opts = {}) {
const aspectRatio = "aspectRatio" in opts ? opts.aspectRatio : 2.2;
const strippedLabels = labels.map(l => stripHtml(l));
const strippedLabels = labels.map((l) => stripHtml(l));
return {
type: PIE_CHART_TYPE,
data: {
datasets: [
{
data,
backgroundColor: getColors(data.length)
}
backgroundColor: getColors(data.length),
},
],
labels: strippedLabels
labels: strippedLabels,
},
options: {
responsive: true,
aspectRatio,
animation: { duration: 0 },
legend: { display: false },
legendCallback: function(chart) {
legendCallback: function (chart) {
let legends = "";
for (let i = 0; i < labels.length; i++) {
legends += `<div class="legend"><span class="swatch" style="background-color:
${chart.data.datasets[0].backgroundColor[i]}"></span>${labels[i]}</div>`;
}
return legends;
}
}
},
},
};
}
@@ -576,7 +578,7 @@ createWidget("discourse-poll-buttons", {
label: "poll.cast-votes.label",
title: "poll.cast-votes.title",
disabled: castVotesDisabled,
action: "castVotes"
action: "castVotes",
})
);
contents.push(" ");
@@ -590,7 +592,7 @@ createWidget("discourse-poll-buttons", {
title: "poll.hide-results.title",
icon: "far-eye-slash",
disabled: hideResultsDisabled,
action: "toggleResults"
action: "toggleResults",
})
);
} else {
@@ -608,7 +610,7 @@ createWidget("discourse-poll-buttons", {
title: "poll.show-results.title",
icon: "far-eye",
disabled: poll.get("voters") === 0,
action: "toggleResults"
action: "toggleResults",
})
);
}
@@ -622,7 +624,7 @@ createWidget("discourse-poll-buttons", {
title: "poll.export-results.title",
icon: "download",
disabled: poll.voters === 0,
action: "exportResults"
action: "exportResults",
})
);
}
@@ -643,7 +645,7 @@ createWidget("discourse-poll-buttons", {
contents.push(
new RawHtml({
html: `<span class="info-text" title="${title}">${label}</span>`
html: `<span class="info-text" title="${title}">${label}</span>`,
})
);
}
@@ -662,7 +664,7 @@ createWidget("discourse-poll-buttons", {
label: "poll.open.label",
title: "poll.open.title",
icon: "unlock-alt",
action: "toggleStatus"
action: "toggleStatus",
})
);
}
@@ -673,19 +675,19 @@ createWidget("discourse-poll-buttons", {
label: "poll.close.label",
title: "poll.close.title",
icon: "lock",
action: "toggleStatus"
action: "toggleStatus",
})
);
}
}
return contents;
}
},
});
export default createWidget("discourse-poll", {
tagName: "div",
buildKey: attrs => `poll-${attrs.id}`,
buildKey: (attrs) => `poll-${attrs.id}`,
buildAttributes(attrs) {
let cssClasses = "poll";
@@ -693,7 +695,7 @@ export default createWidget("discourse-poll", {
return {
class: cssClasses,
"data-poll-name": attrs.poll.get("name"),
"data-poll-type": attrs.poll.get("type")
"data-poll-type": attrs.poll.get("type"),
};
},
@@ -724,13 +726,13 @@ export default createWidget("discourse-poll", {
isMultiple: this.isMultiple(),
max: this.max(),
min: this.min(),
showResults
showResults,
});
return h("div", [
this.attach("discourse-poll-container", newAttrs),
this.attach("discourse-poll-info", newAttrs),
this.attach("discourse-poll-buttons", newAttrs)
this.attach("discourse-poll-buttons", newAttrs),
]);
},
@@ -801,7 +803,7 @@ export default createWidget("discourse-poll", {
I18n.t(this.isClosed() ? "poll.open.confirm" : "poll.close.confirm"),
I18n.t("no_value"),
I18n.t("yes_value"),
confirmed => {
(confirmed) => {
if (confirmed) {
state.loading = true;
const status = this.isClosed() ? "open" : "closed";
@@ -811,8 +813,8 @@ export default createWidget("discourse-poll", {
data: {
post_id: post.get("id"),
poll_name: poll.get("name"),
status
}
status,
},
})
.then(() => {
poll.set("status", status);
@@ -821,7 +823,7 @@ export default createWidget("discourse-poll", {
}
this.scheduleRerender();
})
.catch(error => {
.catch((error) => {
if (error) {
popupAjaxError(error);
} else {
@@ -852,17 +854,17 @@ export default createWidget("discourse-poll", {
// needed for data-explorer route compatibility
params: JSON.stringify({
poll_name: attrs.poll.name,
post_id: attrs.post.id.toString() // needed for data-explorer route compatibility
post_id: attrs.post.id.toString(), // needed for data-explorer route compatibility
}),
explain: false,
limit: 1000000,
download: 1
}
download: 1,
},
})
.then(csvContent => {
.then((csvContent) => {
const downloadLink = document.createElement("a");
const blob = new Blob([csvContent], {
type: "text/csv;charset=utf-8;"
type: "text/csv;charset=utf-8;",
});
downloadLink.href = URL.createObjectURL(blob);
downloadLink.setAttribute(
@@ -872,7 +874,7 @@ export default createWidget("discourse-poll", {
downloadLink.click();
downloadLink.remove();
})
.catch(error => {
.catch((error) => {
if (error) {
popupAjaxError(error);
} else {
@@ -926,8 +928,8 @@ export default createWidget("discourse-poll", {
data: {
post_id: attrs.post.id,
poll_name: attrs.poll.get("name"),
options: attrs.vote
}
options: attrs.vote,
},
})
.then(({ poll }) => {
attrs.poll.setProperties(poll);
@@ -942,7 +944,7 @@ export default createWidget("discourse-poll", {
}
}
})
.catch(error => {
.catch((error) => {
if (error) {
popupAjaxError(error);
} else {
@@ -959,8 +961,8 @@ export default createWidget("discourse-poll", {
model: this.attrs,
panels: [
{ id: "percentage", title: "poll.breakdown.percentage" },
{ id: "count", title: "poll.breakdown.count" }
]
{ id: "count", title: "poll.breakdown.count" },
],
});
}
},
});