0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-10 04:12:53 +01:00
discourse-custom-wizard/controllers/admin.rb

71 Zeilen
1,6 KiB
Ruby

2017-09-23 04:34:07 +02:00
class CustomWizard::AdminController < ::ApplicationController
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
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
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
def find_submissions
params.require(:wizard_id)
2017-10-07 04:27:38 +02:00
wizard = PluginStore.get('custom_wizard_submissions', params[:wizard_id].underscore)
2017-10-05 02:36:46 +02:00
render json: success_json.merge(submissions: submissions)
end
def submissions
rows = PluginStoreRow.where(plugin_name: 'custom_wizard_submissions').order(:id)
all = [*rows].map do |r|
wizard = PluginStore.get('custom_wizard', r.key)
name = wizard ? wizard['name'] : r.key
{
id: r.key,
name: name,
submissions: ::JSON.parse(r.value)
}
end
render json: success_json.merge(submissions: all)
end
2017-09-23 04:34:07 +02:00
end