From 7b3ed54f29a19d160ae8d99693511249c97568f8 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Sun, 5 Apr 2020 11:37:09 +1000 Subject: [PATCH] various --- .../components/wizard-custom-action.js.es6 | 10 +- .../components/wizard-custom-field.js.es6 | 52 +++---- .../components/wizard-custom-step.js.es6 | 3 +- .../discourse/components/wizard-export.js.es6 | 7 +- .../discourse/components/wizard-import.js.es6 | 10 +- .../discourse/components/wizard-links.js.es6 | 20 +-- .../components/wizard-mapper-input.js.es6 | 11 +- .../components/wizard-mapper-pair.js.es6 | 11 +- .../wizard-mapper-selector-type.js.es6 | 22 +-- .../components/wizard-mapper-selector.js.es6 | 97 +++++++++---- .../discourse/components/wizard-mapper.js.es6 | 49 ++++--- .../components/wizard-text-editor.js.es6 | 8 +- .../discourse/controllers/admin-wizard.js.es6 | 7 +- .../controllers/admin-wizards-api.js.es6 | 24 ++-- .../controllers/admin-wizards-apis.js.es6 | 4 +- .../controllers/admin-wizards-transfer.js.es6 | 4 +- .../controllers/next-session-scheduled.js.es6 | 3 +- .../discourse/helpers/custom-wizard.js.es6 | 3 +- .../discourse/lib/wizard-json.js.es6 | 19 +-- .../discourse/lib/wizard-mapper.js.es6 | 22 ++- .../javascripts/discourse/lib/wizard.js.es6 | 7 +- .../discourse/models/custom-wizard-api.js.es6 | 5 +- .../discourse/models/custom-wizard.js.es6 | 3 +- .../discourse/routes/admin-wizard.js.es6 | 9 +- .../discourse/templates/admin-wizard.hbs | 1 - .../discourse/templates/admin-wizards-api.hbs | 4 +- .../components/wizard-custom-action.hbs | 27 ++-- .../components/wizard-custom-field.hbs | 135 +++++++----------- .../components/wizard-custom-step.hbs | 8 +- .../components/wizard-mapper-input.hbs | 13 +- .../components/wizard-mapper-pair.hbs | 2 - .../components/wizard-mapper-selector.hbs | 92 +++--------- .../templates/components/wizard-mapper.hbs | 2 - .../wizard/initializers/custom.js.es6 | 3 +- .../components/wizard-field-dropdown.hbs | 2 +- assets/stylesheets/common/wizard-admin.scss | 11 -- assets/stylesheets/common/wizard-mapper.scss | 29 ++-- config/locales/client.en.yml | 47 +++--- config/locales/client.fr.yml | 13 -- controllers/custom_wizard/admin.rb | 8 -- lib/custom_wizard/builder.rb | 24 ---- lib/wizard/choice.rb | 17 --- lib/wizard/field.rb | 4 - plugin.rb | 1 - .../custom_wizard/wizard_field_serializer.rb | 4 +- spec/components/custom_wizard/builder_spec.rb | 2 - 46 files changed, 363 insertions(+), 496 deletions(-) delete mode 100644 lib/wizard/choice.rb diff --git a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 index 8e17ea9f..6f04993b 100644 --- a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 @@ -1,13 +1,9 @@ import { default as discourseComputed, observes, on } from 'discourse-common/utils/decorators'; import { equal, not, empty, or } from "@ember/object/computed"; -import { - actionTypes, - generateName, - selectKitContent, - profileFields -} from '../lib/wizard'; +import { actionTypes, generateName, selectKitContent, profileFields } from '../lib/wizard'; +import Component from "@ember/component"; -export default Ember.Component.extend({ +export default Component.extend({ classNames: 'wizard-custom-action', types: actionTypes.map(t => ({ id: t, name: generateName(t) })), createTopic: equal('action.type', 'create_topic'), diff --git a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 index 632ddd12..609908ec 100644 --- a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 @@ -1,8 +1,9 @@ import { default as discourseComputed, observes, on } from 'discourse-common/utils/decorators'; import { equal, not, or } from "@ember/object/computed"; import { selectKitContent } from '../lib/wizard'; +import Component from "@ember/component"; -export default Ember.Component.extend({ +export default Component.extend({ classNames: 'wizard-custom-field', isDropdown: equal('field.type', 'dropdown'), isUpload: equal('field.type', 'upload'), @@ -10,13 +11,9 @@ export default Ember.Component.extend({ isGroup: equal('field.type', 'group'), isTag: equal('field.type', 'tag'), disableId: not('field.isNew'), - choicesTypes: selectKitContent(['translation', 'custom']), - choicesTranslation: equal('field.choices_type', 'translation'), - choicesCustom: equal('field.choices_type', 'custom'), categoryPropertyTypes: selectKitContent(['id', 'slug']), - prefillEnabled: or('isCategory', 'isTag', 'isGroup'), - contentEnabled: or('isCategory', 'isTag', 'isGroup'), - hasAdvanced: or('isCategory', 'isTag', 'isGroup'), + prefillEnabled: or('isCategory', 'isTag', 'isGroup', 'isDropdown'), + contentEnabled: or('isCategory', 'isTag', 'isGroup', 'isDropdown'), @discourseComputed('field.type') isInput: (type) => type === 'text' || type === 'textarea' || type === 'url', @@ -33,34 +30,41 @@ export default Ember.Component.extend({ }, @discourseComputed('field.type') - prefillOptions(fieldType) { - if (!this.prefillEnabled) return {}; - + contentOptions(fieldType) { let options = { - hasOutput: true, + wizardFieldSelection: true, textSelection: 'key,value', - wizardSelection: true, userFieldSelection: 'key,value' } - - options[`${fieldType}Selection`] = 'output'; - options[`outputDefaultSelection`] = fieldType; + + if (this.isDropdown) { + options.inputTypes = 'pair,assignment'; + options.pairConnector = 'equal'; + options.keyPlaceholder = 'admin.wizard.key'; + options.valuePlaceholder = 'admin.wizard.value'; + } return options; }, @discourseComputed('field.type') - contentOptions(fieldType) { - if (!this.contentEnabled) return {}; - + prefillOptions(fieldType) { let options = { - hasOutput: true, - wizardSelection: 'key,value', - userFieldSelection: 'key,value', - textSelection: 'key,value' + wizardFieldSelection: true, + textSelection: 'key,value', + userFieldSelection: 'key,value' + } + + if (!this.isDropdown) { + let selectionType = { + category: 'category', + tag: 'tag', + group: 'group', + dropdown: 'text' + }[fieldType]; + options[`${selectionType}Selection`] = 'output'; + options.outputDefaultSelection = selectionType; } - - options[`${fieldType}Selection`] = 'output'; return options; }, diff --git a/assets/javascripts/discourse/components/wizard-custom-step.js.es6 b/assets/javascripts/discourse/components/wizard-custom-step.js.es6 index cd9ad57c..1ddd3fca 100644 --- a/assets/javascripts/discourse/components/wizard-custom-step.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-step.js.es6 @@ -1,8 +1,9 @@ import { observes, on, default as discourseComputed } from 'discourse-common/utils/decorators'; import { not } from "@ember/object/computed"; import EmberObject from "@ember/object"; +import Component from "@ember/component"; -export default Ember.Component.extend({ +export default Component.extend({ classNames: 'wizard-custom-step', currentField: null, currentAction: null, diff --git a/assets/javascripts/discourse/components/wizard-export.js.es6 b/assets/javascripts/discourse/components/wizard-export.js.es6 index a2505d24..2537511d 100644 --- a/assets/javascripts/discourse/components/wizard-export.js.es6 +++ b/assets/javascripts/discourse/components/wizard-export.js.es6 @@ -1,6 +1,9 @@ -export default Ember.Component.extend({ +import Component from "@ember/component"; +import { A } from "@ember/array"; + +export default Component.extend({ classNames: ['container', 'export'], - selected: Ember.A(), + selected: A(), actions: { checkChanged(event) { diff --git a/assets/javascripts/discourse/components/wizard-import.js.es6 b/assets/javascripts/discourse/components/wizard-import.js.es6 index 5058aecb..d844d5a6 100644 --- a/assets/javascripts/discourse/components/wizard-import.js.es6 +++ b/assets/javascripts/discourse/components/wizard-import.js.es6 @@ -1,11 +1,13 @@ import { ajax } from 'discourse/lib/ajax'; -import { default as computed } from 'discourse-common/utils/decorators'; +import { default as discourseComputed } from 'discourse-common/utils/decorators'; +import { notEmpty } from "@ember/object/computed"; +import Component from "@ember/component"; -export default Ember.Component.extend({ +export default Component.extend({ classNames: ['container', 'import'], - hasLogs: Ember.computed.notEmpty('logs'), + hasLogs: notEmpty('logs'), - @computed('successIds', 'failureIds') + @discourseComputed('successIds', 'failureIds') logs(successIds, failureIds) { let logs = []; diff --git a/assets/javascripts/discourse/components/wizard-links.js.es6 b/assets/javascripts/discourse/components/wizard-links.js.es6 index ecfa2bd8..761d0521 100644 --- a/assets/javascripts/discourse/components/wizard-links.js.es6 +++ b/assets/javascripts/discourse/components/wizard-links.js.es6 @@ -1,11 +1,13 @@ -import { default as computed, on, observes } from 'discourse-common/utils/decorators'; +import { default as discourseComputed, on, observes } from 'discourse-common/utils/decorators'; import { notEmpty } from "@ember/object/computed"; -import { scheduleOnce } from "@ember/runloop"; +import { scheduleOnce, bind } from "@ember/runloop"; import EmberObject from "@ember/object"; +import Component from "@ember/component"; +import { A } from "@ember/array"; -export default Ember.Component.extend({ +export default Component.extend({ classNameBindings: [':wizard-links', 'type'], - items: Ember.A(), + items: A(), anyLinks: notEmpty('links'), @on('didInsertElement') @@ -18,7 +20,7 @@ export default Ember.Component.extend({ $(this.element).find("ul").sortable({tolerance: 'pointer'}).on('sortupdate', (e, ui) => { const itemId = ui.item.data('id'); const index = ui.item.index(); - Ember.run.bind(this, this.updateItemOrder(itemId, index)); + bind(this, this.updateItemOrder(itemId, index)); }); }, @@ -30,10 +32,10 @@ export default Ember.Component.extend({ scheduleOnce('afterRender', this, () => this.applySortable()); }, - @computed('type') + @discourseComputed('type') header: (type) => `admin.wizard.${type}.header`, - @computed('items.@each.id', 'current') + @discourseComputed('items.@each.id', 'current') links(items, current) { if (!items) return; @@ -64,8 +66,8 @@ export default Ember.Component.extend({ let params = { id: newId, isNew: true }; if (type === 'step') { - params['fields'] = Ember.A(); - params['actions'] = Ember.A(); + params['fields'] = A(); + params['actions'] = A(); }; const newItem = EmberObject.create(params); diff --git a/assets/javascripts/discourse/components/wizard-mapper-input.js.es6 b/assets/javascripts/discourse/components/wizard-mapper-input.js.es6 index 08b77c10..ce175398 100644 --- a/assets/javascripts/discourse/components/wizard-mapper-input.js.es6 +++ b/assets/javascripts/discourse/components/wizard-mapper-input.js.es6 @@ -1,13 +1,16 @@ import { computed, set } from "@ember/object"; -import { alias, equal } from "@ember/object/computed"; +import { alias, equal, or } from "@ember/object/computed"; import { newPair, connectorContent, inputTypesContent } from '../lib/wizard-mapper'; +import Component from "@ember/component"; -export default Ember.Component.extend({ +export default Component.extend({ classNameBindings: [':mapper-input', 'type'], inputType: alias('input.type'), isConditional: equal('inputType', 'conditional'), - hasOutput: alias('options.hasOutput'), - hasPairs: computed('hasOutput', 'isConditional', function() { return !this.hasOutput || this.isConditional; }), + isAssignment: equal('inputType', 'assignment'), + isPair: equal('inputType', 'pair'), + hasOutput: or('isConditional', 'isAssignment'), + hasPairs: or('isConditional', 'isPair'), connectors: computed(function() { return connectorContent('output', this.input.type, this.options) }), inputTypes: computed(function() { return inputTypesContent(this.options) }), diff --git a/assets/javascripts/discourse/components/wizard-mapper-pair.js.es6 b/assets/javascripts/discourse/components/wizard-mapper-pair.js.es6 index 9de326b9..b7d88c5e 100644 --- a/assets/javascripts/discourse/components/wizard-mapper-pair.js.es6 +++ b/assets/javascripts/discourse/components/wizard-mapper-pair.js.es6 @@ -1,15 +1,12 @@ import { connectorContent } from '../lib/wizard-mapper'; import { gt, or, alias } from "@ember/object/computed"; import { computed, observes } from "@ember/object"; +import Component from "@ember/component"; -export default Ember.Component.extend({ +export default Component.extend({ classNameBindings: [':mapper-pair', 'hasConnector::no-connector'], firstPair: gt('pair.index', 0), showRemove: alias('firstPair'), - showJoin: computed('pair.pairCount', function() { - return this.pair.index < (this.pair.pairCount - 1); - }), - connectors: computed(function() { - return connectorContent('pair', this.inputType, this.options); - }) + showJoin: computed('pair.pairCount', function() { return this.pair.index < (this.pair.pairCount - 1) }), + connectors: computed(function() { return connectorContent('pair', this.inputType, this.options) }) }); \ No newline at end of file diff --git a/assets/javascripts/discourse/components/wizard-mapper-selector-type.js.es6 b/assets/javascripts/discourse/components/wizard-mapper-selector-type.js.es6 index 71c98c22..d5041871 100644 --- a/assets/javascripts/discourse/components/wizard-mapper-selector-type.js.es6 +++ b/assets/javascripts/discourse/components/wizard-mapper-selector-type.js.es6 @@ -1,27 +1,17 @@ import discourseComputed from 'discourse-common/utils/decorators'; +import { snakeCase } from '../lib/wizard'; +import { selectionTypes } from '../lib/wizard-mapper'; +import Component from "@ember/component"; -export default Ember.Component.extend({ +export default Component.extend({ tagName: 'a', classNameBindings: ['type', 'active'], @discourseComputed('type', 'activeType') - active(type, activeType) { - return type === activeType; - }, + active(type, activeType) { return type === activeType }, @discourseComputed('type') - label(type) { - let map = { - text: I18n.t('admin.wizard.text'), - wizard: I18n.t('admin.wizard.label'), - userField: I18n.t('users_lowercase.one'), - category: I18n.t('categories.category'), - tag: I18n.t('tagging.tags'), - group: I18n.t('groups.title.one'), - user: I18n.t('users_lowercase.other') - }; - return map[type].toLowerCase(); - }, + label(type) { return I18n.t(`admin.wizard.selector.label.${snakeCase(type)}`) }, click() { this.toggle(this.type) diff --git a/assets/javascripts/discourse/components/wizard-mapper-selector.js.es6 b/assets/javascripts/discourse/components/wizard-mapper-selector.js.es6 index 6fce93c8..38ed763a 100644 --- a/assets/javascripts/discourse/components/wizard-mapper-selector.js.es6 +++ b/assets/javascripts/discourse/components/wizard-mapper-selector.js.es6 @@ -1,15 +1,38 @@ -import { alias } from "@ember/object/computed"; +import { alias, or } from "@ember/object/computed"; import { computed } from "@ember/object"; import { default as discourseComputed, observes } from "discourse-common/utils/decorators"; import { getOwner } from 'discourse-common/lib/get-owner'; -import { defaultSelectionType } from '../lib/wizard-mapper'; +import { defaultSelectionType, selectionTypes } from '../lib/wizard-mapper'; +import { snakeCase, selectKitContent } from '../lib/wizard'; +import Component from "@ember/component"; -export default Ember.Component.extend({ +export default Component.extend({ classNames: 'mapper-selector', groups: alias('site.groups'), - categories: computed(function() { - return this.site.categories.map(c => ({ id: c.id, name: c.name })); - }), + categories: computed(function() { return selectKitContent(this.site.categories) }), + showText: computed('activeType', function() { return this.showInput('text') }), + showWizardField: computed('activeType', function() { return this.showInput('wizardField') }), + showUserField: computed('activeType', function() { return this.showInput('userField') }), + showCategory: computed('activeType', function() { return this.showInput('category') }), + showTag: computed('activeType', function() { return this.showInput('tag') }), + showGroup: computed('activeType', function() { return this.showInput('group') }), + showUser: computed('activeType', function() { return this.showInput('user') }), + showList: computed('activeType', function() { return this.showInput('list') }), + showComboBox: or('showWizardField', 'showUserField'), + showMultiSelect: or('showCategory', 'showGroup'), + textEnabled: computed('options.textSelection', 'inputType', function() { return this.optionEnabled('textSelection') }), + wizardFieldEnabled: computed('options.wizardFieldSelection', 'inputType', function() { return this.optionEnabled('wizardFieldSelection') }), + userFieldEnabled: computed('options.userFieldSelection', 'inputType', function() { return this.optionEnabled('userFieldSelection') }), + categoryEnabled: computed('options.categorySelection', 'inputType', function() { return this.optionEnabled('categorySelection') }), + tagEnabled: computed('options.tagSelection', 'inputType', function() { return this.optionEnabled('tagSelection') }), + groupEnabled: computed('options.groupSelection', 'inputType', function() { return this.optionEnabled('groupSelection') }), + userEnabled: computed('options.userSelection', 'inputType', function() { return this.optionEnabled('userSelection') }), + listEnabled: computed('options.listSelection', 'inputType', function() { return this.optionEnabled('listSelection') }), + + @discourseComputed('activeType') + selectorTypes(activeType) { + return selectionTypes.filter(type => (this[`${type}Enabled`])); + }, @discourseComputed userFields() { @@ -32,23 +55,41 @@ export default Ember.Component.extend({ clearValue() { this.set('value', null); }, - - @discourseComputed('customPlaceholder') - textPlaceholder(customPlaceholder) { - return customPlaceholder || 'admin.wizard.text'; + + @discourseComputed('activeType') + comboBoxContent(activeType) { + return this[`${activeType}Fields`]; }, - showInput(type) { - return this.activeType === type && this[`${type}Enabled`]; + @discourseComputed('activeType') + multiSelectContent(activeType) { + return { + category: this.categories, + group: this.groups, + list: '' + }[activeType]; }, - showText: computed('activeType', function() { return this.showInput('text') }), - showWizard: computed('activeType', function() { return this.showInput('wizard') }), - showUserField: computed('activeType', function() { return this.showInput('userField') }), - showCategory: computed('activeType', function() { return this.showInput('category') }), - showTag: computed('activeType', function() { return this.showInput('tag') }), - showGroup: computed('activeType', function() { return this.showInput('group') }), - showUser: computed('activeType', function() { return this.showInput('user') }), + @discourseComputed('activeType') + placeholder(activeType) { + if (activeType === 'text' && this.options[`${this.selectorType}Placeholder`]) { + return this.options[`${this.selectorType}Placeholder`]; + } + return `admin.wizard.selector.placeholder.${snakeCase(activeType)}`; + }, + + @discourseComputed('activeType') + multiSelectOptions(activeType) { + let result = { + none: this.placeholder + }; + + if (activeType === 'list') { + result.allowAny = true; + } + + return result; + }, optionEnabled(type) { const options = this.options; @@ -57,19 +98,15 @@ export default Ember.Component.extend({ const option = options[type]; if (option === true) return true; if (typeof option !== 'string') return false; - - const types = [this.selectorType, this.inputType]; - - return option.split(',').filter(o => types.indexOf(o) !== -1).length + + return option.split(',').filter(option => { + return [this.selectorType, this.inputType].indexOf(option) !== -1; + }).length; }, - textEnabled: computed('options.textSelection', 'inputType', function() { return this.optionEnabled('textSelection') }), - wizardEnabled: computed('options.wizardSelection', 'inputType', function() { return this.optionEnabled('wizardSelection') }), - userFieldEnabled: computed('options.userFieldSelection', 'inputType', function() { return this.optionEnabled('userFieldSelection') }), - categoryEnabled: computed('options.categorySelection', 'inputType', function() { return this.optionEnabled('categorySelection') }), - tagEnabled: computed('options.tagSelection', 'inputType', function() { return this.optionEnabled('tagSelection') }), - groupEnabled: computed('options.groupSelection', 'inputType', function() { return this.optionEnabled('groupSelection') }), - userEnabled: computed('options.userSelection', 'inputType', function() { return this.optionEnabled('userSelection') }), + showInput(type) { + return this.activeType === type && this[`${type}Enabled`]; + }, actions: { toggleType(type) { diff --git a/assets/javascripts/discourse/components/wizard-mapper.js.es6 b/assets/javascripts/discourse/components/wizard-mapper.js.es6 index 29a765a5..27363917 100644 --- a/assets/javascripts/discourse/components/wizard-mapper.js.es6 +++ b/assets/javascripts/discourse/components/wizard-mapper.js.es6 @@ -1,9 +1,11 @@ import { getOwner } from 'discourse-common/lib/get-owner'; import { on } from 'discourse-common/utils/decorators'; -import { newInput } from '../lib/wizard-mapper'; -import { default as discourseComputed } from 'discourse-common/utils/decorators'; +import { newInput, selectionTypes } from '../lib/wizard-mapper'; +import { default as discourseComputed, observes } from 'discourse-common/utils/decorators'; +import Component from "@ember/component"; +import { A } from "@ember/array"; -export default Ember.Component.extend({ +export default Component.extend({ classNames: 'wizard-mapper', @discourseComputed('inputs.[]', 'options.singular') @@ -11,29 +13,38 @@ export default Ember.Component.extend({ return !singular || !inputs || inputs.length < 1; }, - @discourseComputed('options') + @discourseComputed('options.@each') inputOptions(options) { - return { - hasOutput: options.hasOutput || false, - inputTypes: options.inputTypes || null, + let result = { + inputTypes: options.inputTypes || 'conditional,assignment', pairConnector: options.pairConnector || null, - outputConnector: options.outputConnector || null, - textSelection: options.textSelection || true, - wizardSelection: options.wizardSelection || false, - userFieldSelection: options.userFieldSelection || false, - categorySelection: options.categorySelection || false, - tagSelection: options.tagSelection || false, - groupSelection: options.groupSelection || false, - userSelection: options.userSelection || false, - keyDefaultSelection: options.keyDefaultSelection || null, - valueDefaultSelection: options.valueDefaultSelection || null, - outputDefaultSelection: options.outputDefaultSelection || null + outputConnector: options.outputConnector || null } + + let inputTypes = ['key', 'value', 'output']; + inputTypes.forEach(type => { + result[`${type}DefaultSelection`] = options[`${type}DefaultSelection`] || null; + }); + + selectionTypes.forEach(type => { + if (options[`${type}Selection`]) { + result[`${type}Selection`] = options[`${type}Selection`] + } else { + result[`${type}Selection`] = type === 'text' ? true : false; + } + }); + + return result; + }, + + @observes('options.inputTypes') + clearInputs() { + this.get('inputs').clear(); }, actions: { add() { - if (!this.get('inputs')) this.set('inputs', Ember.A()); + if (!this.get('inputs')) this.set('inputs', A()); this.get('inputs').pushObject(newInput(this.inputOptions)); }, diff --git a/assets/javascripts/discourse/components/wizard-text-editor.js.es6 b/assets/javascripts/discourse/components/wizard-text-editor.js.es6 index 4d2a8475..08966890 100644 --- a/assets/javascripts/discourse/components/wizard-text-editor.js.es6 +++ b/assets/javascripts/discourse/components/wizard-text-editor.js.es6 @@ -1,11 +1,9 @@ -import { - default as discourseComputed, - on -} from 'discourse-common/utils/decorators'; +import { default as discourseComputed, on } from 'discourse-common/utils/decorators'; import { profileFields } from '../lib/wizard'; import { scheduleOnce } from "@ember/runloop"; +import Component from "@ember/component"; -export default Ember.Component.extend({ +export default Component.extend({ classNames: 'wizard-text-editor', barEnabled: true, previewEnabled: true, diff --git a/assets/javascripts/discourse/controllers/admin-wizard.js.es6 b/assets/javascripts/discourse/controllers/admin-wizard.js.es6 index 0c4622f8..b99ba6d8 100644 --- a/assets/javascripts/discourse/controllers/admin-wizard.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizard.js.es6 @@ -5,9 +5,10 @@ import { generateId } from '../lib/wizard'; import { buildProperties } from '../lib/wizard-json'; import { dasherize } from "@ember/string"; import EmberObject from "@ember/object"; -import { scheduleOnce } from "@ember/runloop"; +import { scheduleOnce, later } from "@ember/runloop"; +import Controller from "@ember/controller"; -export default Ember.Controller.extend({ +export default Controller.extend({ hasName: notEmpty('model.name'), init() { @@ -84,7 +85,7 @@ export default Ember.Controller.extend({ }).catch((result) => { this.set('saving', false); this.set('error', I18n.t(`admin.wizard.error.${result.error}`)); - Ember.run.later(() => this.set('error', null), 10000); + later(() => this.set('error', null), 10000); }); }, diff --git a/assets/javascripts/discourse/controllers/admin-wizards-api.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-api.js.es6 index 53a98f18..d083b157 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-api.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-api.js.es6 @@ -1,42 +1,44 @@ import { ajax } from 'discourse/lib/ajax'; import { popupAjaxError } from 'discourse/lib/ajax-error'; import CustomWizardApi from '../models/custom-wizard-api'; -import { default as computed } from 'discourse-common/utils/decorators'; +import { default as discourseComputed } from 'discourse-common/utils/decorators'; +import { not, and, equal } from "@ember/object/computed"; import { selectKitContent } from '../lib/wizard'; +import Controller from "@ember/controller"; -export default Ember.Controller.extend({ +export default Controller.extend({ queryParams: ['refresh_list'], loadingSubscriptions: false, - notAuthorized: Ember.computed.not('api.authorized'), + notAuthorized: not('api.authorized'), endpointMethods: selectKitContent(['GET', 'PUT', 'POST', 'PATCH', 'DELETE']), - showRemove: Ember.computed.not('isNew'), - showRedirectUri: Ember.computed.and('threeLeggedOauth', 'api.name'), + showRemove: not('isNew'), + showRedirectUri: and('threeLeggedOauth', 'api.name'), responseIcon: null, contentTypes: selectKitContent(['application/json', 'application/x-www-form-urlencoded']), successCodes: selectKitContent([100, 101, 102, 200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 300, 301, 302, 303, 303, 304, 305, 306, 307, 308]), - @computed('saveDisabled', 'api.authType', 'api.authUrl', 'api.tokenUrl', 'api.clientId', 'api.clientSecret', 'threeLeggedOauth') + @discourseComputed('saveDisabled', 'api.authType', 'api.authUrl', 'api.tokenUrl', 'api.clientId', 'api.clientSecret', 'threeLeggedOauth') authDisabled(saveDisabled, authType, authUrl, tokenUrl, clientId, clientSecret, threeLeggedOauth) { if (saveDisabled || !authType || !tokenUrl || !clientId || !clientSecret) return true; if (threeLeggedOauth) return !authUrl; return false; }, - @computed('api.name', 'api.authType') + @discourseComputed('api.name', 'api.authType') saveDisabled(name, authType) { return !name || !authType; }, authorizationTypes: selectKitContent(['none', 'basic', 'oauth_2', 'oauth_3']), - isBasicAuth: Ember.computed.equal('api.authType', 'basic'), + isBasicAuth: equal('api.authType', 'basic'), - @computed('api.authType') + @discourseComputed('api.authType') isOauth(authType) { return authType && authType.indexOf('oauth') > -1; }, - twoLeggedOauth: Ember.computed.equal('api.authType', 'oauth_2'), - threeLeggedOauth: Ember.computed.equal('api.authType', 'oauth_3'), + twoLeggedOauth: equal('api.authType', 'oauth_2'), + threeLeggedOauth: equal('api.authType', 'oauth_3'), actions: { addParam() { diff --git a/assets/javascripts/discourse/controllers/admin-wizards-apis.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-apis.js.es6 index 52748bc8..7b087af3 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-apis.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-apis.js.es6 @@ -1,3 +1,5 @@ -export default Ember.Controller.extend({ +import Controller from "@ember/controller"; + +export default Controller.extend({ queryParams: ['refresh'] }); diff --git a/assets/javascripts/discourse/controllers/admin-wizards-transfer.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-transfer.js.es6 index 77c79b72..7ae8f5a1 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-transfer.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-transfer.js.es6 @@ -1 +1,3 @@ -export default Ember.Controller.extend(); +import Controller from "@ember/controller"; + +export default Controller.extend(); diff --git a/assets/javascripts/discourse/controllers/next-session-scheduled.js.es6 b/assets/javascripts/discourse/controllers/next-session-scheduled.js.es6 index 592de089..00c0add2 100644 --- a/assets/javascripts/discourse/controllers/next-session-scheduled.js.es6 +++ b/assets/javascripts/discourse/controllers/next-session-scheduled.js.es6 @@ -1,7 +1,8 @@ import { default as computed } from 'discourse-common/utils/decorators'; import { scheduleOnce } from "@ember/runloop"; +import Controller from "@ember/controller"; -export default Ember.Controller.extend({ +export default Controller.extend({ title: 'admin.wizard.after_time_modal.title', setup() { diff --git a/assets/javascripts/discourse/helpers/custom-wizard.js.es6 b/assets/javascripts/discourse/helpers/custom-wizard.js.es6 index c761d9a0..3b73e476 100644 --- a/assets/javascripts/discourse/helpers/custom-wizard.js.es6 +++ b/assets/javascripts/discourse/helpers/custom-wizard.js.es6 @@ -1,5 +1,6 @@ import { registerUnbound } from 'discourse-common/lib/helpers'; +import { dasherize } from "@ember/string"; registerUnbound('dasherize', function(string) { - return Ember.String.dasherize(string); + return dasherize(string); }); diff --git a/assets/javascripts/discourse/lib/wizard-json.js.es6 b/assets/javascripts/discourse/lib/wizard-json.js.es6 index d56cb35c..14fdef97 100644 --- a/assets/javascripts/discourse/lib/wizard-json.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-json.js.es6 @@ -1,11 +1,6 @@ -import { - properties, - mappedProperties, - advancedProperties, - camelCase, - snakeCase -} from '../lib/wizard'; +import { properties, mappedProperties, advancedProperties, camelCase, snakeCase } from '../lib/wizard'; import EmberObject from '@ember/object'; +import { A } from "@ember/array"; function present(val) { if (val === null || val === undefined) { @@ -197,7 +192,7 @@ function buildObject(json, type) { ); }); - params[prop] = Ember.A(inputs); + params[prop] = A(inputs); } else { params[prop] = json[prop]; } @@ -223,7 +218,7 @@ function hasAdvanced(params, type) { } function buildProperties(json) { - let steps = Ember.A(); + let steps = A(); let props = { steps }; @@ -254,7 +249,7 @@ function buildProperties(json) { } }); - stepParams.fields = Ember.A(); + stepParams.fields = A(); if (present(stepJson.fields)) { stepJson.fields.forEach((f) => { @@ -268,7 +263,7 @@ function buildProperties(json) { }); } - stepParams.actions = Ember.A(); + stepParams.actions = A(); if (present(stepJson.actions)) { stepJson.actions.forEach((a) => { @@ -299,7 +294,7 @@ function buildProperties(json) { props.prompt_completion = false; props.restart_on_revisit = false; props.permitted = null; - props.steps = Ember.A(); + props.steps = A(); } return props; diff --git a/assets/javascripts/discourse/lib/wizard-mapper.js.es6 b/assets/javascripts/discourse/lib/wizard-mapper.js.es6 index 8ce304ae..38f9429b 100644 --- a/assets/javascripts/discourse/lib/wizard-mapper.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-mapper.js.es6 @@ -1,15 +1,9 @@ import EmberObject from "@ember/object"; +import { A } from "@ember/array"; // Inputs -const selectableInputTypes = [ - 'conditional', - 'assignment' -] - function defaultInputType(options = {}) { - if (!options.hasOutput) return 'pair'; - if (!options.inputTypes) return selectableInputTypes[0]; return options.inputTypes.split(',')[0]; } @@ -73,12 +67,13 @@ function connectorContent(connectorType, inputType, opts) { const selectionTypes = [ 'text', - 'wizard', + 'wizardField', 'userField', 'group', 'category', 'tag', - 'user' + 'user', + 'list' ] function defaultSelectionType(inputType, options = {}) { @@ -122,9 +117,11 @@ function newPair(inputType, options = {}) { function newInput(options = {}) { const inputType = defaultInputType(options); + console.log(inputType); + let params = { type: inputType, - pairs: Ember.A( + pairs: A( [ newPair( inputType, @@ -137,7 +134,7 @@ function newInput(options = {}) { ) } - if (options.hasOutput) { + if (['conditional', 'assignment'].indexOf(inputType) > -1) { params['output_type'] = defaultSelectionType('output', options); params['connector'] = defaultConnector('output', inputType, options); } @@ -150,6 +147,7 @@ export { defaultSelectionType, connectorContent, inputTypesContent, + selectionTypes, newInput, - newPair, + newPair } \ No newline at end of file diff --git a/assets/javascripts/discourse/lib/wizard.js.es6 b/assets/javascripts/discourse/lib/wizard.js.es6 index 690b249a..9b085038 100644 --- a/assets/javascripts/discourse/lib/wizard.js.es6 +++ b/assets/javascripts/discourse/lib/wizard.js.es6 @@ -1,5 +1,5 @@ function selectKitContent(content) { - return content.map(i => ({id: i, name: i})) + return content.map(i => ({id: i, name: i})); } function generateName(id) { @@ -13,13 +13,13 @@ function generateId(name) { function sentenceCase(string) { return string.replace(/[_\-]+/g, ' ') .toLowerCase() - .replace(/(^\w|\b\w)/g, (m) => m.toUpperCase()) + .replace(/(^\w|\b\w)/g, (m) => m.toUpperCase()); } function snakeCase(string) { return string.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g) .map(x => x.toLowerCase()) - .join('_') + .join('_'); } function camelCase(string) { @@ -124,7 +124,6 @@ const mappedProperties = { 'permitted_params' ], field: [ - 'choices', 'prefill', 'content' ], diff --git a/assets/javascripts/discourse/models/custom-wizard-api.js.es6 b/assets/javascripts/discourse/models/custom-wizard-api.js.es6 index 2aab7a0c..90e74a7e 100644 --- a/assets/javascripts/discourse/models/custom-wizard-api.js.es6 +++ b/assets/javascripts/discourse/models/custom-wizard-api.js.es6 @@ -1,6 +1,7 @@ import { ajax } from 'discourse/lib/ajax'; import { default as computed } from 'discourse-common/utils/decorators'; import EmberObject from "@ember/object"; +import { A } from "@ember/array"; const CustomWizardApi = EmberObject.extend({ @computed('name') @@ -28,14 +29,14 @@ CustomWizardApi.reopenClass({ clientSecret: authorization.client_secret, username: authorization.username, password: authorization.password, - authParams: Ember.A(authorization.auth_params), + authParams: A(authorization.auth_params), authorized: authorization.authorized, accessToken: authorization.access_token, refreshToken: authorization.refresh_token, code: authorization.code, tokenExpiresAt: authorization.token_expires_at, tokenRefreshAt: authorization.token_refresh_at, - endpoints: Ember.A(endpoints), + endpoints: A(endpoints), isNew: params.isNew, log: params.log }); diff --git a/assets/javascripts/discourse/models/custom-wizard.js.es6 b/assets/javascripts/discourse/models/custom-wizard.js.es6 index e289f3ce..9fcc0cf3 100644 --- a/assets/javascripts/discourse/models/custom-wizard.js.es6 +++ b/assets/javascripts/discourse/models/custom-wizard.js.es6 @@ -1,10 +1,11 @@ import { ajax } from 'discourse/lib/ajax'; import EmberObject from "@ember/object"; import { buildStepJson, buildJson, buildProperties } from '../lib/wizard-json'; +import { Promise } from "rsvp"; const CustomWizard = EmberObject.extend({ save() { - return new Ember.RSVP.Promise((resolve, reject) => { + return new Promise((resolve, reject) => { let wizardJson = buildJson(this, 'wizard'); if (wizardJson.after_time && !wizardJson.after_time_scheduled) { diff --git a/assets/javascripts/discourse/routes/admin-wizard.js.es6 b/assets/javascripts/discourse/routes/admin-wizard.js.es6 index dee0f0f5..8f5173d3 100644 --- a/assets/javascripts/discourse/routes/admin-wizard.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizard.js.es6 @@ -1,11 +1,8 @@ import CustomWizard from '../models/custom-wizard'; import { ajax } from 'discourse/lib/ajax'; -import { - selectKitContent, - profileFields, - generateName -} from '../lib/wizard'; +import { selectKitContent, profileFields, generateName } from '../lib/wizard'; import DiscourseRoute from "discourse/routes/discourse"; +import { all } from "rsvp"; export default DiscourseRoute.extend({ beforeModel() { @@ -39,7 +36,7 @@ export default DiscourseRoute.extend({ }, afterModel(model) { - return Ember.RSVP.all([ + return all([ this._getFieldTypes(model), this._getThemes(model), this._getApis(model), diff --git a/assets/javascripts/discourse/templates/admin-wizard.hbs b/assets/javascripts/discourse/templates/admin-wizard.hbs index 3f50c479..ba6fac31 100644 --- a/assets/javascripts/discourse/templates/admin-wizard.hbs +++ b/assets/javascripts/discourse/templates/admin-wizard.hbs @@ -114,7 +114,6 @@ options=(hash singular=true inputTypes='assignment' - hasOutput=true groupSelection='output' textSelection='key,value' )}} diff --git a/assets/javascripts/discourse/templates/admin-wizards-api.hbs b/assets/javascripts/discourse/templates/admin-wizards-api.hbs index fce6c1fa..c484ab77 100644 --- a/assets/javascripts/discourse/templates/admin-wizards-api.hbs +++ b/assets/javascripts/discourse/templates/admin-wizards-api.hbs @@ -135,8 +135,8 @@
{{#each api.authParams as |param|}}
- {{input value=param.key placeholder=(i18n 'admin.wizard.api.auth.params.key')}} - {{input value=param.value placeholder=(i18n 'admin.wizard.api.auth.params.value')}} + {{input value=param.key placeholder=(i18n 'admin.wizard.key')}} + {{input value=param.value placeholder=(i18n 'admin.wizard.value')}} {{d-button action=(action "removeParam") actionParam=param icon='times'}}
{{/each}} diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs index ebda8aa3..5fe96814 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -24,8 +24,7 @@ {{wizard-mapper inputs=action.title options=(hash - hasOutput=true - wizardSelection=true + wizardFieldSelection=true userFieldSelection='key,value' )}}
@@ -43,7 +42,7 @@ nameProperty='label' onChange=(action (mut action.post)) options=(hash - none='admin.wizard.select_field' + none='admin.wizard.selector.placeholder.wizard_field' isDisabled=action.post_builder )}} @@ -79,9 +78,8 @@ {{wizard-mapper inputs=action.category options=(hash - hasOutput=true textSelection='key,value' - wizardSelection=true + wizardFieldSelection=true userFieldSelection='key,value' categorySelection='output' outputDefaultSelection='category' @@ -98,9 +96,8 @@ {{wizard-mapper inputs=action.tags options=(hash - hasOutput=true tagSelection='output' - wizardSelection=true + wizardFieldSelection=true userFieldSelection='key,value' )}} @@ -117,9 +114,8 @@ {{wizard-mapper inputs=action.recipient options=(hash - hasOutput=true textSelection='value,output' - wizardSelection=true + wizardFieldSelection=true userFieldSelection='key,value' groupSelection='key,value' userSelection='output' @@ -137,12 +133,12 @@ {{wizard-mapper inputs=action.profile_updates - keyPlaceholder='admin.wizard.action.update_profile.key' options=(hash pairConnector='set' userFieldSelection='key' - wizardSelection='value' + wizardFieldSelection='value' keyDefaultSelection='userField' + keyPlaceholder='admin.wizard.action.update_profile.key' )}} {{/if}} @@ -208,9 +204,8 @@ {{wizard-mapper inputs=action.group options=(hash - hasOutput=true textSelection='value,output' - wizardSelection='key,value,assignment' + wizardFieldSelection='key,value,assignment' userFieldSelection='key,value,assignment' groupSelection='value,output' outputDefaultSelection='group' @@ -246,11 +241,11 @@
{{wizard-mapper inputs=action.custom_fields - keyPlaceholder='admin.wizard.action.custom_fields.key' options=(hash pairConnector='set' - wizardSelection='value' + wizardFieldSelection='value' userFieldSelection='value' + keyPlaceholder='admin.wizard.action.custom_fields.key' )}}
@@ -267,7 +262,7 @@ inputs=action.required options=(hash textSelection='value' - wizardSelection=true + wizardFieldSelection=true userFieldSelection=true groupSelection=true )}} diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs index 6c61eea5..4e39ba4a 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs @@ -69,41 +69,6 @@ {{/if}} -{{#if isDropdown}} -
-
- {{i18n 'admin.wizard.field.choices_label'}} -
- - {{combo-box - value=field.choices_type - content=choicesTypes - onChange=(action (mut field.choices_type)) - options=(hash - none="admin.wizard.field.choices_type" - )}} - - {{#if choicesTranslation}} -
- {{i18n 'admin.wizard.field.choices_translation'}} -
- {{input name="key" value=field.choices_key placeholderKey="admin.wizard.translation_placeholder"}} - {{/if}} - - {{#if choicesCustom}} -
- {{i18n 'admin.wizard.field.choices_custom'}} -
- {{wizard-mapper inputs=field.choices}} - {{/if}} - -
- {{i18n 'admin.wizard.field.dropdown_none'}} -
- {{input name="dropdown_none" value=field.dropdown_none placeholder=(i18n 'admin.wizard.field.dropdown_none_placeholder')}} -
-{{/if}} - {{#if isUpload}}
@@ -128,63 +93,61 @@
{{/if}} -{{#if hasAdvanced}} - {{wizard-advanced-toggle showAdvanced=field.showAdvanced}} +{{wizard-advanced-toggle showAdvanced=field.showAdvanced}} - {{#if field.showAdvanced}} -
- - {{#if isCategory}} -
-
- -
- -
- {{combo-box - value=field.property - content=categoryPropertyTypes - onChange=(action (mut field.property)) - options=(hash - none='admin.wizard.select_property' - )}} -
-
- {{/if}} - - {{#if prefillEnabled}} -
-
- -
- -
- {{wizard-mapper inputs=field.prefill options=prefillOptions}} -
-
- {{/if}} - - {{#if contentEnabled}} -
-
- -
- -
- {{wizard-mapper inputs=field.content options=contentOptions}} -
-
- {{/if}} - +{{#if field.showAdvanced}} +
+ + {{#if isCategory}}
- +
+
- {{input name="key" value=field.key placeholderKey="admin.wizard.translation_placeholder"}} + {{combo-box + value=field.property + content=categoryPropertyTypes + onChange=(action (mut field.property)) + options=(hash + none='admin.wizard.select_property' + )}}
- + {{/if}} + + {{#if prefillEnabled}} +
+
+ +
+ +
+ {{wizard-mapper inputs=field.prefill options=prefillOptions}} +
+
+ {{/if}} + + {{#if contentEnabled}} +
+
+ +
+ +
+ {{wizard-mapper inputs=field.content options=contentOptions}} +
+
+ {{/if}} + +
+
+ +
+
+ {{input name="key" value=field.key placeholderKey="admin.wizard.translation_placeholder"}} +
- {{/if}} + +
{{/if}} diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs index 76841409..770ef844 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs @@ -46,10 +46,10 @@
{{wizard-mapper inputs=step.required_data - keyPlaceholder="admin.wizard.submission_key" options=(hash - wizardSelection='value' + wizardFieldSelection='value' userFieldSelection='value' + keyPlaceholder="admin.wizard.submission_key" )}} {{#if step.required_data}}
@@ -69,10 +69,10 @@
{{wizard-mapper inputs=step.permitted_params - keyPlaceholder='admin.wizard.param_key' - valuePlaceholder='admin.wizard.submission_key' options=(hash pairConnector='set' + keyPlaceholder='admin.wizard.param_key' + valuePlaceholder='admin.wizard.submission_key' )}}
diff --git a/assets/javascripts/discourse/templates/components/wizard-mapper-input.hbs b/assets/javascripts/discourse/templates/components/wizard-mapper-input.hbs index bfd9ea9a..adf58e6a 100644 --- a/assets/javascripts/discourse/templates/components/wizard-mapper-input.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-mapper-input.hbs @@ -1,9 +1,7 @@ -{{#if hasOutput}} - {{wizard-mapper-connector - connector=input.type - connectors=inputTypes - inputTypes=true}} -{{/if}} +{{wizard-mapper-connector + connector=input.type + connectors=inputTypes + inputTypes=true}} {{#if hasPairs}}
@@ -12,8 +10,6 @@ pair=pair last=pair.last inputType=inputType - keyPlaceholder=keyPlaceholder - valuePlaceholder=valuePlaceholder options=options removePair=(action 'removePair')}} {{/each}} @@ -39,7 +35,6 @@ inputType=inputType value=input.output activeType=input.output_type - customPlaceholder=outputPlaceholder options=options}}
{{/if}} diff --git a/assets/javascripts/discourse/templates/components/wizard-mapper-pair.hbs b/assets/javascripts/discourse/templates/components/wizard-mapper-pair.hbs index 7aea5a02..4fda761f 100644 --- a/assets/javascripts/discourse/templates/components/wizard-mapper-pair.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-mapper-pair.hbs @@ -4,7 +4,6 @@ inputType=inputType value=pair.key activeType=pair.key_type - customPlaceholder=keyPlaceholder options=options}}
@@ -18,7 +17,6 @@ inputType=inputType value=pair.value activeType=pair.value_type - customPlaceholder=valuePlaceholder options=options}}
diff --git a/assets/javascripts/discourse/templates/components/wizard-mapper-selector.hbs b/assets/javascripts/discourse/templates/components/wizard-mapper-selector.hbs index 8f375de9..8f5683f8 100644 --- a/assets/javascripts/discourse/templates/components/wizard-mapper-selector.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-mapper-selector.hbs @@ -1,52 +1,10 @@
- {{#if textEnabled}} + {{#each selectorTypes as |type|}} {{wizard-mapper-selector-type activeType=activeType - type='text' + type=type toggle=(action 'toggleType')}} - {{/if}} - - {{#if wizardEnabled}} - {{wizard-mapper-selector-type - activeType=activeType - type='wizard' - toggle=(action 'toggleType')}} - {{/if}} - - {{#if userFieldEnabled}} - {{wizard-mapper-selector-type - activeType=activeType - type='userField' - toggle=(action 'toggleType')}} - {{/if}} - - {{#if categoryEnabled}} - {{wizard-mapper-selector-type - activeType=activeType - type='category' - toggle=(action 'toggleType')}} - {{/if}} - - {{#if tagEnabled}} - {{wizard-mapper-selector-type - activeType=activeType - type='tag' - toggle=(action 'toggleType')}} - {{/if}} - - {{#if groupEnabled}} - {{wizard-mapper-selector-type - activeType=activeType - type='group' - toggle=(action 'toggleType')}} - {{/if}} - - {{#if userEnabled}} - {{wizard-mapper-selector-type - activeType=activeType - type='user' - toggle=(action 'toggleType')}} - {{/if}} + {{/each}}
@@ -54,60 +12,44 @@ {{input type="text" value=value - placeholder=(i18n textPlaceholder)}} - {{/if}} - - {{#if showWizard}} - {{combo-box - value=value - content=wizardFields - onChange=(action (mut value)) - options=(hash - none='admin.wizard.wizard_field' - )}} + placeholder=(i18n placeholder)}} {{/if}} - {{#if showUserField}} + {{#if showComboBox}} {{combo-box value=value - content=userFields + content=comboBoxContent onChange=(action (mut value)) options=(hash - none='admin.wizard.user_field' + none=placeholder )}} {{/if}} - {{#if showCategory}} + {{#if showMultiSelect}} {{multi-select - content=categories + content=multiSelectContent value=value onChange=(action (mut value)) - options=(hash - none='admin.wizard.select_category' - )}} + options=multiSelectOptions}} + {{/if}} + + {{#if showList}} + {{value-list values=value}} {{/if}} {{#if showTag}} {{tag-chooser tags=value - filterable=true}} - {{/if}} - - {{#if showGroup}} - {{multi-select - content=groups - value=value - onChange=(action (mut value)) + filterable=true options=(hash - none='admin.wizard.select_group' + none=placeholder )}} {{/if}} {{#if showUser}} {{user-selector - topicId=topicId includeMessageableGroups='true' - placeholderKey="composer.users_placeholder" + placeholderKey=placeholder usernames=value autocomplete="discourse"}} {{/if}} diff --git a/assets/javascripts/discourse/templates/components/wizard-mapper.hbs b/assets/javascripts/discourse/templates/components/wizard-mapper.hbs index d849c7b6..219e0fd6 100644 --- a/assets/javascripts/discourse/templates/components/wizard-mapper.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-mapper.hbs @@ -1,8 +1,6 @@ {{#each inputs as |input|}} {{wizard-mapper-input input=input - keyPlaceholder=keyPlaceholder - valuePlaceholder=valuePlaceholder options=inputOptions remove=(action 'remove')}} {{/each}} diff --git a/assets/javascripts/wizard/initializers/custom.js.es6 b/assets/javascripts/wizard/initializers/custom.js.es6 index 308f9c92..0738244c 100644 --- a/assets/javascripts/wizard/initializers/custom.js.es6 +++ b/assets/javascripts/wizard/initializers/custom.js.es6 @@ -1,4 +1,5 @@ import { default as computed } from 'discourse-common/utils/decorators'; +import { dasherize } from "@ember/string"; export default { name: 'custom-routes', @@ -219,7 +220,7 @@ export default { const type = this.get('field.type'); const id = this.get('field.id'); if (['text-only'].includes(type)) return false; - return (type === 'component') ? Ember.String.dasherize(id) : `wizard-field-${type}`; + return (type === 'component') ? dasherize(id) : `wizard-field-${type}`; }.property('field.type', 'field.id') }); diff --git a/assets/javascripts/wizard/templates/components/wizard-field-dropdown.hbs b/assets/javascripts/wizard/templates/components/wizard-field-dropdown.hbs index 4f411ce3..87b9bf51 100644 --- a/assets/javascripts/wizard/templates/components/wizard-field-dropdown.hbs +++ b/assets/javascripts/wizard/templates/components/wizard-field-dropdown.hbs @@ -1,7 +1,7 @@ {{combo-box elementId=field.id class=fieldClass value=field.value - content=field.choices + content=field.content none=(hash id="__none__" label=field.dropdown_none) nameProperty="label" tabindex="9"}} \ No newline at end of file diff --git a/assets/stylesheets/common/wizard-admin.scss b/assets/stylesheets/common/wizard-admin.scss index 3f698725..49b960e6 100644 --- a/assets/stylesheets/common/wizard-admin.scss +++ b/assets/stylesheets/common/wizard-admin.scss @@ -379,17 +379,6 @@ body.admin-wizard { position: relative; } -.wizard-dropdown-choices { - padding: 15px; - margin-bottom: 20px; - background-color: $secondary; - width: 100%; - - .wizard-header:not(.underline) { - margin-top: 15px; - } -} - .required-data-message { display: inline-block; margin-top: 20px; diff --git a/assets/stylesheets/common/wizard-mapper.scss b/assets/stylesheets/common/wizard-mapper.scss index 0d900182..29fded74 100644 --- a/assets/stylesheets/common/wizard-mapper.scss +++ b/assets/stylesheets/common/wizard-mapper.scss @@ -24,11 +24,10 @@ align-items: flex-start; width: min-content; position: relative; - padding-bottom: 30px; - - &:last-of-type { - padding-bottom: 0; - } + padding: 25px 7px 7px 7px; + margin-bottom: 10px; + background: rgba($secondary, 0.5); + border: 2px solid $primary-low; .d-icon { text-align: center; @@ -42,11 +41,16 @@ background-color: $primary-low; border-color: #ddd; } + + .output { + position: relative; + } a.remove-input { position: absolute; right: -25px; - top: 5px; + top: 50%; + transform: translateY(-50%); } } @@ -54,10 +58,6 @@ display: block; } -.mapper-input + .add-mapper-input { - padding-top: 10px; -} - .mapper-connector { width: auto; min-width: 40px; @@ -105,6 +105,15 @@ margin-right: 0; } } + + .value-list .remove-value-btn { + background: none; + border: none; + + .d-icon { + color: $primary; + } + } } .mapper-pairs { diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index ac2a5168..8cf0a3da 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -42,20 +42,13 @@ en: remove: "Delete Wizard" add: "Add" url: "Url" + key: "Key" value: "Value" - property: "Property" - text: "text" profile: "profile" translation: "Translation" translation_placeholder: "key" type: "Type" - none: "Make a selection" - user_field: "User Field" - wizard_field: "Wizard Field" - select_field: "Select Field" - select_property: "Select Property" - select_group: "Select Group" - profile_field: "Profile Field" + none: "Make a selection" submission_key: 'submission key' param_key: 'param' group: "Group" @@ -74,7 +67,31 @@ en: output: 'then' assignment: name: 'set' + pair: + name: 'pair' + selector: + label: + text: "text" + wizard_field: "wizard ○" + user_field: "user ○" + user: "user" + category: "category" + tag: "tag" + group: "group" + list: "list" + + placeholder: + text: "Enter text" + property: "Select property" + wizard_field: "Select field" + user_field: "Select field" + user: "Select user" + category: "Select category" + tag: "Select tag" + group: "Select group" + list: "Enter item" + error: name_required: "Wizards must have a name." steps_required: "Wizards must have at least one step." @@ -83,9 +100,6 @@ en: type_required: "All fields need a type." after_time_need_time: "After time is enabled but no time is set." after_time_invalid: "After time is invalid." - field: - need_choices: "All dropdowns need choices." - choices_label_empty: "Custom choice labels cannot be empty." step: header: "Steps" @@ -107,13 +121,6 @@ en: image_placeholder: "Image url" dropdown_none: "None" dropdown_none_placeholder: "Label" - choices_label: "Dropdown Choices" - choices_type: "Choose a type" - choices_translation: "Translation" - choices_custom: "Custom" - choice: - value: "Value" - label: "Label" required: "Required" required_label: "Field is Required" min_length: "Min Length" @@ -214,8 +221,6 @@ en: params: label: 'Params' new: 'New param' - key: 'key' - value: 'value' status: label: "Status" diff --git a/config/locales/client.fr.yml b/config/locales/client.fr.yml index 45169ac4..08c68f28 100644 --- a/config/locales/client.fr.yml +++ b/config/locales/client.fr.yml @@ -59,9 +59,6 @@ fr: type_required: "Tous les champs ont besoin d'un type." after_time_need_time: "Le délai est activé mais aucune heure n'est établie." after_time_invalid: "Le délai est invalide." - field: - need_choices: "Tous les menus déroulants ont besoin d'options." - choices_label_empty: "Les étiquettes pour le choix personnalisé ne peuvent être vides." step: header: "Étapes" title: "Titre" @@ -74,15 +71,6 @@ fr: description: "Description" image: "Image" image_placeholder: "URL de l'image" - dropdown_none: "Aucun" - dropdown_none_placeholder: "Clé de traduction" - choices_label: "Options du menu déroulant" - choices_type: "Choisir un type" - choices_translation: "Traduction" - choices_custom: "Personnalisé" - choice: - value: "Valeur" - label: "Étiquette" required: "Requis" required_label: "Le champ est obligatoire" min_length: "Longueur min." @@ -103,7 +91,6 @@ fr: category: "Catégorie" update_profile: label: "Mettre à jour le profil" - profile_field: "Champ du profil" post_builder: checkbox: "Générateur de message" label: "Générateur" diff --git a/controllers/custom_wizard/admin.rb b/controllers/custom_wizard/admin.rb index da1bde0f..c66474ec 100644 --- a/controllers/custom_wizard/admin.rb +++ b/controllers/custom_wizard/admin.rb @@ -63,14 +63,6 @@ class CustomWizard::AdminController < ::ApplicationController error = 'type_required' break end - - if f["type"] === 'dropdown' - choices = f["choices"] - if (!choices || choices.length < 1) && !f["choices_key"] - error = 'field.need_choices' - break - end - end end end diff --git a/lib/custom_wizard/builder.rb b/lib/custom_wizard/builder.rb index 8d7686f7..734d71f0 100644 --- a/lib/custom_wizard/builder.rb +++ b/lib/custom_wizard/builder.rb @@ -244,10 +244,6 @@ class CustomWizard::Builder end field = step.add_field(params) - - if field_template['type'] === 'dropdown' - build_dropdown_list(field, field_template) - end end def prefill_field(field_template, step_template) @@ -260,26 +256,6 @@ class CustomWizard::Builder end end - def build_dropdown_list(field, template) - field.dropdown_none = template['dropdown_none'] if template['dropdown_none'] - method = "build_dropdown_#{template['choices_type']}" - self.send(method, field, template) if self.respond_to?(method) - end - - def build_dropdown_custom(field, template) - template['choices'].each do |c| - field.add_choice(c['key'], label: c['value']) - end - end - - def build_dropdown_translation(field, template) - choices = I18n.t(template['choices_key']) - - if choices.is_a?(Hash) - choices.each { |k, v| field.add_choice(k, label: v) } - end - end - def validate_field(field, updater, step_template) value = updater.fields[field['id']] min_length = false diff --git a/lib/wizard/choice.rb b/lib/wizard/choice.rb deleted file mode 100644 index f0aa6bf3..00000000 --- a/lib/wizard/choice.rb +++ /dev/null @@ -1,17 +0,0 @@ -module CustomWizardChoiceExtension - def initialize(id, opts) - @id = id - @opts = opts - @data = opts[:data] - @extra_label = opts[:extra_label] - @icon = opts[:icon] - end - - def label - @label ||= PrettyText.cook(@opts[:label]) - end -end - -class Wizard::Choice - prepend CustomWizardChoiceExtension if SiteSetting.custom_wizard_enabled -end \ No newline at end of file diff --git a/lib/wizard/field.rb b/lib/wizard/field.rb index eefaa063..2ee96dd6 100644 --- a/lib/wizard/field.rb +++ b/lib/wizard/field.rb @@ -9,8 +9,6 @@ module CustomWizardFieldExtension :property, :content - attr_accessor :dropdown_none - def initialize(attrs) @attrs = attrs || {} @id = attrs[:id] @@ -21,8 +19,6 @@ module CustomWizardFieldExtension @key = attrs[:key] @min_length = attrs[:min_length] @value = attrs[:value] - @choices = [] - @dropdown_none = attrs[:dropdown_none] @file_types = attrs[:file_types] @limit = attrs[:limit] @property = attrs[:property] diff --git a/plugin.rb b/plugin.rb index d51fcca3..7a4196fe 100644 --- a/plugin.rb +++ b/plugin.rb @@ -63,7 +63,6 @@ after_initialize do ../lib/custom_wizard/api/authorization.rb ../lib/custom_wizard/api/endpoint.rb ../lib/custom_wizard/api/log_entry.rb - ../lib/wizard/choice.rb ../lib/wizard/field.rb ../lib/wizard/step.rb ../serializers/custom_wizard/api/authorization_serializer.rb diff --git a/serializers/custom_wizard/wizard_field_serializer.rb b/serializers/custom_wizard/wizard_field_serializer.rb index 11bad2e9..7f7d6505 100644 --- a/serializers/custom_wizard/wizard_field_serializer.rb +++ b/serializers/custom_wizard/wizard_field_serializer.rb @@ -8,9 +8,7 @@ class CustomWizardFieldSerializer < ::WizardFieldSerializer :limit, :property, :content - - has_many :choices, serializer: WizardFieldChoiceSerializer, embed: :objects - + def label return object.label if object.label.present? I18n.t("#{object.key || i18n_key}.label", default: '') diff --git a/spec/components/custom_wizard/builder_spec.rb b/spec/components/custom_wizard/builder_spec.rb index d63ba6e3..c53b8430 100644 --- a/spec/components/custom_wizard/builder_spec.rb +++ b/spec/components/custom_wizard/builder_spec.rb @@ -28,8 +28,6 @@ describe CustomWizard::Builder do let(:text_only_field) {{"id": "text_only","type": "text-only","label": "Text only"}} let(:upload_field) {{"id": "upload","type": "upload","file_types": ".jpg,.png,.pdf","label": "Upload"}} let(:user_selector_field) {{"id": "user_selector","type": "user-selector","label": "User selector"}} - let(:dropdown_custom_field) {{"id": "dropdown_custom","type": "dropdown","choices_type": "custom","choices": [{"key": "option_1","value": "Option 1"},{"key": "option_2","value": "Option 2"}]}} - let(:dropdown_translation_field) {{"id": "dropdown_translation","type": "dropdown","choices_type": "translation","choices_key": "key1.key2"}} let(:create_topic_action) {{"id":"create_topic","type":"create_topic","title":"text","post":"textarea"}} let(:send_message_action) {{"id":"send_message","type":"send_message","title":"text","post":"textarea","username":"angus"}} let(:route_to_action) {{"id":"route_to","type":"route_to","url":"https://google.com"}}