showAdvancedGuestFilterModal displays structured filters for the Guests page.
()
| 271 | |
| 272 | // showAdvancedGuestFilterModal displays structured filters for the Guests page. |
| 273 | func (a *App) showAdvancedGuestFilterModal() { |
| 274 | currentPage, _ := a.pages.GetFrontPage() |
| 275 | if currentPage != api.PageGuests { |
| 276 | return |
| 277 | } |
| 278 | |
| 279 | state, exists := models.GlobalState.SearchStates[api.PageGuests] |
| 280 | if !exists { |
| 281 | state = &models.SearchState{CurrentPage: api.PageGuests} |
| 282 | models.GlobalState.SearchStates[api.PageGuests] = state |
| 283 | } |
| 284 | |
| 285 | statusOptions := append([]string{"Any"}, uniqueSortedVMStatuses(models.GlobalState.OriginalVMs)...) |
| 286 | typeOptions := []string{"Any", api.VMTypeQemu, api.VMTypeLXC} |
| 287 | nodeOptions := append([]string{"Any"}, uniqueSortedVMNodes(models.GlobalState.OriginalVMs)...) |
| 288 | |
| 289 | form := newStandardForm() |
| 290 | form.SetBorder(true) |
| 291 | form.SetTitle(" Advanced Guest Filter ") |
| 292 | |
| 293 | form.AddInputField("Query", state.Filter, 0, nil, nil) |
| 294 | form.AddDropDown("Status", statusOptions, indexOfOption(statusOptions, state.VMFilters.Status), nil) |
| 295 | form.AddDropDown("Type", typeOptions, indexOfOption(typeOptions, state.VMFilters.Type), nil) |
| 296 | form.AddDropDown("Node", nodeOptions, indexOfOption(nodeOptions, state.VMFilters.Node), nil) |
| 297 | form.AddInputField("Tag Contains", state.VMFilters.TagContains, 0, nil, nil) |
| 298 | |
| 299 | form.AddButton("Apply", func() { |
| 300 | query := strings.TrimSpace(form.GetFormItemByLabel("Query").(*tview.InputField).GetText()) |
| 301 | state.Filter = query |
| 302 | |
| 303 | _, selectedStatus := form.GetFormItemByLabel("Status").(*tview.DropDown).GetCurrentOption() |
| 304 | if strings.EqualFold(selectedStatus, "Any") { |
| 305 | selectedStatus = "" |
| 306 | } |
| 307 | |
| 308 | _, selectedType := form.GetFormItemByLabel("Type").(*tview.DropDown).GetCurrentOption() |
| 309 | if strings.EqualFold(selectedType, "Any") { |
| 310 | selectedType = "" |
| 311 | } |
| 312 | |
| 313 | _, selectedNode := form.GetFormItemByLabel("Node").(*tview.DropDown).GetCurrentOption() |
| 314 | if strings.EqualFold(selectedNode, "Any") { |
| 315 | selectedNode = "" |
| 316 | } |
| 317 | |
| 318 | tagContains := strings.TrimSpace(form.GetFormItemByLabel("Tag Contains").(*tview.InputField).GetText()) |
| 319 | |
| 320 | state.VMFilters = models.VMFilterOptions{ |
| 321 | Status: selectedStatus, |
| 322 | Type: selectedType, |
| 323 | Node: selectedNode, |
| 324 | TagContains: tagContains, |
| 325 | } |
| 326 | state.SelectedIndex = 0 |
| 327 | |
| 328 | models.FilterVMs(state.Filter) |
| 329 | a.refreshVMSelection(api.PageGuests) |
| 330 | a.removePageIfPresent("advancedGuestFilter") |
no test coverage detected