mirror of
https://github.com/discourse/discourse.git
synced 2025-02-20 11:48:26 -06:00
DEV: Allow plugins to add wizard steps after specific steps (#9315)
This commit is contained in:
parent
b2f30aa0b5
commit
689c61b462
@ -61,6 +61,11 @@ export default Component.extend({
|
|||||||
return getUrl(`/images/wizard/${src}`);
|
return getUrl(`/images/wizard/${src}`);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@discourseComputed("step.id")
|
||||||
|
bannerAndDescriptionClass(id) {
|
||||||
|
return `wizard-banner-and-description wizard-banner-and-description-${id}`;
|
||||||
|
},
|
||||||
|
|
||||||
@observes("step.id")
|
@observes("step.id")
|
||||||
_stepChanged() {
|
_stepChanged() {
|
||||||
this.set("saving", false);
|
this.set("saving", false);
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
<h1 class='wizard-step-title'>{{step.title}}</h1>
|
<h1 class='wizard-step-title'>{{step.title}}</h1>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
<div class={{bannerAndDescriptionClass}}>
|
||||||
{{#if bannerImage}}
|
{{#if bannerImage}}
|
||||||
<img src={{bannerImage}} class="wizard-step-banner">
|
<img src={{bannerImage}} class="wizard-step-banner">
|
||||||
{{/if}}
|
{{/if}}
|
||||||
@ -10,6 +11,7 @@
|
|||||||
{{#if step.description}}
|
{{#if step.description}}
|
||||||
<p class='wizard-step-description'>{{html-safe step.description}}</p>
|
<p class='wizard-step-description'>{{html-safe step.description}}</p>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
</div>
|
||||||
|
|
||||||
{{#wizard-step-form step=step}}
|
{{#wizard-step-form step=step}}
|
||||||
{{#each step.fields as |field|}}
|
{{#each step.fields as |field|}}
|
||||||
|
@ -18,15 +18,30 @@ class Wizard
|
|||||||
Step.new(step_name)
|
Step.new(step_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def append_step(step)
|
def append_step(step, after: nil)
|
||||||
return if @@excluded_steps.include?(step)
|
return if @@excluded_steps.include?(step)
|
||||||
|
|
||||||
step = create_step(step) if step.is_a?(String)
|
step = create_step(step) if step.is_a?(String)
|
||||||
|
|
||||||
yield step if block_given?
|
yield step if block_given?
|
||||||
|
|
||||||
last_step = @steps.last
|
if after
|
||||||
|
before_step = @steps.detect { |s| s.id == after }
|
||||||
|
|
||||||
|
if before_step
|
||||||
|
step.previous = before_step
|
||||||
|
step.index = before_step.index + 1
|
||||||
|
if before_step.next
|
||||||
|
step.next = before_step.next
|
||||||
|
before_step.next.previous = step
|
||||||
|
end
|
||||||
|
before_step.next = step
|
||||||
|
@steps.insert(before_step.index + 1, step)
|
||||||
|
step.index += 1 while (step = step.next)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
last_step = @steps.last
|
||||||
@steps << step
|
@steps << step
|
||||||
|
|
||||||
# If it's the first step
|
# If it's the first step
|
||||||
|
@ -81,6 +81,56 @@ describe Wizard do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#append_step with after specified" do
|
||||||
|
let(:user) { Fabricate.build(:moderator) }
|
||||||
|
let(:wizard) { Wizard.new(user) }
|
||||||
|
|
||||||
|
it 'inserts steps after the proper step' do
|
||||||
|
wizard.append_step('first') do |step|
|
||||||
|
step.add_field(id: 'another_element', type: 'text')
|
||||||
|
end
|
||||||
|
wizard.append_step('second') do |step|
|
||||||
|
step.add_field(id: 'another_element', type: 'text')
|
||||||
|
end
|
||||||
|
wizard.append_step('actually-second', after: 'first') do |step|
|
||||||
|
step.add_field(id: 'another_element', type: 'text')
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(wizard.steps.sort_by(&:index).map(&:id)).to eq(["first", "actually-second", "second"])
|
||||||
|
expect(wizard.steps.map(&:index).sort).to eq([0, 1, 2])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'inserts steps at the end if the after value does not match an existing step' do
|
||||||
|
wizard.append_step('first') do |step|
|
||||||
|
step.add_field(id: 'another_element', type: 'text')
|
||||||
|
end
|
||||||
|
wizard.append_step('second') do |step|
|
||||||
|
step.add_field(id: 'another_element', type: 'text')
|
||||||
|
end
|
||||||
|
wizard.append_step('should_be_last', after: 'abcdefghi') do |step|
|
||||||
|
step.add_field(id: 'another_element', type: 'text')
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(wizard.steps.sort_by(&:index).map(&:id)).to eq(["first", "second", "should_be_last"])
|
||||||
|
expect(wizard.steps.map(&:index).sort).to eq([0, 1, 2])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'inserts steps at the end' do
|
||||||
|
wizard.append_step('first') do |step|
|
||||||
|
step.add_field(id: 'another_element', type: 'text')
|
||||||
|
end
|
||||||
|
wizard.append_step('second') do |step|
|
||||||
|
step.add_field(id: 'another_element', type: 'text')
|
||||||
|
end
|
||||||
|
wizard.append_step('last', after: 'second') do |step|
|
||||||
|
step.add_field(id: 'another_element', type: 'text')
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(wizard.steps.sort_by(&:index).map(&:id)).to eq(["first", "second", "last"])
|
||||||
|
expect(wizard.steps.map(&:index).sort).to eq([0, 1, 2])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "completed?" do
|
describe "completed?" do
|
||||||
let(:user) { Fabricate.build(:moderator) }
|
let(:user) { Fabricate.build(:moderator) }
|
||||||
let(:wizard) { Wizard.new(user) }
|
let(:wizard) { Wizard.new(user) }
|
||||||
|
Loading…
Reference in New Issue
Block a user