From e3fa75597b879b1bcd0d624c38e8ce362c6ae6a0 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Tue, 7 Apr 2020 14:56:16 +1000 Subject: [PATCH] various --- .../components/wizard-custom-field.js.es6 | 7 +++ .../discourse/components/wizard-mapper.js.es6 | 7 ++- .../discourse/lib/wizard-json.js.es6 | 14 +++-- .../javascripts/discourse/lib/wizard.js.es6 | 56 ++++++++++++------- .../components/wizard-custom-field.hbs | 2 +- assets/stylesheets/common/wizard-mapper.scss | 9 ++- 6 files changed, 65 insertions(+), 30 deletions(-) diff --git a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 index 355a5a83..035208c5 100644 --- a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 @@ -80,6 +80,13 @@ export default Component.extend({ this.set('field.prefill', null); }, + @observes('isCategory') + setupCategoryType() { + if (this.isCategory && !this.field.property) { + this.set('field.property', 'id'); + } + }, + actions: { imageUploadDone(upload) { this.set("field.image", upload.url); diff --git a/assets/javascripts/discourse/components/wizard-mapper.js.es6 b/assets/javascripts/discourse/components/wizard-mapper.js.es6 index d862462f..b4e1f7a9 100644 --- a/assets/javascripts/discourse/components/wizard-mapper.js.es6 +++ b/assets/javascripts/discourse/components/wizard-mapper.js.es6 @@ -53,7 +53,12 @@ export default Component.extend({ }, remove(input) { - this.get('inputs').removeObject(input); + const inputs = this.inputs; + inputs.removeObject(input); + + if (inputs.length) { + inputs[0].set('connector', null); + } } } }); diff --git a/assets/javascripts/discourse/lib/wizard-json.js.es6 b/assets/javascripts/discourse/lib/wizard-json.js.es6 index 9a39b0e9..d7aa8a09 100644 --- a/assets/javascripts/discourse/lib/wizard-json.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-json.js.es6 @@ -214,9 +214,11 @@ function stepHasAdvanced(property, value) { return advancedProperties.step[property] && present(value); } -function hasAdvanced(params, type) { +function objectHasAdvanced(params, type) { return Object.keys(params).some(p => { - return advancedProperties[type].indexOf(p) > -1 && present(params[p]); + let value = params[p]; + let advanced = advancedProperties[type][params.type]; + return advanced && advanced.indexOf(p) > -1 && present(value); }); } @@ -245,7 +247,7 @@ function buildProperties(json) { }; properties.step.forEach((p) => { - stepParams[p] = buildProperty(stepJson, p, 'wizard');; + stepParams[p] = buildProperty(stepJson, p, 'wizard'); if (stepHasAdvanced(p, stepJson[p])) { stepParams.showAdvanced = true; @@ -257,8 +259,8 @@ function buildProperties(json) { if (present(stepJson.fields)) { stepJson.fields.forEach((f) => { let params = buildObject(f, 'field'); - - if (hasAdvanced(params, 'field')) { + + if (objectHasAdvanced(params, 'field')) { params.showAdvanced = true; } @@ -272,7 +274,7 @@ function buildProperties(json) { stepJson.actions.forEach((a) => { let params = buildObject(a, 'action'); - if (hasAdvanced(params, 'action')) { + if (objectHasAdvanced(params, 'action')) { params.showAdvanced = true; } diff --git a/assets/javascripts/discourse/lib/wizard.js.es6 b/assets/javascripts/discourse/lib/wizard.js.es6 index 00bba29b..c4772f8c 100644 --- a/assets/javascripts/discourse/lib/wizard.js.es6 +++ b/assets/javascripts/discourse/lib/wizard.js.es6 @@ -83,7 +83,7 @@ const fieldProperties = [ 'property', 'limit', 'prefill', - 'content', + 'content' ] const actionProperties = [ @@ -139,27 +139,12 @@ const mappedProperties = { ] } -const advancedProperties = { - step: [ - 'required_data', - 'permitted_params' - ], - field: [ - 'property', - 'prefill', - 'content' - ], - action: [ - 'code', - 'custom_fields', - 'skip_redirect', - 'required' - ] -} +const advancedFieldProperties = [ + 'prefill', + 'content' +] const actionTypes = [ - 'create_topic', - 'update_profile', 'create_topic', 'update_profile', 'send_message', @@ -171,6 +156,37 @@ const actionTypes = [ return Discourse.SiteSettings.wizard_api_features || type !== 'send_to_api'; }); +const advancedProperties = { + step: [ + 'required_data', + 'permitted_params' + ], + field: advancedFieldProperties.reduce( + function(map, type) { + console.log(map, type); + map[type] = advancedFieldProperties; + if (type === 'category') { + map.push('property'); + } + return map; + }, {} + ), + action: actionTypes.reduce( + function(map, type) { + if (type === 'route_to') { + map[type] = ['code']; + } else if (['create_topic', 'send_message', 'open_composer'].indexOf(type) > -1) { + map[type] = ['custom_fields']; + } else if (['create_topic', 'send_message'].indexOf(type) > -1) { + map[type].push('skip_redirect'); + } else if (type === 'send_message') { + map[type].push('required'); + } + return map; + }, {} + ) +} + export { selectKitContent, generateName, diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs index 909e7ae4..bc3c2942 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs @@ -110,7 +110,7 @@ content=categoryPropertyTypes onChange=(action (mut field.property)) options=(hash - none='admin.wizard.select_property' + none='admin.wizard.selector.placeholder.property' )}} diff --git a/assets/stylesheets/common/wizard-mapper.scss b/assets/stylesheets/common/wizard-mapper.scss index ff1f7160..8322749f 100644 --- a/assets/stylesheets/common/wizard-mapper.scss +++ b/assets/stylesheets/common/wizard-mapper.scss @@ -54,9 +54,14 @@ a.remove-input { position: absolute; - right: -25px; - top: 50%; + right: -14px; + top: 0px; + padding: 2px 5px; transform: translateY(-50%); + background: $secondary; + border-radius: 50%; + font-size: 0.8em; + border: 2px solid $primary-low; } }