1
0
Fork 0

init example (WIP)

Dieser Commit ist enthalten in:
angus 2021-03-29 17:17:57 +11:00
Ursprung cf50a7deb3
Commit 1db9793d3e
10 geänderte Dateien mit 93 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -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,

Datei anzeigen

@ -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}}

Datei anzeigen

@ -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"],

Datei anzeigen

@ -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,

Datei anzeigen

@ -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'],

Datei anzeigen

@ -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

Datei anzeigen

@ -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

Datei anzeigen

@ -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

Datei anzeigen

@ -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'

Datei anzeigen

@ -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,