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 = { const field = {
basic: { basic: {
id: null, id: null,

Datei anzeigen

@ -111,6 +111,18 @@
checked=field.char_counter}} checked=field.char_counter}}
</div> </div>
</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}}
{{#if isUpload}} {{#if isUpload}}

Datei anzeigen

@ -14,7 +14,18 @@ export default {
const DEditor = requirejs("discourse/components/d-editor").default; const DEditor = requirejs("discourse/components/d-editor").default;
const { clipboardHelpers } = requirejs("discourse/lib/utilities"); const { clipboardHelpers } = requirejs("discourse/lib/utilities");
const { toMarkdown } = requirejs("discourse/lib/to-markdown"); 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({ FieldComponent.reopen({
classNameBindings: ["field.id"], classNameBindings: ["field.id"],

Datei anzeigen

@ -65,6 +65,14 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController
output: [], output: [],
] ]
end 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 def save_wizard_params
params.require(:wizard).permit( params.require(:wizard).permit(

Datei anzeigen

@ -147,6 +147,14 @@ class CustomWizard::Builder
@wizard @wizard
end 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) def append_field(step, step_template, field_template, build_opts, index)
params = { params = {
id: field_template['id'], id: field_template['id'],

Datei anzeigen

@ -9,7 +9,14 @@ class CustomWizard::Template
def initialize(data) def initialize(data)
@data = data @data = data
end 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 = {}) def save(opts = {})
@opts = opts @opts = opts

Datei anzeigen

@ -8,6 +8,14 @@ class CustomWizard::TemplateValidator
@opts = opts @opts = opts
end 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 def perform
data = @data data = @data

Datei anzeigen

@ -6,6 +6,14 @@ require_dependency 'wizard/builder'
UserHistory.actions[:custom_wizard_step] = 1000 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 class CustomWizard::Wizard
include ActiveModel::SerializerSupport include ActiveModel::SerializerSupport

Datei anzeigen

@ -6,6 +6,14 @@
# url: https://github.com/paviliondev/discourse-custom-wizard # url: https://github.com/paviliondev/discourse-custom-wizard
# contact emails: angus@thepavilion.io # 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-admin.scss'
register_asset 'stylesheets/common/wizard-mapper.scss' register_asset 'stylesheets/common/wizard-mapper.scss'
register_asset 'lib/jquery.timepicker.min.js' register_asset 'lib/jquery.timepicker.min.js'

Datei anzeigen

@ -1,5 +1,12 @@
# frozen_string_literal: true # 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 class CustomWizard::FieldSerializer < ::WizardFieldSerializer
attributes :image, attributes :image,