mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 06:01:26 +08:00
DEV: apply coding standards to plugins (#10594)
This commit is contained in:
@ -40,27 +40,27 @@ export default Component.extend({
|
||||
timezones: [],
|
||||
formats: (this.siteSettings.discourse_local_dates_default_formats || "")
|
||||
.split("|")
|
||||
.filter(f => f),
|
||||
.filter((f) => f),
|
||||
timezone: moment.tz.guess(),
|
||||
date: moment().format(this.dateFormat)
|
||||
date: moment().format(this.dateFormat),
|
||||
});
|
||||
},
|
||||
|
||||
didInsertElement() {
|
||||
this._super(...arguments);
|
||||
|
||||
this._setupPicker().then(picker => {
|
||||
this._setupPicker().then((picker) => {
|
||||
this._picker = picker;
|
||||
this.send("focusFrom");
|
||||
});
|
||||
},
|
||||
|
||||
@observes("markup")
|
||||
_renderPreview: discourseDebounce(function() {
|
||||
_renderPreview: discourseDebounce(function () {
|
||||
const markup = this.markup;
|
||||
|
||||
if (markup) {
|
||||
cookAsync(markup).then(result => {
|
||||
cookAsync(markup).then((result) => {
|
||||
this.set("currentPreview", result);
|
||||
schedule("afterRender", () =>
|
||||
this.$(".preview .discourse-local-date").applyLocalDates()
|
||||
@ -121,7 +121,7 @@ export default Component.extend({
|
||||
time,
|
||||
dateTime,
|
||||
format,
|
||||
range: isRange ? "start" : false
|
||||
range: isRange ? "start" : false,
|
||||
});
|
||||
},
|
||||
|
||||
@ -154,7 +154,7 @@ export default Component.extend({
|
||||
time,
|
||||
dateTime,
|
||||
format,
|
||||
range: isRange ? "end" : false
|
||||
range: isRange ? "end" : false,
|
||||
});
|
||||
},
|
||||
|
||||
@ -164,7 +164,7 @@ export default Component.extend({
|
||||
recurring,
|
||||
timezones,
|
||||
timezone,
|
||||
format
|
||||
format,
|
||||
});
|
||||
},
|
||||
|
||||
@ -177,7 +177,7 @@ export default Component.extend({
|
||||
return EmberObject.create({
|
||||
from: fromConfig,
|
||||
to: toConfig,
|
||||
options
|
||||
options,
|
||||
});
|
||||
},
|
||||
|
||||
@ -198,18 +198,15 @@ export default Component.extend({
|
||||
|
||||
@computed("currentUserTimezone")
|
||||
formatedCurrentUserTimezone(timezone) {
|
||||
return timezone
|
||||
.replace("_", " ")
|
||||
.replace("Etc/", "")
|
||||
.split("/");
|
||||
return timezone.replace("_", " ").replace("Etc/", "").split("/");
|
||||
},
|
||||
|
||||
@computed("formats")
|
||||
previewedFormats(formats) {
|
||||
return formats.map(format => {
|
||||
return formats.map((format) => {
|
||||
return {
|
||||
format: format,
|
||||
preview: moment().format(format)
|
||||
preview: moment().format(format),
|
||||
};
|
||||
});
|
||||
},
|
||||
@ -221,36 +218,36 @@ export default Component.extend({
|
||||
return [
|
||||
{
|
||||
name: I18n.t(`${key}.every_day`),
|
||||
id: "1.days"
|
||||
id: "1.days",
|
||||
},
|
||||
{
|
||||
name: I18n.t(`${key}.every_week`),
|
||||
id: "1.weeks"
|
||||
id: "1.weeks",
|
||||
},
|
||||
{
|
||||
name: I18n.t(`${key}.every_two_weeks`),
|
||||
id: "2.weeks"
|
||||
id: "2.weeks",
|
||||
},
|
||||
{
|
||||
name: I18n.t(`${key}.every_month`),
|
||||
id: "1.months"
|
||||
id: "1.months",
|
||||
},
|
||||
{
|
||||
name: I18n.t(`${key}.every_two_months`),
|
||||
id: "2.months"
|
||||
id: "2.months",
|
||||
},
|
||||
{
|
||||
name: I18n.t(`${key}.every_three_months`),
|
||||
id: "3.months"
|
||||
id: "3.months",
|
||||
},
|
||||
{
|
||||
name: I18n.t(`${key}.every_six_months`),
|
||||
id: "6.months"
|
||||
id: "6.months",
|
||||
},
|
||||
{
|
||||
name: I18n.t(`${key}.every_year`),
|
||||
id: "1.years"
|
||||
}
|
||||
id: "1.years",
|
||||
},
|
||||
];
|
||||
},
|
||||
|
||||
@ -360,7 +357,7 @@ export default Component.extend({
|
||||
|
||||
cancel() {
|
||||
this._closeModal();
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
_setTimeIfValid(time, key) {
|
||||
@ -375,7 +372,7 @@ export default Component.extend({
|
||||
},
|
||||
|
||||
_setupPicker() {
|
||||
return new Promise(resolve => {
|
||||
return new Promise((resolve) => {
|
||||
loadScript("/javascripts/pikaday.js").then(() => {
|
||||
const options = {
|
||||
field: this.$(`.fake-input`)[0],
|
||||
@ -391,9 +388,9 @@ export default Component.extend({
|
||||
nextMonth: I18n.t("dates.next_month"),
|
||||
months: moment.months(),
|
||||
weekdays: moment.weekdays(),
|
||||
weekdaysShort: moment.weekdaysMin()
|
||||
weekdaysShort: moment.weekdaysMin(),
|
||||
},
|
||||
onSelect: date => {
|
||||
onSelect: (date) => {
|
||||
const formattedDate = moment(date).format("YYYY-MM-DD");
|
||||
|
||||
if (this.fromSelected) {
|
||||
@ -403,7 +400,7 @@ export default Component.extend({
|
||||
if (this.toSelected) {
|
||||
this.set("toDate", formattedDate);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
resolve(new Pikaday(options));
|
||||
@ -434,5 +431,5 @@ export default Component.extend({
|
||||
_closeModal() {
|
||||
const composer = Discourse.__container__.lookup("controller:composer");
|
||||
composer.send("closeModal");
|
||||
}
|
||||
},
|
||||
});
|
||||
|
@ -17,5 +17,5 @@ export default Controller.extend(ModalFunctionality, {
|
||||
);
|
||||
localDatesBtn && localDatesBtn.focus();
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
@ -13,18 +13,18 @@ const DATE_TEMPLATE = `
|
||||
|
||||
function initializeDiscourseLocalDates(api) {
|
||||
api.decorateCooked(
|
||||
$elem => $(".discourse-local-date", $elem).applyLocalDates(),
|
||||
($elem) => $(".discourse-local-date", $elem).applyLocalDates(),
|
||||
{ id: "discourse-local-date" }
|
||||
);
|
||||
|
||||
api.onToolbarCreate(toolbar => {
|
||||
api.onToolbarCreate((toolbar) => {
|
||||
toolbar.addButton({
|
||||
title: "discourse_local_dates.title",
|
||||
id: "local-dates",
|
||||
group: "extras",
|
||||
icon: "calendar-alt",
|
||||
sendAction: event =>
|
||||
toolbar.context.send("insertDiscourseLocalDate", event)
|
||||
sendAction: (event) =>
|
||||
toolbar.context.send("insertDiscourseLocalDate", event),
|
||||
});
|
||||
});
|
||||
|
||||
@ -32,10 +32,10 @@ function initializeDiscourseLocalDates(api) {
|
||||
actions: {
|
||||
insertDiscourseLocalDate(toolbarEvent) {
|
||||
showModal("discourse-local-dates-create-modal").setProperties({
|
||||
toolbarEvent
|
||||
toolbarEvent,
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@ -45,8 +45,8 @@ export default {
|
||||
initialize(container) {
|
||||
const siteSettings = container.lookup("site-settings:main");
|
||||
if (siteSettings.discourse_local_dates_enabled) {
|
||||
$.fn.applyLocalDates = function() {
|
||||
return this.each(function() {
|
||||
$.fn.applyLocalDates = function () {
|
||||
return this.each(function () {
|
||||
const opts = {};
|
||||
const dataset = this.dataset;
|
||||
opts.time = dataset.time;
|
||||
@ -70,7 +70,7 @@ export default {
|
||||
moment.tz.guess()
|
||||
).build();
|
||||
|
||||
const htmlPreviews = localDateBuilder.previews.map(preview => {
|
||||
const htmlPreviews = localDateBuilder.previews.map((preview) => {
|
||||
const previewNode = document.createElement("div");
|
||||
previewNode.classList.add("preview");
|
||||
if (preview.current) {
|
||||
@ -92,7 +92,7 @@ export default {
|
||||
|
||||
const previewsNode = document.createElement("div");
|
||||
previewsNode.classList.add("locale-dates-previews");
|
||||
htmlPreviews.forEach(htmlPreview =>
|
||||
htmlPreviews.forEach((htmlPreview) =>
|
||||
previewsNode.appendChild(htmlPreview)
|
||||
);
|
||||
|
||||
@ -110,5 +110,5 @@ export default {
|
||||
|
||||
withPluginApi("0.8.8", initializeDiscourseLocalDates);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
@ -25,7 +25,7 @@ export default class DateWithZoneHelper {
|
||||
"day",
|
||||
"hour",
|
||||
"minute",
|
||||
"second"
|
||||
"second",
|
||||
]),
|
||||
this.timezone
|
||||
);
|
||||
@ -79,7 +79,7 @@ export default class DateWithZoneHelper {
|
||||
minute: datetime.minute(),
|
||||
second: datetime.second(),
|
||||
timezone,
|
||||
localTimezone
|
||||
localTimezone,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ function addLocalDate(buffer, matches, state) {
|
||||
format: null,
|
||||
timezones: null,
|
||||
displayedTimezone: null,
|
||||
countdown: null
|
||||
countdown: null,
|
||||
};
|
||||
|
||||
const matchString = matches[1].replace(/„|“/g, '"');
|
||||
@ -64,14 +64,14 @@ function addLocalDate(buffer, matches, state) {
|
||||
if (config.countdown) {
|
||||
token.attrs.push([
|
||||
"data-countdown",
|
||||
state.md.utils.escapeHtml(config.countdown)
|
||||
state.md.utils.escapeHtml(config.countdown),
|
||||
]);
|
||||
}
|
||||
|
||||
if (config.calendar) {
|
||||
token.attrs.push([
|
||||
"data-calendar",
|
||||
state.md.utils.escapeHtml(config.calendar)
|
||||
state.md.utils.escapeHtml(config.calendar),
|
||||
]);
|
||||
}
|
||||
|
||||
@ -81,25 +81,25 @@ function addLocalDate(buffer, matches, state) {
|
||||
) {
|
||||
token.attrs.push([
|
||||
"data-displayed-timezone",
|
||||
state.md.utils.escapeHtml(config.displayedTimezone)
|
||||
state.md.utils.escapeHtml(config.displayedTimezone),
|
||||
]);
|
||||
}
|
||||
|
||||
if (config.timezones) {
|
||||
const timezones = config.timezones.split("|").filter(timezone => {
|
||||
const timezones = config.timezones.split("|").filter((timezone) => {
|
||||
return moment.tz.names().includes(timezone);
|
||||
});
|
||||
|
||||
token.attrs.push([
|
||||
"data-timezones",
|
||||
state.md.utils.escapeHtml(timezones.join("|"))
|
||||
state.md.utils.escapeHtml(timezones.join("|")),
|
||||
]);
|
||||
}
|
||||
|
||||
if (config.timezone && moment.tz.names().includes(config.timezone)) {
|
||||
token.attrs.push([
|
||||
"data-timezone",
|
||||
state.md.utils.escapeHtml(config.timezone)
|
||||
state.md.utils.escapeHtml(config.timezone),
|
||||
]);
|
||||
dateTime = moment.tz(dateTime, config.timezone);
|
||||
} else {
|
||||
@ -109,7 +109,7 @@ function addLocalDate(buffer, matches, state) {
|
||||
if (config.recurring) {
|
||||
token.attrs.push([
|
||||
"data-recurring",
|
||||
state.md.utils.escapeHtml(config.recurring)
|
||||
state.md.utils.escapeHtml(config.recurring),
|
||||
]);
|
||||
}
|
||||
|
||||
@ -141,7 +141,7 @@ export function setup(helper) {
|
||||
helper.whiteList([
|
||||
"span.discourse-local-date",
|
||||
"span[data-*]",
|
||||
"span[aria-label]"
|
||||
"span[aria-label]",
|
||||
]);
|
||||
|
||||
helper.registerOptions((opts, siteSettings) => {
|
||||
@ -152,10 +152,10 @@ export function setup(helper) {
|
||||
] = !!siteSettings.discourse_local_dates_enabled;
|
||||
});
|
||||
|
||||
helper.registerPlugin(md => {
|
||||
helper.registerPlugin((md) => {
|
||||
const rule = {
|
||||
matcher: /\[date(=.+?)\]/,
|
||||
onMatch: addLocalDate
|
||||
onMatch: addLocalDate,
|
||||
};
|
||||
|
||||
md.core.textPostProcess.ruler.push("discourse-local-dates", rule);
|
||||
|
@ -23,10 +23,10 @@ export default class LocalDateBuilder {
|
||||
}
|
||||
|
||||
build() {
|
||||
const [year, month, day] = this.date.split("-").map(x => parseInt(x, 10));
|
||||
const [year, month, day] = this.date.split("-").map((x) => parseInt(x, 10));
|
||||
const [hour, minute, second] = (this.time || "")
|
||||
.split(":")
|
||||
.map(x => (x ? parseInt(x, 10) : undefined));
|
||||
.map((x) => (x ? parseInt(x, 10) : undefined));
|
||||
|
||||
let displayedTimezone;
|
||||
if (this.time) {
|
||||
@ -44,7 +44,7 @@ export default class LocalDateBuilder {
|
||||
minute,
|
||||
second,
|
||||
timezone: this.timezone,
|
||||
localTimezone: this.localTimezone
|
||||
localTimezone: this.localTimezone,
|
||||
});
|
||||
|
||||
if (this.recurring) {
|
||||
@ -66,13 +66,13 @@ export default class LocalDateBuilder {
|
||||
moment.tz(this.localTimezone).isAfter(localDate.datetime),
|
||||
formated: this._applyFormatting(localDate, displayedTimezone),
|
||||
previews,
|
||||
textPreview: this._generateTextPreviews(previews)
|
||||
textPreview: this._generateTextPreviews(previews),
|
||||
};
|
||||
}
|
||||
|
||||
_generateTextPreviews(previews) {
|
||||
return previews
|
||||
.map(preview => {
|
||||
.map((preview) => {
|
||||
const formatedZone = this._zoneWithoutPrefix(preview.timezone);
|
||||
return `${formatedZone} ${preview.formated}`;
|
||||
})
|
||||
@ -83,7 +83,7 @@ export default class LocalDateBuilder {
|
||||
const previewedTimezones = [];
|
||||
|
||||
const timezones = this.timezones.filter(
|
||||
timezone => !this._isEqualZones(timezone, this.localTimezone)
|
||||
(timezone) => !this._isEqualZones(timezone, this.localTimezone)
|
||||
);
|
||||
|
||||
previewedTimezones.push({
|
||||
@ -96,7 +96,7 @@ export default class LocalDateBuilder {
|
||||
this.localTimezone
|
||||
),
|
||||
this.time
|
||||
)
|
||||
),
|
||||
});
|
||||
|
||||
if (
|
||||
@ -104,12 +104,12 @@ export default class LocalDateBuilder {
|
||||
displayedTimezone === this.localTimezone &&
|
||||
this.timezone !== displayedTimezone &&
|
||||
!this._isEqualZones(displayedTimezone, this.timezone) &&
|
||||
!this.timezones.any(t => this._isEqualZones(t, this.timezone))
|
||||
!this.timezones.any((t) => this._isEqualZones(t, this.timezone))
|
||||
) {
|
||||
timezones.unshift(this.timezone);
|
||||
}
|
||||
|
||||
timezones.forEach(timezone => {
|
||||
timezones.forEach((timezone) => {
|
||||
if (this._isEqualZones(timezone, displayedTimezone)) {
|
||||
return;
|
||||
}
|
||||
@ -127,7 +127,7 @@ export default class LocalDateBuilder {
|
||||
timezone
|
||||
),
|
||||
this.time
|
||||
)
|
||||
),
|
||||
});
|
||||
});
|
||||
|
||||
@ -158,7 +158,7 @@ export default class LocalDateBuilder {
|
||||
return [
|
||||
startRange.format("LLLL"),
|
||||
RANGE_SEPARATOR,
|
||||
endRange.format("LLLL")
|
||||
endRange.format("LLLL"),
|
||||
].join(" ");
|
||||
}
|
||||
}
|
||||
@ -209,19 +209,19 @@ export default class LocalDateBuilder {
|
||||
sameDay: this._translateCalendarKey(time, "today"),
|
||||
nextDay: this._translateCalendarKey(time, "tomorrow"),
|
||||
lastDay: this._translateCalendarKey(time, "yesterday"),
|
||||
sameElse: "L"
|
||||
sameElse: "L",
|
||||
};
|
||||
}
|
||||
|
||||
_translateCalendarKey(time, key) {
|
||||
const translated = I18n.t(`discourse_local_dates.relative_dates.${key}`, {
|
||||
time: "LT"
|
||||
time: "LT",
|
||||
});
|
||||
|
||||
if (time) {
|
||||
return translated
|
||||
.split("LT")
|
||||
.map(w => `[${w}]`)
|
||||
.map((w) => `[${w}]`)
|
||||
.join("LT");
|
||||
} else {
|
||||
return `[${translated.replace(" LT", "")}]`;
|
||||
@ -229,10 +229,7 @@ export default class LocalDateBuilder {
|
||||
}
|
||||
|
||||
_formatTimezone(timezone) {
|
||||
return timezone
|
||||
.replace("_", " ")
|
||||
.replace("Etc/", "")
|
||||
.split("/");
|
||||
return timezone.replace("_", " ").replace("Etc/", "").split("/");
|
||||
}
|
||||
|
||||
_zoneWithoutPrefix(timezone) {
|
||||
|
Reference in New Issue
Block a user