Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-15 14:22:53 +01:00
init example (WIP)
Dieser Commit ist enthalten in:
Ursprung
cf50a7deb3
Commit
1db9793d3e
10 geänderte Dateien mit 93 neuen und 2 gelöschten Zeilen
|
@ -57,6 +57,20 @@ const step = {
|
|||
},
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* unit: custom_wizard:templates_and_builder
|
||||
* type: step
|
||||
* number: 2
|
||||
* title: Add the attribute to the wizard schema
|
||||
* description: Custom Wizard templates are modeled in the client via
|
||||
* the wizard-schema, which, along with the serialization in
|
||||
* wizard-json and models/custom-wizard, models and serializes
|
||||
* data on the client. Normally when adding an attribute, you
|
||||
* just need to add it to the schema, for the rest of the
|
||||
* modeling and serialization to work.
|
||||
*/
|
||||
|
||||
const field = {
|
||||
basic: {
|
||||
id: null,
|
||||
|
|
|
@ -111,6 +111,18 @@
|
|||
checked=field.char_counter}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{!--
|
||||
/*
|
||||
* unit: custom_wizard:templates_and_builder
|
||||
* type: step
|
||||
* number: 1
|
||||
* title: Add the attribute to the template
|
||||
* description: First... [describe how it's often not necessary to update
|
||||
* the component javascript]
|
||||
*/
|
||||
--}}
|
||||
|
||||
{{/if}}
|
||||
|
||||
{{#if isUpload}}
|
||||
|
|
|
@ -15,6 +15,17 @@ export default {
|
|||
const { clipboardHelpers } = requirejs("discourse/lib/utilities");
|
||||
const { toMarkdown } = requirejs("discourse/lib/to-markdown");
|
||||
|
||||
/*
|
||||
* unit: custom_wizard:templates_and_builder
|
||||
* type: step
|
||||
* number: 9
|
||||
* title: Handle the attribute in the wizard client
|
||||
* description: We can now handle our new attribute in the wizard client.
|
||||
* For our "highlighted" attribute, we would add a
|
||||
* classNameBinding in the wizard-field component which
|
||||
* we've imported from the discourse/discourse wizard and are
|
||||
* extending here.
|
||||
*/
|
||||
FieldComponent.reopen({
|
||||
classNameBindings: ["field.id"],
|
||||
|
||||
|
|
|
@ -66,6 +66,14 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController
|
|||
]
|
||||
end
|
||||
|
||||
##
|
||||
# type: step
|
||||
# number: 3
|
||||
# title: Add a permitted parameter
|
||||
# description: The custom wizard server admin will only accept permitted
|
||||
# attributes...
|
||||
##
|
||||
|
||||
def save_wizard_params
|
||||
params.require(:wizard).permit(
|
||||
:id,
|
||||
|
|
|
@ -147,6 +147,14 @@ class CustomWizard::Builder
|
|||
@wizard
|
||||
end
|
||||
|
||||
##
|
||||
# type: step
|
||||
# number: 7
|
||||
# title: Add it to the builder
|
||||
# description: When our template is built into a wizard, we need our new
|
||||
# attribute to be built here in the builder so it's ready to
|
||||
# be sent to the wizard client.
|
||||
##
|
||||
def append_field(step, step_template, field_template, build_opts, index)
|
||||
params = {
|
||||
id: field_template['id'],
|
||||
|
|
|
@ -10,6 +10,13 @@ class CustomWizard::Template
|
|||
@data = data
|
||||
end
|
||||
|
||||
##
|
||||
# type: step
|
||||
# number: 4
|
||||
# title: Our new field is saved to the template
|
||||
# description: The template is loaded into the wizard model when it is built,
|
||||
# our attribute has to be present, for it to build properly...
|
||||
##
|
||||
def save(opts = {})
|
||||
@opts = opts
|
||||
|
||||
|
|
|
@ -8,6 +8,14 @@ class CustomWizard::TemplateValidator
|
|||
@opts = opts
|
||||
end
|
||||
|
||||
##
|
||||
# type: step
|
||||
# number: 5
|
||||
# title: Add a validation
|
||||
# description: If our new attribute requires validation, that should be
|
||||
# handled here, which is run before the template is saved
|
||||
# to the database.
|
||||
##
|
||||
def perform
|
||||
data = @data
|
||||
|
||||
|
|
|
@ -6,6 +6,14 @@ require_dependency 'wizard/builder'
|
|||
|
||||
UserHistory.actions[:custom_wizard_step] = 1000
|
||||
|
||||
##
|
||||
# type: step
|
||||
# number: 6
|
||||
# title: Add the parameter to the wizard model
|
||||
# description: The template is loaded into the wizard model when it is built,
|
||||
# our attribute has to be present, for it to build properly...
|
||||
##
|
||||
|
||||
class CustomWizard::Wizard
|
||||
include ActiveModel::SerializerSupport
|
||||
|
||||
|
|
|
@ -6,6 +6,14 @@
|
|||
# url: https://github.com/paviliondev/discourse-custom-wizard
|
||||
# contact emails: angus@thepavilion.io
|
||||
|
||||
##
|
||||
# unit: custom_wizard:templates_and_builder
|
||||
# type: introduction
|
||||
# title: Adding a new wizard field attribute.
|
||||
# description: In this unit, we'll learn about creating, editing, validating
|
||||
# and building wizard templates by adding a new field attribute.
|
||||
##
|
||||
|
||||
register_asset 'stylesheets/common/wizard-admin.scss'
|
||||
register_asset 'stylesheets/common/wizard-mapper.scss'
|
||||
register_asset 'lib/jquery.timepicker.min.js'
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
##
|
||||
# type: step
|
||||
# number: 8
|
||||
# title: Add it to the serializer
|
||||
# description: We want our new attribute to be serialized to the wizard client...
|
||||
##
|
||||
|
||||
class CustomWizard::FieldSerializer < ::WizardFieldSerializer
|
||||
|
||||
attributes :image,
|
||||
|
|
Laden …
In neuem Issue referenzieren