Events Plugin 📆

Will try to repro this.

2 Likes

How can I execute javascript after the calendar page has loaded?


edit: I explain my case.
I was asked to have multi-colored events, like:

I don’t want to create a fork of the plugin, so I achieved something with the following code.
The colors are related to event tags and replace the default category color.

I added the tag list in the event HTML this way: data-tags="{{event.topic.tags}}"

<script type="text/x-handlebars" data-template-name="javascripts/components/events-calendar-event">
<div class="{{event.classes}}" data-tags="{{event.topic.tags}}" {{action 'selectEvent' event.topic.url}} style="{{event.listStyle}}">
  {{#unless event.allDay}}
    <span style='{{event.dotStyle}}'>{{d-icon 'circle'}}</span>
  {{/unless}}
  {{#if event.time}}
    <span class="time">{{event.time}}</span>
  {{/if}}
  {{#if event.title}}
    <span class="title" style="{{event.titleStyle}}">{{replace-emoji event.title}}</span>
  {{/if}}
</div>

{{#if showEventCard}}
  {{events-calendar-card topic=event.topic selectEvent="selectEvent"}}
{{/if}}
</script>

I generate stripped patterns:

<script type="text/discourse-plugin" version="0.8.23">
api.onPageChange((url, title) => {
    // tags colors
    let colors = {muni: "#91D0B5", road: "#8ABBE2", freestyle: "#CFB3D3"};

    let events = document.getElementsByClassName("event");
    for (var i = 0; i < events.length; i++) {
        let event = events[i];
        let gradient = "";
        let tags = event.getAttribute("data-tags").split(",");
        for (j = 1; j <= tags.length; j++) {
            gradient +=
                ", " +
                colors[tags[j - 1]] +
                " " +
                j * 8 +
                "px, " +
                colors[tags[j - 1]] +
                " " +
                (j * 8 + 8) +
                "px";
        }
        event.style.background = "repeating-linear-gradient(-45deg" + gradient + ")";
    }
});
</script>

And I added a bit of CSS.

The result:
2 tags event:

3 tags event:
image

The issue I encounter is that my javascript is executed at the page change and won’t apply stripped colors on previous/next months’ events since the calendar dynamically loads its content.

If I’m in October and and I click “next” twice, going for December, this is how it appears:

This is why I’d like my js to be executed when the calendar content has loaded.

1 Like

I tried another method and achieved the striped effect by editing the function eventsForDay in /assets/javascripts/discourse/lib/date-utilities.js.es6:

I replaced this line:

let tStyle = `width:calc((100%*${daysInRow}) - ${buffer}px);background-color:#${topic.category.color};`;

By:

let tStyle = `width:calc((100%*${daysInRow}) - ${buffer}px);`;

And I added this:

if (topic.tags.length > 0) {
  let colors = {muni: "#91D0B5", road: "#8ABBE2", freestyle: "#CFB3D3"};
  let gradient = "";
  for (let i = 1; i <= topic.tags.length; i++) {
    gradient +=
      ", " +
      colors[topic.tags[i - 1]] +
      " " +
      i * 8 +
      "px, " +
      colors[topic.tags[i - 1]] +
      " " +
      (i * 8 + 8) +
      "px";
  }
   attrs['listStyle'] += `background:repeating-linear-gradient(-45deg ${gradient});`;
}

It works very well and it’s a cleaner way to do what I want to achieve. However, I don’t know how to override this function or file without having to create a fork of the plugin…

1 Like

plugin seems to be incompatible with the latest Discourse version.
from the rebuild log file:

1: from /var/www/discourse/lib/plugin/instance.rb:417:in block in notify_after_initialize' /var/www/discourse/plugins/discourse-events/plugin.rb:190:in block in activate!’: uninitialized constant #Class:0x0000562a2a10fa90::SCOPES
Did you mean? Sprockets (NameError)

** INCOMPATIBLE PLUGIN **

You are unable to build Discourse due to errors in the plugin at
/var/www/discourse/plugins/discourse-events

Please try removing this plugin and rebuilding again!

3 Likes

seems that it had been a problem in Discourse and not in the plugin.
In the latest beta version of Discourse at least the plugins is working again.

1 Like

I can confirm that it is currently not possible to rebuild the latest stable version of Discourse with the current events plugin. :worried:

Unfortunately we can’t switch to tests-passed — we choose the stable branch precisely to avoid this sort of issues. Is anyone looking into this?

I have tried rebuilding with v2.5.2 (which used to work) and that fails with the same error, so I’m not sure where the issue is. Is there a particular commit (of the plugin or of stable Discourse) that I can point the container to?

1 Like

Our support policy is to ensure compatibility with the latest tests-passed version of discourse(due to the fact that its the default setting in discourse_docker). Although, we would like to understand how many of the users of Pavilion family Plugins are on stable branch of discourse.

Also, we’re planning to depricate the events plugin in favour of the discourse team’s events plugin in the near future.

2 Likes

I understand that developers have to look forward to keep compatibility with the future of Discourse — that makes sense. But if there’s no stable branch of sorts for the plugin, then it leaves people looking for a stable setup on a scenario where their setup breaks because due to a beta version they are not using.

Any tips on what commit broke the compatibility? I could try to work with that, but I’m lost on what change made this.

Edit to add: for anyone who has trouble with this and needs a temporary workaround, this commit seems to be the culprit.

2 Likes

There was an issue with webcal api keys which has been resolved.

Thanks for the report @md-misko

3 Likes

again the plugin seems to be incompatible with the latest discourse release 2.6.0.beta5 ( 2bb7676ba4 ).
This time it creates just a blank page when accessing the site. But other than last time there had not been an error when using admin/upgrade.
After disabling the plugin and rebuilding the container Discourse is working fine again.

3 Likes

Hi, does this Events plugin produce the “Add To Calendar” links at the top of posts, like on this page:

Also, here in 2021 what are people’s opinions on using this Pavilion Events plugin vs the official Calendar plugin?

I’m mainly interested in finding ways to make it easy to aggregate views of topics on a calendar, and would also love the ability for our users to be able to add individual events onto their own Google / .ics calendars.

Cheers.

Hey there,

As mentioned in the OP

Please take a moment to consider whether the new Event features in the Discourse Calendar plugin made by the Discourse team are right for you. If they meet your needs, we recommend using that plugin. You should only use this plugin if you’ve already first considered Discourse Calendar.

We recommend you use the Discourse Calendar Plugin if you can. We only support this plugin for specific use cases that are not fulfiled by that plugin. Happily, the Calendar Plugin has both features you mentioned.

Yup, that’s this plugin. But, as mentioned, it sounds like you’ve got a good use case for Discourse Calendar, so I suggest you use that.

Internally, we actually use the Discourse Calendar Plugin to organise events for our members, rather than this plugin. We support specific use cases for a few clients, and we’re open to specific use cases if anyone has any, but that’s it.

2 Likes

Thanks Angus. I read all that advice and I was asking you specifically because it looked like you were involved with setting up the Legal Empowerment Network community in question, and I liked how it was working. But glad to hear you recommend the official Calendar plugin; I’ll explore that.

2 Likes

Am I correct in saying that the official Discourse Calendar plugin doesn’t have anything like the “Agenda” filter in the topic list? Sorting the topic list by the event dates in a topic is one of the main use cases I’m interested in. It’s more so for project management (treating topics as tasks and scheduling them accordingly) than events.

3 Likes

I’m thinking of adding something like this also. Have you come up with any solutions?

This is my thought: Each event should be considered a reply like pinning a topic. The add event button becomes a drop-down menu that lists all events in the topic.

1 Like

I’ll check and get back.

We aren’t developing new features for this plugin. We’ve depricated this in favour of the Official Events feature in the discourse-calendar plugin.

1 Like

I don’t think there’s an agenda style topic list in the official plugin yet.

Does anyone know if there’s a new link that formerly contained the content at https://thepavilion.io/t/subscribing-to-events-ical-and-rss-feeds/2883 has gone?

When this plugin is running in a restricted category, we see:

… but the documentation link is broken and generates a 404. I looked around the site in question and here too, but didn’t know if there was some other home for this user instruction.

1 Like

We moved that topic to a closed category somehow. Need to bring it back to public. We’ll discuss and get back soon.

p.s.
The page should be back now.

2 Likes