added default settings

This commit is contained in:
sqshq 2019-01-31 19:02:34 -05:00
parent 843375bc14
commit ec79619f38
4 changed files with 58 additions and 28 deletions

View File

@ -10,7 +10,6 @@ run-charts:
script: curl -o /dev/null -s -w '%{time_total}' http://example.com
refresh-rate-ms: 300
time-scale-sec: 1
style: dots/lines
position:
x: 0
y: 0
@ -22,8 +21,6 @@ run-charts:
- label: posts
script: mongo --quiet --host=localhost blog --eval "db.getCollection('post').find({}).size()" | grep 2
color: 3
refresh-rate-ms: 200
time-scale-sec: 1
position:
x: 15
y: 0

View File

@ -26,8 +26,10 @@ type RunChart struct {
func Load(location string) *Config {
cfg := readFile(location)
validate(cfg)
setColors(cfg)
cfg.validate()
cfg.setDefaultValues()
cfg.setDefaultColors()
cfg.setDefaultLayout()
return cfg
}
@ -48,26 +50,3 @@ func readFile(location string) *Config {
return cfg
}
/*
TODO validation
- title uniquness and mandatory within a single type of widget
- label uniqueness and mandatory (if > 1 data bullets)
*/
func validate(config *Config) {
}
func setColors(config *Config) {
palette := settings.GetPalette(config.Theme)
for i, chart := range config.RunCharts {
for j, item := range chart.Items {
if item.Color == 0 {
item.Color = palette.Colors[i+j]
chart.Items[j] = item
}
}
}
}

44
config/default.go Normal file
View File

@ -0,0 +1,44 @@
package config
import "github.com/sqshq/vcmd/settings"
const (
defaultRefreshRateMs = 300
defaultTimeScaleSec = 1
defaultTheme = settings.ThemeDark
)
func (self *Config) setDefaultValues() {
if len(self.Theme) == 0 {
self.Theme = defaultTheme
}
for i, chart := range self.RunCharts {
if chart.RefreshRateMs == 0 {
chart.RefreshRateMs = defaultRefreshRateMs
}
if chart.TimeScaleSec == 0 {
chart.TimeScaleSec = defaultTimeScaleSec
}
self.RunCharts[i] = chart
}
}
func (config *Config) setDefaultLayout() {
}
func (config *Config) setDefaultColors() {
palette := settings.GetPalette(config.Theme)
for i, chart := range config.RunCharts {
for j, item := range chart.Items {
if item.Color == 0 {
item.Color = palette.Colors[i+j]
chart.Items[j] = item
}
}
}
}

10
config/validator.go Normal file
View File

@ -0,0 +1,10 @@
package config
/*
TODO validation
- title uniquness and mandatory within a single type of widget
- label uniqueness and mandatory (if > 1 data bullets)
*/
func (self *Config) validate() {
}