0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-09-19 15:21:11 +02:00

Add wizard actions and fix field listings

Dieser Commit ist enthalten in:
Angus McLeod 2020-07-17 17:02:48 +10:00
Ursprung 2e6c6ff4d6
Commit 290bacc4bd
10 geänderte Dateien mit 70 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -13,6 +13,7 @@ export default Component.extend({
showText: computed('activeType', function() { return this.showInput('text') }),
showWizardField: computed('activeType', function() { return this.showInput('wizardField') }),
showWizardAction: computed('activeType', function() { return this.showInput('wizardAction') }),
showUserField: computed('activeType', function() { return this.showInput('userField') }),
showUserFieldOptions: computed('activeType', function() { return this.showInput('userFieldOptions') }),
showCategory: computed('activeType', function() { return this.showInput('category') }),
@ -22,6 +23,7 @@ export default Component.extend({
showList: computed('activeType', function() { return this.showInput('list') }),
textEnabled: computed('options.textSelection', 'inputType', function() { return this.optionEnabled('textSelection') }),
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') }),
userFieldOptionsEnabled: computed('options.userFieldOptionsSelection', 'inputType', function() { return this.optionEnabled('userFieldOptionsSelection') }),
categoryEnabled: computed('options.categorySelection', 'inputType', function() { return this.optionEnabled('categorySelection') }),
@ -32,7 +34,7 @@ export default Component.extend({
groups: alias('site.groups'),
categories: alias('site.categories'),
showComboBox: or('showWizardField', 'showUserField', 'showUserFieldOptions'),
showComboBox: or('showWizardField', 'showWizardAction', 'showUserField', 'showUserFieldOptions'),
showMultiSelect: or('showCategory', 'showGroup'),
hasTypes: gt('selectorTypes.length', 1),
showTypes: false,
@ -73,20 +75,48 @@ export default Component.extend({
return type ? I18n.t(`admin.wizard.selector.label.${snakeCase(type)}`) : null;
},
comboBoxAllowAny: alias('showWizardField'),
comboBoxAllowAny: or('showWizardField', 'showWizardAction'),
@discourseComputed('activeType')
comboBoxContent(activeType) {
const controller = getOwner(this).lookup('controller:admin-wizards-wizard-show');
const wizardFields = controller.wizardFields;
const userFields = controller.userFields;
@discourseComputed
showController() {
return getOwner(this).lookup('controller:admin-wizards-wizard-show');
},
@discourseComputed(
'activeType',
'showController.wizardFields.[]',
'showController.wizard.actions.[]',
'showController.userFields.[]',
'showController.currentField.id',
'showController.currentAction.id'
)
comboBoxContent(
activeType,
wizardFields,
wizardActions,
userFields,
currentFieldId,
currentActionId
) {
let content;
if (activeType === 'wizardField') {
content = wizardFields;
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);
}
}

Datei anzeigen

@ -11,6 +11,7 @@ export default Component.extend({
previewEnabled: true,
fieldsEnabled: true,
hasWizardFields: notEmpty('wizardFieldList'),
hasWizardActions: notEmpty('wizardActionList'),
didReceiveAttrs() {
this._super(...arguments);
@ -46,6 +47,11 @@ export default Component.extend({
return wizardFields.map((f) => ` w{${f.id}}`);
},
@discourseComputed('wizardActions')
wizardActionList(wizardActions) {
return wizardActions.map((a) => ` w{${a.id}}`);
},
actions: {
togglePreview() {
this.toggleProperty('forcePreview');

Datei anzeigen

@ -46,7 +46,7 @@ export default Controller.extend({
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) {
let steps = this.wizard.steps;
if (!saveSubmissions) {

Datei anzeigen

@ -80,6 +80,7 @@ const selectionTypes = [
'text',
'list',
'wizardField',
'wizardAction',
'userField',
'userFieldOptions',
'group',

Datei anzeigen

@ -654,6 +654,7 @@
inputTypes='association'
textSelection=true
wizardFieldSelection=true
wizardActionSelection='key'
userFieldSelection=true
groupSelection='key'
context='action'

Datei anzeigen

@ -28,6 +28,13 @@
{{wizardFieldList}}
</label>
{{/if}}
{{#if hasWizardActions}}
<label>
{{i18n 'admin.wizard.action.post_builder.wizard_actions'}}
{{wizardActionList}}
</label>
{{/if}}
</div>
{{/if}}
{{/if}}

Datei anzeigen

@ -94,6 +94,7 @@ en:
label:
text: "text"
wizard_field: "wizard field"
wizard_action: "wizard action"
user_field: "user field"
user_field_options: "user field options"
user: "user"
@ -106,6 +107,7 @@ en:
text: "Enter text"
property: "Select property"
wizard_field: "Select field"
wizard_action: "Select action"
user_field: "Select field"
user_field_options: "Select field"
user: "Select user"
@ -226,6 +228,7 @@ en:
label: "Builder"
user_properties: "User Properties"
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{}."
add_to_group:
label: "Add to Group"

Datei anzeigen

@ -24,6 +24,10 @@ class CustomWizard::Action
@result.handler.enqueue_jobs
end
if @result.success? && @result.output.present?
data[action['id']] = @result.output
end
save_log
end
@ -51,6 +55,7 @@ class CustomWizard::Action
if creator.errors.blank?
log_success("created topic", "id: #{post.topic.id}")
result.handler = creator
result.output = post.topic.id
end
else
log_error("invalid topic params", "title: #{params[:title]}; post: #{params[:raw]}")
@ -89,6 +94,7 @@ class CustomWizard::Action
if creator.errors.blank?
log_success("created message", "id: #{post.topic.id}")
result.handler = creator
result.output = post.topic.id
end
else
log_error(
@ -289,6 +295,7 @@ class CustomWizard::Action
if group.save
GroupActionLogger.new(user, group).log_change_group_settings
log_success("Group created", group.name)
result.output = group.name
else
log_error("Group creation failed")
end
@ -307,6 +314,7 @@ class CustomWizard::Action
if category.save
StaffActionLogger.new(user).log_category_creation(category)
log_success("Category created", category.name)
result.output = category.id
else
log_error("Category creation failed")
end

Datei anzeigen

@ -1,5 +1,5 @@
class CustomWizard::ActionResult
attr_accessor :success, :handler
attr_accessor :success, :handler, :output
def initialize
@success = false

Datei anzeigen

@ -187,6 +187,10 @@ class CustomWizard::Mapper
def map_wizard_field(value)
data && !data.key?("submitted_at") && data[value]
end
def map_wizard_action(value)
data && !data.key?("submitted_at") && data[value]
end
def map_user_field(value)
if value.include?(User::USER_FIELD_PREFIX)