From ab3412b62f7cdf5a1272683da409a42e6ede0fdd Mon Sep 17 00:00:00 2001 From: d-m-u Date: Wed, 4 Jan 2017 10:27:43 -0700 Subject: [PATCH 1/7] Removes files split off in classic ui --- app/models/dialog_field_drop_down_list.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/models/dialog_field_drop_down_list.rb b/app/models/dialog_field_drop_down_list.rb index 3142ef509cc..1192f806407 100644 --- a/app/models/dialog_field_drop_down_list.rb +++ b/app/models/dialog_field_drop_down_list.rb @@ -3,6 +3,14 @@ def show_refresh_button? !!show_refresh_button end + def multi_value? + return true if options[:force_multi_value].present? && options[:force_multi_value] != "null" + end + + def force_multi_value=(setting) + options[:force_multi_value] = setting + end + def initial_values [[nil, ""]] end From ee9df1e348f8cdb764334f1a07f183bfd0e6d8eb Mon Sep 17 00:00:00 2001 From: d-m-u Date: Mon, 8 Aug 2016 15:49:06 -0400 Subject: [PATCH 2/7] Add tests for model change --- .../dialog_field_drop_down_list_spec.rb | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/spec/models/dialog_field_drop_down_list_spec.rb b/spec/models/dialog_field_drop_down_list_spec.rb index d0a6815aa37..29640871104 100644 --- a/spec/models/dialog_field_drop_down_list_spec.rb +++ b/spec/models/dialog_field_drop_down_list_spec.rb @@ -181,6 +181,35 @@ end end + context "dialog field dropdown without options hash" do + before do + @df = FactoryGirl.create(:dialog_field_drop_down_list, :name => 'test drop down') + end + + it "#multi_value?" do + expect(@df.multi_value?).to be_falsey + + @df.force_multi_value = true + expect(@df.multi_value?).to be_truthy + end + + it "#automate_key_name" do + expect(@df.automate_key_name).to eq("dialog_#{@df.name}") + end + end + + context "dialog field dropdown with options hash" do + before do + @df = FactoryGirl.create(:dialog_field_drop_down_list, + :name => 'test drop down', + :options => {:force_multi_value => true}) + end + + it "#multi_value?" do + expect(@df.multi_value?).to be_truthy + end + end + context "when the raw values are not already set" do before do dialog_field.values = %w(original values) From d9837b735f2f536d506b0f014667999bc4edb4f0 Mon Sep 17 00:00:00 2001 From: d-m-u Date: Thu, 10 Nov 2016 06:03:09 -0700 Subject: [PATCH 3/7] fix merge conflicts --- app/models/dialog_field_drop_down_list.rb | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app/models/dialog_field_drop_down_list.rb b/app/models/dialog_field_drop_down_list.rb index 1192f806407..81b0c7836dd 100644 --- a/app/models/dialog_field_drop_down_list.rb +++ b/app/models/dialog_field_drop_down_list.rb @@ -14,4 +14,30 @@ def force_multi_value=(setting) def initial_values [[nil, ""]] end + + def refresh_json_value(checked_value) + @raw_values = @default_value = nil + + refreshed_values = values + + if refreshed_values.collect { |value_pair| value_pair[0].to_s }.include?(checked_value) + @value = checked_value + else + @value = @default_value + end + + {:refreshed_values => refreshed_values, :checked_value => @value, :read_only => read_only?, :visible => visible?} + end + + def automate_output_value + return nil if @value.blank? + MiqAeEngine.create_automation_attribute_array_value(@value.split.map(&:to_i)) + end + + private + + def load_values_on_init? + return true unless show_refresh_button + load_values_on_init + end end From f13906f5882d8401f7c7eb8d8cf2c56590d11dd3 Mon Sep 17 00:00:00 2001 From: d-m-u Date: Wed, 4 Jan 2017 10:34:57 -0700 Subject: [PATCH 4/7] Removes file split into classic ui repo --- app/models/dialog_field_drop_down_list.rb | 37 +++-- .../dialog_field_drop_down_list_spec.rb | 128 ++++++++++++------ 2 files changed, 115 insertions(+), 50 deletions(-) diff --git a/app/models/dialog_field_drop_down_list.rb b/app/models/dialog_field_drop_down_list.rb index 81b0c7836dd..61716b9befc 100644 --- a/app/models/dialog_field_drop_down_list.rb +++ b/app/models/dialog_field_drop_down_list.rb @@ -4,7 +4,9 @@ def show_refresh_button? end def multi_value? - return true if options[:force_multi_value].present? && options[:force_multi_value] != "null" + return true if options[:force_multi_value].present? && + options[:force_multi_value] != "null" && + options[:force_multi_value] end def force_multi_value=(setting) @@ -16,22 +18,37 @@ def initial_values end def refresh_json_value(checked_value) - @raw_values = @default_value = nil + self.default_value = nil + @raw_values = nil refreshed_values = values - if refreshed_values.collect { |value_pair| value_pair[0].to_s }.include?(checked_value) - @value = checked_value - else - @value = @default_value - end - + selectbox_options = refreshed_values.collect { |value_pair| value_pair[0].to_s } + + @value = if checked_value.kind_of?(Array) && (selectbox_options & checked_value).present? + # if checked value is [1,2,4] and the intersection is [1,2], removes non-valid option 4 + # and does final check to make sure it's not returning [], otherwise, defaults + selectbox_options & checked_value + elsif selectbox_options.include?(checked_value) + # checks if [1,2,3].includes?(3) + checked_value + else + default_value + end {:refreshed_values => refreshed_values, :checked_value => @value, :read_only => read_only?, :visible => visible?} end def automate_output_value - return nil if @value.blank? - MiqAeEngine.create_automation_attribute_array_value(@value.split.map(&:to_i)) + return super unless multi_value? + a = if @value.kind_of?(Integer) + [@value] + elsif @value.kind_of?(Array) + @value + else + @value.blank? ? [] : @value.chomp.split(',') + end + automate_values = a.first.kind_of?(Integer) ? a.map(&:to_i) : a + MiqAeEngine.create_automation_attribute_array_value(automate_values) end private diff --git a/spec/models/dialog_field_drop_down_list_spec.rb b/spec/models/dialog_field_drop_down_list_spec.rb index 29640871104..4a8395e9469 100644 --- a/spec/models/dialog_field_drop_down_list_spec.rb +++ b/spec/models/dialog_field_drop_down_list_spec.rb @@ -92,51 +92,75 @@ describe "#refresh_json_value" do let(:dialog_field) { described_class.new(:dynamic => dynamic, :read_only => true) } - context "when the dialog_field is dynamic" do + context "dynamic" do let(:dynamic) { true } - - before do - allow(DynamicDialogFieldValueProcessor).to receive(:values_from_automate).with(dialog_field).and_return( - [["123", 456], ["789", 101]] - ) - dialog_field.value = "123" + context "array" do + context "included" do + # TODO + end + context "not-included" do + # TODO + end end - it "sets the value" do - dialog_field.refresh_json_value("789") - expect(dialog_field.value).to eq("789") - end + context "not-array" do + before do + allow(DynamicDialogFieldValueProcessor).to receive(:values_from_automate).with(dialog_field).and_return( + [["123", 456], ["789", 101]] + ) + dialog_field.value = "123" + end - it "returns the values from automate" do - expect(dialog_field.refresh_json_value("789")).to eq( - :refreshed_values => [["789", 101], ["123", 456]], - :checked_value => "789", - :read_only => true, - :visible => true - ) + it "sets the value" do + dialog_field.refresh_json_value("789") + expect(dialog_field.value).to eq("789") + end + + it "returns the values from automate" do + expect(dialog_field.refresh_json_value("789")).to eq( + :refreshed_values => [["789", 101], ["123", 456]], + :checked_value => "789", + :read_only => true, + :visible => true + ) + end end end - context "when the dialog_field is not dynamic" do + context "non-dynamic" do let(:dynamic) { false } - - before do - dialog_field.values = [["123", 456], ["789", 101]] - dialog_field.value = "123" - end - - it "sets the value" do - dialog_field.refresh_json_value("789") - expect(dialog_field.value).to eq("789") + context "array" do + context "included" do + # TODO + end + context "not-included" do + # TODO + end end - it "returns the values" do - expect(dialog_field.refresh_json_value("789")).to eq( - :refreshed_values => [["789", 101], ["123", 456]], - :checked_value => "789", - :read_only => true, - :visible => true - ) + context "not-array" do + context "when the dialog_field is not dynamic" do + let(:dynamic) { false } + + before do + dialog_field.values = [["123", 456], ["789", 101]] + dialog_field.value = "123" + end + + it "sets the value" do + dialog_field.refresh_json_value("789") + expect(dialog_field.value).to eq("789") + end + + it "returns the values" do + expect(dialog_field.refresh_json_value("789")).to eq( + :refreshed_values => [["789", 101], ["123", 456]], + :checked_value => "789", + :read_only => true, + :visible => true + ) + end + end end end end @@ -186,11 +210,35 @@ @df = FactoryGirl.create(:dialog_field_drop_down_list, :name => 'test drop down') end - it "#multi_value?" do - expect(@df.multi_value?).to be_falsey - - @df.force_multi_value = true - expect(@df.multi_value?).to be_truthy + describe "#multi_value?" do + context "when force_multi_value is present" do + context "when force_multi_value is null" do + it "multivalue false" do + expect(@df.multi_value?).to be_falsey + end + end + + context "when force_multi_value is not null" do + context "when force_multi_value is truthy" do + it "multivalue true" do + @df.force_multi_value = true + expect(@df.multi_value?).to be_truthy + end + end + + context "when force_multi_value is falsy" do + it "multivalue false" do + expect(@df.multi_value?).to be_falsey + end + end + end + end + + context "when force_multi_value is not present" do + it "multivalue false" do + expect(@df.multi_value?).to be_falsey + end + end end it "#automate_key_name" do From 594d0e7cc83e301884f45b834d7973a818de7912 Mon Sep 17 00:00:00 2001 From: d-m-u Date: Mon, 19 Dec 2016 15:14:03 -0700 Subject: [PATCH 5/7] Fix tests per Erik's comment --- spec/models/dialog_field_drop_down_list_spec.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/spec/models/dialog_field_drop_down_list_spec.rb b/spec/models/dialog_field_drop_down_list_spec.rb index 4a8395e9469..0d74ca16823 100644 --- a/spec/models/dialog_field_drop_down_list_spec.rb +++ b/spec/models/dialog_field_drop_down_list_spec.rb @@ -240,10 +240,6 @@ end end end - - it "#automate_key_name" do - expect(@df.automate_key_name).to eq("dialog_#{@df.name}") - end end context "dialog field dropdown with options hash" do From 0309a17b21abd259342e59c389acd2630324746a Mon Sep 17 00:00:00 2001 From: d-m-u Date: Thu, 2 Feb 2017 10:12:54 -0700 Subject: [PATCH 6/7] Fixes failing test --- app/models/dialog_field_drop_down_list.rb | 4 ++-- spec/models/dialog_field_drop_down_list_spec.rb | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/models/dialog_field_drop_down_list.rb b/app/models/dialog_field_drop_down_list.rb index 61716b9befc..5b1e13d06f2 100644 --- a/app/models/dialog_field_drop_down_list.rb +++ b/app/models/dialog_field_drop_down_list.rb @@ -3,7 +3,7 @@ def show_refresh_button? !!show_refresh_button end - def multi_value? + def force_multi_value return true if options[:force_multi_value].present? && options[:force_multi_value] != "null" && options[:force_multi_value] @@ -39,7 +39,7 @@ def refresh_json_value(checked_value) end def automate_output_value - return super unless multi_value? + return super unless force_multi_value a = if @value.kind_of?(Integer) [@value] elsif @value.kind_of?(Array) diff --git a/spec/models/dialog_field_drop_down_list_spec.rb b/spec/models/dialog_field_drop_down_list_spec.rb index 0d74ca16823..e6f5a538416 100644 --- a/spec/models/dialog_field_drop_down_list_spec.rb +++ b/spec/models/dialog_field_drop_down_list_spec.rb @@ -210,11 +210,11 @@ @df = FactoryGirl.create(:dialog_field_drop_down_list, :name => 'test drop down') end - describe "#multi_value?" do + describe "#force_multi_value" do context "when force_multi_value is present" do context "when force_multi_value is null" do it "multivalue false" do - expect(@df.multi_value?).to be_falsey + expect(@df.force_multi_value).to be_falsey end end @@ -222,13 +222,13 @@ context "when force_multi_value is truthy" do it "multivalue true" do @df.force_multi_value = true - expect(@df.multi_value?).to be_truthy + expect(@df.force_multi_value).to be_truthy end end context "when force_multi_value is falsy" do it "multivalue false" do - expect(@df.multi_value?).to be_falsey + expect(@df.force_multi_value).to be_falsey end end end @@ -236,7 +236,7 @@ context "when force_multi_value is not present" do it "multivalue false" do - expect(@df.multi_value?).to be_falsey + expect(@df.force_multi_value).to be_falsey end end end @@ -249,8 +249,8 @@ :options => {:force_multi_value => true}) end - it "#multi_value?" do - expect(@df.multi_value?).to be_truthy + it "#force_multi_value" do + expect(@df.force_multi_value).to be_truthy end end From 390f8fad341960a684ebef8ec494184f6272f982 Mon Sep 17 00:00:00 2001 From: d-m-u Date: Thu, 2 Feb 2017 16:00:43 -0700 Subject: [PATCH 7/7] Removes extraneous method that's already in superclass --- app/models/dialog.rb | 12 +++++++++--- app/models/dialog_field_drop_down_list.rb | 8 +++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/models/dialog.rb b/app/models/dialog.rb index f223f7d386d..e6aa7fcfe4f 100644 --- a/app/models/dialog.rb +++ b/app/models/dialog.rb @@ -47,7 +47,13 @@ def dialog_resources end def automate_values_hash - dialog_fields.each_with_object({}) { |df, result| result[df.automate_key_name] = df.automate_output_value } + dialog_fields.each_with_object({}) do |df, result| + if df.options.include?("multiple") + result[MiqAeEngine.create_automation_attribute_array_key(df.automate_key_name)] = df.automate_output_value + else + result[df.automate_key_name] = df.automate_output_value + end + end end def validate_children @@ -61,7 +67,7 @@ def validate_children next if dt.valid? dt.errors.full_messages.each do |err_msg| errors.add(:base, _("Dialog %{dialog_label} / %{error_message}") % - {:dialog_label => label, :error_message => err_msg}) + {:dialog_label => label, :error_message => err_msg}) end end end @@ -82,7 +88,7 @@ def validate_field_data def init_fields_with_values(values) dialog_field_hash.each do |key, field| values[key] = field.value - field.dialog = self + field.dialog = self end dialog_field_hash.each { |key, field| values[key] = field.initialize_with_values(values) } dialog_field_hash.each { |_key, field| field.update_values(values) } diff --git a/app/models/dialog_field_drop_down_list.rb b/app/models/dialog_field_drop_down_list.rb index 5b1e13d06f2..cd88848fca0 100644 --- a/app/models/dialog_field_drop_down_list.rb +++ b/app/models/dialog_field_drop_down_list.rb @@ -51,10 +51,8 @@ def automate_output_value MiqAeEngine.create_automation_attribute_array_value(automate_values) end - private - - def load_values_on_init? - return true unless show_refresh_button - load_values_on_init + def automate_key_name + return super unless force_multi_value + MiqAeEngine.create_automation_attribute_array_key(super) end end