1
0
Fork 0

Step description mapper updates

Dieser Commit ist enthalten in:
Angus McLeod 2020-04-16 15:14:03 +10:00
Ursprung aa5f455c6b
Commit a25d69eb5f
4 geänderte Dateien mit 39 neuen und 32 gelöschten Zeilen

Datei anzeigen

@ -1,15 +1,9 @@
import Component from "@ember/component"; import Component from "@ember/component";
import { default as discourseComputed } from 'discourse-common/utils/decorators'; import { default as discourseComputed } from 'discourse-common/utils/decorators';
import { wizardFieldList } from '../lib/wizard';
export default Component.extend({ export default Component.extend({
classNames: 'wizard-custom-step', classNames: 'wizard-custom-step',
@discourseComputed('wizard.steps', 'step.id')
descriptionWizardFields(steps, stepId) {
return wizardFieldList(steps, { upTo: stepId });
},
actions: { actions: {
bannerUploadDone(upload) { bannerUploadDone(upload) {
this.set("step.banner", upload.url); this.set("step.banner", upload.url);

Datei anzeigen

@ -29,8 +29,7 @@
</div> </div>
<div class="setting-value"> <div class="setting-value">
{{wizard-text-editor {{wizard-text-editor
value=step.raw_description value=step.raw_description}}
wizardFields=descriptionWizardFields}}
</div> </div>
</div> </div>

Datei anzeigen

@ -56,7 +56,11 @@ class CustomWizard::Builder
step.banner = step_template['banner'] if step_template['banner'] step.banner = step_template['banner'] if step_template['banner']
if step_template['description'] if step_template['description']
step.description = mapper.interpolate(step_template['description']) step.description = mapper.interpolate(
step_template['description'],
user: true,
value: true
)
end end
step.key = step_template['key'] if step_template['key'] step.key = step_template['key'] if step_template['key']

Datei anzeigen

@ -92,7 +92,7 @@ class CustomWizard::Mapper
operator = map_operator(connector) operator = map_operator(connector)
value = cast_value( value = cast_value(
key, key,
interpolate(map_field(pair['value'], pair['value_type'])), map_field(pair['value'], pair['value_type']),
connector connector
) )
@ -178,32 +178,42 @@ class CustomWizard::Mapper
end end
end end
def interpolate(string) def interpolate(string, opts={ user: true, wizard: true, value: true })
string.gsub!(/u\{(.*?)\}/) do |match| return string if string.blank?
result = ''
result = user.send($1) if USER_FIELDS.include?($1) if opts[:user]
result = user.user_profile.send($1) if PROFILE_FIELDS.include?($1) string.gsub!(/u\{(.*?)\}/) do |match|
result result = ''
result = user.send($1) if USER_FIELDS.include?($1)
result = user.user_profile.send($1) if PROFILE_FIELDS.include?($1)
result
end
end end
string.gsub(/v\{(.*?)\}/) do |match| if opts[:wizard]
attrs = $1.split(':') string.gsub!(/w\{(.*?)\}/) do |match|
key = attrs.first value = recurse(data, [*$1.split('.')])
value = data[key] value.present? ? value : ''
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)
end end
if value.present?
return recurse(value, [*$1.split('.')])
end
result
end 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 end
def recurse(data, keys) def recurse(data, keys)