Events Plugin šŸ“†

Will try to repro this.

3 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.

3 Likes

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ā€¦

2 Likes

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!

4 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.

2 Likes

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?

2 Likes

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.

3 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.

3 Likes

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

Thanks for the report @md-misko

4 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.

4 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.

1 Like

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.

3 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.

3 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.

4 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.

2 Likes

Iā€™ll check and get back.

1 Like

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.

2 Likes

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

1 Like

Does anyone know if thereā€™s a new link that formerly contained the content at Pavilion 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.

2 Likes

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.

3 Likes