Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-09 11:52:54 +01:00
Merge branch 'main' into pro-release
Dieser Commit ist enthalten in:
Commit
919ac702af
9 geänderte Dateien mit 78 neuen und 7 gelöschten Zeilen
|
@ -163,7 +163,8 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController
|
||||||
mentionable_level: mapped_params,
|
mentionable_level: mapped_params,
|
||||||
messageable_level: mapped_params,
|
messageable_level: mapped_params,
|
||||||
visibility_level: mapped_params,
|
visibility_level: mapped_params,
|
||||||
members_visibility_level: mapped_params
|
members_visibility_level: mapped_params,
|
||||||
|
add_event: mapped_params
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
@ -98,4 +98,9 @@ export default Component.extend(UndoChanges, {
|
||||||
actionTypes() {
|
actionTypes() {
|
||||||
return subscriptionSelectKitContent("action", "types");
|
return subscriptionSelectKitContent("action", "types");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@discourseComputed("fieldTypes")
|
||||||
|
hasEventsField(fieldTypes) {
|
||||||
|
return fieldTypes.map((ft) => ft.id).includes("event");
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -98,6 +98,7 @@ const action = {
|
||||||
custom_fields: null,
|
custom_fields: null,
|
||||||
skip_redirect: null,
|
skip_redirect: null,
|
||||||
suppress_notifications: null,
|
suppress_notifications: null,
|
||||||
|
add_event: null,
|
||||||
},
|
},
|
||||||
send_message: {
|
send_message: {
|
||||||
title: null,
|
title: null,
|
||||||
|
@ -194,6 +195,7 @@ const action = {
|
||||||
"messageable_level",
|
"messageable_level",
|
||||||
"visibility_level",
|
"visibility_level",
|
||||||
"members_visibility_level",
|
"members_visibility_level",
|
||||||
|
"add_event",
|
||||||
],
|
],
|
||||||
required: ["id", "type"],
|
required: ["id", "type"],
|
||||||
dependent: {},
|
dependent: {},
|
||||||
|
|
|
@ -176,7 +176,9 @@
|
||||||
currentActionId=currentAction.id
|
currentActionId=currentAction.id
|
||||||
wizard=wizard
|
wizard=wizard
|
||||||
apis=apis
|
apis=apis
|
||||||
wizardFields=wizardFields}}
|
removeAction="removeAction"
|
||||||
|
wizardFields=wizardFields
|
||||||
|
fieldTypes=fieldTypes}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
||||||
<div class="admin-wizard-buttons">
|
<div class="admin-wizard-buttons">
|
||||||
|
|
|
@ -160,6 +160,25 @@
|
||||||
)}}
|
)}}
|
||||||
</div>
|
</div>
|
||||||
</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}}
|
||||||
|
|
||||||
{{#if sendMessage}}
|
{{#if sendMessage}}
|
||||||
|
|
|
@ -313,6 +313,7 @@ en:
|
||||||
date: Date
|
date: Date
|
||||||
time: Time
|
time: Time
|
||||||
date_time: Date & Time
|
date_time: Date & Time
|
||||||
|
event: Event (Events Plugin)
|
||||||
|
|
||||||
connector:
|
connector:
|
||||||
and: "and"
|
and: "and"
|
||||||
|
@ -356,6 +357,7 @@ en:
|
||||||
category: "Category"
|
category: "Category"
|
||||||
tags: "Tags"
|
tags: "Tags"
|
||||||
visible: "Visible"
|
visible: "Visible"
|
||||||
|
add_event: "Add Event (Events Plugin)"
|
||||||
open_composer:
|
open_composer:
|
||||||
label: "Open Composer"
|
label: "Open Composer"
|
||||||
update_profile:
|
update_profile:
|
||||||
|
|
|
@ -43,9 +43,17 @@ class CustomWizard::Action
|
||||||
@mapper ||= CustomWizard::Mapper.new(user: user, data: mapper_data)
|
@mapper ||= CustomWizard::Mapper.new(user: user, data: mapper_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def callbacks_for(action)
|
||||||
|
self.class.callbacks[action] || []
|
||||||
|
end
|
||||||
|
|
||||||
def create_topic
|
def create_topic
|
||||||
params = basic_topic_params.merge(public_topic_params)
|
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?
|
if params[:title].present? && params[:raw].present?
|
||||||
creator = PostCreator.new(user, params)
|
creator = PostCreator.new(user, params)
|
||||||
post = creator.create
|
post = creator.create
|
||||||
|
@ -417,6 +425,15 @@ class CustomWizard::Action
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.callbacks
|
||||||
|
@callbacks ||= {}
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.register_callback(action, &block)
|
||||||
|
callbacks[action] ||= []
|
||||||
|
callbacks[action] << block
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def action_category
|
def action_category
|
||||||
|
|
|
@ -130,17 +130,22 @@ class CustomWizard::Field
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.require_assets
|
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 ||= {}
|
@require_assets ||= {}
|
||||||
end
|
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
|
if type
|
||||||
types[type.to_sym] ||= {}
|
types[type.to_sym] ||= {}
|
||||||
types[type.to_sym] = opts[:type_opts] if opts[:type_opts].present?
|
types[type.to_sym] = opts[:type_opts] if opts[:type_opts].present?
|
||||||
end
|
end
|
||||||
|
|
||||||
if plugin && asset_paths
|
|
||||||
require_assets[plugin] = asset_paths
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -373,4 +373,22 @@ describe CustomWizard::Action do
|
||||||
expect(log_entry.status).to eq('FAIL')
|
expect(log_entry.status).to eq('FAIL')
|
||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
Laden …
In neuem Issue referenzieren