Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multiselect option to dropdowns #10270

Merged
merged 7 commits into from
Feb 16, 2017
Merged

Add multiselect option to dropdowns #10270

merged 7 commits into from
Feb 16, 2017

Conversation

d-m-u
Copy link
Contributor

@d-m-u d-m-u commented Aug 4, 2016

Adds multiselect flag to dropdowns much like the existing single option for tag controls.

@miq-bot add_label ui
@miq-bot assign @gmcculloug
@miq-bot add_label wip

@gmcculloug
Copy link
Member

@d-m-u Changes look good. You still need to handle processing an array of values when passing to automate. You can see an example of that here: app/models/dialog_field_tag_control.rb#L70

I did not test with a data_type for the field set to integer. It would be good to test that use case and make sure it is passing integers to automate.

Also, it would be good if the service dialog preview screen worked as a mult-select control.

@@ -31,7 +31,15 @@
= render(:partial => "shared/dialogs/dialog_field_radio_button", :locals => locals)

- when "DialogFieldDropDownList"
= render(:partial => "shared/dialogs/dialog_field_drop_down_list", :locals => locals)
- category_tags = field.values.collect(&:reverse)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

category_tags is probably not an accurate description of the values being collected here.

Also, is there a reason we're blindly reversing the collection? Shouldn't field.values already return the values in the correct order based on what the sort_order is set to?

@eclarizio
Copy link
Member

I know the methods you added code to in app/controllers/miq_ae_customization_controller/dialogs.rb are pretty huge, so it may be difficult to add specs, but if possible it would be nice.

app/models/dialog_field_drop_down_list.rb however shouldn't be too bad to add specs for.

@d-m-u d-m-u changed the title Add multiselect option to dropdowns [WIP] Add multiselect option to dropdowns Aug 8, 2016
@chessbyte chessbyte added the wip label Aug 8, 2016
end

def automate_key_name
MiqAeEngine.create_automation_attribute_array_key(super)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs the same return super unless multi_value? as the automate_output_value call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

K, does it also need the def value_from_dialog_fields(dialog_values) that's in tagControl?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I believe it does. Hoping @eclarizio can help you with that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already in the parent DialogField class, so I don't think we need def value_from_dialog_fields in this file. The one that is in the tag control does something special with classifications.

@d-m-u d-m-u changed the title [WIP] Add multiselect option to dropdowns Add multiselect option to dropdowns Aug 22, 2016
@d-m-u
Copy link
Contributor Author

d-m-u commented Aug 22, 2016

@miq-bot remove_label wip

@miq-bot miq-bot removed the wip label Aug 22, 2016
@@ -1,7 +1,13 @@
- if edit
- select_values = field.values.collect(&:reverse)
- select_values = field.values.collect
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the (&:reverse) seems to be important, without that, the names and ids in the selectboxes have switched

@d-m-u
Copy link
Contributor Author

d-m-u commented Sep 1, 2016

@miq-bot add_label wip

@miq-bot miq-bot added the wip label Sep 1, 2016
@d-m-u d-m-u changed the title Add multiselect option to dropdowns [WIP] Add multiselect option to dropdowns Sep 1, 2016
@Ladas
Copy link
Contributor

Ladas commented Sep 1, 2016

@d-m-u could you chrry-pick this commit Ladas@8c88baa

I made it on top of your commits https://github.com/Ladas/manageiq/commits/multiselect

These are the fixes I needed, to make multiselectboxes work. When have multiple dynamic multiselectboxes, it throws various failures, without that commit.

After that, it works nicely. :-)

@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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkanoor Can you verify that this is going to pass data to the automate engine as expect? This is the last part before merging this feature.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmcculloug @d-m-u
MiqAeEngine.create_automation_attribute_array_value([1,2,3]) => gives you back 1,2,3

For Automate to use it as an array the keyname should be prefixed with Array::

We have a helper method that does that
MiqAeEngine.create_automation_attribute_array_key("my_key")
which returns Array::my_key

You have to use the key and value together

In https://github.com/ManageIQ/manageiq/blob/master/app/models/dialog.rb#L50
We would have to detect that if it is a multi value field it should use

result[MiqAeEngine.create_automation_attribute_array_key(df.automate_key_name)] = df.automate_output_value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this Sunday at 8:05 Mahwah time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@d-m-u Along with overriding the automate_output_value you need to override automate_key_name like we do here app/models/dialog_field_tag_control.rb#L78.

You need the same check for force_multi_value as above.

Something like this:

def automate_key_name
  return super unless force_multi_value
  MiqAeEngine.create_automation_attribute_array_key(super)
end

@miq-bot miq-bot added the ui label Feb 10, 2017
@miq-bot miq-bot assigned gmcculloug and unassigned eclarizio Feb 10, 2017
@miq-bot miq-bot added the wip label Feb 10, 2017
@miq-bot miq-bot changed the title Add multiselect option to dropdowns [WIP] Add multiselect option to dropdowns Feb 10, 2017
@miq-bot miq-bot added wip and removed wip labels Feb 10, 2017
@d-m-u
Copy link
Contributor Author

d-m-u commented Feb 13, 2017

@miq-bot remove_label wip

@miq-bot miq-bot changed the title [WIP] Add multiselect option to dropdowns Add multiselect option to dropdowns Feb 13, 2017
@miq-bot miq-bot removed the wip label Feb 13, 2017
@@ -47,7 +47,9 @@ 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|
result[MiqAeEngine.create_automation_attribute_array_key(df.automate_key_name)] = df.automate_output_value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@d-m-u Not every attribute is going to be an array type should this be done only for array types?

@miq-bot
Copy link
Member

miq-bot commented Feb 15, 2017

Checked commits d-m-u/manageiq@ab3412b~...390f8fa with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
3 files checked, 0 offenses detected
Everything looks good. 🍪

@gmcculloug
Copy link
Member

Wow, a labor of love. Tested last night after the key changes and data is being passed to the automate method as expected. Thanks @d-m-u! 🥇

@gmcculloug gmcculloug merged commit fd5e8ac into ManageIQ:master Feb 16, 2017
@gmcculloug gmcculloug added this to the Sprint 55 Ending Feb 27, 2017 milestone Feb 16, 2017
simaishi pushed a commit that referenced this pull request Mar 20, 2017
@simaishi
Copy link
Contributor

Euwe backport details:

$ git log -1
commit a21cb2147654f231b25046c14f37137472c81a0d
Author: Greg McCullough <gmccullo@redhat.com>
Date:   Thu Feb 16 08:59:29 2017 -0500

    Merge pull request #10270 from d-m-u/multiselect
    
    Add multiselect option to dropdowns
    (cherry picked from commit fd5e8acce71d53b28360eeb0167eed0f151e7df3)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1430542

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants