nodes: 0, module; 1, function_definition; 2, function_name:add_item; 3, parameters; 4, block; 5, identifier:self; 6, identifier:path; 7, identifier:name; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, expression_statement; 14, if_statement; 15, expression_statement; 16, expression_statement; 17, for_statement; 18, expression_statement; 19, expression_statement; 20, if_statement; 21, identifier:icon; 22, None; 23, identifier:url; 24, None; 25, identifier:order; 26, None; 27, identifier:permission; 28, None; 29, identifier:active_regex; 30, None; 31, comment:"""
          Add new menu item to menu
  
          :param path: Path of menu
          :param name: Display name
          :param icon: CSS icon
          :param url: link to page
          :param order: Sort order
          :param permission:
          :return:
          """; 32, comparison_operator:self.root_item is None; 33, block; 34, assignment; 35, assignment; 36, identifier:node; 37, subscript; 38, block; 39, assignment; 40, assignment; 41, identifier:current_item; 42, block; 43, else_clause; 44, attribute; 45, None; 46, expression_statement; 47, identifier:root_item; 48, attribute; 49, identifier:current_path; 50, string; 51, call; 52, slice; 53, if_statement; 54, expression_statement; 55, expression_statement; 56, if_statement; 57, expression_statement; 58, identifier:new_item; 59, call; 60, identifier:current_item; 61, call; 62, expression_statement; 63, block; 64, identifier:self; 65, identifier:root_item; 66, assignment; 67, identifier:self; 68, identifier:root_item; 69, attribute; 70, argument_list; 71, unary_operator; 72, not_operator; 73, block; 74, assignment; 75, assignment; 76, not_operator; 77, comment:# Create menu item if not exists; 78, block; 79, assignment; 80, identifier:MenuItem; 81, argument_list; 82, attribute; 83, argument_list; 84, call; 85, expression_statement; 86, attribute; 87, call; 88, identifier:path; 89, identifier:split; 90, string; 91, integer:1; 92, identifier:node; 93, continue_statement; 94, identifier:current_path; 95, binary_operator:'/' + '{}/{}'.format(current_path, node).strip('/'); 96, identifier:new_root; 97, call; 98, identifier:new_root; 99, expression_statement; 100, expression_statement; 101, identifier:root_item; 102, identifier:new_root; 103, identifier:path; 104, identifier:name; 105, identifier:icon; 106, identifier:url; 107, identifier:order; 108, identifier:permission; 109, identifier:active_regex; 110, identifier:root_item; 111, identifier:child_by_code; 112, subscript; 113, attribute; 114, argument_list; 115, call; 116, identifier:self; 117, identifier:root_item; 118, identifier:MenuItem; 119, argument_list; 120, string_content:/; 121, string; 122, call; 123, attribute; 124, argument_list; 125, assignment; 126, call; 127, call; 128, unary_operator; 129, identifier:current_item; 130, identifier:merge; 131, identifier:new_item; 132, attribute; 133, argument_list; 134, string; 135, string; 136, string_content:/; 137, attribute; 138, argument_list; 139, identifier:root_item; 140, identifier:child_by_code; 141, identifier:node; 142, identifier:new_root; 143, call; 144, attribute; 145, argument_list; 146, attribute; 147, argument_list; 148, integer:1; 149, identifier:root_item; 150, identifier:add_child; 151, identifier:new_item; 152, string_content:ROOT; 153, string_content:ROOT; 154, call; 155, identifier:strip; 156, string; 157, identifier:MenuItem; 158, argument_list; 159, identifier:root_item; 160, identifier:add_child; 161, identifier:new_root; 162, identifier:path; 163, identifier:split; 164, string; 165, attribute; 166, argument_list; 167, string_content:/; 168, identifier:current_path; 169, keyword_argument; 170, string_content:/; 171, string; 172, identifier:format; 173, identifier:current_path; 174, identifier:node; 175, identifier:name; 176, call; 177, string_content:{}/{}; 178, attribute; 179, argument_list; 180, call; 181, identifier:capitalize; 182, identifier:str; 183, argument_list; 184, identifier:node
code: def add_item(self, path, name, icon=None, url=None, order=None, permission=None, active_regex=None):
          """
          Add new menu item to menu
  
          :param path: Path of menu
          :param name: Display name
          :param icon: CSS icon
          :param url: link to page
          :param order: Sort order
          :param permission:
          :return:
          """
          if self.root_item is None:
              self.root_item = MenuItem('ROOT', 'ROOT')
  
          root_item = self.root_item
          current_path = ''
          for node in path.split('/')[:-1]:
              if not node:
                  continue
  
              current_path = '/' + '{}/{}'.format(current_path, node).strip('/')
              new_root = root_item.child_by_code(node)
              if not new_root:  # Create menu item if not exists
                  new_root = MenuItem(current_path, name=str(node).capitalize())
                  root_item.add_child(new_root)
              root_item = new_root
  
          new_item = MenuItem(path, name, icon, url, order, permission, active_regex)
  
          current_item = root_item.child_by_code(path.split('/')[-1])
          if current_item:
              current_item.merge(new_item)
          else:
              root_item.add_child(new_item)