Merge remote-tracking branch 'upstream/dev' into theme_switcher
This commit is contained in:
@@ -18,11 +18,17 @@ import (
|
||||
var widgetIDCounter atomic.Uint64
|
||||
|
||||
func newWidget(widgetType string) (widget, error) {
|
||||
if widgetType == "" {
|
||||
return nil, errors.New("widget 'type' property is empty or not specified")
|
||||
}
|
||||
|
||||
var w widget
|
||||
|
||||
switch widgetType {
|
||||
case "calendar":
|
||||
w = &calendarWidget{}
|
||||
case "calendar-legacy":
|
||||
w = &oldCalendarWidget{}
|
||||
case "clock":
|
||||
w = &clockWidget{}
|
||||
case "weather":
|
||||
@@ -71,6 +77,8 @@ func newWidget(widgetType string) (widget, error) {
|
||||
w = &customAPIWidget{}
|
||||
case "docker-containers":
|
||||
w = &dockerContainersWidget{}
|
||||
case "server-stats":
|
||||
w = &serverStatsWidget{}
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown widget type: %s", widgetType)
|
||||
}
|
||||
@@ -100,7 +108,7 @@ func (w *widgets) UnmarshalYAML(node *yaml.Node) error {
|
||||
|
||||
widget, err := newWidget(meta.Type)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("line %d: %w", node.Line, err)
|
||||
}
|
||||
|
||||
if err = node.Decode(widget); err != nil {
|
||||
@@ -117,13 +125,13 @@ type widget interface {
|
||||
// These need to be exported because they get called in templates
|
||||
Render() template.HTML
|
||||
GetType() string
|
||||
GetID() uint64
|
||||
|
||||
initialize() error
|
||||
requiresUpdate(*time.Time) bool
|
||||
setProviders(*widgetProviders)
|
||||
update(context.Context)
|
||||
setID(uint64)
|
||||
id() uint64
|
||||
handleRequest(w http.ResponseWriter, r *http.Request)
|
||||
setHideHeader(bool)
|
||||
}
|
||||
@@ -145,6 +153,7 @@ type widgetBase struct {
|
||||
CSSClass string `yaml:"css-class"`
|
||||
CustomCacheDuration durationField `yaml:"cache"`
|
||||
ContentAvailable bool `yaml:"-"`
|
||||
WIP bool `yaml:"-"`
|
||||
Error error `yaml:"-"`
|
||||
Notice error `yaml:"-"`
|
||||
templateBuffer bytes.Buffer `yaml:"-"`
|
||||
@@ -171,11 +180,15 @@ func (w *widgetBase) requiresUpdate(now *time.Time) bool {
|
||||
return now.After(w.nextUpdate)
|
||||
}
|
||||
|
||||
func (w *widgetBase) IsWIP() bool {
|
||||
return w.WIP
|
||||
}
|
||||
|
||||
func (w *widgetBase) update(ctx context.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (w *widgetBase) id() uint64 {
|
||||
func (w *widgetBase) GetID() uint64 {
|
||||
return w.ID
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user