2017-09-23 04:34:07 +02:00
|
|
|
class CustomWizard::AdminController < ::ApplicationController
|
2017-09-29 13:27:03 +02:00
|
|
|
before_action :ensure_logged_in
|
|
|
|
before_action :ensure_admin
|
2017-09-23 04:34:07 +02:00
|
|
|
|
|
|
|
def index
|
|
|
|
render nothing: true
|
|
|
|
end
|
|
|
|
|
2017-10-05 02:36:46 +02:00
|
|
|
def field_types
|
2017-10-09 07:52:09 +02:00
|
|
|
render json: { types: CustomWizard::Field.types }
|
2017-10-05 02:36:46 +02:00
|
|
|
end
|
|
|
|
|
2017-09-23 04:34:07 +02:00
|
|
|
def save
|
2017-09-24 05:01:18 +02:00
|
|
|
params.require(:wizard)
|
2017-09-23 04:34:07 +02:00
|
|
|
|
2017-09-24 05:01:18 +02:00
|
|
|
wizard = ::JSON.parse(params[:wizard])
|
2017-09-23 04:34:07 +02:00
|
|
|
|
2017-10-13 15:02:34 +02:00
|
|
|
PluginStore.set('custom_wizard', wizard["id"], wizard)
|
2017-09-23 04:34:07 +02:00
|
|
|
|
|
|
|
render json: success_json
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove
|
2017-09-24 05:01:18 +02:00
|
|
|
params.require(:id)
|
2017-09-23 04:34:07 +02:00
|
|
|
|
2017-09-29 13:27:03 +02:00
|
|
|
PluginStore.remove('custom_wizard', params[:id])
|
2017-09-23 04:34:07 +02:00
|
|
|
|
|
|
|
render json: success_json
|
|
|
|
end
|
|
|
|
|
2017-10-05 02:36:46 +02:00
|
|
|
def find_wizard
|
|
|
|
params.require(:wizard_id)
|
2017-09-23 04:34:07 +02:00
|
|
|
|
2017-10-07 04:27:38 +02:00
|
|
|
wizard = PluginStore.get('custom_wizard', params[:wizard_id].underscore)
|
2017-09-23 04:34:07 +02:00
|
|
|
|
|
|
|
render json: success_json.merge(wizard: wizard)
|
|
|
|
end
|
|
|
|
|
2017-10-05 02:36:46 +02:00
|
|
|
def custom_wizards
|
2017-09-29 13:27:03 +02:00
|
|
|
rows = PluginStoreRow.where(plugin_name: 'custom_wizard').order(:id)
|
2017-09-23 04:34:07 +02:00
|
|
|
|
2017-10-15 05:58:22 +02:00
|
|
|
wizards = [*rows].map { |r| CustomWizard::Template.new(r.value) }
|
2017-09-23 04:34:07 +02:00
|
|
|
|
|
|
|
render json: success_json.merge(wizards: wizards)
|
|
|
|
end
|
2017-10-05 02:36:46 +02:00
|
|
|
|
2017-10-22 05:37:58 +02:00
|
|
|
def submissions
|
2017-10-05 02:36:46 +02:00
|
|
|
params.require(:wizard_id)
|
|
|
|
|
2017-10-22 05:37:58 +02:00
|
|
|
rows = PluginStoreRow.where(plugin_name: "#{params[:wizard_id]}_submissions").order(:id)
|
2017-10-05 02:36:46 +02:00
|
|
|
|
2017-10-22 05:37:58 +02:00
|
|
|
submissions = [*rows].map { |r| ::JSON.parse(r.value) }
|
2017-10-05 02:36:46 +02:00
|
|
|
|
2017-10-22 05:37:58 +02:00
|
|
|
render json: success_json.merge(submissions: submissions)
|
2017-10-05 02:36:46 +02:00
|
|
|
end
|
2017-09-23 04:34:07 +02:00
|
|
|
end
|