FEATURE: allows to add a url to an event (#52)
This commit is contained in:
parent
f4738ca442
commit
c6b531d741
|
@ -92,6 +92,7 @@ module DiscoursePostEvent
|
|||
:starts_at,
|
||||
:ends_at,
|
||||
:status,
|
||||
:url,
|
||||
raw_invitees: []
|
||||
)
|
||||
end
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -6,6 +6,7 @@ const ATTRIBUTES = {
|
|||
starts_at: {},
|
||||
ends_at: {},
|
||||
raw_invitees: {},
|
||||
url: {},
|
||||
status: {
|
||||
transform(value) {
|
||||
return STATUSES[value];
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
)
|
||||
];
|
||||
}
|
||||
});
|
|
@ -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"
|
||||
|
|
|
@ -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`;
|
||||
|
||||
|
|
|
@ -27,6 +27,10 @@ const rule = {
|
|||
token.attrs.push(["data-allowed-groups", info.attrs.allowedGroups]);
|
||||
}
|
||||
|
||||
if (info.attrs.url) {
|
||||
token.attrs.push(["data-url", info.attrs.url]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -62,7 +62,8 @@
|
|||
margin: 1em 0;
|
||||
flex-direction: column;
|
||||
|
||||
&.name {
|
||||
&.name,
|
||||
&.url {
|
||||
input {
|
||||
width: 100%;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
margin: 5px 0;
|
||||
flex-direction: column;
|
||||
flex: 1 0 auto;
|
||||
max-width: 100%;
|
||||
|
||||
.widget-dropdown {
|
||||
margin: 0;
|
||||
|
@ -271,20 +272,32 @@
|
|||
margin: 0;
|
||||
}
|
||||
|
||||
.event-url,
|
||||
.event-dates {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0 1em;
|
||||
height: 50px;
|
||||
|
||||
.participants {
|
||||
margin-left: 0.5em;
|
||||
color: $primary-medium;
|
||||
}
|
||||
flex: 1;
|
||||
|
||||
.d-icon {
|
||||
color: $primary-high;
|
||||
}
|
||||
}
|
||||
|
||||
.event-url {
|
||||
.url {
|
||||
margin-left: 1em;
|
||||
max-width: 80%;
|
||||
@include ellipsis;
|
||||
}
|
||||
}
|
||||
|
||||
.event-dates {
|
||||
.participants {
|
||||
margin-left: 0.5em;
|
||||
color: $primary-medium;
|
||||
}
|
||||
|
||||
.date {
|
||||
color: $primary-high;
|
||||
|
|
|
@ -315,6 +315,9 @@ en:
|
|||
create: Create
|
||||
update: Save
|
||||
attach: Create event
|
||||
url:
|
||||
label: URL
|
||||
placeholder: Optional
|
||||
name:
|
||||
label: Event name
|
||||
placeholder: Optional, defaults to topic title
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddUrlColumnToEvent < ActiveRecord::Migration[6.0]
|
||||
def up
|
||||
add_column :discourse_post_event_events, :url, :string, limit: 1000
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :discourse_post_event_events, :url
|
||||
end
|
||||
end
|
|
@ -5,6 +5,7 @@ VALID_OPTIONS = [
|
|||
:end,
|
||||
:status,
|
||||
:"allowed-groups",
|
||||
:url,
|
||||
:name
|
||||
]
|
||||
|
||||
|
|
|
@ -80,6 +80,19 @@ describe Post do
|
|||
expect(post.event.name).to be_blank
|
||||
end
|
||||
|
||||
it 'works with url attribute' do
|
||||
url = 'https://www.discourse.org'
|
||||
|
||||
post = create_post_with_event(user, "url=\"#{url}\"").reload
|
||||
expect(post.event.url).to eq(url)
|
||||
|
||||
post = create_post_with_event(user, 'url=""').reload
|
||||
expect(post.event.url).to be_blank
|
||||
|
||||
post = create_post_with_event(user, 'url=').reload
|
||||
expect(post.event.url).to be_blank
|
||||
end
|
||||
|
||||
it 'works with status attribute' do
|
||||
post = create_post_with_event(user, 'status="private"').reload
|
||||
expect(post.event.status).to eq(DiscoursePostEvent::Event.statuses[:private])
|
||||
|
|
|
@ -141,6 +141,20 @@ module DiscoursePostEvent
|
|||
let(:event) { Fabricate(:event, post: post1) }
|
||||
|
||||
context 'when we update the event' do
|
||||
context 'when an url is defined' do
|
||||
it 'changes the url' do
|
||||
url = 'https://www.google.fr'
|
||||
|
||||
put "/discourse-post-event/events/#{event.id}.json", params: {
|
||||
event: { url: url }
|
||||
}
|
||||
|
||||
event.reload
|
||||
|
||||
expect(event.url).to eq(url)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when status changes from standalone to private' do
|
||||
it 'changes the status, raw_invitees and invitees' do
|
||||
event.update!(status: Event.statuses[:standalone])
|
Loading…
Reference in New Issue