mirror of
https://github.com/RWejlgaard/org.git
synced 2026-09-02 01:15:35 +00:00
add findState() helper
This commit is contained in:
parent
98a55ce534
commit
486c9f4bb2
1 changed files with 22 additions and 19 deletions
|
|
@ -475,12 +475,22 @@ func (c *Config) UpdateTagColor(name, color string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// findState returns a pointer to the state with the given name, or nil if no
|
||||||
|
// such state is configured. The pointer aliases the backing slice, so callers
|
||||||
|
// may mutate the state in place.
|
||||||
|
func (c *Config) findState(name string) *StateConfig {
|
||||||
|
for i := range c.States.States {
|
||||||
|
if c.States.States[i].Name == name {
|
||||||
|
return &c.States.States[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetStateColor returns the color for a given state name
|
// GetStateColor returns the color for a given state name
|
||||||
func (c *Config) GetStateColor(stateName string) string {
|
func (c *Config) GetStateColor(stateName string) string {
|
||||||
for _, state := range c.States.States {
|
if state := c.findState(stateName); state != nil {
|
||||||
if state.Name == stateName {
|
return state.Color
|
||||||
return state.Color
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Return a default color if state not found
|
// Return a default color if state not found
|
||||||
return "99"
|
return "99"
|
||||||
|
|
@ -489,12 +499,10 @@ func (c *Config) GetStateColor(stateName string) string {
|
||||||
// AddState adds (or upgrades) a state in the configuration, marking it as a
|
// AddState adds (or upgrades) a state in the configuration, marking it as a
|
||||||
// done state when done is true.
|
// done state when done is true.
|
||||||
func (c *Config) AddState(name, color string, done bool) {
|
func (c *Config) AddState(name, color string, done bool) {
|
||||||
for i := range c.States.States {
|
if state := c.findState(name); state != nil {
|
||||||
if c.States.States[i].Name == name {
|
state.Color = color
|
||||||
c.States.States[i].Color = color
|
state.Done = done
|
||||||
c.States.States[i].Done = done
|
return
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
c.States.States = append(c.States.States, StateConfig{Name: name, Color: color, Done: done})
|
c.States.States = append(c.States.States, StateConfig{Name: name, Color: color, Done: done})
|
||||||
}
|
}
|
||||||
|
|
@ -511,11 +519,8 @@ func (c *Config) RemoveState(name string) {
|
||||||
|
|
||||||
// UpdateStateColor updates the color of an existing state
|
// UpdateStateColor updates the color of an existing state
|
||||||
func (c *Config) UpdateStateColor(name, color string) {
|
func (c *Config) UpdateStateColor(name, color string) {
|
||||||
for i, state := range c.States.States {
|
if state := c.findState(name); state != nil {
|
||||||
if state.Name == name {
|
state.Color = color
|
||||||
c.States.States[i].Color = color
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -533,10 +538,8 @@ func (c *Config) IsDoneState(name string) bool {
|
||||||
if name == "" {
|
if name == "" {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for _, state := range c.States.States {
|
if state := c.findState(name); state != nil {
|
||||||
if state.Name == name {
|
return state.Done
|
||||||
return state.Done
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue