0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-26 19:10:29 +01:00

Merge pull request #28 from paviliondev/select_kit_2

Update to select-kit-2
Dieser Commit ist enthalten in:
Angus McLeod 2020-02-05 19:13:22 +11:00 committet von GitHub
Commit dd898a9921
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
17 geänderte Dateien mit 127 neuen und 87 gelöschten Zeilen

Datei anzeigen

@ -1,4 +1,5 @@
import { default as computed, observes, on } from 'ember-addons/ember-computed-decorators'; import { default as computed, observes, on } from 'ember-addons/ember-computed-decorators';
import { generateSelectKitContent } from '../lib/custom-wizard';
export default Ember.Component.extend({ export default Ember.Component.extend({
classNames: 'wizard-custom-field', classNames: 'wizard-custom-field',
@ -6,11 +7,11 @@ export default Ember.Component.extend({
isUpload: Ember.computed.equal('field.type', 'upload'), isUpload: Ember.computed.equal('field.type', 'upload'),
isCategory: Ember.computed.equal('field.type', 'category'), isCategory: Ember.computed.equal('field.type', 'category'),
disableId: Ember.computed.not('field.isNew'), disableId: Ember.computed.not('field.isNew'),
choicesTypes: ['translation', 'preset', 'custom'], choicesTypes: generateSelectKitContent(['translation', 'preset', 'custom']),
choicesTranslation: Ember.computed.equal('field.choices_type', 'translation'), choicesTranslation: Ember.computed.equal('field.choices_type', 'translation'),
choicesPreset: Ember.computed.equal('field.choices_type', 'preset'), choicesPreset: Ember.computed.equal('field.choices_type', 'preset'),
choicesCustom: Ember.computed.equal('field.choices_type', 'custom'), choicesCustom: Ember.computed.equal('field.choices_type', 'custom'),
categoryPropertyTypes: ['id', 'slug'], categoryPropertyTypes: generateSelectKitContent(['id', 'slug']),
@computed('field.type') @computed('field.type')
isInput: (type) => type === 'text' || type === 'textarea', isInput: (type) => type === 'text' || type === 'textarea',

Datei anzeigen

@ -2,17 +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 'ember-addons/ember-computed-decorators'; import { default as computed } from 'ember-addons/ember-computed-decorators';
import { generateSelectKitContent } from '../lib/custom-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: ['GET', 'PUT', 'POST', 'PATCH', 'DELETE'], endpointMethods: generateSelectKitContent(['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: ['application/json', 'application/x-www-form-urlencoded'], contentTypes: generateSelectKitContent(['application/json', 'application/x-www-form-urlencoded']),
successCodes: [100, 101, 102, 200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 300, 301, 302, 303, 303, 304, 305, 306, 307, 308], 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]),
@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) {
@ -26,7 +27,7 @@ export default Ember.Controller.extend({
return !name || !authType; return !name || !authType;
}, },
authorizationTypes: ['none', 'basic', 'oauth_2', 'oauth_3'], authorizationTypes: generateSelectKitContent(['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

@ -0,0 +1,5 @@
function generateSelectKitContent(content) {
return content.map(i => ({id: i, name: i}))
}
export { generateSelectKitContent };

Datei anzeigen

@ -1,5 +1,6 @@
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 { generateSelectKitContent } from '../lib/custom-wizard';
export default Discourse.Route.extend({ export default Discourse.Route.extend({
beforeModel() { beforeModel() {
@ -40,7 +41,12 @@ export default Discourse.Route.extend({
_getFieldTypes(model) { _getFieldTypes(model) {
return ajax('/admin/wizards/field-types') return ajax('/admin/wizards/field-types')
.then((result) => model.set('fieldTypes', result.types)); .then((result) => {
model.set(
'fieldTypes',
generateSelectKitContent([...result.types])
)
});
}, },
_getThemes(model) { _getThemes(model) {

Datei anzeigen

@ -107,7 +107,11 @@
<h3>{{i18n 'admin.wizard.theme_id'}}</h3> <h3>{{i18n 'admin.wizard.theme_id'}}</h3>
</div> </div>
<div class="setting-value"> <div class="setting-value">
{{combo-box content=model.themes valueAttribute='id' value=model.theme_id none='admin.wizard.no_theme'}} {{combo-box
content=model.themes
valueProperty='id'
value=model.theme_id
none='admin.wizard.no_theme'}}
</div> </div>
</div> </div>

Datei anzeigen

@ -89,7 +89,10 @@
<div class="control-group auth-type"> <div class="control-group auth-type">
<label>{{i18n 'admin.wizard.api.auth.type'}}</label> <label>{{i18n 'admin.wizard.api.auth.type'}}</label>
<div class="controls"> <div class="controls">
{{combo-box value=api.authType content=authorizationTypes none='admin.wizard.api.auth.type_none'}} {{combo-box
value=api.authType
content=authorizationTypes
none='admin.wizard.api.auth.type_none'}}
</div> </div>
</div> </div>
@ -240,15 +243,18 @@
class='remove-endpoint'}} class='remove-endpoint'}}
</div> </div>
<div class="bottom"> <div class="bottom">
{{combo-box content=endpointMethods {{combo-box
value=endpoint.method content=endpointMethods
none="admin.wizard.api.endpoint.method"}} value=endpoint.method
{{combo-box content=contentTypes none="admin.wizard.api.endpoint.method"}}
value=endpoint.content_type {{combo-box
none="admin.wizard.api.endpoint.content_type"}} content=contentTypes
{{multi-select content=successCodes value=endpoint.content_type
values=endpoint.success_codes none="admin.wizard.api.endpoint.content_type"}}
none="admin.wizard.api.endpoint.success_codes"}} {{multi-select
content=successCodes
values=endpoint.success_codes
none="admin.wizard.api.endpoint.success_codes"}}
</div> </div>
</div> </div>
</div> </div>

Datei anzeigen

@ -12,7 +12,10 @@
<h3>{{i18n "admin.wizard.type"}}</h3> <h3>{{i18n "admin.wizard.type"}}</h3>
</div> </div>
<div class="setting-value"> <div class="setting-value">
{{combo-box value=action.type content=types none="admin.wizard.field.type"}} {{combo-box
value=action.type
content=types
none="admin.wizard.field.type"}}
</div> </div>
</div> </div>
@ -22,11 +25,12 @@
<h3>{{i18n "admin.wizard.action.title"}}</h3> <h3>{{i18n "admin.wizard.action.title"}}</h3>
</div> </div>
<div class="setting-value"> <div class="setting-value">
{{combo-box value=action.title {{combo-box
content=availableFields value=action.title
nameProperty="label" content=availableFields
none='admin.wizard.select_field' nameProperty="label"
isDisabled=action.custom_title_enabled}} isDisabled=action.custom_title_enabled
none='admin.wizard.select_field'}}
<div class="setting-gutter"> <div class="setting-gutter">
{{input type='checkbox' checked=action.custom_title_enabled}} {{input type='checkbox' checked=action.custom_title_enabled}}
<span>{{i18n 'admin.wizard.action.custom_title'}}</span> <span>{{i18n 'admin.wizard.action.custom_title'}}</span>
@ -42,10 +46,12 @@
<h3>{{i18n "admin.wizard.action.post"}}</h3> <h3>{{i18n "admin.wizard.action.post"}}</h3>
</div> </div>
<div class="setting-value"> <div class="setting-value">
{{combo-box value=action.post content=availableFields {{combo-box
nameProperty='label' value=action.post
none='admin.wizard.select_field' content=availableFields
isDisabled=action.post_builder}} nameProperty='label'
isDisabled=action.post_builder
none='admin.wizard.select_field'}}
<div class="setting-gutter"> <div class="setting-gutter">
{{input type='checkbox' checked=action.post_builder}} {{input type='checkbox' checked=action.post_builder}}
<span>{{i18n 'admin.wizard.action.post_builder.checkbox'}}</span> <span>{{i18n 'admin.wizard.action.post_builder.checkbox'}}</span>
@ -77,7 +83,9 @@
<h3>{{i18n "admin.wizard.action.create_topic.category"}}</h3> <h3>{{i18n "admin.wizard.action.create_topic.category"}}</h3>
</div> </div>
<div class="setting-value"> <div class="setting-value">
{{category-chooser value=action.category_id isDisabled=action.custom_category_enabled}} {{category-chooser
value=action.category_id
isDisabled=action.custom_category_enabled}}
<div class="setting-gutter"> <div class="setting-gutter">
{{input type='checkbox' checked=action.custom_category_enabled}} {{input type='checkbox' checked=action.custom_category_enabled}}
<span>{{i18n 'admin.wizard.action.custom_category.label'}}</span> <span>{{i18n 'admin.wizard.action.custom_category.label'}}</span>
@ -87,10 +95,11 @@
{{input type='checkbox' checked=action.custom_category_wizard_field}} {{input type='checkbox' checked=action.custom_category_wizard_field}}
<span>{{i18n 'admin.wizard.action.custom_category.wizard_field'}}</span> <span>{{i18n 'admin.wizard.action.custom_category.wizard_field'}}</span>
{{#if action.custom_category_wizard_field}} {{#if action.custom_category_wizard_field}}
{{combo-box value=action.category_id {{combo-box
content=categoryFields value=action.category_id
nameProperty="label" content=categoryFields
none='admin.wizard.select_field'}} nameProperty="label"
none='admin.wizard.select_field'}}
{{/if}} {{/if}}
</div> </div>
<div> <div>
@ -111,19 +120,21 @@
<h3>{{i18n "admin.wizard.action.create_topic.tags"}}</h3> <h3>{{i18n "admin.wizard.action.create_topic.tags"}}</h3>
</div> </div>
<div class="setting-value"> <div class="setting-value">
{{tag-chooser tags=action.tags {{tag-chooser
filterable=true tags=action.tags
allowCreate=true filterable=true
isDisabled=action.custom_tag_enabled}} allowCreate=true
isDisabled=action.custom_tag_enabled}}
<div class="setting-gutter"> <div class="setting-gutter">
{{input type='checkbox' checked=action.custom_tag_enabled}} {{input type='checkbox' checked=action.custom_tag_enabled}}
<span>{{i18n 'admin.wizard.action.custom_tag.label'}}</span> <span>{{i18n 'admin.wizard.action.custom_tag.label'}}</span>
{{#if action.custom_tag_enabled}} {{#if action.custom_tag_enabled}}
<div class="custom-tag"> <div class="custom-tag">
{{combo-box value=action.custom_tag_field {{combo-box
content=tagFields value=action.custom_tag_field
nameProperty="label" content=tagFields
none='admin.wizard.select_field'}} nameProperty="label"
none='admin.wizard.select_field'}}
</div> </div>
{{/if}} {{/if}}
</div> </div>
@ -160,10 +171,11 @@
<h3>{{i18n 'admin.wizard.required'}}</h3> <h3>{{i18n 'admin.wizard.required'}}</h3>
</div> </div>
<div class="setting-value"> <div class="setting-value">
{{combo-box content=availableFields {{combo-box
nameProperty='label' value=action.required
none='admin.wizard.select_field' content=availableFields
value=action.required}} nameProperty='label'
none='admin.wizard.select_field'}}
</div> </div>
</div> </div>
<div class="setting"> <div class="setting">
@ -204,10 +216,11 @@
<h3>{{i18n "admin.wizard.action.send_to_api.api"}}</h3> <h3>{{i18n "admin.wizard.action.send_to_api.api"}}</h3>
</div> </div>
<div class="setting-value"> <div class="setting-value">
{{combo-box value=action.api {{combo-box
content=availableApis value=action.api
none='admin.wizard.action.send_to_api.select_an_api' content=availableApis
isDisabled=action.custom_title_enabled}} isDisabled=action.custom_title_enabled
none='admin.wizard.action.send_to_api.select_an_api'}}
</div> </div>
</div> </div>
@ -216,10 +229,11 @@
<h3>{{i18n "admin.wizard.action.send_to_api.endpoint"}}</h3> <h3>{{i18n "admin.wizard.action.send_to_api.endpoint"}}</h3>
</div> </div>
<div class="setting-value"> <div class="setting-value">
{{combo-box value=action.api_endpoint {{combo-box
content=availableEndpoints value=action.api_endpoint
none='admin.wizard.action.send_to_api.select_an_endpoint' content=availableEndpoints
isDisabled=apiEmpty}} isDisabled=apiEmpty
none='admin.wizard.action.send_to_api.select_an_endpoint'}}
</div> </div>
</div> </div>
@ -242,11 +256,12 @@
<h3>{{i18n "admin.wizard.action.add_to_group.group_selection"}}</h3> <h3>{{i18n "admin.wizard.action.add_to_group.group_selection"}}</h3>
</div> </div>
<div class="setting-value"> <div class="setting-value">
{{combo-box value=action.group_id {{combo-box
content=availableFields value=action.group_id
nameProperty="label" content=availableFields
none='admin.wizard.select_field' isDisabled=action.custom_group_enabled
isDisabled=action.custom_group_enabled}} nameProperty="label"
none='admin.wizard.select_field'}}
<div class="setting-gutter"> <div class="setting-gutter">
{{input type='checkbox' checked=action.custom_group_enabled}} {{input type='checkbox' checked=action.custom_group_enabled}}
<span>{{i18n 'admin.wizard.action.add_to_group.custom_group'}}</span> <span>{{i18n 'admin.wizard.action.add_to_group.custom_group'}}</span>

Datei anzeigen

@ -48,7 +48,10 @@
<h3>{{i18n 'admin.wizard.type'}}</h3> <h3>{{i18n 'admin.wizard.type'}}</h3>
</div> </div>
<div class="setting-value"> <div class="setting-value">
{{combo-box value=field.type content=types none="admin.wizard.field.type"}} {{combo-box
value=field.type
content=types
none="admin.wizard.field.type"}}
</div> </div>
</div> </div>
@ -79,7 +82,10 @@
{{i18n 'admin.wizard.field.choices_label'}} {{i18n 'admin.wizard.field.choices_label'}}
</div> </div>
{{combo-box value=field.choices_type content=choicesTypes none="admin.wizard.field.choices_type"}} {{combo-box
value=field.choices_type
content=choicesTypes
none="admin.wizard.field.choices_type"}}
{{#if choicesTranslation}} {{#if choicesTranslation}}
<div class="wizard-header small"> <div class="wizard-header small">
@ -92,7 +98,10 @@
<div class="wizard-header small"> <div class="wizard-header small">
{{i18n 'admin.wizard.field.choices_preset.label'}} {{i18n 'admin.wizard.field.choices_preset.label'}}
</div> </div>
{{combo-box value=field.choices_preset content=presetChoices none='admin.wizard.none'}} {{combo-box
value=field.choices_preset
content=presetChoices
none='admin.wizard.none'}}
<div class="wizard-header small"> <div class="wizard-header small">
{{i18n 'admin.wizard.field.choices_preset.filter'}} {{i18n 'admin.wizard.field.choices_preset.filter'}}
</div> </div>
@ -141,7 +150,9 @@
<h3>{{i18n 'admin.wizard.field.property'}}</h3> <h3>{{i18n 'admin.wizard.field.property'}}</h3>
</div> </div>
<div class="setting-value"> <div class="setting-value">
{{combo-box content=categoryPropertyTypes value=field.property}} {{combo-box
content=categoryPropertyTypes
value=field.property}}
</div> </div>
</div> </div>
{{/if}} {{/if}}

Datei anzeigen

@ -64,6 +64,9 @@
//= require discourse/helpers/category-link //= require discourse/helpers/category-link
//= require discourse/helpers/user-avatar //= require discourse/helpers/user-avatar
//= require discourse/helpers/format-username //= require discourse/helpers/format-username
//= require discourse/helpers/component-for-collection
//= require discourse/helpers/component-for-row
//= require discourse/helpers/discourse-tag
//= require discourse/services/app-events //= require discourse/services/app-events
//= require discourse/services/emoji-store //= require discourse/services/emoji-store
@ -97,6 +100,7 @@
//= require jquery.putcursoratend.js //= require jquery.putcursoratend.js
//= require template_include.js //= require template_include.js
//= require caret_position.js //= require caret_position.js
//= require popper.js
//= require ./wizard/custom-wizard //= require ./wizard/custom-wizard
//= require_tree ./wizard/components //= require_tree ./wizard/components

Datei anzeigen

@ -64,15 +64,6 @@ export default ComposerEditor.extend({
sendAction: this.showUploadModal sendAction: this.showUploadModal
}); });
} }
toolbar.addButton({
id: "options",
group: "extras",
icon: "cog",
title: "composer.options",
sendAction: this.onExpandPopupMenuOptions.bind(this),
popupMenu: true
});
} }
} }
}) })

Datei anzeigen

@ -31,14 +31,10 @@ export default Ember.Component.extend({
}, },
afterRefresh() { afterRefresh() {
}, },
storeToolbarState() {
},
cannotSeeMention() { cannotSeeMention() {
}, },
importQuote() { importQuote() {
}, },
onPopupMenuAction() {
},
showUploadSelector() { showUploadSelector() {
} }
} }

Datei anzeigen

@ -12,8 +12,5 @@
loading=composer.loading loading=composer.loading
showLink=showLink showLink=showLink
composerEvents=true composerEvents=true
onExpandPopupMenuOptions=(action "onExpandPopupMenuOptions")
onPopupMenuAction=onPopupMenuAction
popupMenuOptions=popupMenuOptions
disabled=disableTextarea disabled=disableTextarea
outletArgs=(hash composer=composer editorType="composer")}} outletArgs=(hash composer=composer editorType="composer")}}

Datei anzeigen

@ -16,10 +16,12 @@
{{toolbar-popup-menu-options {{toolbar-popup-menu-options
onPopupMenuAction=onPopupMenuAction onPopupMenuAction=onPopupMenuAction
onExpand=(action b.action b) onExpand=(action b.action b)
title=b.title
headerIcon=b.icon
class=b.className class=b.className
content=popupMenuOptions}} content=popupMenuOptions
options=(hash
popupTitle=b.title
icon=b.icon
)}}
{{else}} {{else}}
<div>{{d.icon}}</div> <div>{{d.icon}}</div>
<button class='wizard-btn {{b.className}}' {{action b.action b}} title="{{b.title}}"> <button class='wizard-btn {{b.className}}' {{action b.action b}} title="{{b.title}}">

Datei anzeigen

@ -1,2 +1,5 @@
{{category-selector categories=categories maximum=field.limit}} {{category-selector
categories=categories
maximum=field.limit
onChange=(action (mut categories))}}

Datei anzeigen

@ -1,8 +1,5 @@
{{wizard-composer-editor replyPlaceholder=field.placeholder {{wizard-composer-editor replyPlaceholder=field.placeholder
composer=composer composer=composer
storeToolbarState=(action "storeToolbarState")
onPopupMenuAction=(action "onPopupMenuAction")
showUploadModal=(action "showUploadSelector")
groupsMentioned=(action "groupsMentioned") groupsMentioned=(action "groupsMentioned")
cannotSeeMention=(action "cannotSeeMention") cannotSeeMention=(action "cannotSeeMention")
importQuote=(action "importQuote") importQuote=(action "importQuote")

Datei anzeigen

@ -299,7 +299,7 @@ class CustomWizard::Builder
case template['choices_preset'] case template['choices_preset']
when 'categories' when 'categories'
objects = site.categories objects = Set.new(Category.topic_create_allowed(guardian))
when 'groups' when 'groups'
objects = site.groups objects = site.groups
when 'tags' when 'tags'

Datei anzeigen

@ -192,6 +192,7 @@ describe CustomWizard::Builder do
end end
it 'returns a preset dropdown' do it 'returns a preset dropdown' do
SiteSetting.allow_uncategorized_topics = false
template['steps'][0]['fields'][0] = dropdown_categories_field template['steps'][0]['fields'][0] = dropdown_categories_field
choices = build_wizard(template, user).steps[0].fields[0].choices choices = build_wizard(template, user).steps[0].fields[0].choices
expect(choices.present?).to eq(true) expect(choices.present?).to eq(true)