2021-03-11 07:30:15 +01:00
|
|
|
# frozen_string_literal: true
|
2020-04-13 14:17:22 +02:00
|
|
|
class CustomWizard::AdminWizardController < CustomWizard::AdminController
|
|
|
|
before_action :find_wizard, only: [:show, :remove]
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-04-13 14:17:22 +02:00
|
|
|
def index
|
|
|
|
render_json_dump(
|
|
|
|
wizard_list: ActiveModel::ArraySerializer.new(
|
2020-11-03 01:24:20 +01:00
|
|
|
CustomWizard::Wizard.list(current_user),
|
2020-04-13 14:17:22 +02:00
|
|
|
each_serializer: CustomWizard::BasicWizardSerializer
|
|
|
|
),
|
2020-10-20 07:40:23 +02:00
|
|
|
field_types: CustomWizard::Field.types,
|
2021-01-27 06:08:26 +01:00
|
|
|
realtime_validations: CustomWizard::RealtimeValidation.types,
|
2020-10-20 07:40:23 +02:00
|
|
|
custom_fields: custom_field_list
|
2020-04-13 14:17:22 +02:00
|
|
|
)
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-04-13 14:17:22 +02:00
|
|
|
def show
|
|
|
|
params.require(:wizard_id)
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-10-31 08:05:50 +01:00
|
|
|
if data = CustomWizard::Template.find(params[:wizard_id].underscore)
|
2020-04-13 14:17:22 +02:00
|
|
|
render json: data.as_json
|
|
|
|
else
|
|
|
|
render json: { none: true }
|
|
|
|
end
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-04-13 14:17:22 +02:00
|
|
|
def remove
|
2020-10-31 08:05:50 +01:00
|
|
|
if CustomWizard::Template.remove(@wizard.id)
|
|
|
|
render json: success_json
|
|
|
|
else
|
|
|
|
render json: failed_json
|
|
|
|
end
|
2020-04-13 14:17:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
2020-11-03 01:24:20 +01:00
|
|
|
template = CustomWizard::Template.new(save_wizard_params.to_h)
|
|
|
|
wizard_id = template.save(create: params[:create])
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-11-03 01:24:20 +01:00
|
|
|
if template.errors.any?
|
2022-01-31 10:41:14 +01:00
|
|
|
render json: failed_json.merge(backend_validation_error: template.errors.full_messages.join("\n\n"))
|
2021-03-11 07:30:15 +01:00
|
|
|
else
|
2020-11-03 01:24:20 +01:00
|
|
|
render json: success_json.merge(wizard_id: wizard_id)
|
2020-04-13 14:17:22 +02:00
|
|
|
end
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-04-13 14:17:22 +02:00
|
|
|
private
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-04-13 14:17:22 +02:00
|
|
|
def mapped_params
|
|
|
|
[
|
|
|
|
:type,
|
|
|
|
:connector,
|
|
|
|
:output,
|
|
|
|
:output_type,
|
|
|
|
:output_connector,
|
|
|
|
pairs: [
|
|
|
|
:index,
|
|
|
|
:key,
|
|
|
|
:key_type,
|
|
|
|
:value,
|
|
|
|
:value_type,
|
|
|
|
:connector,
|
|
|
|
value: [],
|
|
|
|
key: [],
|
|
|
|
],
|
|
|
|
output: [],
|
|
|
|
]
|
|
|
|
end
|
2021-01-30 18:46:04 +01:00
|
|
|
|
2020-04-13 14:17:22 +02:00
|
|
|
def save_wizard_params
|
|
|
|
params.require(:wizard).permit(
|
|
|
|
:id,
|
|
|
|
:name,
|
|
|
|
:background,
|
|
|
|
:save_submissions,
|
|
|
|
:multiple_submissions,
|
|
|
|
:after_signup,
|
|
|
|
:after_time,
|
|
|
|
:after_time_scheduled,
|
|
|
|
:required,
|
|
|
|
:prompt_completion,
|
|
|
|
:restart_on_revisit,
|
2021-09-22 10:22:05 +02:00
|
|
|
:resume_on_revisit,
|
2022-12-24 09:42:09 +01:00
|
|
|
:allow_guests,
|
2020-04-13 14:17:22 +02:00
|
|
|
:theme_id,
|
|
|
|
permitted: mapped_params,
|
|
|
|
steps: [
|
|
|
|
:id,
|
2021-04-20 19:58:19 +02:00
|
|
|
:index,
|
2020-04-13 14:17:22 +02:00
|
|
|
:title,
|
|
|
|
:key,
|
|
|
|
:banner,
|
2022-08-02 13:39:56 +02:00
|
|
|
:banner_upload_id,
|
2020-04-13 14:17:22 +02:00
|
|
|
:raw_description,
|
|
|
|
:required_data_message,
|
2021-04-20 19:58:19 +02:00
|
|
|
:force_final,
|
2020-04-13 14:17:22 +02:00
|
|
|
required_data: mapped_params,
|
|
|
|
permitted_params: mapped_params,
|
2021-04-20 19:58:19 +02:00
|
|
|
condition: mapped_params,
|
2020-04-13 14:17:22 +02:00
|
|
|
fields: [
|
|
|
|
:id,
|
2021-04-20 19:58:19 +02:00
|
|
|
:index,
|
2020-04-13 14:17:22 +02:00
|
|
|
:label,
|
|
|
|
:image,
|
2022-08-02 13:39:56 +02:00
|
|
|
:image_upload_id,
|
2020-04-13 14:17:22 +02:00
|
|
|
:description,
|
|
|
|
:required,
|
|
|
|
:key,
|
|
|
|
:type,
|
|
|
|
:min_length,
|
2020-12-08 08:14:37 +01:00
|
|
|
:max_length,
|
2021-01-12 11:46:24 +01:00
|
|
|
:char_counter,
|
2020-04-13 14:17:22 +02:00
|
|
|
:file_types,
|
2020-07-16 05:26:56 +02:00
|
|
|
:format,
|
2020-04-13 14:17:22 +02:00
|
|
|
:limit,
|
|
|
|
:property,
|
2021-07-12 13:35:05 +02:00
|
|
|
:preview_template,
|
2021-07-03 12:11:49 +02:00
|
|
|
:placeholder,
|
2022-10-26 10:04:50 +02:00
|
|
|
:can_create_tag,
|
2020-04-13 14:17:22 +02:00
|
|
|
prefill: mapped_params,
|
2021-01-30 18:46:04 +01:00
|
|
|
content: mapped_params,
|
2021-04-20 19:58:19 +02:00
|
|
|
condition: mapped_params,
|
|
|
|
index: mapped_params,
|
2021-01-30 18:46:04 +01:00
|
|
|
validations: {},
|
2022-02-07 06:40:52 +01:00
|
|
|
tag_groups: [],
|
2020-04-13 14:17:22 +02:00
|
|
|
]
|
|
|
|
],
|
|
|
|
actions: [
|
|
|
|
:id,
|
|
|
|
:run_after,
|
|
|
|
:type,
|
|
|
|
:code,
|
|
|
|
:skip_redirect,
|
2020-10-20 02:42:10 +02:00
|
|
|
:suppress_notifications,
|
2020-04-14 01:39:21 +02:00
|
|
|
:post,
|
2020-04-15 03:23:41 +02:00
|
|
|
:post_builder,
|
2020-04-14 01:39:21 +02:00
|
|
|
:post_template,
|
2020-05-25 15:59:31 +02:00
|
|
|
:notification_level,
|
2020-05-30 21:26:14 +02:00
|
|
|
:api,
|
|
|
|
:api_endpoint,
|
|
|
|
:api_body,
|
2020-07-20 05:06:36 +02:00
|
|
|
:wizard_user,
|
2020-04-13 14:17:22 +02:00
|
|
|
title: mapped_params,
|
|
|
|
category: mapped_params,
|
|
|
|
tags: mapped_params,
|
|
|
|
custom_fields: mapped_params,
|
2020-07-20 06:26:11 +02:00
|
|
|
visible: mapped_params,
|
2020-04-13 14:17:22 +02:00
|
|
|
required: mapped_params,
|
|
|
|
recipient: mapped_params,
|
2020-05-24 12:20:15 +02:00
|
|
|
categories: mapped_params,
|
2020-05-23 00:42:26 +02:00
|
|
|
mute_remainder: mapped_params,
|
2020-04-13 14:17:22 +02:00
|
|
|
profile_updates: mapped_params,
|
2020-04-29 03:47:08 +02:00
|
|
|
group: mapped_params,
|
2020-07-09 04:19:36 +02:00
|
|
|
url: mapped_params,
|
|
|
|
name: mapped_params,
|
|
|
|
slug: mapped_params,
|
|
|
|
color: mapped_params,
|
|
|
|
text_color: mapped_params,
|
|
|
|
parent_category_id: mapped_params,
|
2020-07-16 07:25:06 +02:00
|
|
|
permissions: mapped_params,
|
|
|
|
full_name: mapped_params,
|
|
|
|
bio_raw: mapped_params,
|
2020-07-16 09:50:09 +02:00
|
|
|
usernames: mapped_params,
|
|
|
|
owner_usernames: mapped_params,
|
2020-07-16 07:25:06 +02:00
|
|
|
grant_trust_level: mapped_params,
|
|
|
|
mentionable_level: mapped_params,
|
|
|
|
messageable_level: mapped_params,
|
|
|
|
visibility_level: mapped_params,
|
2022-09-19 12:09:34 +02:00
|
|
|
members_visibility_level: mapped_params,
|
2022-10-10 14:04:55 +02:00
|
|
|
add_event: mapped_params,
|
|
|
|
add_location: mapped_params
|
2020-04-13 14:17:22 +02:00
|
|
|
]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|