MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / FilterVMs

Function FilterVMs

internal/ui/models/state.go:164–262  ·  view source on GitHub ↗

FilterVMs filters the VMs based on the given search string.

(filter string)

Source from the content-addressed store, hash-verified

162
163// FilterVMs filters the VMs based on the given search string.
164func FilterVMs(filter string) {
165 filter = strings.ToLower(strings.TrimSpace(filter))
166
167 vmSearchState := GlobalState.GetSearchState(api.PageGuests)
168 vmFilters := VMFilterOptions{}
169 if vmSearchState != nil {
170 vmFilters = vmSearchState.VMFilters
171 }
172
173 statusFilter := strings.ToLower(strings.TrimSpace(vmFilters.Status))
174 typeFilter := strings.ToLower(strings.TrimSpace(vmFilters.Type))
175 nodeFilter := strings.ToLower(strings.TrimSpace(vmFilters.Node))
176 tagFilter := strings.ToLower(strings.TrimSpace(vmFilters.TagContains))
177
178 if filter == "" && statusFilter == "" && typeFilter == "" && nodeFilter == "" && tagFilter == "" {
179 // No filter, use all VMs
180 GlobalState.FilteredVMs = make([]*api.VM, len(GlobalState.OriginalVMs))
181 copy(GlobalState.FilteredVMs, GlobalState.OriginalVMs)
182
183 return
184 }
185
186 // Create a new filtered list
187 GlobalState.FilteredVMs = make([]*api.VM, 0)
188
189 // Add VMs that match the filter
190 for _, vm := range GlobalState.OriginalVMs {
191 if vm == nil {
192 continue
193 }
194
195 if statusFilter != "" && !strings.EqualFold(vm.Status, statusFilter) {
196 continue
197 }
198
199 if typeFilter != "" && !strings.EqualFold(vm.Type, typeFilter) {
200 continue
201 }
202
203 if nodeFilter != "" && !strings.EqualFold(vm.Node, nodeFilter) {
204 continue
205 }
206
207 if tagFilter != "" && !strings.Contains(strings.ToLower(vm.Tags), tagFilter) {
208 continue
209 }
210
211 if filter != "" {
212 matchesTextFilter := false
213
214 // Check VM name
215 if strings.Contains(strings.ToLower(vm.Name), filter) {
216 matchesTextFilter = true
217 }
218
219 // Check VM ID (convert int to string)
220 if !matchesTextFilter {
221 vmIDStr := fmt.Sprintf("%d", vm.ID)

Callers 11

doManualRefreshMethod · 0.92
doFastRefreshMethod · 0.92
doEnrichNodesMethod · 0.92
doRefreshVMDataMethod · 0.92
autoRefreshDataMethod · 0.92
activateSearchMethod · 0.92
NewAppFunction · 0.92

Calls 1

GetSearchStateMethod · 0.80

Tested by 1