1
0
Fork 0
Dieser Commit ist enthalten in:
Angus McLeod 2019-01-14 13:53:53 +11:00
Ursprung e8ac4f7ca8
Commit 0ea0524dcf
6 geänderte Dateien mit 40 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,3 @@
export default Ember.Controller.extend({
queryParams: ['reset']
})

Datei anzeigen

@ -31,8 +31,11 @@ CustomWizard.reopenClass({
}
});
export function findCustomWizard(wizardId) {
return ajax({ url: `/w/${wizardId}`, cache: false, dataType: 'json' }).then(result => {
export function findCustomWizard(wizardId, opts = {}) {
let url = `/w/${wizardId}`;
if (opts.reset) url += '?reset=true';
return ajax({ url, cache: false, dataType: 'json' }).then(result => {
const wizard = result.wizard;
if (!wizard) return null;

Datei anzeigen

@ -5,7 +5,9 @@ import { ajax } from 'wizard/lib/ajax';
export default Ember.Route.extend({
model(params) {
return findCustomWizard(params.wizard_id);
let opts = {};
if (params.reset == 'true') opts['reset'] = true;
return findCustomWizard(params.wizard_id, opts);
},
afterModel() {

Datei anzeigen

@ -23,8 +23,11 @@ class CustomWizard::WizardController < ::ApplicationController
format.json do
builder = CustomWizard::Builder.new(current_user, params[:wizard_id].underscore)
builder_opts = {}
builder_opts[:reset] = params[:reset] if params[:reset]
if builder.wizard.present?
wizard = builder.build
wizard = builder.build(builder_opts)
render_serialized(wizard, WizardSerializer)
else
render json: { error: I18n.t('wizard.none') }

Datei anzeigen

@ -52,8 +52,11 @@ class CustomWizard::Builder
result.gsub!(/w\{(.*?)\}/) { |match| data[$1.to_sym] }
end
def build
def build(build_opts = {})
unless (@wizard.completed? && !@wizard.multiple_submissions && !@wizard.user.admin) || !@steps || !@wizard.permitted?
reset_submissions if build_opts[:reset]
@steps.each do |step_template|
@wizard.append_step(step_template['id']) do |step|
step.title = step_template['title'] if step_template['title']
@ -63,7 +66,7 @@ class CustomWizard::Builder
if step_template['fields'] && step_template['fields'].length
step_template['fields'].each do |field_template|
append_field(step, step_template, field_template)
append_field(step, step_template, field_template, build_opts)
end
end
@ -126,7 +129,7 @@ class CustomWizard::Builder
@wizard
end
def append_field(step, step_template, field_template)
def append_field(step, step_template, field_template, build_opts)
params = {
id: field_template['id'],
type: field_template['type'],
@ -139,7 +142,7 @@ class CustomWizard::Builder
params[:key] = field_template['key'] if field_template['key']
## Load previously submitted values
if @submissions.last && !@submissions.last.key?("submitted_at")
if !build_opts[:reset] && @submissions.last && !@submissions.last.key?("submitted_at")
submission = @submissions.last
params[:value] = submission[field_template['id']] if submission[field_template['id']]
end
@ -401,4 +404,10 @@ class CustomWizard::Builder
PluginStore.set("#{@wizard.id}_submissions", @wizard.user.id, @submissions)
end
end
def reset_submissions
@submissions.pop(1) if @wizard.unfinished?
PluginStore.set("#{@wizard.id}_submissions", @wizard.user.id, @submissions)
@wizard.reset
end
end

Datei anzeigen

@ -82,7 +82,9 @@ class CustomWizard::Wizard
context: @id,
).distinct.order('updated_at DESC').first
if most_recent
if most_recent.subject == "reset"
false
elsif most_recent
last_finished_step = most_recent.subject
last_step = CustomWizard::Wizard.step_ids(@id).last
last_finished_step != last_step
@ -113,6 +115,15 @@ class CustomWizard::Wizard
user.staff? || user.trust_level.to_i >= min_trust.to_i
end
def reset
::UserHistory.create(
action: ::UserHistory.actions[:custom_wizard_step],
acting_user_id: @user.id,
context: @id,
subject: "reset"
)
end
def self.after_signup
rows = PluginStoreRow.where(plugin_name: 'custom_wizard')
wizards = [*rows].select { |r| r.value['after_signup'] }