Merge branch 'split-dbs'

This commit is contained in:
Brian Buller 2017-10-03 09:03:07 -05:00
commit 7fc7d023ec
5 changed files with 112 additions and 2 deletions

4
.gitignore vendored
View File

@ -7,5 +7,5 @@ gjvote.linuxarm
gjvote.win386.exe
gjvote.win64.exe
# Ignore the DB
gjvote.db
# Ignore the DBs
*.db

20
admin_archive.go Normal file
View File

@ -0,0 +1,20 @@
package main
import (
"net/http"
"github.com/gorilla/mux"
)
func handleAdminArchive(w http.ResponseWriter, req *http.Request, page *pageData) {
vars := mux.Vars(req)
page.SubTitle = "GameJam Archive"
id := vars["id"]
if id == "" {
// Archive List
type archivePageData struct {
Gamejams []Gamejam
}
apd := new(archivePageData)
}
}

View File

@ -47,6 +47,8 @@ func handleAdmin(w http.ResponseWriter, req *http.Request) {
handleAdminSetMode(w, req, page)
case "authmode":
handleAdminSetAuthMode(w, req, page)
case "archive":
handleAdminArchive(w, req, page)
default:
page.TemplateData = getCondorcetResult()
page.show("admin-main.html", w)

View File

@ -251,6 +251,7 @@ func InitPageData(w http.ResponseWriter, req *http.Request) *pageData {
p.Menu = append(p.Menu, menuItem{"Teams", "/admin/teams", "fa-users"})
p.Menu = append(p.Menu, menuItem{"Games", "/admin/games", "fa-gamepad"})
p.Menu = append(p.Menu, menuItem{"Votes", "/admin/votes", "fa-sticky-note"})
p.Menu = append(p.Menu, menuItem{"Archive", "/admin/archive", "fa-archive"})
p.Menu = append(p.Menu, menuItem{"Clients", "/admin/clients", "fa-desktop"})
p.BottomMenu = append(p.BottomMenu, menuItem{"Users", "/admin/users", "fa-user"})

87
model_gamejam.go Normal file
View File

@ -0,0 +1,87 @@
package main
import (
"time"
"github.com/br0xen/boltease"
)
// Gamejam is specifically for an archived game jam
type Gamejam struct {
UUID string
Name string
Date time.Time
Teams []Team
Votes []Vote
db *boltease.DB
dbOpened int
}
// Archived Gamejam data is stored in it's own file to keep things nice and organized
func (gj *Gamejam) openDB() error {
gj.dbOpened += 1
if gj.dbOpened == 1 {
var err error
gj.db, err = boltease.Create(gj.UUID+".db", 0600, nil)
if err != nil {
return err
}
}
return nil
}
func (gj *Gamejam) closeDB() error {
gj.dbOpened -= 1
if gj.dbOpened == 0 {
return gj.db.CloseDB()
}
return nil
}
// archiveGameJam creates a separate gamejam file and populates it with the
// given name, teams, and votes
func archiveGamejam(nm string, teams []Team, votes []Vote) error {
// TODO
return nil
}
// dbGetGamejam returns a gamejam with the given uuid
// or nil if it couldn't be found
func dbGetGamejam(id string) *Gamejam {
var err error
if err = openDatabase(); err != nil {
return nil
}
defer closeDatabase()
ret := Gamejam{UUID: id}
// TODO: Load gamejam teams, other details
return ret
}
// dbGetGamejamByName looks for a gamejam with the given name
// and returns it, or it returns nil if it couldn't find it
func dbGetGamejamByName(nm string) *Gamejam {
var err error
if err = openDatabase(); err != nil {
return err
}
defer closeDatabase()
var gjid string
if gjs, err = db.GetBucketList([]string{"gamejams"}); err == nil {
for _, v := range gjUids {
tstNm, _ := db.GetValue([]string{"gamejams", v}, "name")
if tstNm == nm {
// We've got it
gjid = v
break
}
}
}
if gjid == "" {
return nil
}
return dbGetGamejam(gjid)
}