Class: Aidp::Harness::UI::Navigation::SubMenu

Inherits:
MainMenu
  • Object
show all
Defined in:
lib/aidp/harness/ui/navigation/submenu.rb

Overview

Specialized submenu for drill-down functionality

Defined Under Namespace

Classes: InvalidSubMenuError, SubMenuError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from MainMenu

#add_menu_item, #add_menu_items, #at_root?, #can_navigate_back?, #clear_navigation_history, #current_path, #current_section, #display_breadcrumb, #display_menu, #display_navigation_help, #get_breadcrumb_path, #get_navigation_history, #get_user_input, #go_back, #menu_depth, #navigate_back, #navigate_to, #navigate_to_root, #navigate_to_submenu, #navigation_depth, #select_option, #show_menu

Constructor Details

#initialize(title, parent_menu = nil, ui_components = {}) ⇒ SubMenu

Returns a new instance of SubMenu.



15
16
17
18
19
20
21
22
23
# File 'lib/aidp/harness/ui/navigation/submenu.rb', line 15

def initialize(title, parent_menu = nil, ui_components = {})
  super(ui_components)
  @title = title
  @parent_menu = parent_menu
  @ui_components = ui_components
  @submenu_items = []
  @drill_down_enabled = true
  @max_depth = 5
end

Instance Attribute Details

#drill_down_enabledObject

Returns the value of attribute drill_down_enabled.



26
27
28
# File 'lib/aidp/harness/ui/navigation/submenu.rb', line 26

def drill_down_enabled
  @drill_down_enabled
end

#max_depthObject

Returns the value of attribute max_depth.



26
27
28
# File 'lib/aidp/harness/ui/navigation/submenu.rb', line 26

def max_depth
  @max_depth
end

#parent_menuObject (readonly)

Returns the value of attribute parent_menu.



25
26
27
# File 'lib/aidp/harness/ui/navigation/submenu.rb', line 25

def parent_menu
  @parent_menu
end

#titleObject (readonly)

Returns the value of attribute title.



25
26
27
# File 'lib/aidp/harness/ui/navigation/submenu.rb', line 25

def title
  @title
end

Instance Method Details

#add_submenu_item(item) ⇒ Object



28
29
30
31
32
# File 'lib/aidp/harness/ui/navigation/submenu.rb', line 28

def add_submenu_item(item)
  validate_submenu_item(item)
  @submenu_items << item
  add_menu_item(item)
end

#add_submenu_items(items) ⇒ Object



34
35
36
37
# File 'lib/aidp/harness/ui/navigation/submenu.rb', line 34

def add_submenu_items(items)
  validate_submenu_items(items)
  items.each { |item| add_submenu_item(item) }
end

#can_show_submenu?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/aidp/harness/ui/navigation/submenu.rb', line 49

def can_show_submenu?
  @drill_down_enabled && @submenu_items.any? && within_depth_limit?
end

#create_child_submenu(title) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/aidp/harness/ui/navigation/submenu.rb', line 81

def create_child_submenu(title)
  validate_title(title)
  raise InvalidSubMenuError, "Maximum depth reached" unless within_depth_limit?

  child_submenu = SubMenu.new(title, self, @ui_components)
  child_submenu.max_depth = @max_depth
  child_submenu
end

#get_full_pathObject



75
76
77
78
79
# File 'lib/aidp/harness/ui/navigation/submenu.rb', line 75

def get_full_path
  parent_path = get_parent_path
  parent_path << @title
  parent_path
end

#get_parent_pathObject



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/aidp/harness/ui/navigation/submenu.rb', line 61

def get_parent_path
  return [] unless has_parent?

  path = [@title]
  current_parent = @parent_menu

  while current_parent&.parent_menu
    path.unshift(current_parent.title)
    current_parent = current_parent.parent_menu
  end

  path
end

#has_parent?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/aidp/harness/ui/navigation/submenu.rb', line 57

def has_parent?
  !@parent_menu.nil?
end


90
91
92
93
94
95
# File 'lib/aidp/harness/ui/navigation/submenu.rb', line 90

def navigate_to_parent
  return false unless has_parent?

  @parent_menu.show_menu(@parent_menu.title)
  true
end

#show_submenuObject



39
40
41
42
43
44
45
46
47
# File 'lib/aidp/harness/ui/navigation/submenu.rb', line 39

def show_submenu
  return unless can_show_submenu?

  display_submenu_header
  display_submenu_items
  handle_submenu_interaction
rescue => e
  raise SubMenuError, "Failed to show submenu: #{e.message}"
end

#within_depth_limit?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/aidp/harness/ui/navigation/submenu.rb', line 53

def within_depth_limit?
  @current_level < @max_depth
end