Skip to content

Commit

Permalink
Refactor TUIModel
Browse files Browse the repository at this point in the history
Get rid of the internals in Config and move everything to TUIModel.
  • Loading branch information
grisu48 committed Dec 16, 2024
1 parent d9863be commit 6ae9f47
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 234 deletions.
23 changes: 0 additions & 23 deletions cmd/openqa-revtui/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"strings"

"github.com/BurntSushi/toml"
"github.com/os-autoinst/gopenqa"
)

/* Group is a single configurable monitoring unit. A group contains all parameters that will be queried from openQA */
Expand All @@ -29,17 +28,8 @@ type Config struct {
MaxJobs int // Maximum number of jobs per group to consider
GroupBy string // Display group mode: "none", "groups"
RequestJobLimit int // Maximum number of jobs in a single request

// Internal settings
jobGroups map[int]gopenqa.JobGroup // Fetched JobGroup instances from openQA
jobs []gopenqa.Job // Fetched jobs for this config
knownJobs []gopenqa.Job // Known jobs for this configuration
instance *gopenqa.Instance // openQA instance for this config
}

var cfs []Config // All available configurations
var cfi int // Current configuration

func (cf Config) Validate() error {
if len(cf.Groups) == 0 {
return fmt.Errorf("no review groups defined")
Expand Down Expand Up @@ -92,16 +82,3 @@ func CreateConfig() Config {
cf.RequestJobLimit = 100
return cf
}

/** Try to update the job with the given status, if present. Returns the found job and true if the job was present */
func (cf *Config) UpdateJobStatus(status gopenqa.JobStatus) (gopenqa.Job, bool) {
var job gopenqa.Job
for i, j := range cf.knownJobs {
if j.ID == status.ID {
cf.knownJobs[i].State = "done"
cf.knownJobs[i].Result = fmt.Sprintf("%s", status.Result)
return cf.knownJobs[i], true
}
}
return job, false
}
Loading

0 comments on commit 6ae9f47

Please sign in to comment.