diff --git a/assets/javascripts/discourse/components/input-type-toggle.js.es6 b/assets/javascripts/discourse/components/input-type-toggle.js.es6 index b73759e1..b6cd7d1b 100644 --- a/assets/javascripts/discourse/components/input-type-toggle.js.es6 +++ b/assets/javascripts/discourse/components/input-type-toggle.js.es6 @@ -12,9 +12,12 @@ export default Ember.Component.extend({ @discourseComputed('type') label(type) { let map = { + text: I18n.t('admin.wizard.text'), wizard: I18n.t('admin.wizard.label'), user: I18n.t('users_lowercase.one'), - text: I18n.t('admin.wizard.text') + category: I18n.t('categories.category'), + tag: I18n.t('tagging.tags'), + group: I18n.t('groups.title.one') }; return map[type].toLowerCase(); }, diff --git a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 index 1d8ff0b9..2777f4ef 100644 --- a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 @@ -1,15 +1,18 @@ import { default as computed, observes, on } from 'discourse-common/utils/decorators'; +import { equal, not } from "@ember/object/computed"; import { generateSelectKitContent } from '../lib/custom-wizard'; export default Ember.Component.extend({ classNames: 'wizard-custom-field', - isDropdown: Ember.computed.equal('field.type', 'dropdown'), - isUpload: Ember.computed.equal('field.type', 'upload'), - isCategory: Ember.computed.equal('field.type', 'category'), - disableId: Ember.computed.not('field.isNew'), + isDropdown: equal('field.type', 'dropdown'), + isUpload: equal('field.type', 'upload'), + isCategory: equal('field.type', 'category'), + isGroup: equal('field.type', 'group'), + isTag: equal('field.type', 'tag'), + disableId: not('field.isNew'), choicesTypes: generateSelectKitContent(['translation', 'custom']), - choicesTranslation: Ember.computed.equal('field.choices_type', 'translation'), - choicesCustom: Ember.computed.equal('field.choices_type', 'custom'), + choicesTranslation: equal('field.choices_type', 'translation'), + choicesCustom: equal('field.choices_type', 'custom'), categoryPropertyTypes: generateSelectKitContent(['id', 'slug']), @computed('field.type') @@ -24,5 +27,32 @@ export default Ember.Component.extend({ if (this.get('isUpload') && !this.get('field.file_types')) { this.set('field.file_types', '.jpg,.png'); } + }, + + @computed('isCategory', 'isGroup', 'isTag') + prefillOptions(isCategory, isGroup, isTag) { + let options = { + hasOutput: true, + enableConnectors: true, + allowWizard: true, + allowUser: true + } + + if (isCategory) { + options.allowUser = 'key,value'; + options.allowCategory = 'output'; + } + + if (isGroup) { + options.allowUser = 'key,value'; + options.allowGroup = 'output'; + } + + if (isTag) { + options.allowUser = 'key,value'; + options.allowTag = 'output'; + } + + return options; } }); diff --git a/assets/javascripts/discourse/components/wizard-custom-input-chooser.js.es6 b/assets/javascripts/discourse/components/wizard-custom-input-chooser.js.es6 index 10b1c96a..9dd44751 100644 --- a/assets/javascripts/discourse/components/wizard-custom-input-chooser.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-input-chooser.js.es6 @@ -16,28 +16,34 @@ export default Ember.Component.extend({ return customPlaceholder || 'admin.wizard.text'; }, - @discourseComputed('activeType', 'userEnabled') - showUser(activeType, userEnabled) { - return activeType === 'user' && userEnabled; - }, - - @discourseComputed('activeType', 'wizardEnabled') - showWizard(activeType, wizardEnabled) { - return activeType === 'wizard' && wizardEnabled; - }, - showText: equal('activeType', 'text'), - @discourseComputed('options.allowWizardField', 'inputType') - wizardEnabled(allowWizardField, inputType) { - return allowWizardField === true || allowWizardField === inputType; + showInput(type) { + return this.activeType === type && this[`${type}Enabled`]; }, - @discourseComputed('options.allowUserField', 'inputType') - userEnabled(allowUserField, inputType) { - return allowUserField === true || allowUserField === inputType; + showWizard: computed('activeType', function() { return this.showInput('wizard') }), + showUser: computed('activeType', function() { return this.showInput('user') }), + showCategory: computed('activeType', function() { return this.showInput('category') }), + showTag: computed('activeType', function() { return this.showInput('tag') }), + showGroup: computed('activeType', function() { return this.showInput('group') }), + + optionEnabled(type) { + const options = this.options; + if (!options) return false; + + const option = options[type]; + if (option === true) return true; + if (typeof option !== 'string') return false; + return option.split(',').indexOf(this.inputType) > -1; }, + wizardEnabled: computed('options.allowWizard', function() { return this.optionEnabled('allowWizard') }), + userEnabled: computed('options.allowUser', function() { return this.optionEnabled('allowUser') }), + categoryEnabled: computed('options.allowCategory', function() { return this.optionEnabled('allowCategory') }), + tagEnabled: computed('options.allowTag', function() { return this.optionEnabled('allowTag') }), + groupEnabled: computed('options.allowGroup', function() { return this.optionEnabled('allowGroup') }), + actions: { toggleType(type) { this.set('activeType', type); diff --git a/assets/javascripts/discourse/components/wizard-custom-input-pair.js.es6 b/assets/javascripts/discourse/components/wizard-custom-input-pair.js.es6 index a4666bf6..e2045b64 100644 --- a/assets/javascripts/discourse/components/wizard-custom-input-pair.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-input-pair.js.es6 @@ -1,9 +1,14 @@ import { connectors } from '../lib/custom-wizard'; -import { gt } from "@ember/object/computed"; +import { gt, or, alias } from "@ember/object/computed"; +import { computed, observes} from "@ember/object"; export default Ember.Component.extend({ classNames: 'pair', - connectorNone: 'admin.wizard.connector.none', connectors: connectors, - showRemove: gt('pair.index', 0) + hasConnector: or('options.enableConnectors', 'connectorKey'), + firstPair: gt('pair.index', 0), + showRemove: alias('firstPair'), + showJoin: computed('pair.pairCount', function() { + return this.pair.index < (this.pair.pairCount - 1); + }) }) \ No newline at end of file diff --git a/assets/javascripts/discourse/components/wizard-custom-input.js.es6 b/assets/javascripts/discourse/components/wizard-custom-input.js.es6 index ed15b5a3..0c69a9c3 100644 --- a/assets/javascripts/discourse/components/wizard-custom-input.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-input.js.es6 @@ -1,19 +1,36 @@ import { newPair } from '../lib/custom-wizard'; +import { computed } from "@ember/object"; export default Ember.Component.extend({ classNames: 'custom-input', - outputConnectorKey: 'admin.wizard.connector.prefill', - outputPrefixKey: 'admin.wizard.if', + outputConnector: computed(function() { + return I18n.t(this.outputConnectorKey || 'admin.wizard.output.connector').toLowerCase(); + }), actions: { addPair() { - this.get('input.pairs').pushObject( - newPair(this.options, this.input.pairs.length) + const pairs = this.get('input.pairs'); + + const pairCount = pairs.length + 1; + pairs.forEach(p => (p.set('pairCount', pairCount))); + + pairs.pushObject( + newPair(Object.assign( + {}, + this.options, + { + index: pairs.length, + pairCount, + } + )) ); }, removePair(pair) { - this.get('input.pairs').removeObject(pair); + const pairs = this.get('input.pairs'); + const pairCount = pairs.length - 1; + pairs.forEach(p => (p.set('pairCount', pairCount))); + pairs.removeObject(pair); } } }); diff --git a/assets/javascripts/discourse/lib/custom-wizard.js.es6 b/assets/javascripts/discourse/lib/custom-wizard.js.es6 index 2adc9867..cc7ba277 100644 --- a/assets/javascripts/discourse/lib/custom-wizard.js.es6 +++ b/assets/javascripts/discourse/lib/custom-wizard.js.es6 @@ -55,7 +55,7 @@ const actionTypes = [ function newInput(options = {}) { let params = { - pairs: Ember.A([newPair(options, 0)]) + pairs: Ember.A([newPair({ index: 0, pairCount: 1 })]) } if (options.hasOutput) { @@ -66,9 +66,11 @@ function newInput(options = {}) { return Ember.Object.create(params); } -function newPair(options = {}, index) { +function newPair(options = {}) { + console.log('newPair: ', options) let params = { - index, + index: options.index, + pairCount: options.pairCount, key: '', key_type: 'text', value: '', diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs index 87bfcf6b..2e639b46 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -175,7 +175,7 @@ userFields=userFields wizardFields=wizardFields options=(hash - allowWizardField=true + allowWizard=true )}} {{/if}} @@ -227,8 +227,8 @@ userFields=userFields wizardFields=wizardFields options=(hash - allowWizardField=true - allowUserField=true + allowWizard=true + allowUser=true )}} {{/if}} @@ -281,39 +281,20 @@ {{#if addToGroup}}