0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-26 19:10:29 +01:00
Dieser Commit ist enthalten in:
Angus McLeod 2020-03-23 16:41:04 +11:00
Ursprung ffde10c217
Commit 3a14cb0805
15 geänderte Dateien mit 229 neuen und 130 gelöschten Zeilen

Datei anzeigen

@ -12,9 +12,12 @@ export default Ember.Component.extend({
@discourseComputed('type') @discourseComputed('type')
label(type) { label(type) {
let map = { let map = {
text: I18n.t('admin.wizard.text'),
wizard: I18n.t('admin.wizard.label'), wizard: I18n.t('admin.wizard.label'),
user: I18n.t('users_lowercase.one'), 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(); return map[type].toLowerCase();
}, },

Datei anzeigen

@ -1,15 +1,18 @@
import { default as computed, observes, on } from 'discourse-common/utils/decorators'; import { default as computed, observes, on } from 'discourse-common/utils/decorators';
import { equal, not } from "@ember/object/computed";
import { generateSelectKitContent } from '../lib/custom-wizard'; import { generateSelectKitContent } from '../lib/custom-wizard';
export default Ember.Component.extend({ export default Ember.Component.extend({
classNames: 'wizard-custom-field', classNames: 'wizard-custom-field',
isDropdown: Ember.computed.equal('field.type', 'dropdown'), isDropdown: equal('field.type', 'dropdown'),
isUpload: Ember.computed.equal('field.type', 'upload'), isUpload: equal('field.type', 'upload'),
isCategory: Ember.computed.equal('field.type', 'category'), isCategory: equal('field.type', 'category'),
disableId: Ember.computed.not('field.isNew'), isGroup: equal('field.type', 'group'),
isTag: equal('field.type', 'tag'),
disableId: not('field.isNew'),
choicesTypes: generateSelectKitContent(['translation', 'custom']), choicesTypes: generateSelectKitContent(['translation', 'custom']),
choicesTranslation: Ember.computed.equal('field.choices_type', 'translation'), choicesTranslation: equal('field.choices_type', 'translation'),
choicesCustom: Ember.computed.equal('field.choices_type', 'custom'), choicesCustom: equal('field.choices_type', 'custom'),
categoryPropertyTypes: generateSelectKitContent(['id', 'slug']), categoryPropertyTypes: generateSelectKitContent(['id', 'slug']),
@computed('field.type') @computed('field.type')
@ -24,5 +27,32 @@ export default Ember.Component.extend({
if (this.get('isUpload') && !this.get('field.file_types')) { if (this.get('isUpload') && !this.get('field.file_types')) {
this.set('field.file_types', '.jpg,.png'); 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;
} }
}); });

Datei anzeigen

@ -16,28 +16,34 @@ export default Ember.Component.extend({
return customPlaceholder || 'admin.wizard.text'; 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'), showText: equal('activeType', 'text'),
@discourseComputed('options.allowWizardField', 'inputType') showInput(type) {
wizardEnabled(allowWizardField, inputType) { return this.activeType === type && this[`${type}Enabled`];
return allowWizardField === true || allowWizardField === inputType;
}, },
@discourseComputed('options.allowUserField', 'inputType') showWizard: computed('activeType', function() { return this.showInput('wizard') }),
userEnabled(allowUserField, inputType) { showUser: computed('activeType', function() { return this.showInput('user') }),
return allowUserField === true || allowUserField === inputType; 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: { actions: {
toggleType(type) { toggleType(type) {
this.set('activeType', type); this.set('activeType', type);

Datei anzeigen

@ -1,9 +1,14 @@
import { connectors } from '../lib/custom-wizard'; 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({ export default Ember.Component.extend({
classNames: 'pair', classNames: 'pair',
connectorNone: 'admin.wizard.connector.none',
connectors: connectors, 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);
})
}) })

Datei anzeigen

@ -1,19 +1,36 @@
import { newPair } from '../lib/custom-wizard'; import { newPair } from '../lib/custom-wizard';
import { computed } from "@ember/object";
export default Ember.Component.extend({ export default Ember.Component.extend({
classNames: 'custom-input', classNames: 'custom-input',
outputConnectorKey: 'admin.wizard.connector.prefill', outputConnector: computed(function() {
outputPrefixKey: 'admin.wizard.if', return I18n.t(this.outputConnectorKey || 'admin.wizard.output.connector').toLowerCase();
}),
actions: { actions: {
addPair() { addPair() {
this.get('input.pairs').pushObject( const pairs = this.get('input.pairs');
newPair(this.options, this.input.pairs.length)
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) { 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);
} }
} }
}); });

Datei anzeigen

@ -55,7 +55,7 @@ const actionTypes = [
function newInput(options = {}) { function newInput(options = {}) {
let params = { let params = {
pairs: Ember.A([newPair(options, 0)]) pairs: Ember.A([newPair({ index: 0, pairCount: 1 })])
} }
if (options.hasOutput) { if (options.hasOutput) {
@ -66,9 +66,11 @@ function newInput(options = {}) {
return Ember.Object.create(params); return Ember.Object.create(params);
} }
function newPair(options = {}, index) { function newPair(options = {}) {
console.log('newPair: ', options)
let params = { let params = {
index, index: options.index,
pairCount: options.pairCount,
key: '', key: '',
key_type: 'text', key_type: 'text',
value: '', value: '',

Datei anzeigen

@ -175,7 +175,7 @@
userFields=userFields userFields=userFields
wizardFields=wizardFields wizardFields=wizardFields
options=(hash options=(hash
allowWizardField=true allowWizard=true
)}} )}}
</div> </div>
{{/if}} {{/if}}
@ -227,8 +227,8 @@
userFields=userFields userFields=userFields
wizardFields=wizardFields wizardFields=wizardFields
options=(hash options=(hash
allowWizardField=true allowWizard=true
allowUserField=true allowUser=true
)}} )}}
</div> </div>
{{/if}} {{/if}}
@ -281,39 +281,20 @@
{{#if addToGroup}} {{#if addToGroup}}
<div class="setting"> <div class="setting">
<div class="setting-label"> <div class="setting-label">
<h3>{{i18n "admin.wizard.action.add_to_group.group_selection"}}</h3> <h3>{{i18n "admin.wizard.action.add_to_group.group"}}</h3>
</div> </div>
<div class="setting-value"> <div class="setting-value">
{{combo-box {{wizard-custom-inputs
value=action.value inputs=action.selection
content=wizardFields userFields=userFields
isDisabled=action.custom wizardFields=wizardFields
nameProperty="label" outputConnectorKey='admin.wizard.action.add_to_group.output_connector'
options=(hash options=(hash
none='admin.wizard.select_field' hasOutput=true
)}} enableConnectors=true
allowWizard='key,value'
<div class="setting-gutter"> allowUser='key,value'
{{input type='checkbox' checked=action.custom_group_enabled}} allowGroup='value,output'
<span>{{i18n 'admin.wizard.action.add_to_group.custom_group'}}</span>
{{#if action.custom_group_enabled}}
{{input value=action.custom}}
{{/if}}
</div>
</div>
</div>
<div class="setting">
<div class="setting-label">
<h3>{{i18n "admin.wizard.action.add_to_group.property"}}</h3>
</div>
<div class="setting-value">
{{combo-box
value=action.property
content=groupPropertyTypes
options=(hash
none='admin.wizard.select_property'
)}} )}}
</div> </div>
</div> </div>

Datei anzeigen

@ -162,11 +162,7 @@
inputs=field.prefill inputs=field.prefill
userFields=userFields userFields=userFields
wizardFields=wizardFields wizardFields=wizardFields
options=(hash outputConnectorKey='admin.wizard.field.prefill'
hasOutput=true options=prefillOptions}}
enableConnectors=true
allowWizardField=true
allowUserField=true
)}}
</div> </div>
</div> </div>

Datei anzeigen

@ -17,6 +17,27 @@
type='user' type='user'
toggle=(action 'toggleType')}} toggle=(action 'toggleType')}}
{{/if}} {{/if}}
{{#if categoryEnabled}}
{{input-type-toggle
activeType=activeType
type='category'
toggle=(action 'toggleType')}}
{{/if}}
{{#if tagEnabled}}
{{input-type-toggle
activeType=activeType
type='tag'
toggle=(action 'toggleType')}}
{{/if}}
{{#if groupEnabled}}
{{input-type-toggle
activeType=activeType
type='group'
toggle=(action 'toggleType')}}
{{/if}}
</div> </div>
<div class="input"> <div class="input">
@ -31,6 +52,7 @@
{{combo-box {{combo-box
value=value value=value
content=wizardFields content=wizardFields
onChange=(action (mut value))
options=(hash options=(hash
none='admin.wizard.wizard_field' none='admin.wizard.wizard_field'
)}} )}}
@ -40,8 +62,30 @@
{{combo-box {{combo-box
value=value value=value
content=userFields content=userFields
onChange=(action (mut value))
options=(hash options=(hash
none='admin.wizard.user_field' none='admin.wizard.user_field'
)}} )}}
{{/if}} {{/if}}
{{#if showCategory}}
{{category-chooser value=value}}
{{/if}}
{{#if showTag}}
{{tag-chooser
tags=value
filterable=true
allowCreate=true}}
{{/if}}
{{#if showGroup}}
{{combo-box
content=site.groups
value=value
onChange=(action (mut value))
options=(hash
none='admin.wizard.select_group'
)}}
{{/if}}
</div> </div>

Datei anzeigen

@ -9,14 +9,12 @@
options=options}} options=options}}
</div> </div>
{{#if hasConnector}}
<div class="connector"> <div class="connector">
{{#if options.enableConnectors}} {{#if options.enableConnectors}}
{{combo-box {{combo-box
value=pair.connector value=pair.connector
content=connectors content=connectors}}
options=(hash
none=connectorNone
)}}
{{/if}} {{/if}}
{{#if connectorKey}} {{#if connectorKey}}
@ -25,6 +23,7 @@
</span> </span>
{{/if}} {{/if}}
</div> </div>
{{/if}}
<div class="value input-block"> <div class="value input-block">
{{wizard-custom-input-chooser {{wizard-custom-input-chooser
@ -37,6 +36,10 @@
options=options}} options=options}}
</div> </div>
{{#if showJoin}}
<div class="join-pair">&</div>
{{/if}}
{{#if showRemove}} {{#if showRemove}}
<a {{action removePair pair}} class="remove-pair">{{d-icon 'minus'}}</a> <a {{action removePair pair}} class="remove-pair">{{d-icon 'minus'}}</a>
{{/if}} {{/if}}

Datei anzeigen

@ -1,15 +1,18 @@
{{#if options.hasOutput}} {{#if options.hasOutput}}
{{#if outputPrefixKey}}
<div class="prefix"> <div class="prefix">
<span>{{i18n outputPrefixKey}}</span> {{combo-box
value=input.type
contents=inputTypes
onChange=(mut (input.prefix))}}
</div> </div>
{{/if}} {{/if}}
{{/if}}
{{#if hasPairs}}
<div class="pairs"> <div class="pairs">
{{#each input.pairs as |pair|}} {{#each input.pairs as |pair|}}
{{wizard-custom-input-pair {{wizard-custom-input-pair
pair=pair pair=pair
last=pair.last
keyPlaceholder=keyPlaceholder keyPlaceholder=keyPlaceholder
valuePlaceholder=valuePlaceholder valuePlaceholder=valuePlaceholder
userFields=userFields userFields=userFields
@ -21,14 +24,13 @@
<a {{action 'addPair'}} class="add-pair">{{d-icon 'plus'}}</a> <a {{action 'addPair'}} class="add-pair">{{d-icon 'plus'}}</a>
{{/if}} {{/if}}
</div> </div>
{{/if }}
{{#if options.hasOutput}} {{#if options.hasOutput}}
<div class="connector"> <div class="connector">
{{#if outputConnectorKey}}
<span class="output-connector"> <span class="output-connector">
{{i18n outputConnectorKey}} {{outputConnector}}
</span> </span>
{{/if}}
</div> </div>
<div class="output input-block"> <div class="output input-block">

Datei anzeigen

@ -5,8 +5,8 @@
wizardFields=wizardFields wizardFields=wizardFields
keyPlaceholder=keyPlaceholder keyPlaceholder=keyPlaceholder
valuePlaceholder=valuePlaceholder valuePlaceholder=valuePlaceholder
connectorContent=connectorContent
connectorKey=connectorKey connectorKey=connectorKey
outputConnectorKey=outputConnectorKey
options=options options=options
remove=(action 'remove')}} remove=(action 'remove')}}
{{/each}} {{/each}}

Datei anzeigen

@ -57,8 +57,8 @@
keyPlaceholder="admin.wizard.submission_key" keyPlaceholder="admin.wizard.submission_key"
options=(hash options=(hash
enableConnectors=true enableConnectors=true
allowWizardField='value' allowWizard='value'
allowUserField='value' allowUser='value'
)}} )}}
{{#if step.required_data}} {{#if step.required_data}}
<div class="required-data-message"> <div class="required-data-message">

Datei anzeigen

@ -194,12 +194,16 @@
.type-selector a { .type-selector a {
color: $primary; color: $primary;
margin-right: 10px; margin-right: 4px;
&.active { &.active {
color: $tertiary; color: $tertiary;
text-decoration: underline; text-decoration: underline;
} }
&:last-of-type {
margin-right: 0;
}
} }
.pairs { .pairs {
@ -217,13 +221,20 @@
top: 25px; top: 25px;
right: -30px; right: -30px;
} }
.join-pair {
position: absolute;
bottom: -25px;
left: 50%;
transform: translateX(-50%);
}
} }
.pair { .pair {
display: flex; display: flex;
align-items: flex-end; align-items: flex-end;
position: relative; position: relative;
margin-bottom: 5px; margin-bottom: 10px;
} }
.d-icon { .d-icon {
@ -240,8 +251,8 @@
} }
.input-block, .select-kit, input { .input-block, .select-kit, input {
width: 150px; width: 160px;
min-width: 150px; min-width: 160px;
} }
button.remove-input { button.remove-input {
@ -263,6 +274,7 @@
.output-connector { .output-connector {
margin-top: 25px; margin-top: 25px;
display: inline-block; display: inline-block;
white-space: nowrap;
} }
} }

Datei anzeigen

@ -46,10 +46,7 @@ en:
add: "Add" add: "Add"
url: "Url" url: "Url"
key: "Key" key: "Key"
or: "Or"
if: "if"
value: "Value" value: "Value"
output: "Output"
property: "Property" property: "Property"
text: "text" text: "text"
profile: "profile" profile: "profile"
@ -63,12 +60,15 @@ en:
wizard_field: "Wizard Field" wizard_field: "Wizard Field"
select_field: "Select Field" select_field: "Select Field"
select_property: "Select Property" select_property: "Select Property"
select_group: "Select Group"
profile_field: "Profile Field" profile_field: "Profile Field"
submission_key: 'submission key' submission_key: 'submission key'
param_key: 'param' param_key: 'param'
connector:
none: "op" output:
prefill: "prefill" label: "Output"
prefix: 'if'
connector: 'then'
error: error:
name_required: "Wizards must have a name." name_required: "Wizards must have a name."
@ -153,9 +153,7 @@ en:
add_to_group: add_to_group:
label: "Add to Group" label: "Add to Group"
group: "Group" group: "Group"
group_selection: "Field" output_connector: "add to"
custom_group: "Custom"
property: "Property"
route_to: route_to:
label: "Route To" label: "Route To"
url: "Url" url: "Url"