ba36814d8d
Added Basic IP Search. Added more items to .gitignore Add a VSCode settings file. Refactored the theme system to allow me to add a per-user theme switcher in the following commit. Fixed h1s, rowmenus, profiles and the Control Panel Dashboard on Tempra Simple. We now catch more extreme edge case errors. Renamed route_panel_themes_default to route_panel_themes_set_default. Centralised some of the per-route ExtData fields. Added an ExtData field to headerLite. Moved SettingLabels into the Phrase System.
105 lines
1.8 KiB
Go
105 lines
1.8 KiB
Go
/* Copyright Azareal 2017 - 2018 */
|
|
package main
|
|
|
|
import "log"
|
|
import "bytes"
|
|
import "sync"
|
|
import "encoding/json"
|
|
|
|
//import "html/template"
|
|
|
|
var docks WidgetDocks
|
|
var widgetUpdateMutex sync.RWMutex
|
|
|
|
type WidgetDocks struct {
|
|
LeftSidebar []Widget
|
|
RightSidebar []Widget
|
|
//PanelLeft []Menus
|
|
}
|
|
|
|
type Widget struct {
|
|
Enabled bool
|
|
Location string // Coming Soon: overview, topics, topic / topic_view, forums, forum, global
|
|
Position int
|
|
Body string
|
|
}
|
|
|
|
type WidgetMenu struct {
|
|
Name string
|
|
MenuList []WidgetMenuItem
|
|
}
|
|
|
|
type WidgetMenuItem struct {
|
|
Text string
|
|
Location string
|
|
Compact bool
|
|
}
|
|
|
|
type NameTextPair struct {
|
|
Name string
|
|
Text string
|
|
}
|
|
|
|
func initWidgets() error {
|
|
rows, err := get_widgets_stmt.Query()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer rows.Close()
|
|
|
|
var sbytes []byte
|
|
var side, wtype, data string
|
|
|
|
var leftWidgets []Widget
|
|
var rightWidgets []Widget
|
|
|
|
for rows.Next() {
|
|
var widget Widget
|
|
err = rows.Scan(&widget.Position, &side, &wtype, &widget.Enabled, &widget.Location, &data)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
sbytes = []byte(data)
|
|
switch wtype {
|
|
case "simple":
|
|
var tmp NameTextPair
|
|
err = json.Unmarshal(sbytes, &tmp)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var b bytes.Buffer
|
|
err = templates.ExecuteTemplate(&b, "widget_simple.html", tmp)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
widget.Body = string(b.Bytes())
|
|
default:
|
|
widget.Body = data
|
|
}
|
|
|
|
if side == "left" {
|
|
leftWidgets = append(leftWidgets, widget)
|
|
} else if side == "right" {
|
|
rightWidgets = append(rightWidgets, widget)
|
|
}
|
|
}
|
|
err = rows.Err()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
widgetUpdateMutex.Lock()
|
|
docks.LeftSidebar = leftWidgets
|
|
docks.RightSidebar = rightWidgets
|
|
widgetUpdateMutex.Unlock()
|
|
|
|
if dev.SuperDebug {
|
|
log.Print("docks.LeftSidebar", docks.LeftSidebar)
|
|
log.Print("docks.RightSidebar", docks.RightSidebar)
|
|
}
|
|
|
|
return nil
|
|
}
|