gosora/widgets.go
Azareal d976a192fb Added the new theme, Shadow. It still isn't complete yet.
Revamped the configuration system.
If you have trouble installing this, try installing my fork of gopsutil with `go get` and delete the users_penalties table from the schema folder. That stuff will be cleaned up in the next commit.

Fixed an issue with the links for the Uncategorised forum being broken.
Swapped out NOW() for UTC_TIMESTAMP() in MySQL queries.
We now get an error message when the server goes down for whatever reason.
The template compiler now supports pointers.
Swapped out shirou/gopsutil for a fork locked on an older and more stable commit of the same library.
Fixed a bug where the preprocessor didn't play nice with empty CSS files.

Added the site name to the navbar.
Added more things to .gitignore
Laid the foundations for the next commit.
2017-07-17 11:23:42 +01:00

109 lines
1.9 KiB
Go

/* Copyright Azareal 2017 - 2018 */
package main
import "fmt"
import "bytes"
import "sync"
import "encoding/json"
//import "html/template"
var docks WidgetDocks
var widget_update_mutex 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 init_widgets() 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
}
widget_update_mutex.Lock()
docks.LeftSidebar = leftWidgets
docks.RightSidebar = rightWidgets
widget_update_mutex.Unlock()
if dev.SuperDebug {
fmt.Println("docks.LeftSidebar",docks.LeftSidebar)
fmt.Println("docks.RightSidebar",docks.RightSidebar)
}
return nil
}