admin.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. class CustomWizard::AdminController < ::ApplicationController
  2. before_action :ensure_logged_in
  3. before_action :ensure_admin
  4. def index
  5. render nothing: true
  6. end
  7. def field_types
  8. render json: { types: CustomWizard::Field.types }
  9. end
  10. def save
  11. params.require(:wizard)
  12. wizard = ::JSON.parse(params[:wizard])
  13. PluginStore.set('custom_wizard', wizard["id"], wizard)
  14. render json: success_json
  15. end
  16. def remove
  17. params.require(:id)
  18. PluginStore.remove('custom_wizard', params[:id])
  19. render json: success_json
  20. end
  21. def find_wizard
  22. params.require(:wizard_id)
  23. wizard = PluginStore.get('custom_wizard', params[:wizard_id].underscore)
  24. render json: success_json.merge(wizard: wizard)
  25. end
  26. def custom_wizards
  27. rows = PluginStoreRow.where(plugin_name: 'custom_wizard').order(:id)
  28. wizards = [*rows].map { |r| CustomWizard::Template.new(r.value) }
  29. render json: success_json.merge(wizards: wizards)
  30. end
  31. def find_submissions
  32. params.require(:wizard_id)
  33. wizard = PluginStore.get('custom_wizard_submissions', params[:wizard_id].underscore)
  34. render json: success_json.merge(submissions: submissions)
  35. end
  36. def submissions
  37. rows = PluginStoreRow.where(plugin_name: 'custom_wizard_submissions').order(:id)
  38. all = [*rows].map do |r|
  39. wizard = PluginStore.get('custom_wizard', r.key)
  40. name = wizard ? wizard['name'] : r.key
  41. {
  42. id: r.key,
  43. name: name,
  44. submissions: ::JSON.parse(r.value)
  45. }
  46. end
  47. render json: success_json.merge(submissions: all)
  48. end
  49. end