0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-14 13:52:54 +01:00
discourse-custom-wizard/controllers/custom_wizard/admin/wizard.rb
Angus McLeod ceef3f4bc9
Step and field conditionality (#87)
* Re structure builder logic to allow for step conditionality

Concerns
- Performance. Look at whether the additional build in the steps controller can be reduced
- Does not work if applied to the last step.
- Certain conditions will not work with the first step(?)
- How should this be scoped to known functionality?

* Add indexes and conditions to steps and fields

* Complete and add spec

* Complete backend

* Complete step conditionality and field indexing

* Fix failing spec

* Update coverage

* Apply rubocop

* Apply prettier

* Apply prettier to wizard js

* Fix schema issues created in merge

* Remove setting label for force_final

* Improve client wizard cache naming

* Improve steps controller and spec conditionality

* Improve final step attribute naming

* Fix failing spec

* Linting

* Add one more final step test

* Linting

* Fix eslint issues

* Apply prettier

* Linting, syntax, merge and copy cleanups

* Update wizard-admin.scss

* Fix template linting

* Rubocop fixes
2021-04-20 23:28:19 +05:30

164 Zeilen
3,9 KiB
Ruby

# frozen_string_literal: true
class CustomWizard::AdminWizardController < CustomWizard::AdminController
before_action :find_wizard, only: [:show, :remove]
def index
render_json_dump(
wizard_list: ActiveModel::ArraySerializer.new(
CustomWizard::Wizard.list(current_user),
each_serializer: CustomWizard::BasicWizardSerializer
),
field_types: CustomWizard::Field.types,
realtime_validations: CustomWizard::RealtimeValidation.types,
custom_fields: custom_field_list
)
end
def show
params.require(:wizard_id)
if data = CustomWizard::Template.find(params[:wizard_id].underscore)
render json: data.as_json
else
render json: { none: true }
end
end
def remove
if CustomWizard::Template.remove(@wizard.id)
render json: success_json
else
render json: failed_json
end
end
def save
template = CustomWizard::Template.new(save_wizard_params.to_h)
wizard_id = template.save(create: params[:create])
if template.errors.any?
render json: failed_json.merge(errors: template.errors.full_messages)
else
render json: success_json.merge(wizard_id: wizard_id)
end
end
private
def mapped_params
[
:type,
:connector,
:output,
:output_type,
:output_connector,
pairs: [
:index,
:key,
:key_type,
:value,
:value_type,
:connector,
value: [],
key: [],
],
output: [],
]
end
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,
:theme_id,
permitted: mapped_params,
steps: [
:id,
:index,
:title,
:key,
:banner,
:raw_description,
:required_data_message,
:force_final,
required_data: mapped_params,
permitted_params: mapped_params,
condition: mapped_params,
fields: [
:id,
:index,
:label,
:image,
:description,
:required,
:key,
:type,
:min_length,
:max_length,
:char_counter,
:file_types,
:format,
:limit,
:property,
prefill: mapped_params,
content: mapped_params,
condition: mapped_params,
index: mapped_params,
validations: {},
]
],
actions: [
:id,
:run_after,
:type,
:code,
:skip_redirect,
:suppress_notifications,
:post,
:post_builder,
:post_template,
:notification_level,
:api,
:api_endpoint,
:api_body,
:wizard_user,
title: mapped_params,
category: mapped_params,
tags: mapped_params,
custom_fields: mapped_params,
visible: mapped_params,
required: mapped_params,
recipient: mapped_params,
categories: mapped_params,
mute_remainder: mapped_params,
profile_updates: mapped_params,
group: mapped_params,
url: mapped_params,
name: mapped_params,
slug: mapped_params,
color: mapped_params,
text_color: mapped_params,
parent_category_id: mapped_params,
permissions: mapped_params,
full_name: mapped_params,
bio_raw: mapped_params,
usernames: mapped_params,
owner_usernames: mapped_params,
grant_trust_level: mapped_params,
mentionable_level: mapped_params,
messageable_level: mapped_params,
visibility_level: mapped_params,
members_visibility_level: mapped_params
]
)
end
end