minor refactorings
This commit is contained in:
parent
90edefff0a
commit
d38d3478c6
|
|
@ -38,17 +38,13 @@ export default Component.extend({
|
|||
this._super(...arguments);
|
||||
|
||||
(this.events || []).forEach(event => {
|
||||
const { starts_at, ends_at, post } = event;
|
||||
this._calendar.addEvent({
|
||||
title: formatEventName(event),
|
||||
start: event.starts_at,
|
||||
end: event.ends_at || event.starts_at,
|
||||
allDay: !isNotFullDayEvent(
|
||||
moment(event.starts_at),
|
||||
moment(event.ends_at)
|
||||
),
|
||||
url: Discourse.getURL(
|
||||
`/t/-/${event.post.topic.id}/${event.post.post_number}`
|
||||
)
|
||||
start: starts_at,
|
||||
end: ends_at || starts_at,
|
||||
allDay: !isNotFullDayEvent(moment(starts_at), moment(ends_at)),
|
||||
url: Discourse.getURL(`/t/-/${post.topic.id}/${post.post_number}`)
|
||||
});
|
||||
});
|
||||
this._calendar.render();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { Promise } from "rsvp";
|
||||
import { isPresent } from "@ember/utils";
|
||||
import DiscourseURL from "discourse/lib/url";
|
||||
import { Promise } from "rsvp";
|
||||
import { cookAsync } from "discourse/lib/text";
|
||||
import { escapeExpression } from "discourse/lib/utilities";
|
||||
import loadScript from "discourse/lib/load-script";
|
||||
|
|
@ -25,6 +25,14 @@ function stringToHexColor(str) {
|
|||
return hex;
|
||||
}
|
||||
|
||||
function loadFullCalendar() {
|
||||
return new Promise(resolve =>
|
||||
loadScript(
|
||||
"/plugins/discourse-calendar/javascripts/fullcalendar-with-moment-timezone.min.js"
|
||||
).then(resolve)
|
||||
);
|
||||
}
|
||||
|
||||
function initializeDiscourseCalendar(api) {
|
||||
let _topicController;
|
||||
const outletName = Discourse.SiteSettings.calendar_categories_outlet;
|
||||
|
|
@ -71,9 +79,7 @@ function initializeDiscourseCalendar(api) {
|
|||
'<div class="calendar"><div class="spinner medium"></div></div>'
|
||||
);
|
||||
$calendarContainer.html($spinner);
|
||||
loadScript(
|
||||
"/plugins/discourse-calendar/javascripts/fullcalendar-with-moment-timezone.min.js"
|
||||
).then(() => {
|
||||
loadFullCalendar().then(() => {
|
||||
const options = [`postId=${postId}`];
|
||||
|
||||
const optionals = ["weekends", "tzPicker", "defaultView"];
|
||||
|
|
@ -114,11 +120,9 @@ function initializeDiscourseCalendar(api) {
|
|||
const $calendar = $op.find(".calendar").first();
|
||||
|
||||
if (post && $calendar.length > 0) {
|
||||
ajax(`/posts/${post.id}.json`).then(post => {
|
||||
loadScript(
|
||||
"/plugins/discourse-calendar/javascripts/fullcalendar-with-moment-timezone.min.js"
|
||||
).then(() => render($calendar, post));
|
||||
});
|
||||
ajax(`/posts/${post.id}.json`).then(post =>
|
||||
loadFullCalendar().then(() => render($calendar, post))
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -154,9 +158,7 @@ function initializeDiscourseCalendar(api) {
|
|||
return;
|
||||
}
|
||||
|
||||
loadScript(
|
||||
"/plugins/discourse-calendar/javascripts/fullcalendar-with-moment-timezone.min.js"
|
||||
).then(() => render($calendar, helper.getModel()));
|
||||
loadFullCalendar().then(() => render($calendar, helper.getModel()));
|
||||
}
|
||||
|
||||
function _buildCalendar($calendar, timeZone) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue