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