bf851bd9fc
Added support for dyntmpl to the template system. The Account Dashboard now sort of uses dyntmpl, more work needed here. Renamed the pre_render_view_topic hook to pre_render_topic. Added the GetCurrentLangPack() function. Added the alerts_no_new_alerts phrase. Added the account_level_list phrase. Refactored the route rename logic in the patcher to cut down on the amount of boilerplate. Added more route renames to the patcher. You will need to run the patcher / updater in this commit.
76 lines
2.0 KiB
Go
76 lines
2.0 KiB
Go
package common
|
|
|
|
import (
|
|
"database/sql"
|
|
"strconv"
|
|
"sync/atomic"
|
|
|
|
"github.com/Azareal/Gosora/query_gen"
|
|
)
|
|
|
|
var Menus *DefaultMenuStore
|
|
|
|
type DefaultMenuStore struct {
|
|
menus map[int]*atomic.Value
|
|
itemStore *DefaultMenuItemStore
|
|
}
|
|
|
|
func NewDefaultMenuStore() *DefaultMenuStore {
|
|
return &DefaultMenuStore{
|
|
make(map[int]*atomic.Value),
|
|
NewDefaultMenuItemStore(),
|
|
}
|
|
}
|
|
|
|
// TODO: Add actual support for multiple menus
|
|
func (store *DefaultMenuStore) GetAllMap() (out map[int]*MenuListHolder) {
|
|
out = make(map[int]*MenuListHolder)
|
|
for mid, atom := range store.menus {
|
|
out[mid] = atom.Load().(*MenuListHolder)
|
|
}
|
|
return out
|
|
}
|
|
|
|
func (store *DefaultMenuStore) Get(mid int) (*MenuListHolder, error) {
|
|
aStore, ok := store.menus[mid]
|
|
if ok {
|
|
return aStore.Load().(*MenuListHolder), nil
|
|
}
|
|
return nil, ErrNoRows
|
|
}
|
|
|
|
func (store *DefaultMenuStore) Items(mid int) (mlist MenuItemList, err error) {
|
|
err = qgen.NewAcc().Select("menu_items").Columns("miid, name, htmlID, cssClass, position, path, aria, tooltip, order, tmplName, guestOnly, memberOnly, staffOnly, adminOnly").Where("mid = " + strconv.Itoa(mid)).Orderby("order ASC").Each(func(rows *sql.Rows) error {
|
|
var mitem = MenuItem{MenuID: mid}
|
|
err := rows.Scan(&mitem.ID, &mitem.Name, &mitem.HTMLID, &mitem.CSSClass, &mitem.Position, &mitem.Path, &mitem.Aria, &mitem.Tooltip, &mitem.Order, &mitem.TmplName, &mitem.GuestOnly, &mitem.MemberOnly, &mitem.SuperModOnly, &mitem.AdminOnly)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store.itemStore.Add(mitem)
|
|
mlist = append(mlist, mitem)
|
|
return nil
|
|
})
|
|
return mlist, err
|
|
}
|
|
|
|
func (store *DefaultMenuStore) Load(mid int) error {
|
|
mlist, err := store.Items(mid)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
hold := &MenuListHolder{mid, mlist, make(map[int]menuTmpl)}
|
|
err = hold.Preparse()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var aStore = &atomic.Value{}
|
|
aStore.Store(hold)
|
|
store.menus[mid] = aStore
|
|
return nil
|
|
}
|
|
|
|
func (store *DefaultMenuStore) ItemStore() *DefaultMenuItemStore {
|
|
return store.itemStore
|
|
}
|