FilterNodes filters the nodes based on the given search string.
(filter string)
| 109 | |
| 110 | // FilterNodes filters the nodes based on the given search string. |
| 111 | func FilterNodes(filter string) { |
| 112 | if filter == "" { |
| 113 | // No filter, use all nodes |
| 114 | GlobalState.FilteredNodes = make([]*api.Node, len(GlobalState.OriginalNodes)) |
| 115 | copy(GlobalState.FilteredNodes, GlobalState.OriginalNodes) |
| 116 | |
| 117 | return |
| 118 | } |
| 119 | |
| 120 | // Convert filter to lowercase for case-insensitive search |
| 121 | filter = strings.ToLower(filter) |
| 122 | |
| 123 | // Create a new filtered list |
| 124 | GlobalState.FilteredNodes = make([]*api.Node, 0) |
| 125 | |
| 126 | // Add nodes that match the filter |
| 127 | for _, node := range GlobalState.OriginalNodes { |
| 128 | if node == nil { |
| 129 | continue |
| 130 | } |
| 131 | |
| 132 | // Check node name |
| 133 | if strings.Contains(strings.ToLower(node.Name), filter) { |
| 134 | GlobalState.FilteredNodes = append(GlobalState.FilteredNodes, node) |
| 135 | |
| 136 | continue |
| 137 | } |
| 138 | |
| 139 | // Check node IP |
| 140 | if strings.Contains(strings.ToLower(node.IP), filter) { |
| 141 | GlobalState.FilteredNodes = append(GlobalState.FilteredNodes, node) |
| 142 | |
| 143 | continue |
| 144 | } |
| 145 | |
| 146 | // Check node status (using online status instead) |
| 147 | statusText := "offline" |
| 148 | if node.Online { |
| 149 | statusText = "online" |
| 150 | } |
| 151 | |
| 152 | if strings.Contains(statusText, filter) { |
| 153 | GlobalState.FilteredNodes = append(GlobalState.FilteredNodes, node) |
| 154 | |
| 155 | continue |
| 156 | } |
| 157 | } |
| 158 | // GetUILogger().Debug("Filtered nodes from %d to %d with filter '%s'", |
| 159 | // |
| 160 | // len(GlobalState.OriginalNodes), len(GlobalState.FilteredNodes), filter) |
| 161 | } |
| 162 | |
| 163 | // FilterVMs filters the VMs based on the given search string. |
| 164 | func FilterVMs(filter string) { |
no outgoing calls
no test coverage detected