From b212eaa2f341c4e0e2dd76d2a99678fe5de9c5e8 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Mon, 30 Mar 2020 10:53:28 +1100 Subject: [PATCH] wip --- .../components/wizard-custom-field.js.es6 | 10 ++ .../components/wizard-custom-step.js.es6 | 10 ++ .../discourse/components/wizard-links.js.es6 | 7 +- .../components/wizard-text-editor.js.es6 | 18 ++- .../discourse/controllers/admin-wizard.js.es6 | 18 ++- .../controllers/next-session-scheduled.js.es6 | 3 +- .../discourse/lib/custom-wizard.js.es6 | 9 +- .../discourse/templates/admin-wizard.hbs | 53 ++++----- .../components/wizard-custom-action.hbs | 58 ++++------ .../components/wizard-custom-field.hbs | 104 +++++++++--------- .../components/wizard-custom-step.hbs | 59 +++++----- .../templates/components/wizard-export.hbs | 8 +- .../templates/components/wizard-links.hbs | 26 ++--- .../components/wizard-text-editor.hbs | 11 +- .../components/wizard-composer-editor.js.es6 | 1 - .../templates/components/wizard-field.hbs | 6 +- .../templates/components/wizard-step.hbs | 10 +- assets/stylesheets/wizard/wizard_custom.scss | 60 ++++------ assets/stylesheets/wizard_custom_admin.scss | 69 ++++++++---- config/locales/client.en.yml | 10 +- config/locales/client.fr.yml | 1 - plugin.rb | 4 +- 22 files changed, 296 insertions(+), 259 deletions(-) diff --git a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 index 654fea42..f5d85a48 100644 --- a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 @@ -65,4 +65,14 @@ export default Ember.Component.extend({ return options; }, + + actions: { + imageUploadDone(upload) { + this.set("field.image", upload.url); + }, + + imageUploadDeleted() { + this.set("field.image", null); + } + } }); diff --git a/assets/javascripts/discourse/components/wizard-custom-step.js.es6 b/assets/javascripts/discourse/components/wizard-custom-step.js.es6 index c8945b80..066deff2 100644 --- a/assets/javascripts/discourse/components/wizard-custom-step.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-step.js.es6 @@ -67,4 +67,14 @@ export default Ember.Component.extend({ return fields; }, + + actions: { + bannerUploadDone(upload) { + this.set("step.banner", upload.url); + }, + + bannerUploadDeleted() { + this.set("step.banner", null); + } + } }); diff --git a/assets/javascripts/discourse/components/wizard-links.js.es6 b/assets/javascripts/discourse/components/wizard-links.js.es6 index e7113c17..5a351296 100644 --- a/assets/javascripts/discourse/components/wizard-links.js.es6 +++ b/assets/javascripts/discourse/components/wizard-links.js.es6 @@ -1,15 +1,16 @@ import { default as computed, on, observes } from 'discourse-common/utils/decorators'; import { notEmpty } from "@ember/object/computed"; +import { scheduleOnce } from "@ember/runloop"; export default Ember.Component.extend({ - classNames: 'wizard-links', + classNameBindings: [':wizard-links', 'type'], items: Ember.A(), anyLinks: notEmpty('links'), @on('didInsertElement') @observes('links.@each') didInsertElement() { - Ember.run.scheduleOnce('afterRender', () => (this.applySortable())); + scheduleOnce('afterRender', () => (this.applySortable())); }, applySortable() { @@ -25,7 +26,7 @@ export default Ember.Component.extend({ const item = items.findBy('id', itemId); items.removeObject(item); items.insertAt(newIndex, item); - Ember.run.scheduleOnce('afterRender', this, () => this.applySortable()); + scheduleOnce('afterRender', this, () => this.applySortable()); }, @computed('type') diff --git a/assets/javascripts/discourse/components/wizard-text-editor.js.es6 b/assets/javascripts/discourse/components/wizard-text-editor.js.es6 index 2a24cd0b..7335f75f 100644 --- a/assets/javascripts/discourse/components/wizard-text-editor.js.es6 +++ b/assets/javascripts/discourse/components/wizard-text-editor.js.es6 @@ -1,8 +1,24 @@ -import { default as discourseComputed } from 'discourse-common/utils/decorators'; +import { + default as discourseComputed, + on +} from 'discourse-common/utils/decorators'; import { profileFields } from '../lib/custom-wizard'; +import { scheduleOnce } from "@ember/runloop"; export default Ember.Component.extend({ classNames: 'wizard-text-editor', + barEnabled: true, + previewEnabled: true, + fieldsEnabled: true, + + didReceiveAttrs() { + this._super(...arguments); + if (!this.barEnabled) { + scheduleOnce('afterRender', () => { + $(this.element).find('.d-editor-button-bar').addClass('hidden'); + }); + } + }, @discourseComputed('forcePreview') previewLabel(forcePreview) { diff --git a/assets/javascripts/discourse/controllers/admin-wizard.js.es6 b/assets/javascripts/discourse/controllers/admin-wizard.js.es6 index acd25f95..f9960371 100644 --- a/assets/javascripts/discourse/controllers/admin-wizard.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizard.js.es6 @@ -1,10 +1,22 @@ -import { default as computed } from 'discourse-common/utils/decorators'; +import { default as computed, observes } from 'discourse-common/utils/decorators'; +import { notEmpty } from "@ember/object/computed"; import showModal from 'discourse/lib/show-modal'; +import { generateId } from '../lib/custom-wizard'; +import { dasherize } from "@ember/string"; export default Ember.Controller.extend({ - @computed('model.id', 'model.name') + hasName: notEmpty('model.name'), + + @computed('model.id') wizardUrl(wizardId) { - return window.location.origin + '/w/' + Ember.String.dasherize(wizardId); + return window.location.origin + '/w/' + dasherize(wizardId); + }, + + @observes('model.name') + setId() { + if (!this.model.existingId) { + this.set('model.id', generateId(this.model.name)); + } }, @computed('model.after_time_scheduled') diff --git a/assets/javascripts/discourse/controllers/next-session-scheduled.js.es6 b/assets/javascripts/discourse/controllers/next-session-scheduled.js.es6 index 9e925b26..592de089 100644 --- a/assets/javascripts/discourse/controllers/next-session-scheduled.js.es6 +++ b/assets/javascripts/discourse/controllers/next-session-scheduled.js.es6 @@ -1,4 +1,5 @@ import { default as computed } from 'discourse-common/utils/decorators'; +import { scheduleOnce } from "@ember/runloop"; export default Ember.Controller.extend({ title: 'admin.wizard.after_time_modal.title', @@ -14,7 +15,7 @@ export default Ember.Controller.extend({ this.setProperties({ date, time }); - Ember.run.scheduleOnce('afterRender', this, () => { + scheduleOnce('afterRender', this, () => { const $timePicker = $("#time-picker"); $timePicker.timepicker({ timeFormat: 'H:i' }); $timePicker.timepicker('setTime', time); diff --git a/assets/javascripts/discourse/lib/custom-wizard.js.es6 b/assets/javascripts/discourse/lib/custom-wizard.js.es6 index 90c7036c..8ffdcd97 100644 --- a/assets/javascripts/discourse/lib/custom-wizard.js.es6 +++ b/assets/javascripts/discourse/lib/custom-wizard.js.es6 @@ -121,6 +121,12 @@ function newPair(options = {}) { return Ember.Object.create(params); } +function generateId(name) { + return name.replace(/[^\w ]/g, '') + .replace(/ /g,"_") + .toLowerCase(); +} + export { generateSelectKitContent, profileFields, @@ -130,5 +136,6 @@ export { defaultSelectionType, connectors, newInput, - newPair + newPair, + generateId }; \ No newline at end of file diff --git a/assets/javascripts/discourse/templates/admin-wizard.hbs b/assets/javascripts/discourse/templates/admin-wizard.hbs index 87265cc2..31064780 100644 --- a/assets/javascripts/discourse/templates/admin-wizard.hbs +++ b/assets/javascripts/discourse/templates/admin-wizard.hbs @@ -1,30 +1,19 @@
- -
- {{model.name}} - -
- {{wizardUrl}} + + {{#if hasName}} +
+ {{model.name}} + +
-
+ {{/if}}
-

{{i18n 'admin.wizard.id'}}

-
-
- {{input - name="name" - value=model.id - placeholderKey="admin.wizard.id_placeholder" - disabled=model.existingId}} -
-
- -
-
-

{{i18n 'admin.wizard.name'}}

+
{{input @@ -42,7 +31,7 @@
-

{{i18n 'admin.wizard.background'}}

+
{{input @@ -54,7 +43,7 @@
-

{{i18n 'admin.wizard.save_submissions'}}

+
{{input type='checkbox' checked=model.save_submissions}} @@ -64,7 +53,7 @@
-

{{i18n 'admin.wizard.multiple_submissions'}}

+
{{input type='checkbox' checked=model.multiple_submissions}} @@ -74,7 +63,7 @@
-

{{i18n 'admin.wizard.required'}}

+
{{input type='checkbox' checked=model.required}} @@ -84,7 +73,7 @@
-

{{i18n 'admin.wizard.after_signup'}}

+
{{input type='checkbox' checked=model.after_signup}} @@ -94,7 +83,7 @@
-

{{i18n 'admin.wizard.after_time'}}

+
{{input type='checkbox' checked=model.after_time}} @@ -109,7 +98,7 @@
-

{{i18n 'admin.wizard.prompt_completion'}}

+
{{input type='checkbox' checked=model.prompt_completion}} @@ -119,7 +108,7 @@
-

{{i18n 'admin.wizard.min_trust'}}

+
{{i18n 'admin.wizard.min_trust_label'}} @@ -129,7 +118,7 @@
-

{{i18n 'admin.wizard.theme_id'}}

+
{{combo-box @@ -145,7 +134,7 @@
-

{{i18n 'admin.wizard.restart_on_revisit'}}

+
{{input type='checkbox' checked=model.restart_on_revisit}} @@ -155,7 +144,7 @@
-

{{i18n 'admin.wizard.group'}}

+
{{wizard-field-mapper diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs index 5a7442be..8c31baa8 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -1,19 +1,6 @@
-

{{i18n "admin.wizard.id"}}

-
- -
- {{input - value=action.id - placeholderKey='admin.wizard.id_placeholder' - disabled=disableId}} -
-
- -
-
-

{{i18n "admin.wizard.type"}}

+
@@ -30,7 +17,7 @@ {{#if basicTopicFields}}
-

{{i18n "admin.wizard.action.title"}}

+
@@ -56,7 +43,7 @@
-

{{i18n "admin.wizard.action.post"}}

+
@@ -80,13 +67,12 @@ {{#if action.post_builder}}
-

{{i18n 'admin.wizard.action.post_builder.label'}}

+
{{wizard-text-editor value=action.post_template - fieldsEnabled=true wizardFields=wizardFields}}
@@ -96,7 +82,7 @@ {{#if publicTopicFields}}
-

{{i18n "admin.wizard.action.create_topic.category"}}

+
@@ -140,7 +126,7 @@
-

{{i18n "admin.wizard.action.create_topic.tags"}}

+
@@ -174,7 +160,7 @@ {{#if newTopicFields}}
-

{{i18n "admin.wizard.action.skip_redirect.label"}}

+
@@ -190,7 +176,7 @@ {{#if createTopic}}
-

{{i18n 'admin.wizard.action.add_fields'}}

+
@@ -207,7 +193,7 @@ {{#if sendMessage}}
-

{{i18n 'admin.wizard.required'}}

+
@@ -224,7 +210,7 @@
-

{{i18n "admin.wizard.action.send_message.recipient"}}

+
@@ -238,7 +224,7 @@
-

{{i18n 'admin.wizard.action.add_fields'}}

+
{{wizard-field-mapper @@ -250,7 +236,7 @@ {{#if updateProfile}}
-

{{i18n 'admin.wizard.action.add_fields'}}

+
{{wizard-field-mapper @@ -266,7 +252,7 @@ {{#if sendToApi}}
-

{{i18n "admin.wizard.action.send_to_api.api"}}

+
@@ -283,7 +269,7 @@
-

{{i18n "admin.wizard.action.send_to_api.endpoint"}}

+
@@ -298,16 +284,18 @@
-
+
-

{{i18n "admin.wizard.action.send_to_api.body"}}

+
{{wizard-text-editor value=action.api_body - fieldsEnabled=true - wizardFields=wizardFields}} + previewEnabled=false + barEnabled=false + wizardFields=wizardFields + placeholder='admin.wizard.action.send_to_api.body_placeholder'}}
{{/if}} @@ -315,7 +303,7 @@ {{#if addToGroup}}
-

{{i18n "admin.wizard.group"}}

+
@@ -337,7 +325,7 @@ {{#if routeTo}}
-

{{i18n "admin.wizard.action.route_to.url"}}

+
@@ -347,7 +335,7 @@
-

{{i18n "admin.wizard.action.route_to.code"}}

+
diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs index 8c846120..d4251c2e 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs @@ -1,24 +1,6 @@
-

{{i18n 'admin.wizard.id'}}

-
-
- {{input name="id" value=field.id placeholderKey="admin.wizard.id_placeholder" disabled=disableId}} -
-
- -
-
-

{{i18n 'admin.wizard.key'}}

-
-
- {{input name="key" value=field.key placeholderKey="admin.wizard.key_placeholder"}} -
-
- -
-
-

{{i18n 'admin.wizard.field.label'}}

+
{{input name="label" value=field.label}} @@ -27,7 +9,30 @@
-

{{i18n 'admin.wizard.field.description'}}

+ +
+
+ {{input name="key" value=field.key placeholderKey="admin.wizard.translation_placeholder"}} +
+
+ +
+
+ +
+
+ {{image-uploader + imageUrl=field.image + onUploadDone=(action "imageUploadDone") + onUploadDeleted=(action "imageUploadDeleted") + type="wizard-step" + class="no-repeat contain-image"}} +
+
+ +
+
+
{{textarea name="description" value=field.description}} @@ -36,17 +41,9 @@
-

{{i18n 'admin.wizard.field.image'}}

-
-
- {{input name="image" value=field.image placeholderKey="admin.wizard.field.image_placeholder"}} -
-
- -
-
-

{{i18n 'admin.wizard.type'}}

+
+
{{combo-box value=field.type @@ -60,21 +57,23 @@
-

{{i18n 'admin.wizard.field.required'}}

+
+
- {{input type='checkbox' checked=field.required}} {{i18n 'admin.wizard.field.required_label'}} + {{input type='checkbox' checked=field.required}}
{{#if isInput}}
-

{{i18n 'admin.wizard.field.min_length'}}

+
+
- {{input type="number" name="min_length" value=field.min_length placeholder=(i18n 'admin.wizard.field.min_length_placeholder')}} + {{input type="number" name="min_length" value=field.min_length}}
{{/if}} @@ -97,7 +96,7 @@
{{i18n 'admin.wizard.field.choices_translation'}}
- {{input name="key" value=field.choices_key placeholderKey="admin.wizard.key_placeholder"}} + {{input name="key" value=field.choices_key placeholderKey="admin.wizard.translation_placeholder"}} {{/if}} {{#if choicesCustom}} @@ -119,30 +118,21 @@ {{#if isUpload}}
-

{{i18n 'admin.wizard.field.file_types'}}

+
+
{{input value=field.file_types}}
{{/if}} -{{#if isCategoryOrTag}} -
-
-

{{i18n 'admin.wizard.field.limit'}}

-
-
- {{input type="number" value=field.limit}} -
-
-{{/if}} - {{#if isCategory}}
-

{{i18n 'admin.wizard.field.property'}}

+
+
{{combo-box value=field.property @@ -155,10 +145,23 @@
{{/if}} +{{#if isCategoryOrTag}} +
+
+ +
+ +
+ {{input type="number" value=field.limit}} +
+
+{{/if}} +
-

{{i18n 'admin.wizard.field.prefill'}}

+
+
{{wizard-field-mapper inputs=field.prefill @@ -170,8 +173,9 @@ {{#if canFilter}}
-

{{i18n 'admin.wizard.field.filter'}}

+
+
{{wizard-field-mapper inputs=field.filters diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs index 28b3b1b1..df25fa50 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs @@ -1,31 +1,6 @@
-

{{i18n 'admin.wizard.id'}}

-
-
- {{input - name="id" - value=step.id - placeholderKey="admin.wizard.id_placeholder" - disabled=disableId}} -
-
- -
-
-

{{i18n 'admin.wizard.key'}}

-
-
- {{input - name="key" - value=step.key - placeholderKey="admin.wizard.key_placeholder"}} -
-
- -
-
-

{{i18n 'admin.wizard.step.title'}}

+
{{input @@ -36,28 +11,44 @@
-

{{i18n 'admin.wizard.step.banner'}}

+
{{input - name="banner" - value=step.banner - placeholderKey="admin.wizard.step.banner_placeholder"}} + name="key" + value=step.key + placeholderKey="admin.wizard.translation_placeholder"}}
-

{{i18n 'admin.wizard.step.description'}}

+
- {{wizard-text-editor value=step.raw_description}} + {{image-uploader + imageUrl=step.banner + onUploadDone=(action "bannerUploadDone") + onUploadDeleted=(action "bannerUploadDeleted") + type="wizard-banner" + class="no-repeat contain-image"}} +
+
+ +
+
+ +
+
+ {{wizard-text-editor + value=step.raw_description + fieldsEnabled=false}}
-

{{i18n 'admin.wizard.step.required_data.label'}}

+
{{wizard-field-mapper @@ -82,7 +73,7 @@
-

{{i18n 'admin.wizard.step.permitted_params.label'}}

+
{{wizard-field-mapper diff --git a/assets/javascripts/discourse/templates/components/wizard-export.hbs b/assets/javascripts/discourse/templates/components/wizard-export.hbs index 869b372a..6f4e0c33 100644 --- a/assets/javascripts/discourse/templates/components/wizard-export.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-export.hbs @@ -3,9 +3,11 @@
    {{#each wizards as |w|}}
  • - {{input type="checkbox" - id=(dasherize w.id) - change=(action 'checkChanged')}} + {{input + type="checkbox" + id=(dasherize w.id) + change=(action 'checkChanged')}} + {{#link-to "adminWizard" (dasherize w.id)}} {{w.name}} {{/link-to}} diff --git a/assets/javascripts/discourse/templates/components/wizard-links.hbs b/assets/javascripts/discourse/templates/components/wizard-links.hbs index f6af79d8..7ef66b76 100644 --- a/assets/javascripts/discourse/templates/components/wizard-links.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-links.hbs @@ -1,14 +1,12 @@ - +
    {{{i18n header}}}
    +{{#if anyLinks}} +
      + {{#each links as |l|}} +
    • + {{d-button action="change" actionParam=l.id translatedLabel=l.label class=l.classes}} + {{d-button action='remove' actionParam=l.id icon='times' class='remove'}} +
    • + {{/each}} +
    +{{/if}} +{{d-button action='add' label='admin.wizard.add' icon='plus'}} diff --git a/assets/javascripts/discourse/templates/components/wizard-text-editor.hbs b/assets/javascripts/discourse/templates/components/wizard-text-editor.hbs index 2fd241ea..b306aee6 100644 --- a/assets/javascripts/discourse/templates/components/wizard-text-editor.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-text-editor.hbs @@ -1,11 +1,14 @@ {{d-editor value=value - forcePreview=forcePreview}} + forcePreview=forcePreview + placeholder=placeholder}}
    - {{d-button - action="togglePreview" - translatedLabel=previewLabel}} + {{#if previewEnabled}} + {{d-button + action="togglePreview" + translatedLabel=previewLabel}} + {{/if}} {{#if fieldsEnabled}} {{d-button diff --git a/assets/javascripts/wizard/components/wizard-composer-editor.js.es6 b/assets/javascripts/wizard/components/wizard-composer-editor.js.es6 index 337d73c7..f7a89464 100644 --- a/assets/javascripts/wizard/components/wizard-composer-editor.js.es6 +++ b/assets/javascripts/wizard/components/wizard-composer-editor.js.es6 @@ -30,7 +30,6 @@ export default ComposerEditor.extend({ key: "@", transformComplete: v => v.username || v.name, afterComplete() { - // ensures textarea scroll position is correct scheduleOnce("afterRender", () => $input.blur().focus()); } }); diff --git a/assets/javascripts/wizard/templates/components/wizard-field.hbs b/assets/javascripts/wizard/templates/components/wizard-field.hbs index 8173fe78..c8c785b0 100644 --- a/assets/javascripts/wizard/templates/components/wizard-field.hbs +++ b/assets/javascripts/wizard/templates/components/wizard-field.hbs @@ -1,7 +1,5 @@ -