-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5617 from martinpovolny/menu_settings
Menu item adding through settings
- Loading branch information
Showing
10 changed files
with
141 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module Menu | ||
class SettingsLoader < YamlLoader | ||
include Singleton | ||
include Vmdb::Logging | ||
|
||
def self.load | ||
instance.load_from_settings | ||
end | ||
|
||
def load_from_settings | ||
begin | ||
settings = ::Settings.ui.custom_menu | ||
items = (settings || []).map { |i| create_custom_item(HashWithIndifferentAccess.new(i)) } | ||
rescue StandardError => e | ||
# if we encounter an error while loading the menus, we ignore the whole settings | ||
_log.error("Error loading custom menu from settings: #{e}") | ||
_log.error("Settings were: #{settings}") | ||
return [[], []] | ||
end | ||
[[], items] | ||
end | ||
|
||
private | ||
|
||
def create_custom_item(item) | ||
# only alow: | ||
# * items, | ||
# * displayed in the iframe, | ||
# * and at the top menu level. | ||
create_custom_menu_item( | ||
item.merge( | ||
'type' => 'items', | ||
'item_type' => 'big_iframe', | ||
'parent' => nil | ||
) | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
:ui: | ||
:custom_menu: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
describe Menu::SettingsLoader do | ||
include Spec::Support::MenuHelper | ||
it "loads custom menu items" do | ||
::Settings.ui.custom_menu = settings_custom_items | ||
sections, items = described_class.load | ||
|
||
expect(sections.length).to be(0) | ||
expect(items.length).to be(2) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters