various
Dieser Commit ist enthalten in:
Ursprung
be81aa7f4d
Commit
11953055fd
7 geänderte Dateien mit 49 neuen und 30 gelöschten Zeilen
|
@ -24,7 +24,7 @@ const CustomWizard = Discourse.Model.extend({
|
||||||
if (value) wizard[p] = value;
|
if (value) wizard[p] = value;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (wizard['after_time'] && wizard['after_time_scheduled']) {
|
if (wizard['after_time'] && !wizard['after_time_scheduled']) {
|
||||||
return reject({ error: 'after_time_need_time' });
|
return reject({ error: 'after_time_need_time' });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,26 +2,28 @@ import CustomWizard from '../models/custom-wizard';
|
||||||
|
|
||||||
export default Discourse.Route.extend({
|
export default Discourse.Route.extend({
|
||||||
model(params) {
|
model(params) {
|
||||||
return Ember.RSVP.hash({
|
return CustomWizard.submissions(params.wizard_id);
|
||||||
submissions: CustomWizard.submissions(params.wizard_id),
|
|
||||||
wizard: this.modelFor('admin-wizards-submissions').findBy('id', params.wizard_id)
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setupController(controller, model) {
|
setupController(controller, model) {
|
||||||
let fields = ['user'];
|
let fields = [];
|
||||||
|
model.forEach((s) => {
|
||||||
model.wizard.steps.forEach((s) => {
|
Object.keys(s).forEach((k) => {
|
||||||
if (s.fields) {
|
if (fields.indexOf(k) < 0) {
|
||||||
s.fields.forEach((f) => {
|
fields.push(k);
|
||||||
fields.push(f.id);
|
}
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
});
|
|
||||||
|
let submissions = [];
|
||||||
controller.setProperties({
|
model.forEach((s) => {
|
||||||
submissions: model.submissions,
|
let submission = {};
|
||||||
fields
|
fields.forEach((f) => {
|
||||||
});
|
submission[f] = s[f];
|
||||||
|
});
|
||||||
|
submissions.push(submission);
|
||||||
|
});
|
||||||
|
|
||||||
|
controller.setProperties({ submissions, fields });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -75,14 +75,18 @@ class CustomWizard::AdminController < ::ApplicationController
|
||||||
|
|
||||||
return render json: { error: error } if error
|
return render json: { error: error } if error
|
||||||
|
|
||||||
existing = PluginStore.get('custom_wizard', params[:id])
|
existing = PluginStore.get('custom_wizard', wizard['id']) || {}
|
||||||
|
new_time = existing['after_time_scheduled'] ?
|
||||||
|
after_time_scheduled != Time.parse(existing['after_time_scheduled']).utc :
|
||||||
|
true
|
||||||
|
|
||||||
if wizard['after_time'] && after_time_scheduled != Time.parse(existing['after_time_scheduled']).utc
|
if wizard['after_time'] && new_time
|
||||||
Jobs.cancel_scheduled_job(:set_after_time_wizard)
|
Jobs.cancel_scheduled_job(:set_after_time_wizard)
|
||||||
Jobs.enqueue_at(after_time_scheduled, :set_after_time_wizard, wizard_id: wizard['id'])
|
Jobs.enqueue_at(after_time_scheduled, :set_after_time_wizard, wizard_id: wizard['id'])
|
||||||
end
|
end
|
||||||
|
|
||||||
if existing['after_time'] && !wizard['after_time']
|
if existing['after_time'] && !wizard['after_time']
|
||||||
|
Jobs.cancel_scheduled_job(:set_after_time_wizard)
|
||||||
Jobs.enqueue(:clear_after_time_wizard, wizard_id: wizard['id'])
|
Jobs.enqueue(:clear_after_time_wizard, wizard_id: wizard['id'])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -97,6 +101,7 @@ class CustomWizard::AdminController < ::ApplicationController
|
||||||
wizard = PluginStore.get('custom_wizard', params[:id])
|
wizard = PluginStore.get('custom_wizard', params[:id])
|
||||||
|
|
||||||
if wizard['after_time']
|
if wizard['after_time']
|
||||||
|
Jobs.cancel_scheduled_job(:set_after_time_wizard)
|
||||||
Jobs.enqueue(:clear_after_time_wizard, wizard_id: wizard['id'])
|
Jobs.enqueue(:clear_after_time_wizard, wizard_id: wizard['id'])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -124,10 +129,14 @@ class CustomWizard::AdminController < ::ApplicationController
|
||||||
def submissions
|
def submissions
|
||||||
params.require(:wizard_id)
|
params.require(:wizard_id)
|
||||||
|
|
||||||
rows = PluginStoreRow.where(plugin_name: "#{params[:wizard_id]}_submissions").order(:id)
|
rows = PluginStoreRow.where(plugin_name: "#{params[:wizard_id]}_submissions").order('id DESC')
|
||||||
|
|
||||||
submissions = [*rows].map { |r| ::JSON.parse(r.value) }.flatten
|
all_submissions = [*rows].map do |r|
|
||||||
|
submissions = ::JSON.parse(r.value)
|
||||||
|
username = User.find(r.key).username
|
||||||
|
submissions.map { |s| { username: username }.merge!(s) }
|
||||||
|
end.flatten
|
||||||
|
|
||||||
render json: success_json.merge(submissions: submissions)
|
render json: success_json.merge(submissions: all_submissions)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module Jobs
|
module Jobs
|
||||||
class ClearNextSessionWizard < Jobs::Base
|
class ClearAfterTimeWizard < Jobs::Base
|
||||||
sidekiq_options queue: 'critical'
|
sidekiq_options queue: 'critical'
|
||||||
|
|
||||||
def execute(args)
|
def execute(args)
|
|
@ -1,5 +1,5 @@
|
||||||
module Jobs
|
module Jobs
|
||||||
class SetNextSessionWizard < Jobs::Base
|
class SetAfterTimeWizard < Jobs::Base
|
||||||
def execute(args)
|
def execute(args)
|
||||||
if PluginStoreRow.exists?(plugin_name: 'custom_wizard', key: args[:wizard_id])
|
if PluginStoreRow.exists?(plugin_name: 'custom_wizard', key: args[:wizard_id])
|
||||||
user_ids = []
|
user_ids = []
|
|
@ -103,6 +103,7 @@ class CustomWizard::Builder
|
||||||
submission = @submissions.last || {}
|
submission = @submissions.last || {}
|
||||||
step_input = updater.fields || {}
|
step_input = updater.fields || {}
|
||||||
user = @wizard.user
|
user = @wizard.user
|
||||||
|
final_step = updater.step.next.nil?
|
||||||
|
|
||||||
if s['fields'] && s['fields'].length
|
if s['fields'] && s['fields'].length
|
||||||
s['fields'].each do |f|
|
s['fields'].each do |f|
|
||||||
|
@ -225,10 +226,6 @@ class CustomWizard::Builder
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if updater.errors.empty?
|
|
||||||
updater.result = { redirect_to: data['redirect_to'] }
|
|
||||||
end
|
|
||||||
|
|
||||||
if @wizard.save_submissions && updater.errors.empty?
|
if @wizard.save_submissions && updater.errors.empty?
|
||||||
if step_input
|
if step_input
|
||||||
step_input.each do |key, value|
|
step_input.each do |key, value|
|
||||||
|
@ -236,6 +233,10 @@ class CustomWizard::Builder
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if final_step
|
||||||
|
data['submitted_at'] = Time.now.iso8601
|
||||||
|
end
|
||||||
|
|
||||||
if data.present?
|
if data.present?
|
||||||
@submissions.pop(1) if @wizard.unfinished?
|
@submissions.pop(1) if @wizard.unfinished?
|
||||||
@submissions.push(data)
|
@submissions.push(data)
|
||||||
|
@ -244,14 +245,21 @@ class CustomWizard::Builder
|
||||||
end
|
end
|
||||||
|
|
||||||
# Ensure there is no submission left over after the user has completed a wizard with save_submissions off
|
# Ensure there is no submission left over after the user has completed a wizard with save_submissions off
|
||||||
if !@wizard.save_submissions && updater.step.next.nil?
|
if !@wizard.save_submissions && final_step
|
||||||
PluginStore.remove("#{@wizard.id}_submissions", @wizard.user.id)
|
PluginStore.remove("#{@wizard.id}_submissions", @wizard.user.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
if @wizard.after_time && updater.step.next.nil?
|
if @wizard.after_time && final_step
|
||||||
@wizard.user.custom_fields.delete('redirect_to_wizard');
|
@wizard.user.custom_fields.delete('redirect_to_wizard');
|
||||||
@wizard.user.save_custom_fields(true)
|
@wizard.user.save_custom_fields(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if updater.errors.empty?
|
||||||
|
# If the user will be redirected to a new wizard send them there straight away
|
||||||
|
user_redirect = user.custom_fields['redirect_to_wizard']
|
||||||
|
redirect_to = user_redirect ? "/w/#{user_redirect}" : data['redirect_to']
|
||||||
|
updater.result = { redirect_to: redirect_to } if redirect_to
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -98,7 +98,7 @@ after_initialize do
|
||||||
|
|
||||||
def redirect_to_wizard_if_required
|
def redirect_to_wizard_if_required
|
||||||
@wizard_id ||= current_user.custom_fields['redirect_to_wizard']
|
@wizard_id ||= current_user.custom_fields['redirect_to_wizard']
|
||||||
if @wizard_id && request.original_url !~ /w/ && request.original_url !~ /admin/
|
if @wizard_id && request.referer !~ /w/ && request.referer !~ /admin/
|
||||||
redirect_to "/w/#{@wizard_id}"
|
redirect_to "/w/#{@wizard_id}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Laden …
In neuem Issue referenzieren