1
0
Fork 0
Dieser Commit ist enthalten in:
Angus McLeod 2020-04-02 19:21:03 +11:00
Ursprung 87a53a8c85
Commit 0d94c1d8c6
17 geänderte Dateien mit 111 neuen und 63 gelöschten Zeilen

Datei anzeigen

@ -3,7 +3,7 @@ import { equal, not, empty, or } from "@ember/object/computed";
import { import {
actionTypes, actionTypes,
generateName, generateName,
generateSelectKitContent, selectKitContent,
profileFields profileFields
} from '../lib/wizard'; } from '../lib/wizard';
@ -18,7 +18,7 @@ export default Ember.Component.extend({
addToGroup: equal('action.type', 'add_to_group'), addToGroup: equal('action.type', 'add_to_group'),
routeTo: equal('action.type', 'route_to'), routeTo: equal('action.type', 'route_to'),
disableId: not('action.isNew'), disableId: not('action.isNew'),
groupPropertyTypes: generateSelectKitContent(['id', 'name']), groupPropertyTypes: selectKitContent(['id', 'name']),
hasAdvanced: or('basicTopicFields', 'routeTo'), hasAdvanced: or('basicTopicFields', 'routeTo'),
@on('didInsertElement') @on('didInsertElement')

Datei anzeigen

@ -1,6 +1,6 @@
import { default as discourseComputed, observes, on } from 'discourse-common/utils/decorators'; import { default as discourseComputed, observes, on } from 'discourse-common/utils/decorators';
import { equal, not, or } from "@ember/object/computed"; import { equal, not, or } from "@ember/object/computed";
import { generateSelectKitContent } from '../lib/wizard'; import { selectKitContent } from '../lib/wizard';
export default Ember.Component.extend({ export default Ember.Component.extend({
classNames: 'wizard-custom-field', classNames: 'wizard-custom-field',
@ -10,10 +10,10 @@ export default Ember.Component.extend({
isGroup: equal('field.type', 'group'), isGroup: equal('field.type', 'group'),
isTag: equal('field.type', 'tag'), isTag: equal('field.type', 'tag'),
disableId: not('field.isNew'), disableId: not('field.isNew'),
choicesTypes: generateSelectKitContent(['translation', 'custom']), choicesTypes: selectKitContent(['translation', 'custom']),
choicesTranslation: equal('field.choices_type', 'translation'), choicesTranslation: equal('field.choices_type', 'translation'),
choicesCustom: equal('field.choices_type', 'custom'), choicesCustom: equal('field.choices_type', 'custom'),
categoryPropertyTypes: generateSelectKitContent(['id', 'slug']), categoryPropertyTypes: selectKitContent(['id', 'slug']),
prefillEnabled: or('isCategory', 'isTag', 'isGroup'), prefillEnabled: or('isCategory', 'isTag', 'isGroup'),
contentEnabled: or('isCategory', 'isTag', 'isGroup'), contentEnabled: or('isCategory', 'isTag', 'isGroup'),
hasAdvanced: or('isCategory', 'isTag', 'isGroup'), hasAdvanced: or('isCategory', 'isTag', 'isGroup'),
@ -40,7 +40,7 @@ export default Ember.Component.extend({
hasOutput: true, hasOutput: true,
textSelection: 'key,value', textSelection: 'key,value',
wizardSelection: true, wizardSelection: true,
userSelection: 'key,value' userFieldSelection: 'key,value'
} }
options[`${fieldType}Selection`] = 'output'; options[`${fieldType}Selection`] = 'output';
@ -56,7 +56,7 @@ export default Ember.Component.extend({
let options = { let options = {
hasOutput: true, hasOutput: true,
wizardSelection: 'key,value', wizardSelection: 'key,value',
userSelection: 'key,value', userFieldSelection: 'key,value',
textSelection: 'key,value' textSelection: 'key,value'
} }

Datei anzeigen

@ -14,10 +14,11 @@ export default Ember.Component.extend({
let map = { let map = {
text: I18n.t('admin.wizard.text'), text: I18n.t('admin.wizard.text'),
wizard: I18n.t('admin.wizard.label'), wizard: I18n.t('admin.wizard.label'),
user: I18n.t('users_lowercase.one'), userField: I18n.t('users_lowercase.one'),
category: I18n.t('categories.category'), category: I18n.t('categories.category'),
tag: I18n.t('tagging.tags'), tag: I18n.t('tagging.tags'),
group: I18n.t('groups.title.one') group: I18n.t('groups.title.one'),
user: I18n.t('users_lowercase.other')
}; };
return map[type].toLowerCase(); return map[type].toLowerCase();
}, },

Datei anzeigen

@ -44,10 +44,11 @@ export default Ember.Component.extend({
showText: computed('activeType', function() { return this.showInput('text') }), showText: computed('activeType', function() { return this.showInput('text') }),
showWizard: computed('activeType', function() { return this.showInput('wizard') }), showWizard: computed('activeType', function() { return this.showInput('wizard') }),
showUser: computed('activeType', function() { return this.showInput('user') }), showUserField: computed('activeType', function() { return this.showInput('userField') }),
showCategory: computed('activeType', function() { return this.showInput('category') }), showCategory: computed('activeType', function() { return this.showInput('category') }),
showTag: computed('activeType', function() { return this.showInput('tag') }), showTag: computed('activeType', function() { return this.showInput('tag') }),
showGroup: computed('activeType', function() { return this.showInput('group') }), showGroup: computed('activeType', function() { return this.showInput('group') }),
showUser: computed('activeType', function() { return this.showInput('user') }),
optionEnabled(type) { optionEnabled(type) {
const options = this.options; const options = this.options;
@ -64,10 +65,11 @@ export default Ember.Component.extend({
textEnabled: computed('options.textSelection', 'inputType', function() { return this.optionEnabled('textSelection') }), textEnabled: computed('options.textSelection', 'inputType', function() { return this.optionEnabled('textSelection') }),
wizardEnabled: computed('options.wizardSelection', 'inputType', function() { return this.optionEnabled('wizardSelection') }), wizardEnabled: computed('options.wizardSelection', 'inputType', function() { return this.optionEnabled('wizardSelection') }),
userEnabled: computed('options.userSelection', 'inputType', function() { return this.optionEnabled('userSelection') }), userFieldEnabled: computed('options.userFieldSelection', 'inputType', function() { return this.optionEnabled('userFieldSelection') }),
categoryEnabled: computed('options.categorySelection', 'inputType', function() { return this.optionEnabled('categorySelection') }), categoryEnabled: computed('options.categorySelection', 'inputType', function() { return this.optionEnabled('categorySelection') }),
tagEnabled: computed('options.tagSelection', 'inputType', function() { return this.optionEnabled('tagSelection') }), tagEnabled: computed('options.tagSelection', 'inputType', function() { return this.optionEnabled('tagSelection') }),
groupEnabled: computed('options.groupSelection', 'inputType', function() { return this.optionEnabled('groupSelection') }), groupEnabled: computed('options.groupSelection', 'inputType', function() { return this.optionEnabled('groupSelection') }),
userEnabled: computed('options.userSelection', 'inputType', function() { return this.optionEnabled('userSelection') }),
actions: { actions: {
toggleType(type) { toggleType(type) {

Datei anzeigen

@ -20,10 +20,11 @@ export default Ember.Component.extend({
outputConnector: options.outputConnector || null, outputConnector: options.outputConnector || null,
textSelection: options.textSelection || true, textSelection: options.textSelection || true,
wizardSelection: options.wizardSelection || false, wizardSelection: options.wizardSelection || false,
userSelection: options.userSelection || false, userFieldSelection: options.userFieldSelection || false,
categorySelection: options.categorySelection || false, categorySelection: options.categorySelection || false,
tagSelection: options.tagSelection || false, tagSelection: options.tagSelection || false,
groupSelection: options.groupSelection || false, groupSelection: options.groupSelection || false,
userSelection: options.userSelection || false,
keyDefaultSelection: options.keyDefaultSelection || null, keyDefaultSelection: options.keyDefaultSelection || null,
valueDefaultSelection: options.valueDefaultSelection || null, valueDefaultSelection: options.valueDefaultSelection || null,
outputDefaultSelection: options.outputDefaultSelection || null outputDefaultSelection: options.outputDefaultSelection || null

Datei anzeigen

@ -2,18 +2,18 @@ import { ajax } from 'discourse/lib/ajax';
import { popupAjaxError } from 'discourse/lib/ajax-error'; import { popupAjaxError } from 'discourse/lib/ajax-error';
import CustomWizardApi from '../models/custom-wizard-api'; import CustomWizardApi from '../models/custom-wizard-api';
import { default as computed } from 'discourse-common/utils/decorators'; import { default as computed } from 'discourse-common/utils/decorators';
import { generateSelectKitContent } from '../lib/wizard'; import { selectKitContent } from '../lib/wizard';
export default Ember.Controller.extend({ export default Ember.Controller.extend({
queryParams: ['refresh_list'], queryParams: ['refresh_list'],
loadingSubscriptions: false, loadingSubscriptions: false,
notAuthorized: Ember.computed.not('api.authorized'), notAuthorized: Ember.computed.not('api.authorized'),
endpointMethods: generateSelectKitContent(['GET', 'PUT', 'POST', 'PATCH', 'DELETE']), endpointMethods: selectKitContent(['GET', 'PUT', 'POST', 'PATCH', 'DELETE']),
showRemove: Ember.computed.not('isNew'), showRemove: Ember.computed.not('isNew'),
showRedirectUri: Ember.computed.and('threeLeggedOauth', 'api.name'), showRedirectUri: Ember.computed.and('threeLeggedOauth', 'api.name'),
responseIcon: null, responseIcon: null,
contentTypes: generateSelectKitContent(['application/json', 'application/x-www-form-urlencoded']), contentTypes: selectKitContent(['application/json', 'application/x-www-form-urlencoded']),
successCodes: generateSelectKitContent([100, 101, 102, 200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 300, 301, 302, 303, 303, 304, 305, 306, 307, 308]), 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') @computed('saveDisabled', 'api.authType', 'api.authUrl', 'api.tokenUrl', 'api.clientId', 'api.clientSecret', 'threeLeggedOauth')
authDisabled(saveDisabled, authType, authUrl, tokenUrl, clientId, clientSecret, threeLeggedOauth) { authDisabled(saveDisabled, authType, authUrl, tokenUrl, clientId, clientSecret, threeLeggedOauth) {
@ -27,7 +27,7 @@ export default Ember.Controller.extend({
return !name || !authType; return !name || !authType;
}, },
authorizationTypes: generateSelectKitContent(['none', 'basic', 'oauth_2', 'oauth_3']), authorizationTypes: selectKitContent(['none', 'basic', 'oauth_2', 'oauth_3']),
isBasicAuth: Ember.computed.equal('api.authType', 'basic'), isBasicAuth: Ember.computed.equal('api.authType', 'basic'),
@computed('api.authType') @computed('api.authType')

Datei anzeigen

@ -1,4 +1,9 @@
import { properties, mappedProperties } from '../lib/wizard'; import {
properties,
mappedProperties,
camelCase,
snakeCase
} from '../lib/wizard';
import EmberObject from '@ember/object'; import EmberObject from '@ember/object';
function present(val) { function present(val) {
@ -48,7 +53,7 @@ function buildMappedJson(inputs) {
if (present(inpt.output)) { if (present(inpt.output)) {
input.output = inpt.output; input.output = inpt.output;
input.output_type = inpt.output_type; input.output_type = snakeCase(inpt.output_type);
input.connector = inpt.connector; input.connector = inpt.connector;
} }
@ -61,9 +66,9 @@ function buildMappedJson(inputs) {
let pairParams = { let pairParams = {
index: pr.index, index: pr.index,
key: pr.key, key: pr.key,
key_type: pr.key_type, key_type: snakeCase(pr.key_type),
value: pr.value, value: pr.value,
value_type: pr.value_type, value_type: snakeCase(pr.value_type),
connector: pr.connector connector: pr.connector
} }
@ -145,6 +150,10 @@ function buildStepJson(object) {
}; };
} }
function mappedProperty(property, value) {
return property.indexOf('_type') > -1 ? camelCase(value) : value;
}
function buildObject(json, type) { function buildObject(json, type) {
let params = { let params = {
isNew: false isNew: false
@ -163,7 +172,12 @@ function buildObject(json, type) {
let pairCount = inputJson.pairs.length; let pairCount = inputJson.pairs.length;
inputJson.pairs.forEach(pairJson => { inputJson.pairs.forEach(pairJson => {
let pair = pairJson; let pair = {};
Object.keys(pairJson).forEach(pairKey => {
pair[pairKey] = mappedProperty(pairKey, pairJson[pairKey]);
});
pair.pairCount = pairCount; pair.pairCount = pairCount;
pairs.push( pairs.push(
@ -173,7 +187,7 @@ function buildObject(json, type) {
input.pairs = pairs; input.pairs = pairs;
} else { } else {
input[inputKey] = inputJson[inputKey]; input[inputKey] = mappedProperty(inputKey, inputJson[inputKey]);
} }
}); });

Datei anzeigen

@ -74,10 +74,11 @@ function connectorContent(connectorType, inputType, opts) {
const selectionTypes = [ const selectionTypes = [
'text', 'text',
'wizard', 'wizard',
'user', 'userField',
'group', 'group',
'category', 'category',
'tag' 'tag',
'user'
] ]
function defaultSelectionType(inputType, options = {}) { function defaultSelectionType(inputType, options = {}) {

Datei anzeigen

@ -1,17 +1,33 @@
function generateSelectKitContent(content) { function selectKitContent(content) {
return content.map(i => ({id: i, name: i})) return content.map(i => ({id: i, name: i}))
} }
function generateName(id) { function generateName(id) {
return id.replace(/[_\-]+/g, ' ') return sentenceCase(id);
}
function generateId(name) {
return snakeCase(name);
}
function sentenceCase(string) {
return string.replace(/[_\-]+/g, ' ')
.toLowerCase() .toLowerCase()
.replace(/(^\w|\b\w)/g, (m) => m.toUpperCase()) .replace(/(^\w|\b\w)/g, (m) => m.toUpperCase())
} }
function generateId(name) { function snakeCase(string) {
return name.replace(/[^\w ]/g, '') return string.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
.replace(/ /g,"_") .map(x => x.toLowerCase())
.toLowerCase(); .join('_')
}
function camelCase(string) {
return string.replace(/([-_][a-z])/ig, ($1) => {
return $1.toUpperCase()
.replace('-', '')
.replace('_', '');
});
} }
const profileFields = [ const profileFields = [
@ -137,9 +153,11 @@ const actionTypes = [
]; ];
export { export {
generateSelectKitContent, selectKitContent,
generateName, generateName,
generateId, generateId,
camelCase,
snakeCase,
properties, properties,
wizardProperties, wizardProperties,
mappedProperties, mappedProperties,

Datei anzeigen

@ -1,7 +1,7 @@
import CustomWizard from '../models/custom-wizard'; import CustomWizard from '../models/custom-wizard';
import { ajax } from 'discourse/lib/ajax'; import { ajax } from 'discourse/lib/ajax';
import { import {
generateSelectKitContent, selectKitContent,
profileFields, profileFields,
generateName generateName
} from '../lib/wizard'; } from '../lib/wizard';
@ -52,7 +52,7 @@ export default DiscourseRoute.extend({
.then((result) => { .then((result) => {
model.set( model.set(
'fieldTypes', 'fieldTypes',
generateSelectKitContent([...result.types]) selectKitContent([...result.types])
) )
}); });
}, },

Datei anzeigen

@ -26,7 +26,7 @@
options=(hash options=(hash
hasOutput=true hasOutput=true
wizardSelection=true wizardSelection=true
userSelection='key,value' userFieldSelection='key,value'
)}} )}}
</div> </div>
</div> </div>
@ -82,7 +82,7 @@
hasOutput=true hasOutput=true
textSelection='key,value' textSelection='key,value'
wizardSelection=true wizardSelection=true
userSelection='key,value' userFieldSelection='key,value'
categorySelection='output' categorySelection='output'
outputDefaultSelection='category' outputDefaultSelection='category'
)}} )}}
@ -101,7 +101,7 @@
hasOutput=true hasOutput=true
tagSelection='output' tagSelection='output'
wizardSelection=true wizardSelection=true
userSelection='key,value' userFieldSelection='key,value'
)}} )}}
</div> </div>
</div> </div>
@ -120,8 +120,10 @@
hasOutput=true hasOutput=true
textSelection='value,output' textSelection='value,output'
wizardSelection=true wizardSelection=true
userSelection='key,value' userFieldSelection='key,value'
groupSelection='key,value' groupSelection='key,value'
userSelection='output'
outputDefaultSelection='user'
)}} )}}
</div> </div>
</div> </div>
@ -138,9 +140,9 @@
keyPlaceholder='admin.wizard.action.update_profile.key' keyPlaceholder='admin.wizard.action.update_profile.key'
options=(hash options=(hash
pairConnector='set' pairConnector='set'
userSelection='key' userFieldSelection='key'
wizardSelection='value' wizardSelection='value'
keyDefaultSelection='user' keyDefaultSelection='userField'
)}} )}}
</div> </div>
{{/if}} {{/if}}
@ -209,7 +211,7 @@
hasOutput=true hasOutput=true
textSelection='value,output' textSelection='value,output'
wizardSelection='key,value,assignment' wizardSelection='key,value,assignment'
userSelection='key,value,assignment' userFieldSelection='key,value,assignment'
groupSelection='value,output' groupSelection='value,output'
outputDefaultSelection='group' outputDefaultSelection='group'
)}} )}}
@ -248,7 +250,7 @@
options=(hash options=(hash
pairConnector='set' pairConnector='set'
wizardSelection='value' wizardSelection='value'
userSelection='value' userFieldSelection='value'
)}} )}}
</div> </div>
</div> </div>
@ -266,7 +268,7 @@
options=(hash options=(hash
textSelection='value' textSelection='value'
wizardSelection=true wizardSelection=true
userSelection=true userFieldSelection=true
groupSelection=true groupSelection=true
)}} )}}
</div> </div>

Datei anzeigen

@ -61,7 +61,7 @@
keyPlaceholder="admin.wizard.submission_key" keyPlaceholder="admin.wizard.submission_key"
options=(hash options=(hash
wizardSelection='value' wizardSelection='value'
userSelection='value' userFieldSelection='value'
)}} )}}
{{#if step.required_data}} {{#if step.required_data}}
<div class="required-data-message"> <div class="required-data-message">

Datei anzeigen

@ -13,10 +13,10 @@
toggle=(action 'toggleType')}} toggle=(action 'toggleType')}}
{{/if}} {{/if}}
{{#if userEnabled}} {{#if userFieldEnabled}}
{{wizard-mapper-selector-type {{wizard-mapper-selector-type
activeType=activeType activeType=activeType
type='user' type='userField'
toggle=(action 'toggleType')}} toggle=(action 'toggleType')}}
{{/if}} {{/if}}
@ -40,6 +40,13 @@
type='group' type='group'
toggle=(action 'toggleType')}} toggle=(action 'toggleType')}}
{{/if}} {{/if}}
{{#if userEnabled}}
{{wizard-mapper-selector-type
activeType=activeType
type='user'
toggle=(action 'toggleType')}}
{{/if}}
</div> </div>
<div class="input"> <div class="input">
@ -60,7 +67,7 @@
)}} )}}
{{/if}} {{/if}}
{{#if showUser}} {{#if showUserField}}
{{combo-box {{combo-box
value=value value=value
content=userFields content=userFields
@ -95,4 +102,13 @@
none='admin.wizard.select_group' none='admin.wizard.select_group'
)}} )}}
{{/if}} {{/if}}
{{#if showUser}}
{{user-selector
topicId=topicId
includeMessageableGroups='true'
placeholderKey="composer.users_placeholder"
usernames=value
autocomplete="discourse"}}
{{/if}}
</div> </div>

Datei anzeigen

@ -82,8 +82,8 @@
max-width: 150px; max-width: 150px;
min-width: 150px; min-width: 150px;
input, .select-kit { input, .select-kit, .ac-wrap, .autocomplete.ac-user {
width: 150px; width: 150px !important;
} }
.type-selector { .type-selector {

Datei anzeigen

@ -22,14 +22,10 @@ class CustomWizard::Action
def create_topic def create_topic
params = basic_topic_params params = basic_topic_params
byebug
if params[:title] && params[:raw] if params[:title] && params[:raw]
params[:category] = action_category params[:category] = action_category
params[:tags] = action_tags params[:tags] = action_tags
byebug
creator = PostCreator.new(user, params) creator = PostCreator.new(user, params)
post = creator.create post = creator.create
@ -48,10 +44,7 @@ class CustomWizard::Action
params[:target_usernames] = CustomWizard::Mapper.new( params[:target_usernames] = CustomWizard::Mapper.new(
inputs: action['recipient'], inputs: action['recipient'],
data: data, data: data,
user: user, user: user
opts: {
multiple: true
}
).output ).output
if params[:title] && params[:raw] if params[:title] && params[:raw]

Datei anzeigen

@ -69,7 +69,7 @@ class CustomWizard::Mapper
end end
def map_field(value, type) def map_field(value, type)
method = "#{type}_field" method = "map_#{type}"
if self.respond_to?(method) if self.respond_to?(method)
self.send(method, value) self.send(method, value)
@ -78,11 +78,11 @@ class CustomWizard::Mapper
end end
end end
def wizard_field(value) def map_wizard(value)
data && !data.key?("submitted_at") && data[value] data && !data.key?("submitted_at") && data[value]
end end
def user_field(value) def map_user_field(value)
if value.include?('user_field_') if value.include?('user_field_')
UserCustomField.where(user_id: user.id, name: value).pluck(:value).first UserCustomField.where(user_id: user.id, name: value).pluck(:value).first
elsif PROFILE_FIELDS.include?(value) elsif PROFILE_FIELDS.include?(value)