0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 01:10:28 +01:00

Merge pull request #203 from paviliondev/update_events_integration

Add automatic events plugin integration
Dieser Commit ist enthalten in:
Angus McLeod 2022-09-23 17:22:06 +02:00 committet von GitHub
Commit 61e80779ce
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
10 geänderte Dateien mit 78 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -163,7 +163,8 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController
mentionable_level: mapped_params,
messageable_level: mapped_params,
visibility_level: mapped_params,
members_visibility_level: mapped_params
members_visibility_level: mapped_params,
add_event: mapped_params
]
)
end

Datei anzeigen

@ -101,4 +101,9 @@ export default Component.extend(UndoChanges, {
}
return apis.find((a) => a.name === api).endpoints;
},
@discourseComputed("fieldTypes")
hasEventsField(fieldTypes) {
return fieldTypes.map((ft) => ft.id).includes("event");
},
});

Datei anzeigen

@ -102,6 +102,7 @@ const action = {
custom_fields: null,
skip_redirect: null,
suppress_notifications: null,
add_event: null,
},
send_message: {
title: null,
@ -198,6 +199,7 @@ const action = {
"messageable_level",
"visibility_level",
"members_visibility_level",
"add_event",
],
advanced: [
"code",

Datei anzeigen

@ -192,7 +192,8 @@
wizard=wizard
apis=apis
removeAction="removeAction"
wizardFields=wizardFields}}
wizardFields=wizardFields
fieldTypes=fieldTypes}}
{{/each}}
<div class="admin-wizard-buttons">

Datei anzeigen

@ -158,6 +158,25 @@
)}}
</div>
</div>
{{#if hasEventsField}}
<div class="setting full">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.create_topic.add_event"}}</label>
</div>
<div class="setting-value">
{{wizard-mapper
inputs=action.add_event
property="add_event"
onUpdate=(action "mappedFieldUpdated")
options=(hash
wizardFieldSelection=true
context="action"
)}}
</div>
</div>
{{/if}}
{{/if}}
{{#if sendMessage}}

Datei anzeigen

@ -293,6 +293,7 @@ en:
date: Date
time: Time
date_time: Date & Time
event: Event (Events Plugin)
connector:
and: "and"
@ -336,6 +337,7 @@ en:
category: "Category"
tags: "Tags"
visible: "Visible"
add_event: "Add Event (Events Plugin)"
open_composer:
label: "Open Composer"
update_profile:

Datei anzeigen

@ -43,9 +43,17 @@ class CustomWizard::Action
@mapper ||= CustomWizard::Mapper.new(user: user, data: mapper_data)
end
def callbacks_for(action)
self.class.callbacks[action] || []
end
def create_topic
params = basic_topic_params.merge(public_topic_params)
callbacks_for(:before_create_topic).each do |acb|
params = acb.call(params, @wizard, @action, @submission)
end
if params[:title].present? && params[:raw].present?
creator = PostCreator.new(user, params)
post = creator.create
@ -417,6 +425,15 @@ class CustomWizard::Action
end
end
def self.callbacks
@callbacks ||= {}
end
def self.register_callback(action, &block)
callbacks[action] ||= []
callbacks[action] << block
end
private
def action_category

Datei anzeigen

@ -132,17 +132,22 @@ class CustomWizard::Field
end
def self.require_assets
Rails.logger.warn("Custom Wizard field regisration no longer requires asset registration. Support will be removed in v2.1.0.")
@require_assets ||= {}
end
def self.register(type, plugin = nil, asset_paths = [], opts = {})
def self.register(type, plugin = nil, opts = {}, legacy_opts = {})
if opts.is_a?(Array)
Rails.logger.warn("Custom Wizard field regisration no longer requires asset registration. Support will be removed in v2.1.0.")
require_assets[plugin] = opts
opts = legacy_opts
end
if type
types[type.to_sym] ||= {}
types[type.to_sym] = opts[:type_opts] if opts[:type_opts].present?
end
if plugin && asset_paths
require_assets[plugin] = asset_paths
end
end
end

Datei anzeigen

@ -1,7 +1,7 @@
# frozen_string_literal: true
# name: discourse-custom-wizard
# about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more.
# version: 1.22.9
# version: 1.22.10
# authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George
# url: https://github.com/paviliondev/discourse-custom-wizard
# contact_emails: development@pavilion.tech

Datei anzeigen

@ -298,4 +298,22 @@ describe CustomWizard::Action do
updater.update
expect(updater.result[:redirect_on_next]).to eq("https://google.com")
end
it 'registers callbacks' do
described_class.register_callback(:before_create_topic) do |params, wizard, action, submission|
params[:topic_opts][:custom_fields]["topic_custom_field"] = true
params
end
wizard = CustomWizard::Builder.new(@template[:id], user).build
action = CustomWizard::Action.new(
wizard: wizard,
action: create_topic.with_indifferent_access,
submission: wizard.current_submission
)
action.perform
expect(action.result.success?).to eq(true)
expect(Topic.find(action.result.output).custom_fields["topic_custom_field"]).to eq("t")
end
end