فهرست منبع

Fix dropdown choices && wizard start

Angus McLeod 7 سال پیش
والد
کامیت
8c173a7b17

+ 3 - 3
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',

+ 1 - 1
assets/javascripts/discourse/templates/components/wizard-custom-field.hbs

@@ -70,7 +70,7 @@
       {{i18n 'admin.wizard.field.choices_label'}}
     </div>
 
-    {{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}}
       <div class="wizard-header small">

+ 4 - 0
assets/stylesheets/wizard/wizard_custom.scss

@@ -64,6 +64,10 @@
     height: 20px;
     vertical-align: middle;
   }
+
+  .combo-box ul {
+    padding: 0;
+  }
 }
 
 .step-message {

+ 8 - 1
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
 

+ 10 - 11
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)