From ffde10c217cad9103fd0fe6144ceae6cdca55a6a Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Sun, 22 Mar 2020 17:47:56 +1100 Subject: [PATCH] wip --- .../wizard-custom-input-pair.js.es6 | 2 +- .../components/wizard-custom-step.js.es6 | 9 +++-- .../custom-wizard-admin-route-map.js.es6 | 1 - .../discourse/lib/custom-wizard.js.es6 | 19 ++++++++-- .../discourse/templates/admin-wizard.hbs | 6 ++-- .../discourse/templates/admin-wizards-api.hbs | 16 ++++++--- .../components/wizard-custom-action.hbs | 36 ++++++++++++++----- .../components/wizard-custom-field.hbs | 8 +++-- config/locales/client.en.yml | 1 - lib/custom_wizard/builder.rb | 33 +++-------------- 10 files changed, 79 insertions(+), 52 deletions(-) diff --git a/assets/javascripts/discourse/components/wizard-custom-input-pair.js.es6 b/assets/javascripts/discourse/components/wizard-custom-input-pair.js.es6 index 772a3c49..a4666bf6 100644 --- a/assets/javascripts/discourse/components/wizard-custom-input-pair.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-input-pair.js.es6 @@ -4,6 +4,6 @@ import { gt } from "@ember/object/computed"; export default Ember.Component.extend({ classNames: 'pair', connectorNone: 'admin.wizard.connector.none', - connectors: connectors.map(c => ({ id: c, name: I18n.t(`admin.wizard.connector.${c}`) })), + connectors: connectors, showRemove: gt('pair.index', 0) }) \ No newline at end of file diff --git a/assets/javascripts/discourse/components/wizard-custom-step.js.es6 b/assets/javascripts/discourse/components/wizard-custom-step.js.es6 index 27515f6e..c8945b80 100644 --- a/assets/javascripts/discourse/components/wizard-custom-step.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-step.js.es6 @@ -1,11 +1,16 @@ -import { observes, default as computed } from 'discourse-common/utils/decorators'; +import { + observes, + on, + default as computed +} from 'discourse-common/utils/decorators'; export default Ember.Component.extend({ classNames: 'wizard-custom-step', currentField: null, currentAction: null, disableId: Ember.computed.not('step.isNew'), - + + @on('didInsertElement') @observes('step') resetCurrentObjects() { const fields = this.get('step.fields'); diff --git a/assets/javascripts/discourse/custom-wizard-admin-route-map.js.es6 b/assets/javascripts/discourse/custom-wizard-admin-route-map.js.es6 index 001569f2..205e2454 100644 --- a/assets/javascripts/discourse/custom-wizard-admin-route-map.js.es6 +++ b/assets/javascripts/discourse/custom-wizard-admin-route-map.js.es6 @@ -13,7 +13,6 @@ export default { }); this.route('adminWizardsTransfer', { path: '/transfer', resetNamespace: true }); - }); } }; diff --git a/assets/javascripts/discourse/lib/custom-wizard.js.es6 b/assets/javascripts/discourse/lib/custom-wizard.js.es6 index a56bc9b4..2adc9867 100644 --- a/assets/javascripts/discourse/lib/custom-wizard.js.es6 +++ b/assets/javascripts/discourse/lib/custom-wizard.js.es6 @@ -23,7 +23,22 @@ const profileFields = [ ]; const connectors = [ - 'equal' + { + id: 'eq', + name: '=' + },{ + id: 'gt', + name: '>' + },{ + id: 'lt', + name: '<' + },{ + id: 'gte', + name: '>=' + },{ + id: 'lte', + name: '<=' + } ] const actionTypes = [ @@ -58,7 +73,7 @@ function newPair(options = {}, index) { key_type: 'text', value: '', value_type: 'text', - connector: 'equal' + connector: 'eq' } return Ember.Object.create(params); diff --git a/assets/javascripts/discourse/templates/admin-wizard.hbs b/assets/javascripts/discourse/templates/admin-wizard.hbs index 2d1f2d0d..fe5d0965 100644 --- a/assets/javascripts/discourse/templates/admin-wizard.hbs +++ b/assets/javascripts/discourse/templates/admin-wizard.hbs @@ -78,7 +78,7 @@
{{input type='checkbox' checked=model.after_time}} {{i18n 'admin.wizard.after_time_label'}} - {{d-button action='setNextSessionScheduled' translatedLabel=nextSessionScheduledLabel icon='calendar-o'}} + {{d-button action='setNextSessionScheduled' translatedLabel=nextSessionScheduledLabel icon='far-calendar'}}
@@ -111,7 +111,9 @@ content=model.themes valueProperty='id' value=model.theme_id - none='admin.wizard.no_theme'}} + options=(hash + none='admin.wizard.no_theme' + )}} diff --git a/assets/javascripts/discourse/templates/admin-wizards-api.hbs b/assets/javascripts/discourse/templates/admin-wizards-api.hbs index 06980f42..cf4ddf9c 100644 --- a/assets/javascripts/discourse/templates/admin-wizards-api.hbs +++ b/assets/javascripts/discourse/templates/admin-wizards-api.hbs @@ -92,7 +92,9 @@ {{combo-box value=api.authType content=authorizationTypes - none='admin.wizard.api.auth.type_none'}} + options=(hash + none='admin.wizard.api.auth.type_none' + )}} @@ -246,15 +248,21 @@ {{combo-box content=endpointMethods value=endpoint.method - none="admin.wizard.api.endpoint.method"}} + options=(hash + none="admin.wizard.api.endpoint.method" + )}} {{combo-box content=contentTypes value=endpoint.content_type - none="admin.wizard.api.endpoint.content_type"}} + options=(hash + none="admin.wizard.api.endpoint.content_type" + )}} {{multi-select content=successCodes values=endpoint.success_codes - none="admin.wizard.api.endpoint.success_codes"}} + options=(hash + none="admin.wizard.api.endpoint.success_codes" + )}} diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs index 4962b480..87bfcf6b 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -15,7 +15,9 @@ {{combo-box value=action.type content=types - none="admin.wizard.field.type"}} + options=(hash + none="admin.wizard.field.type" + )}} @@ -30,7 +32,9 @@ content=wizardFields nameProperty="label" isDisabled=action.custom_title_enabled - none='admin.wizard.select_field'}} + options=(hash + none='admin.wizard.select_field' + )}}
{{input type='checkbox' checked=action.custom_title_enabled}} {{i18n 'admin.wizard.action.custom_title'}} @@ -51,7 +55,9 @@ content=wizardFields nameProperty='label' isDisabled=action.post_builder - none='admin.wizard.select_field'}} + options=(hash + none='admin.wizard.select_field' + )}}
{{input type='checkbox' checked=action.post_builder}} {{i18n 'admin.wizard.action.post_builder.checkbox'}} @@ -100,7 +106,9 @@ value=action.category_id content=categoryFields nameProperty="label" - none='admin.wizard.select_field'}} + options=(hash + none='admin.wizard.select_field' + )}} {{/if}}
@@ -137,7 +145,9 @@ value=action.custom_tag_field content=tagFields nameProperty="label" - none='admin.wizard.select_field'}} + options=(hash + none='admin.wizard.select_field' + )}}
{{/if}}
@@ -181,7 +191,9 @@ value=action.required content=wizardFields nameProperty='label' - none='admin.wizard.select_field'}} + options=(hash + none='admin.wizard.select_field' + )}} @@ -231,7 +243,9 @@ value=action.api content=availableApis isDisabled=action.custom_title_enabled - none='admin.wizard.action.send_to_api.select_an_api'}} + options=(hash + none='admin.wizard.action.send_to_api.select_an_api' + )}} @@ -244,7 +258,9 @@ value=action.api_endpoint content=availableEndpoints isDisabled=apiEmpty - none='admin.wizard.action.send_to_api.select_an_endpoint'}} + options=(hash + none='admin.wizard.action.send_to_api.select_an_endpoint' + )}} @@ -273,7 +289,9 @@ content=wizardFields isDisabled=action.custom nameProperty="label" - none='admin.wizard.select_field'}} + options=(hash + none='admin.wizard.select_field' + )}}
{{input type='checkbox' checked=action.custom_group_enabled}} diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs index a6af6d48..9de83157 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs @@ -51,7 +51,9 @@ {{combo-box value=field.type content=types - none="admin.wizard.field.type"}} + options=(hash + none="admin.wizard.field.type" + )}}
@@ -85,7 +87,9 @@ {{combo-box value=field.choices_type content=choicesTypes - none="admin.wizard.field.choices_type"}} + options=(hash + none="admin.wizard.field.choices_type" + )}} {{#if choicesTranslation}}
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index e68926f6..b8909834 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -69,7 +69,6 @@ en: connector: none: "op" prefill: "prefill" - equal: "=" error: name_required: "Wizards must have a name." diff --git a/lib/custom_wizard/builder.rb b/lib/custom_wizard/builder.rb index e5f5d6dc..ba53e041 100644 --- a/lib/custom_wizard/builder.rb +++ b/lib/custom_wizard/builder.rb @@ -45,7 +45,11 @@ class CustomWizard::Builder USER_FIELDS = ['name', 'username', 'email', 'date_of_birth', 'title', 'locale'] PROFILE_FIELDS = ['location', 'website', 'bio_raw', 'profile_background', 'card_background'] OPERATORS = { - 'equal': '==' + 'eq': '==', + 'gt': '>', + 'lt': '<', + 'gte': '>=', + 'lte': '<=' } def self.fill_placeholders(string, user, data) @@ -272,35 +276,20 @@ class CustomWizard::Builder output = nil prefill.each do |item| - puts "PREFIL: #{item.inspect}" if validate_pairs(item['pairs']) - puts "OUTPUT: #{get_field(item['output'], item['output_type'])}" output = get_field(item['output'], item['output_type']) end end output - else - actions = step_template['actions'] - - if actions && actions.any? - profile_actions = actions.select { |a| a['type'] === 'update_profile' } || [] - - profile_actions.each do |action| - update = action['profile_updates'].select { |u| u['key'] === field_template['id'] }.first - get_user_field(update['value']) if update - end - end end end def validate_pairs(pairs) failed = false pairs.each do |pair| - puts "PAIR: #{pair.inspect}" key = get_field(pair['key'], pair['key_type']) value = get_field(pair['value'], pair['value_type']) - puts "KEY VALUE: #{key.inspect}; #{value.inspect}" failed = true unless key.public_send(get_operator(pair['connector']), value) end !failed @@ -516,18 +505,6 @@ class CustomWizard::Builder action['profile_updates'].each do |pu| value = pu['value'] - custom_field = nil - - if pu['value_custom'].present? - custom_parts = pu['value_custom'].split('.') - if custom_parts.length == 2 && custom_parts[0] == 'custom_field' - custom_field = custom_parts[1] - else - value = custom_parts[0] - end - end - - user_field = pu['user_field'] key = pu['key'] return if data[key].blank?