0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-25 18:50:27 +01:00
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 {
actionTypes,
generateName,
generateSelectKitContent,
selectKitContent,
profileFields
} from '../lib/wizard';
@ -18,7 +18,7 @@ export default Ember.Component.extend({
addToGroup: equal('action.type', 'add_to_group'),
routeTo: equal('action.type', 'route_to'),
disableId: not('action.isNew'),
groupPropertyTypes: generateSelectKitContent(['id', 'name']),
groupPropertyTypes: selectKitContent(['id', 'name']),
hasAdvanced: or('basicTopicFields', 'routeTo'),
@on('didInsertElement')

Datei anzeigen

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

Datei anzeigen

@ -14,10 +14,11 @@ export default Ember.Component.extend({
let map = {
text: I18n.t('admin.wizard.text'),
wizard: I18n.t('admin.wizard.label'),
user: I18n.t('users_lowercase.one'),
userField: I18n.t('users_lowercase.one'),
category: I18n.t('categories.category'),
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();
},

Datei anzeigen

@ -44,10 +44,11 @@ export default Ember.Component.extend({
showText: computed('activeType', function() { return this.showInput('text') }),
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') }),
showTag: computed('activeType', function() { return this.showInput('tag') }),
showGroup: computed('activeType', function() { return this.showInput('group') }),
showUser: computed('activeType', function() { return this.showInput('user') }),
optionEnabled(type) {
const options = this.options;
@ -64,10 +65,11 @@ export default Ember.Component.extend({
textEnabled: computed('options.textSelection', 'inputType', function() { return this.optionEnabled('textSelection') }),
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') }),
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') }),
actions: {
toggleType(type) {

Datei anzeigen

@ -20,10 +20,11 @@ export default Ember.Component.extend({
outputConnector: options.outputConnector || null,
textSelection: options.textSelection || true,
wizardSelection: options.wizardSelection || false,
userSelection: options.userSelection || 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

Datei anzeigen

@ -2,18 +2,18 @@ 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 { generateSelectKitContent } from '../lib/wizard';
import { selectKitContent } from '../lib/wizard';
export default Ember.Controller.extend({
queryParams: ['refresh_list'],
loadingSubscriptions: false,
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'),
showRedirectUri: Ember.computed.and('threeLeggedOauth', 'api.name'),
responseIcon: null,
contentTypes: generateSelectKitContent(['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]),
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')
authDisabled(saveDisabled, authType, authUrl, tokenUrl, clientId, clientSecret, threeLeggedOauth) {
@ -27,7 +27,7 @@ export default Ember.Controller.extend({
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'),
@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';
function present(val) {
@ -48,7 +53,7 @@ function buildMappedJson(inputs) {
if (present(inpt.output)) {
input.output = inpt.output;
input.output_type = inpt.output_type;
input.output_type = snakeCase(inpt.output_type);
input.connector = inpt.connector;
}
@ -61,9 +66,9 @@ function buildMappedJson(inputs) {
let pairParams = {
index: pr.index,
key: pr.key,
key_type: pr.key_type,
key_type: snakeCase(pr.key_type),
value: pr.value,
value_type: pr.value_type,
value_type: snakeCase(pr.value_type),
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) {
let params = {
isNew: false
@ -163,7 +172,12 @@ function buildObject(json, type) {
let pairCount = inputJson.pairs.length;
inputJson.pairs.forEach(pairJson => {
let pair = pairJson;
let pair = {};
Object.keys(pairJson).forEach(pairKey => {
pair[pairKey] = mappedProperty(pairKey, pairJson[pairKey]);
});
pair.pairCount = pairCount;
pairs.push(
@ -173,7 +187,7 @@ function buildObject(json, type) {
input.pairs = pairs;
} else {
input[inputKey] = inputJson[inputKey];
input[inputKey] = mappedProperty(inputKey, inputJson[inputKey]);
}
});

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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