From 8c173a7b17614f96c221f2824313a6fbc8ffc37f Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Wed, 8 Nov 2017 16:52:50 +0800 Subject: [PATCH] Fix dropdown choices && wizard start --- .../components/wizard-custom-field.js.es6 | 6 +++--- .../components/wizard-custom-field.hbs | 2 +- assets/stylesheets/wizard/wizard_custom.scss | 4 ++++ lib/builder.rb | 9 +++++++- lib/wizard.rb | 21 +++++++++---------- 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 index 74d5b848..bdef2d67 100644 --- a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 @@ -5,9 +5,9 @@ export default Ember.Component.extend({ isDropdown: Ember.computed.equal('field.type', 'dropdown'), disableId: Ember.computed.not('field.isNew'), choicesTypes: ['translation', 'preset', 'custom'], - choicesTranslation: Ember.computed.equal('choicesType', 'translation'), - choicesPreset: Ember.computed.equal('choicesType', 'preset'), - choicesCustom: Ember.computed.equal('choicesType', 'custom'), + choicesTranslation: Ember.computed.equal('field.choices_type', 'translation'), + choicesPreset: Ember.computed.equal('field.choices_type', 'preset'), + choicesCustom: Ember.computed.equal('field.choices_type', 'custom'), @computed('field.type') isInput: (type) => type === 'text' || type === 'textarea', diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs index fa59262c..5e15075c 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs @@ -70,7 +70,7 @@ {{i18n 'admin.wizard.field.choices_label'}} - {{combo-box value=choicesType content=choicesTypes none="admin.wizard.field.choices_type"}} + {{combo-box value=field.choices_type content=choicesTypes none="admin.wizard.field.choices_type"}} {{#if choicesTranslation}}
diff --git a/assets/stylesheets/wizard/wizard_custom.scss b/assets/stylesheets/wizard/wizard_custom.scss index e79ddf89..da64792d 100644 --- a/assets/stylesheets/wizard/wizard_custom.scss +++ b/assets/stylesheets/wizard/wizard_custom.scss @@ -64,6 +64,10 @@ height: 20px; vertical-align: middle; } + + .combo-box ul { + padding: 0; + } } .step-message { diff --git a/lib/builder.rb b/lib/builder.rb index d328e086..6f74e53f 100644 --- a/lib/builder.rb +++ b/lib/builder.rb @@ -100,7 +100,14 @@ class CustomWizard::Builder if f['choices_filters'] && f['choices_filters'].length > 0 f['choices_filters'].each do |f| - objects.reject! { |o| o[f['key']] != f['value'] } + objects.reject! do |o| + prop = f['key'] + if prop.include? 'custom_fields' + o.custom_fields[prop.split('.')[1]].to_s != f['value'].to_s + else + o[prop].to_s != f['value'].to_s + end + end end end diff --git a/lib/wizard.rb b/lib/wizard.rb index 4ad97024..cc1db24f 100644 --- a/lib/wizard.rb +++ b/lib/wizard.rb @@ -51,18 +51,17 @@ class CustomWizard::Wizard end def start - completed = ::UserHistory.where( - acting_user_id: @user.id, - action: ::UserHistory.actions[:custom_wizard_step], - context: @id, - subject: @steps.map(&:id) - ).uniq.pluck(:subject) - - @steps.each do |s| - return s unless completed.include?(s.id) + if unfinished? + step_id = ::UserHistory.where( + acting_user_id: @user.id, + action: ::UserHistory.actions[:custom_wizard_step], + context: @id, + subject: @steps.map(&:id) + ).order("created_at").last.subject + @steps.find { |s| s.id == step_id } + else + @first_step end - - @first_step end def create_updater(step_id, fields)