FEATURE: allows to add a url to an event (#52)

FEATURE: allows to add a url to an event (#52)

diff --git a/app/controllers/discourse_post_event/events_controller.rb b/app/controllers/discourse_post_event/events_controller.rb
index efa676f..cd3a4b9 100644
--- a/app/controllers/discourse_post_event/events_controller.rb
+++ b/app/controllers/discourse_post_event/events_controller.rb
@@ -92,6 +92,7 @@ module DiscoursePostEvent
           :starts_at,
           :ends_at,
           :status,
+          :url,
           raw_invitees: []
         )
     end
diff --git a/app/models/discourse_post_event/event.rb b/app/models/discourse_post_event/event.rb
index f413038..c0e11fc 100644
--- a/app/models/discourse_post_event/event.rb
+++ b/app/models/discourse_post_event/event.rb
@@ -162,6 +162,7 @@ module DiscoursePostEvent
           name: event_params[:name],
           starts_at: event_params[:start] || event.starts_at,
           ends_at: event_params[:end],
+          url: event_params[:"url"],
           status: event_params[:status].present? ? Event.statuses[event_params[:status].to_sym] : event.status,
           raw_invitees: event_params[:"allowed-groups"] ? event_params[:"allowed-groups"].split(',') : nil
         }
diff --git a/app/serializers/discourse_post_event/event_serializer.rb b/app/serializers/discourse_post_event/event_serializer.rb
index 235b54e..3dd9253 100644
--- a/app/serializers/discourse_post_event/event_serializer.rb
+++ b/app/serializers/discourse_post_event/event_serializer.rb
@@ -17,6 +17,7 @@ module DiscoursePostEvent
     attributes :can_update_attendance
     attributes :is_expired
     attributes :should_display_invitees
+    attributes :url
 
     def can_act_on_discourse_post_event
       scope.can_act_on_discourse_post_event?(object)
diff --git a/assets/javascripts/discourse/controllers/discourse-post-event-builder.js.es6 b/assets/javascripts/discourse/controllers/discourse-post-event-builder.js.es6
index 4277d64..7351f9d 100644
--- a/assets/javascripts/discourse/controllers/discourse-post-event-builder.js.es6
+++ b/assets/javascripts/discourse/controllers/discourse-post-event-builder.js.es6
@@ -67,7 +67,6 @@ export default Controller.extend(ModalFunctionality, {
             .then(post => {
               const raw = post.raw;
               const newRaw = this._removeRawEvent(raw);
-
               const props = {
                 raw: newRaw,
                 edit_reason: I18n.t("discourse_post_event.destroy_event")
@@ -150,6 +149,10 @@ export default Controller.extend(ModalFunctionality, {
       eventParams.name = this.model.eventModel.name;
     }
 
+    if (this.model.eventModel.url) {
+      eventParams.url = this.model.eventModel.url;
+    }
+
     if (this.endsAt) {
       eventParams.end = moment(this.endsAt)
         .utc()
@@ -170,13 +173,12 @@ export default Controller.extend(ModalFunctionality, {
     return raw.replace(eventRegex, "");
   },
 
-  _replaceRawEvent(eventparams, raw) {
+  _replaceRawEvent(eventParams, raw) {
     const eventRegex = new RegExp(`\\[event\\s(.*?)\\]`, "m");
     const eventMatches = raw.match(eventRegex);
 
     if (eventMatches && eventMatches[1]) {
       const markdownParams = [];
-      const eventParams = this._buildEventParams();
       Object.keys(eventParams).forEach(eventParam => {
         const value = eventParams[eventParam];
         if (value && value.length) {
diff --git a/assets/javascripts/discourse/models/discourse-post-event-event.js.es6 b/assets/javascripts/discourse/models/discourse-post-event-event.js.es6
index c3f4f07..ac14bfe 100644
--- a/assets/javascripts/discourse/models/discourse-post-event-event.js.es6
+++ b/assets/javascripts/discourse/models/discourse-post-event-event.js.es6
@@ -6,6 +6,7 @@ const ATTRIBUTES = {
   starts_at: {},
   ends_at: {},
   raw_invitees: {},
+  url: {},
   status: {
     transform(value) {
       return STATUSES[value];
diff --git a/assets/javascripts/discourse/templates/modal/discourse-post-event-builder.hbs b/assets/javascripts/discourse/templates/modal/discourse-post-event-builder.hbs
index e1cf203..80af407 100644
--- a/assets/javascripts/discourse/templates/modal/discourse-post-event-builder.hbs
+++ b/assets/javascripts/discourse/templates/modal/discourse-post-event-builder.hbs
@@ -11,6 +11,7 @@
         clearable=true
         onChange=(action "onChangeDates")
       }}
+
       {{#event-field class="name" label="discourse_post_event.builder_modal.name.label"}}
         {{input
           value=(readonly model.eventModel.name)
@@ -19,6 +20,14 @@
         }}
       {{/event-field}}
 
+      {{#event-field class="url" label="discourse_post_event.builder_modal.url.label"}}
+        {{input
+          value=(readonly model.eventModel.url)
+          placeholderKey="discourse_post_event.builder_modal.url.placeholder"
+          input=(action (mut model.eventModel.url) value="target.value")
+        }}
+      {{/event-field}}
+
       {{#event-field label="discourse_post_event.builder_modal.status.label"}}
         <label class="radio-label">
           {{radio-button
diff --git a/assets/javascripts/discourse/widgets/discourse-post-event-url.js.es6 b/assets/javascripts/discourse/widgets/discourse-post-event-url.js.es6
new file mode 100644
index 0000000..6568bc2
--- /dev/null
+++ b/assets/javascripts/discourse/widgets/discourse-post-event-url.js.es6
@@ -0,0 +1,25 @@
+import RawHtml from "discourse/widgets/raw-html";
+import { iconNode } from "discourse-common/lib/icon-library";
+import { h } from "virtual-dom";
+import { createWidget } from "discourse/widgets/widget";
+
+export default createWidget("discourse-post-event-url", {
+  tagName: "section.event-url",
+
+  html(attrs) {
+    return [
+      iconNode("link"),
+      h(
+        "a.url",
+        {
+          attributes: {
+            href: attrs.url,
+            target: "_blank",
+            rel: "noopener noreferrer"
+          }
+        },
+        attrs.url
+      )
+    ];
+  }
+});
diff --git a/assets/javascripts/discourse/widgets/discourse-post-event.js.es6 b/assets/javascripts/discourse/widgets/discourse-post-event.js.es6
index c96e3ff..4acbf71 100644
--- a/assets/javascripts/discourse/widgets/discourse-post-event.js.es6
+++ b/assets/javascripts/discourse/widgets/discourse-post-event.js.es6
@@ -180,6 +180,16 @@ export default createWidget("discourse-post-event", {
         </section>
       {{/if}}
 
+      {{#if this.state.eventModel.url}}
+        <hr />
+
+        {{attach widget="discourse-post-event-url"
+          attrs=(hash
+            url=this.state.eventModel.url
+          )
+        }}
+      {{/if}}
+
       <hr />
 
       {{attach widget="discourse-post-event-dates"
diff --git a/assets/javascripts/initializers/discourse-post-event-decorator.js.es6 b/assets/javascripts/initializers/discourse-post-event-decorator.js.es6
index c3fbcbe..a0b2394 100644
--- a/assets/javascripts/initializers/discourse-post-event-decorator.js.es6
+++ b/assets/javascripts/initializers/discourse-post-event-decorator.js.es6
@@ -85,6 +85,7 @@ function _attachWidget(api, cooked, eventModel) {
     eventContainer.innerHTML = "";
 
     const datesHeight = 50;
+    const urlHeight = 50;
     const headerHeight = 75;
     const bordersHeight = 10;
     const separatorsHeight = 4;
@@ -100,6 +101,10 @@ function _attachWidget(api, cooked, eventModel) {
       widgetHeight += 60;
     }
 
+    if (eventModel.url) {
+      widgetHeight += urlHeight;
+    }
+
     eventContainer.classList.add("is-loading");
     eventContainer.style.height = `${widgetHeight}px`;
 
diff --git a/assets/javascripts/lib/discourse-markdown/discourse-post-event-block.js.es6 b/assets/javascripts/lib/discourse-markdown/discourse-post-event-block.js.es6
index ac0a2af..df49f9d 100644
--- a/assets/javascripts/lib/discourse-markdown/discourse-post-event-block.js.es6
+++ b/assets/javascripts/lib/discourse-markdown/discourse-post-event-block.js.es6
@@ -27,6 +27,10 @@ const rule = {
       token.attrs.push(["data-allowed-groups", info.attrs.allowedGroups]);
     }
 
+    if (info.attrs.url) {

[... diff too long, it was truncated ...]

GitHub sha: c6b531d7

1 Like

This commit appears in #52 which was merged by jjaffeux.