Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-25 02:30:28 +01:00
Step description mapper updates
Dieser Commit ist enthalten in:
Ursprung
aa5f455c6b
Commit
a25d69eb5f
4 geänderte Dateien mit 39 neuen und 32 gelöschten Zeilen
|
@ -1,15 +1,9 @@
|
|||
import Component from "@ember/component";
|
||||
import { default as discourseComputed } from 'discourse-common/utils/decorators';
|
||||
import { wizardFieldList } from '../lib/wizard';
|
||||
|
||||
export default Component.extend({
|
||||
classNames: 'wizard-custom-step',
|
||||
|
||||
@discourseComputed('wizard.steps', 'step.id')
|
||||
descriptionWizardFields(steps, stepId) {
|
||||
return wizardFieldList(steps, { upTo: stepId });
|
||||
},
|
||||
|
||||
actions: {
|
||||
bannerUploadDone(upload) {
|
||||
this.set("step.banner", upload.url);
|
||||
|
|
|
@ -29,8 +29,7 @@
|
|||
</div>
|
||||
<div class="setting-value">
|
||||
{{wizard-text-editor
|
||||
value=step.raw_description
|
||||
wizardFields=descriptionWizardFields}}
|
||||
value=step.raw_description}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -56,7 +56,11 @@ class CustomWizard::Builder
|
|||
step.banner = step_template['banner'] if step_template['banner']
|
||||
|
||||
if step_template['description']
|
||||
step.description = mapper.interpolate(step_template['description'])
|
||||
step.description = mapper.interpolate(
|
||||
step_template['description'],
|
||||
user: true,
|
||||
value: true
|
||||
)
|
||||
end
|
||||
|
||||
step.key = step_template['key'] if step_template['key']
|
||||
|
|
|
@ -92,7 +92,7 @@ class CustomWizard::Mapper
|
|||
operator = map_operator(connector)
|
||||
value = cast_value(
|
||||
key,
|
||||
interpolate(map_field(pair['value'], pair['value_type'])),
|
||||
map_field(pair['value'], pair['value_type']),
|
||||
connector
|
||||
)
|
||||
|
||||
|
@ -178,32 +178,42 @@ class CustomWizard::Mapper
|
|||
end
|
||||
end
|
||||
|
||||
def interpolate(string)
|
||||
string.gsub!(/u\{(.*?)\}/) do |match|
|
||||
result = ''
|
||||
result = user.send($1) if USER_FIELDS.include?($1)
|
||||
result = user.user_profile.send($1) if PROFILE_FIELDS.include?($1)
|
||||
result
|
||||
def interpolate(string, opts={ user: true, wizard: true, value: true })
|
||||
return string if string.blank?
|
||||
|
||||
if opts[:user]
|
||||
string.gsub!(/u\{(.*?)\}/) do |match|
|
||||
result = ''
|
||||
result = user.send($1) if USER_FIELDS.include?($1)
|
||||
result = user.user_profile.send($1) if PROFILE_FIELDS.include?($1)
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
string.gsub(/v\{(.*?)\}/) do |match|
|
||||
attrs = $1.split(':')
|
||||
key = attrs.first
|
||||
value = data[key]
|
||||
format = attrs.last if attrs.length > 1
|
||||
result = nil
|
||||
|
||||
if key == 'time'
|
||||
time_format = value.present? ? value : "%B %-d, %Y"
|
||||
return Time.now.strftime(time_format)
|
||||
if opts[:wizard]
|
||||
string.gsub!(/w\{(.*?)\}/) do |match|
|
||||
value = recurse(data, [*$1.split('.')])
|
||||
value.present? ? value : ''
|
||||
end
|
||||
|
||||
if value.present?
|
||||
return recurse(value, [*$1.split('.')])
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
if opts[:value]
|
||||
string.gsub!(/v\{(.*?)\}/) do |match|
|
||||
attrs = $1.split(':')
|
||||
key = attrs.first
|
||||
format = attrs.last if attrs.length > 1
|
||||
result = ''
|
||||
|
||||
if key == 'time' &&
|
||||
time_format = format.present? ? format : "%B %-d, %Y"
|
||||
result = Time.now.strftime(time_format)
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
string
|
||||
end
|
||||
|
||||
def recurse(data, keys)
|
||||
|
|
Laden …
In neuem Issue referenzieren