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 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);
|
||||||
|
|
|
@ -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>
|
||||||
|
|
||||||
|
|
|
@ -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']
|
||||||
|
|
|
@ -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,34 +178,44 @@ class CustomWizard::Mapper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def interpolate(string)
|
def interpolate(string, opts={ user: true, wizard: true, value: true })
|
||||||
|
return string if string.blank?
|
||||||
|
|
||||||
|
if opts[:user]
|
||||||
string.gsub!(/u\{(.*?)\}/) do |match|
|
string.gsub!(/u\{(.*?)\}/) do |match|
|
||||||
result = ''
|
result = ''
|
||||||
result = user.send($1) if USER_FIELDS.include?($1)
|
result = user.send($1) if USER_FIELDS.include?($1)
|
||||||
result = user.user_profile.send($1) if PROFILE_FIELDS.include?($1)
|
result = user.user_profile.send($1) if PROFILE_FIELDS.include?($1)
|
||||||
result
|
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)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if value.present?
|
if opts[:wizard]
|
||||||
return recurse(value, [*$1.split('.')])
|
string.gsub!(/w\{(.*?)\}/) do |match|
|
||||||
|
value = recurse(data, [*$1.split('.')])
|
||||||
|
value.present? ? value : ''
|
||||||
|
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
|
end
|
||||||
|
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
string
|
||||||
|
end
|
||||||
|
|
||||||
def recurse(data, keys)
|
def recurse(data, keys)
|
||||||
k = keys.shift
|
k = keys.shift
|
||||||
result = data[k]
|
result = data[k]
|
||||||
|
|
Laden …
In neuem Issue referenzieren