Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-25 18:50:27 +01:00
various
Dieser Commit ist enthalten in:
Ursprung
ab18769820
Commit
92e61f3f51
10 geänderte Dateien mit 74 neuen und 86 gelöschten Zeilen
|
@ -6,7 +6,7 @@ import { ajax } from 'discourse/lib/ajax';
|
||||||
|
|
||||||
export default DiscourseRoute.extend({
|
export default DiscourseRoute.extend({
|
||||||
model() {
|
model() {
|
||||||
return ajax(`/admin/wizards/wizard`);
|
return ajax("/admin/wizards/wizard");
|
||||||
},
|
},
|
||||||
|
|
||||||
afterModel(model) {
|
afterModel(model) {
|
||||||
|
@ -52,14 +52,20 @@ export default DiscourseRoute.extend({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
currentWizard() {
|
||||||
|
const params = this.paramsFor('adminWizardsWizardShow');
|
||||||
|
|
||||||
|
if (params && params.wizardId) {
|
||||||
|
return params.wizardId;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
setupController(controller, model) {
|
setupController(controller, model) {
|
||||||
let props = {
|
let props = {
|
||||||
wizardList: model.wizard_list
|
wizardList: model.wizard_list,
|
||||||
}
|
wizardId: this.currentWizard()
|
||||||
|
|
||||||
const params = this.paramsFor('adminWizardsWizardShow');
|
|
||||||
if (params && params.wizardId) {
|
|
||||||
props.wizardId = params.wizardId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
controller.setProperties(props);
|
controller.setProperties(props);
|
||||||
|
|
|
@ -80,7 +80,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="setting-value">
|
<div class="setting-value">
|
||||||
{{input value=field.file_types}}
|
{{input value=field.file_types class="medium"}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
@ -156,7 +156,7 @@
|
||||||
{{input
|
{{input
|
||||||
name="key"
|
name="key"
|
||||||
value=field.key
|
value=field.key
|
||||||
class="small"
|
class="medium"
|
||||||
placeholderKey="admin.wizard.translation_placeholder"}}
|
placeholderKey="admin.wizard.translation_placeholder"}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -14,6 +14,12 @@
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
|
||||||
|
.wizard-message {
|
||||||
|
.d-icon {
|
||||||
|
margin-right: 4px;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.admin-wizard-container {
|
.admin-wizard-container {
|
||||||
|
@ -178,6 +184,10 @@
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input[type="number"] {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
input[disabled] {
|
input[disabled] {
|
||||||
background-color: $primary-low;
|
background-color: $primary-low;
|
||||||
cursor: not-allowed;
|
cursor: not-allowed;
|
||||||
|
|
|
@ -13,7 +13,7 @@ en:
|
||||||
name: "Name"
|
name: "Name"
|
||||||
name_placeholder: "wizard name"
|
name_placeholder: "wizard name"
|
||||||
background: "Background"
|
background: "Background"
|
||||||
background_placeholder: "color"
|
background_placeholder: "#hex"
|
||||||
save_submissions: "Save"
|
save_submissions: "Save"
|
||||||
save_submissions_label: "Save wizard submissions."
|
save_submissions_label: "Save wizard submissions."
|
||||||
multiple_submissions: "Multiple"
|
multiple_submissions: "Multiple"
|
||||||
|
@ -105,6 +105,7 @@ en:
|
||||||
invalid: "{{property}} is invalid"
|
invalid: "{{property}} is invalid"
|
||||||
dependent: "{{property}} is dependent on {{dependent}}"
|
dependent: "{{property}} is dependent on {{dependent}}"
|
||||||
conflict: "{{type}} with {{property}} '{{value}}' already exists"
|
conflict: "{{type}} with {{property}} '{{value}}' already exists"
|
||||||
|
after_time: "After time invalid"
|
||||||
|
|
||||||
step:
|
step:
|
||||||
header: "Steps"
|
header: "Steps"
|
||||||
|
|
|
@ -36,9 +36,7 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController
|
||||||
if validation[:error]
|
if validation[:error]
|
||||||
render json: { error: validation[:error] }
|
render json: { error: validation[:error] }
|
||||||
else
|
else
|
||||||
params = validation[:wizard]
|
if wizard_id = CustomWizard::Wizard.save(validation[:wizard])
|
||||||
|
|
||||||
if wizard_id = CustomWizard::Wizard.save(params)
|
|
||||||
render json: success_json.merge(wizard_id: wizard_id)
|
render json: success_json.merge(wizard_id: wizard_id)
|
||||||
else
|
else
|
||||||
render json: failed_json
|
render json: failed_json
|
||||||
|
@ -116,10 +114,9 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController
|
||||||
:code,
|
:code,
|
||||||
:skip_redirect,
|
:skip_redirect,
|
||||||
:url,
|
:url,
|
||||||
|
:post,
|
||||||
|
:post_template,
|
||||||
title: mapped_params,
|
title: mapped_params,
|
||||||
post: mapped_params,
|
|
||||||
post_builder: mapped_params,
|
|
||||||
post_template: mapped_params,
|
|
||||||
category: mapped_params,
|
category: mapped_params,
|
||||||
tags: mapped_params,
|
tags: mapped_params,
|
||||||
custom_fields: mapped_params,
|
custom_fields: mapped_params,
|
||||||
|
|
|
@ -69,7 +69,6 @@ class CustomWizard::Builder
|
||||||
|
|
||||||
if (required_data = step_template['required_data']).present?
|
if (required_data = step_template['required_data']).present?
|
||||||
has_required_data = true
|
has_required_data = true
|
||||||
pairs =
|
|
||||||
|
|
||||||
required_data.each do |required|
|
required_data.each do |required|
|
||||||
required['pairs'].each do |pair|
|
required['pairs'].each do |pair|
|
||||||
|
@ -274,36 +273,31 @@ class CustomWizard::Builder
|
||||||
def validate_field(field, updater, step_template)
|
def validate_field(field, updater, step_template)
|
||||||
value = updater.fields[field['id']]
|
value = updater.fields[field['id']]
|
||||||
min_length = false
|
min_length = false
|
||||||
|
|
||||||
label = field['label'] || I18n.t("#{field['key']}.label")
|
label = field['label'] || I18n.t("#{field['key']}.label")
|
||||||
|
type = field['type']
|
||||||
|
required = field['required']
|
||||||
|
id = field['id'].to_s
|
||||||
|
min_length = field['min_length'] if is_text_type(field)
|
||||||
|
|
||||||
if field['required'] && !value
|
if required && !value
|
||||||
updater.errors.add(field['id'].to_s, I18n.t('wizard.field.required', label: label))
|
updater.errors.add(id, I18n.t('wizard.field.required', label: label))
|
||||||
end
|
|
||||||
|
|
||||||
if is_text_type(field)
|
|
||||||
min_length = field['min_length']
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if min_length && value.is_a?(String) && value.strip.length < min_length.to_i
|
if min_length && value.is_a?(String) && value.strip.length < min_length.to_i
|
||||||
updater.errors.add(
|
updater.errors.add(id, I18n.t('wizard.field.too_short', label: label, min: min_length.to_i))
|
||||||
field['id'].to_s,
|
|
||||||
I18n.t('wizard.field.too_short', label: label, min: min_length.to_i)
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if is_url_type(field)
|
if is_url_type(field) && !check_if_url(value)
|
||||||
if !check_if_url(value)
|
updater.errors.add(id, I18n.t('wizard.field.not_url', label: label))
|
||||||
updater.errors.add(field['id'].to_s, I18n.t('wizard.field.not_url', label: label))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
## ensure all checkboxes are booleans
|
if type === 'checkbox'
|
||||||
if field['type'] === 'checkbox'
|
updater.fields[id] = standardise_boolean(value)
|
||||||
updater.fields[field['id']] = standardise_boolean(value)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
CustomWizard::Builder.field_validators.each do |validator|
|
CustomWizard::Builder.field_validators.each do |validator|
|
||||||
if field['type'] === validator[:type]
|
if type === validator[:type]
|
||||||
validator[:block].call(field, updater, step_template)
|
validator[:block].call(field, updater, step_template)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,10 +18,12 @@ class CustomWizard::StepUpdater
|
||||||
@step.updater.call(self) if @step.present? && @step.updater.present?
|
@step.updater.call(self) if @step.present? && @step.updater.present?
|
||||||
|
|
||||||
if success?
|
if success?
|
||||||
UserHistory.create(action: UserHistory.actions[:custom_wizard_step],
|
UserHistory.create(
|
||||||
|
action: UserHistory.actions[:custom_wizard_step],
|
||||||
acting_user_id: @current_user.id,
|
acting_user_id: @current_user.id,
|
||||||
context: @wizard.id,
|
context: @wizard.id,
|
||||||
subject: @step.id)
|
subject: @step.id
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ class CustomWizard::Validator
|
||||||
after_time = nil
|
after_time = nil
|
||||||
|
|
||||||
if !@error && @params[:after_time]
|
if !@error && @params[:after_time]
|
||||||
after_time = validate_after_time
|
validate_after_time
|
||||||
end
|
end
|
||||||
|
|
||||||
if !@error
|
if !@error
|
||||||
|
@ -46,9 +46,7 @@ class CustomWizard::Validator
|
||||||
if @error
|
if @error
|
||||||
{ error: @error }
|
{ error: @error }
|
||||||
else
|
else
|
||||||
result = { wizard: params }
|
{ wizard: params }
|
||||||
result[:after_time] = after_time if after_time
|
|
||||||
result
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -106,38 +104,15 @@ class CustomWizard::Validator
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_after_time
|
def validate_after_time
|
||||||
if !@opts[:create]
|
wizard = CustomWizard::Wizard.create(@params[:id]) if !@opts[:create]
|
||||||
wizard = CustomWizard::Wizard.create(params)
|
current_time = wizard.present? ? wizard.after_time_scheduled : nil
|
||||||
end
|
new_time = @params[:after_time_scheduled]
|
||||||
|
|
||||||
new = false
|
if (new_time.blank? && current_time.blank?) ||
|
||||||
error = nil
|
(new_time !~ /^([01]?[0-9]|2[0-3])\:[0-5][0-9]$/) ||
|
||||||
scheduled = nil
|
(Time.parse(new_time).utc < Time.now.utc)
|
||||||
|
|
||||||
if !@params[:after_time_scheduled] && !wizard[:after_time_scheduled]
|
@error = { type: 'after_time' }
|
||||||
error = 'after_time_need_time'
|
|
||||||
else
|
|
||||||
scheduled = Time.parse(@params[:after_time_scheduled]).utc
|
|
||||||
new = false
|
|
||||||
|
|
||||||
if wizard[:after_time_scheduled]
|
|
||||||
new = scheduled != Time.parse(wizard[:after_time_scheduled]).utc
|
|
||||||
end
|
|
||||||
|
|
||||||
begin
|
|
||||||
error = 'after_time_invalid' if new && scheduled < Time.now.utc
|
|
||||||
rescue ArgumentError
|
|
||||||
error = 'after_time_invalid'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if error
|
|
||||||
@error = { type: error }
|
|
||||||
else
|
|
||||||
{
|
|
||||||
new: new,
|
|
||||||
scheduled: scheduled
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -298,7 +298,8 @@ class CustomWizard::Wizard
|
||||||
|
|
||||||
if wizard[:after_time]
|
if wizard[:after_time]
|
||||||
Jobs.cancel_scheduled_job(:set_after_time_wizard, wizard_id: wizard[:id])
|
Jobs.cancel_scheduled_job(:set_after_time_wizard, wizard_id: wizard[:id])
|
||||||
Jobs.enqueue_at(wizard[:after_time_scheduled], :set_after_time_wizard, wizard_id: wizard[:id])
|
enqueue_at = Time.parse(wizard[:after_time_scheduled]).utc
|
||||||
|
Jobs.enqueue_at(enqueue_at, :set_after_time_wizard, wizard_id: wizard[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
if existing_wizard && existing_wizard.after_time && !wizard[:after_time]
|
if existing_wizard && existing_wizard.after_time && !wizard[:after_time]
|
||||||
|
@ -330,6 +331,8 @@ class CustomWizard::Wizard
|
||||||
def self.create(wizard_id, user = nil)
|
def self.create(wizard_id, user = nil)
|
||||||
if wizard = self.find(wizard_id)
|
if wizard = self.find(wizard_id)
|
||||||
CustomWizard::Wizard.new(wizard.to_h, user)
|
CustomWizard::Wizard.new(wizard.to_h, user)
|
||||||
|
else
|
||||||
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Laden …
In neuem Issue referenzieren