Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-25 18:50:27 +01:00
Add wizard actions and fix field listings
Dieser Commit ist enthalten in:
Ursprung
2e6c6ff4d6
Commit
290bacc4bd
10 geänderte Dateien mit 70 neuen und 10 gelöschten Zeilen
|
@ -13,6 +13,7 @@ export default Component.extend({
|
||||||
|
|
||||||
showText: computed('activeType', function() { return this.showInput('text') }),
|
showText: computed('activeType', function() { return this.showInput('text') }),
|
||||||
showWizardField: computed('activeType', function() { return this.showInput('wizardField') }),
|
showWizardField: computed('activeType', function() { return this.showInput('wizardField') }),
|
||||||
|
showWizardAction: computed('activeType', function() { return this.showInput('wizardAction') }),
|
||||||
showUserField: computed('activeType', function() { return this.showInput('userField') }),
|
showUserField: computed('activeType', function() { return this.showInput('userField') }),
|
||||||
showUserFieldOptions: computed('activeType', function() { return this.showInput('userFieldOptions') }),
|
showUserFieldOptions: computed('activeType', function() { return this.showInput('userFieldOptions') }),
|
||||||
showCategory: computed('activeType', function() { return this.showInput('category') }),
|
showCategory: computed('activeType', function() { return this.showInput('category') }),
|
||||||
|
@ -22,6 +23,7 @@ export default Component.extend({
|
||||||
showList: computed('activeType', function() { return this.showInput('list') }),
|
showList: computed('activeType', function() { return this.showInput('list') }),
|
||||||
textEnabled: computed('options.textSelection', 'inputType', function() { return this.optionEnabled('textSelection') }),
|
textEnabled: computed('options.textSelection', 'inputType', function() { return this.optionEnabled('textSelection') }),
|
||||||
wizardFieldEnabled: computed('options.wizardFieldSelection', 'inputType', function() { return this.optionEnabled('wizardFieldSelection') }),
|
wizardFieldEnabled: computed('options.wizardFieldSelection', 'inputType', function() { return this.optionEnabled('wizardFieldSelection') }),
|
||||||
|
wizardActionEnabled: computed('options.wizardActionSelection', 'inputType', function() { return this.optionEnabled('wizardActionSelection') }),
|
||||||
userFieldEnabled: computed('options.userFieldSelection', 'inputType', function() { return this.optionEnabled('userFieldSelection') }),
|
userFieldEnabled: computed('options.userFieldSelection', 'inputType', function() { return this.optionEnabled('userFieldSelection') }),
|
||||||
userFieldOptionsEnabled: computed('options.userFieldOptionsSelection', 'inputType', function() { return this.optionEnabled('userFieldOptionsSelection') }),
|
userFieldOptionsEnabled: computed('options.userFieldOptionsSelection', 'inputType', function() { return this.optionEnabled('userFieldOptionsSelection') }),
|
||||||
categoryEnabled: computed('options.categorySelection', 'inputType', function() { return this.optionEnabled('categorySelection') }),
|
categoryEnabled: computed('options.categorySelection', 'inputType', function() { return this.optionEnabled('categorySelection') }),
|
||||||
|
@ -32,7 +34,7 @@ export default Component.extend({
|
||||||
|
|
||||||
groups: alias('site.groups'),
|
groups: alias('site.groups'),
|
||||||
categories: alias('site.categories'),
|
categories: alias('site.categories'),
|
||||||
showComboBox: or('showWizardField', 'showUserField', 'showUserFieldOptions'),
|
showComboBox: or('showWizardField', 'showWizardAction', 'showUserField', 'showUserFieldOptions'),
|
||||||
showMultiSelect: or('showCategory', 'showGroup'),
|
showMultiSelect: or('showCategory', 'showGroup'),
|
||||||
hasTypes: gt('selectorTypes.length', 1),
|
hasTypes: gt('selectorTypes.length', 1),
|
||||||
showTypes: false,
|
showTypes: false,
|
||||||
|
@ -73,20 +75,48 @@ export default Component.extend({
|
||||||
return type ? I18n.t(`admin.wizard.selector.label.${snakeCase(type)}`) : null;
|
return type ? I18n.t(`admin.wizard.selector.label.${snakeCase(type)}`) : null;
|
||||||
},
|
},
|
||||||
|
|
||||||
comboBoxAllowAny: alias('showWizardField'),
|
comboBoxAllowAny: or('showWizardField', 'showWizardAction'),
|
||||||
|
|
||||||
@discourseComputed('activeType')
|
@discourseComputed
|
||||||
comboBoxContent(activeType) {
|
showController() {
|
||||||
const controller = getOwner(this).lookup('controller:admin-wizards-wizard-show');
|
return getOwner(this).lookup('controller:admin-wizards-wizard-show');
|
||||||
const wizardFields = controller.wizardFields;
|
},
|
||||||
const userFields = controller.userFields;
|
|
||||||
|
@discourseComputed(
|
||||||
|
'activeType',
|
||||||
|
'showController.wizardFields.[]',
|
||||||
|
'showController.wizard.actions.[]',
|
||||||
|
'showController.userFields.[]',
|
||||||
|
'showController.currentField.id',
|
||||||
|
'showController.currentAction.id'
|
||||||
|
)
|
||||||
|
comboBoxContent(
|
||||||
|
activeType,
|
||||||
|
wizardFields,
|
||||||
|
wizardActions,
|
||||||
|
userFields,
|
||||||
|
currentFieldId,
|
||||||
|
currentActionId
|
||||||
|
) {
|
||||||
let content;
|
let content;
|
||||||
|
|
||||||
if (activeType === 'wizardField') {
|
if (activeType === 'wizardField') {
|
||||||
content = wizardFields;
|
content = wizardFields;
|
||||||
|
|
||||||
if (this.options.context === 'field') {
|
if (this.options.context === 'field') {
|
||||||
content = content.filter(field => field.id !== controller.currentField.id);
|
content = content.filter(field => field.id !== currentFieldId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (activeType === 'wizardAction') {
|
||||||
|
content = wizardActions.map(a => ({
|
||||||
|
id: a.id,
|
||||||
|
label: `${generateName(a.type)} (${a.id})`,
|
||||||
|
type: a.type
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (this.options.context === 'action') {
|
||||||
|
content = content.filter(a => a.id !== currentActionId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ export default Component.extend({
|
||||||
previewEnabled: true,
|
previewEnabled: true,
|
||||||
fieldsEnabled: true,
|
fieldsEnabled: true,
|
||||||
hasWizardFields: notEmpty('wizardFieldList'),
|
hasWizardFields: notEmpty('wizardFieldList'),
|
||||||
|
hasWizardActions: notEmpty('wizardActionList'),
|
||||||
|
|
||||||
didReceiveAttrs() {
|
didReceiveAttrs() {
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
|
@ -46,6 +47,11 @@ export default Component.extend({
|
||||||
return wizardFields.map((f) => ` w{${f.id}}`);
|
return wizardFields.map((f) => ` w{${f.id}}`);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@discourseComputed('wizardActions')
|
||||||
|
wizardActionList(wizardActions) {
|
||||||
|
return wizardActions.map((a) => ` w{${a.id}}`);
|
||||||
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
togglePreview() {
|
togglePreview() {
|
||||||
this.toggleProperty('forcePreview');
|
this.toggleProperty('forcePreview');
|
||||||
|
|
|
@ -46,7 +46,7 @@ export default Controller.extend({
|
||||||
I18n.t('admin.wizard.after_time_time_label');
|
I18n.t('admin.wizard.after_time_time_label');
|
||||||
},
|
},
|
||||||
|
|
||||||
@discourseComputed('currentStep.id', 'wizard.save_submissions', 'wizard.steps.@each.fields[]')
|
@discourseComputed('currentStep.id', 'wizard.save_submissions', 'currentStep.fields.@each.label')
|
||||||
wizardFields(currentStepId, saveSubmissions) {
|
wizardFields(currentStepId, saveSubmissions) {
|
||||||
let steps = this.wizard.steps;
|
let steps = this.wizard.steps;
|
||||||
if (!saveSubmissions) {
|
if (!saveSubmissions) {
|
||||||
|
|
|
@ -80,6 +80,7 @@ const selectionTypes = [
|
||||||
'text',
|
'text',
|
||||||
'list',
|
'list',
|
||||||
'wizardField',
|
'wizardField',
|
||||||
|
'wizardAction',
|
||||||
'userField',
|
'userField',
|
||||||
'userFieldOptions',
|
'userFieldOptions',
|
||||||
'group',
|
'group',
|
||||||
|
|
|
@ -654,6 +654,7 @@
|
||||||
inputTypes='association'
|
inputTypes='association'
|
||||||
textSelection=true
|
textSelection=true
|
||||||
wizardFieldSelection=true
|
wizardFieldSelection=true
|
||||||
|
wizardActionSelection='key'
|
||||||
userFieldSelection=true
|
userFieldSelection=true
|
||||||
groupSelection='key'
|
groupSelection='key'
|
||||||
context='action'
|
context='action'
|
||||||
|
|
|
@ -28,6 +28,13 @@
|
||||||
{{wizardFieldList}}
|
{{wizardFieldList}}
|
||||||
</label>
|
</label>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
{{#if hasWizardActions}}
|
||||||
|
<label>
|
||||||
|
{{i18n 'admin.wizard.action.post_builder.wizard_actions'}}
|
||||||
|
{{wizardActionList}}
|
||||||
|
</label>
|
||||||
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
|
@ -94,6 +94,7 @@ en:
|
||||||
label:
|
label:
|
||||||
text: "text"
|
text: "text"
|
||||||
wizard_field: "wizard field"
|
wizard_field: "wizard field"
|
||||||
|
wizard_action: "wizard action"
|
||||||
user_field: "user field"
|
user_field: "user field"
|
||||||
user_field_options: "user field options"
|
user_field_options: "user field options"
|
||||||
user: "user"
|
user: "user"
|
||||||
|
@ -106,6 +107,7 @@ en:
|
||||||
text: "Enter text"
|
text: "Enter text"
|
||||||
property: "Select property"
|
property: "Select property"
|
||||||
wizard_field: "Select field"
|
wizard_field: "Select field"
|
||||||
|
wizard_action: "Select action"
|
||||||
user_field: "Select field"
|
user_field: "Select field"
|
||||||
user_field_options: "Select field"
|
user_field_options: "Select field"
|
||||||
user: "Select user"
|
user: "Select user"
|
||||||
|
@ -226,6 +228,7 @@ en:
|
||||||
label: "Builder"
|
label: "Builder"
|
||||||
user_properties: "User Properties"
|
user_properties: "User Properties"
|
||||||
wizard_fields: "Wizard Fields"
|
wizard_fields: "Wizard Fields"
|
||||||
|
wizard_actions: "Wizard Actions"
|
||||||
placeholder: "Insert wizard fields using the field_id in w{}. Insert user properties using property in u{}."
|
placeholder: "Insert wizard fields using the field_id in w{}. Insert user properties using property in u{}."
|
||||||
add_to_group:
|
add_to_group:
|
||||||
label: "Add to Group"
|
label: "Add to Group"
|
||||||
|
|
|
@ -24,6 +24,10 @@ class CustomWizard::Action
|
||||||
@result.handler.enqueue_jobs
|
@result.handler.enqueue_jobs
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if @result.success? && @result.output.present?
|
||||||
|
data[action['id']] = @result.output
|
||||||
|
end
|
||||||
|
|
||||||
save_log
|
save_log
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -51,6 +55,7 @@ class CustomWizard::Action
|
||||||
if creator.errors.blank?
|
if creator.errors.blank?
|
||||||
log_success("created topic", "id: #{post.topic.id}")
|
log_success("created topic", "id: #{post.topic.id}")
|
||||||
result.handler = creator
|
result.handler = creator
|
||||||
|
result.output = post.topic.id
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
log_error("invalid topic params", "title: #{params[:title]}; post: #{params[:raw]}")
|
log_error("invalid topic params", "title: #{params[:title]}; post: #{params[:raw]}")
|
||||||
|
@ -89,6 +94,7 @@ class CustomWizard::Action
|
||||||
if creator.errors.blank?
|
if creator.errors.blank?
|
||||||
log_success("created message", "id: #{post.topic.id}")
|
log_success("created message", "id: #{post.topic.id}")
|
||||||
result.handler = creator
|
result.handler = creator
|
||||||
|
result.output = post.topic.id
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
log_error(
|
log_error(
|
||||||
|
@ -289,6 +295,7 @@ class CustomWizard::Action
|
||||||
if group.save
|
if group.save
|
||||||
GroupActionLogger.new(user, group).log_change_group_settings
|
GroupActionLogger.new(user, group).log_change_group_settings
|
||||||
log_success("Group created", group.name)
|
log_success("Group created", group.name)
|
||||||
|
result.output = group.name
|
||||||
else
|
else
|
||||||
log_error("Group creation failed")
|
log_error("Group creation failed")
|
||||||
end
|
end
|
||||||
|
@ -307,6 +314,7 @@ class CustomWizard::Action
|
||||||
if category.save
|
if category.save
|
||||||
StaffActionLogger.new(user).log_category_creation(category)
|
StaffActionLogger.new(user).log_category_creation(category)
|
||||||
log_success("Category created", category.name)
|
log_success("Category created", category.name)
|
||||||
|
result.output = category.id
|
||||||
else
|
else
|
||||||
log_error("Category creation failed")
|
log_error("Category creation failed")
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class CustomWizard::ActionResult
|
class CustomWizard::ActionResult
|
||||||
attr_accessor :success, :handler
|
attr_accessor :success, :handler, :output
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@success = false
|
@success = false
|
||||||
|
|
|
@ -188,6 +188,10 @@ class CustomWizard::Mapper
|
||||||
data && !data.key?("submitted_at") && data[value]
|
data && !data.key?("submitted_at") && data[value]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def map_wizard_action(value)
|
||||||
|
data && !data.key?("submitted_at") && data[value]
|
||||||
|
end
|
||||||
|
|
||||||
def map_user_field(value)
|
def map_user_field(value)
|
||||||
if value.include?(User::USER_FIELD_PREFIX)
|
if value.include?(User::USER_FIELD_PREFIX)
|
||||||
UserCustomField.where(user_id: user.id, name: value).pluck(:value).first
|
UserCustomField.where(user_id: user.id, name: value).pluck(:value).first
|
||||||
|
|
Laden …
In neuem Issue referenzieren