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

Menu pluggability improvements #3347

Merged
merged 2 commits into from Mar 1, 2018
Merged

Conversation

martinpovolny
Copy link

@martinpovolny martinpovolny commented Jan 31, 2018

Expand menu pluggability:

  • items into existing section
  • sections into existing sections and 2nd level

Details and examples can be seen in the commit message.

TODO:

  • test coverage

Allow plugins to add items and sections at a given position in a
existing section.

Examples:

initializer 'plugin' do
  # create custom section with 2 custom items
  Menu::CustomLoader.register(
    Menu::Section.new(:spike, N_('Plugin'), 'fa fa-map-pin', [
      Menu::Item.new('plug1', N_('Test'), 'miq_report', {:feature => 'miq_report', :any => true}, '/plug'),
      Menu::Item.new('plug2', N_('Demo'), 'miq_report', {:feature => 'miq_report', :any => true}, '/demo')
    ])
  )

  # create custom item placed in an existing section 'vi' (Cloud Intel)
  Menu::CustomLoader.register(
    Menu::Item.new('plug3', N_('Plug Item'), 'miq_report', {:feature => 'miq_report', :any => true}, '/demo', :default, :vi)
  )

  # create custom section and place it before existing section 'compute' (Compute)
  Menu::CustomLoader.register(
    Menu::Section.new(:spike3, N_('Plugin 2'), 'fa fa-map-pin', [
      Menu::Item.new('plug4', N_('Demo'), 'miq_report', {:feature => 'miq_report', :any => true}, '/demo')
    ], :default, :compute)
  )

  # create custom section and place it inside an existing section 'compute' (Compute), before existing subsection 'clo' (Cloud)
  Menu::CustomLoader.register(
    # Struct.new(:id, :name, :icon, :items, :placement, :before, :type, :href, :parent_id
    Menu::Section.new(:spike3, N_('Nested section after'), 'fa fa-map-pin', [
      Menu::Item.new('plug5', N_('Test item'), 'miq_report', {:feature => 'miq_report', :any => true}, '/demo')
    ], :default, :clo, :default, nil, :compute)
  )
end
@martinpovolny martinpovolny changed the title [WIP] Menu pluggability improvements Menu pluggability improvements Mar 1, 2018
@martinpovolny martinpovolny removed the wip label Mar 1, 2018
@martinpovolny
Copy link
Author

@ZitaNemeckova, @himdel : added the specs.

Should be good to merge.

I can change the interface to work with hashes (to have named arguments) but it can by also done in a separate PR.

@himdel
Copy link
Contributor

himdel commented Mar 1, 2018

LGTM 👍 (except for the failing spec :P)

@martinpovolny martinpovolny force-pushed the menu_plug branch 2 times, most recently from ac190d5 to a727485 Compare March 1, 2018 13:10
@miq-bot
Copy link
Member

miq-bot commented Mar 1, 2018

Checked commits martinpovolny/manageiq-ui-classic@928f093~...01fffca with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0
5 files checked, 6 offenses detected

spec/presenters/menu/custom_loader_spec.rb

  • ❗ - Line 12, Col 11 - Layout/IndentArray - Use 2 spaces for indentation in an array, relative to the first position after the preceding left parenthesis.
  • ❗ - Line 14, Col 9 - Layout/IndentArray - Indent the right bracket the same as the first position after the preceding left parenthesis.
  • ❗ - Line 36, Col 11 - Layout/IndentArray - Use 2 spaces for indentation in an array, relative to the first position after the preceding left parenthesis.
  • ❗ - Line 37, Col 9 - Layout/IndentArray - Indent the right bracket the same as the first position after the preceding left parenthesis.
  • ❗ - Line 53, Col 11 - Layout/IndentArray - Use 2 spaces for indentation in an array, relative to the first position after the preceding left parenthesis.
  • ❗ - Line 54, Col 9 - Layout/IndentArray - Indent the right bracket the same as the first position after the preceding left parenthesis.

@himdel
Copy link
Contributor

himdel commented Mar 1, 2018

Tested with https://github.com/priley86/miq_v2v_ui_plugin/pull/48, works just fine 👍

@himdel
Copy link
Contributor

himdel commented May 20, 2018

#3963: Together with #3683, fixes menu for v2v in gaprindashvili. Then #3726 is needed to fix a bug here.

Fixes:

        Menu::Manager::InvalidMenuDefinition (Invalid parent):
        plugins/manageiq-ui-classic/app/presenters/menu/manager.rb:91:in `block in merge_items'
        plugins/manageiq-ui-classic/app/presenters/menu/manager.rb:90:in `each'
        plugins/manageiq-ui-classic/app/presenters/menu/manager.rb:90:in `merge_items'
        plugins/manageiq-ui-classic/app/presenters/menu/manager.rb:101:in `load_custom_items'
        plugins/manageiq-ui-classic/app/presenters/menu/manager.rb:71:in `initialize'
        ...
        /home/himdel/.rbenv/versions/2.4.2/lib/ruby/2.4.0/forwardable.rb:223:in `section'
        plugins/manageiq-ui-classic/app/controllers/application_controller.rb:1908:in `remember_tab'
        plugins/manageiq-ui-classic/app/controllers/application_controller.rb:1901:in `handle_remember_tab'
        plugins/manageiq-ui-classic/app/controllers/application_controller.rb:1952:in `get_global_session_data'

@himdel himdel added the v2v label May 28, 2018
simaishi pushed a commit that referenced this pull request May 31, 2018
Menu pluggability improvements
(cherry picked from commit 19b59d9)
@simaishi
Copy link
Contributor

Gaprindashvili backport details:

$ git log -1
commit 99b027b903527a71975e25fbcd7ed7a4a823aaf4
Author: Martin Hradil <himdel@seznam.cz>
Date:   Thu Mar 1 16:38:03 2018 +0000

    Merge pull request #3347 from martinpovolny/menu_plug
    
    Menu pluggability improvements
    (cherry picked from commit 19b59d9bbca7cd07fb91c97f0d0ba318f1b9fb55)

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.

None yet

4 participants