Commit to push to devICT repo
This commit is contained in:
parent
9a77a25342
commit
844b42cc18
@ -1,6 +1,32 @@
|
||||
package main
|
||||
|
||||
import "net/http"
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func handleAdminGames(w http.ResponseWriter, req *http.Request, page *pageData) {
|
||||
vars := mux.Vars(req)
|
||||
page.SubTitle = "Games"
|
||||
gameId := vars["id"]
|
||||
teamId := req.FormValue("teamid")
|
||||
if strings.TrimSpace(teamId) != "" {
|
||||
page.session.setStringValue("teamid", teamId)
|
||||
page.TeamID = teamId
|
||||
}
|
||||
if gameId == "new" {
|
||||
switch vars["function"] {
|
||||
case "save":
|
||||
name := req.FormValue("gamename")
|
||||
if dbIsValidTeam(teamId) {
|
||||
if dbEditTeamGame(teamId, name) != nil {
|
||||
}
|
||||
}
|
||||
default:
|
||||
page.SubTitle = "Add New Game"
|
||||
page.show("admin-addgame.html", w)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ func handleAdminTeams(w http.ResponseWriter, req *http.Request, page *pageData)
|
||||
switch vars["function"] {
|
||||
case "save":
|
||||
name := req.FormValue("teamname")
|
||||
if dbIsValidTeam(name) {
|
||||
if dbGetTeamByName(name) != nil {
|
||||
// A team with that name already exists
|
||||
page.session.setFlashMessage("A team with the name "+name+" already exists!", "error")
|
||||
} else {
|
||||
@ -48,6 +48,8 @@ func handleAdminTeams(w http.ResponseWriter, req *http.Request, page *pageData)
|
||||
page.session.setFlashMessage("Error deleting team: "+err.Error(), "error")
|
||||
}
|
||||
redirect("/admin/teams", w, req)
|
||||
case "savemember":
|
||||
redirect("/admin/teams/"+teamId, w, req)
|
||||
default:
|
||||
page.SubTitle = "Edit Team"
|
||||
t := dbGetTeam(teamId)
|
||||
|
@ -1,3 +1,7 @@
|
||||
div.content {
|
||||
margin-left: 150px;
|
||||
}
|
||||
|
||||
div.bottom-space {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
@ -57,6 +57,10 @@ div.content {
|
||||
background-color: #191818;
|
||||
}
|
||||
|
||||
input.uuid-field {
|
||||
width: 360px;
|
||||
}
|
||||
|
||||
@media (min-width: 40em) {
|
||||
#menu {
|
||||
width: 150px;
|
||||
|
2
main.go
2
main.go
@ -53,6 +53,7 @@ type pageData struct {
|
||||
CurrentJam string
|
||||
ClientID string
|
||||
ClientIsAuth bool
|
||||
TeamID string
|
||||
|
||||
TemplateData interface{}
|
||||
}
|
||||
@ -237,6 +238,7 @@ func InitPageData(w http.ResponseWriter, req *http.Request) *pageData {
|
||||
|
||||
p.ClientID = p.session.getClientID()
|
||||
p.ClientIsAuth = dbClientIsAuth(p.ClientID)
|
||||
p.TeamID, _ = p.session.getStringValue("teamid")
|
||||
|
||||
return p
|
||||
}
|
||||
|
@ -6,3 +6,7 @@ type Game struct {
|
||||
UUID *uuid.UUID
|
||||
Name string
|
||||
}
|
||||
|
||||
func dbIsValidGame(id string) bool {
|
||||
return true
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/pborman/uuid"
|
||||
)
|
||||
|
||||
@ -145,3 +147,66 @@ func dbDeleteTeam(id string) error {
|
||||
teamPath := []string{"teams"}
|
||||
return db.DeleteBucket(teamPath, id)
|
||||
}
|
||||
|
||||
func dbEditTeamGame(teamid, name string) error {
|
||||
var err error
|
||||
if err = db.OpenDB(); err != nil {
|
||||
return err
|
||||
}
|
||||
defer db.CloseDB()
|
||||
|
||||
gamePath := []string{"teams", teamid, "game"}
|
||||
return db.SetValue(gamePath, "name", name)
|
||||
}
|
||||
|
||||
func dbGetTeamMembers(teamid string) ([]TeamMember, error) {
|
||||
var ret []TeamMember
|
||||
var err error
|
||||
if err = db.OpenDB(); err != nil {
|
||||
return ret, nil
|
||||
}
|
||||
defer db.CloseDB()
|
||||
|
||||
teamMbrPath := []string{"teams", teamid, "members"}
|
||||
var memberUuids []string
|
||||
if memberUuids, err = db.GetBucketList(teamMbrPath); err != nil {
|
||||
for _, v := range memberUuids {
|
||||
var mbr *TeamMember
|
||||
if mbr, err = dbGetTeamMember(teamid, v); err != nil {
|
||||
ret = append(ret, *mbr)
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func dbGetTeamMember(teamid, mbrid string) (*TeamMember, error) {
|
||||
var err error
|
||||
if err = db.OpenDB(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer db.CloseDB()
|
||||
|
||||
teamMbrPath := []string{"teams", teamid, "members", mbrid}
|
||||
var memberUuids []string
|
||||
if memberUuids, err = db.GetBucketList(teamMbrPath); err != nil {
|
||||
for _, v := range memberUuids {
|
||||
mbr := new(TeamMember)
|
||||
mbr.UUID = v
|
||||
if mbr.Name, err = db.GetValue(append(teamMbrPath, v), "name"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if mbr.SlackId, err = db.GetValue(append(teamMbrPath, v), "slackid"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if mbr.Twitter, err = db.GetValue(append(teamMbrPath, v), "twitter"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if mbr.Email, err = db.GetValue(append(teamMbrPath, v), "email"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return mbr, err
|
||||
}
|
||||
}
|
||||
return nil, errors.New("Couldn't find team member")
|
||||
}
|
||||
|
12
templates/admin-addgame.html
Normal file
12
templates/admin-addgame.html
Normal file
@ -0,0 +1,12 @@
|
||||
<div class="center">
|
||||
<form class="pure-form pure-form-aligned" action="/admin/games/new/save" method="POST">
|
||||
<fieldset>
|
||||
<div class="pure-control-group">
|
||||
<label for="teamid">Team Key</label>
|
||||
<input class="uuid-field" id="teamid" name="teamid" type="text" value="{{ .TeamID }}" placeholder="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" autofocus>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="pure-button pure-button-primary">Add Game</button>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
@ -6,6 +6,44 @@
|
||||
<input id="teamname" name="teamname" type="text" placeholder="Team Name" value="" autofocus>
|
||||
</div>
|
||||
|
||||
<h2>Members</h2>
|
||||
<table>
|
||||
<thead>
|
||||
<th>Name</th>
|
||||
<th>Slack ID</th>
|
||||
<th>Twitter</th>
|
||||
<th>Email</th>
|
||||
<th></th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="team-member">
|
||||
<div class="pure-control-group">
|
||||
<label for="membername">Name</label>
|
||||
<input id="membername" name="membername" type="text" placeholder="Name" value="">
|
||||
</div>
|
||||
<div class="pure-control-group">
|
||||
<label for="memberslackid">Slack ID</label>
|
||||
<input id="memberslackid" name="memberslackid" type="text" placeholder="@SlackID" value="">
|
||||
</div>
|
||||
<div class="pure-control-group">
|
||||
<label for="membertwitter">Twitter</label>
|
||||
<input id="membertwitter" name="membertwitter" type="text" placeholder="@TwitterID" value="">
|
||||
</div>
|
||||
<div class="pure-control-group">
|
||||
<label for="memberemail">Email</label>
|
||||
<input id="memberemail" name="memberemail" type="text" placeholder="user@email.com" value="">
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="pure-button pure-button-primary">Add Team</button>
|
||||
</fieldset>
|
||||
</form>
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
<div class="pure-control-group">
|
||||
<label class="control-label" for="teamname">Team Name</label>
|
||||
<input id="teamname" name="teamname" value="{{.TemplateData.Name}}" placeholder="Team Name">
|
||||
<input id="teamname" name="teamname" value="{{ .TemplateData.Name }}" placeholder="Team Name">
|
||||
</div>
|
||||
|
||||
<div class="pure-control-group reset-pull">
|
||||
@ -17,6 +17,48 @@
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
<h2>Members</h2>
|
||||
<form class="pure-form pure-form-aligned" action="/admin/teams/{{ .TemplateData.UUID }}/savemember" method="POST">
|
||||
<fieldset>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Slack ID</th>
|
||||
<th>Twitter</th>
|
||||
<th>Email</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{ range $i, $v := .TemplateData.Members }}
|
||||
<tr>
|
||||
<td>{{ $v.Name }}</td>
|
||||
<td>{{ $v.SlackID }}</td>
|
||||
<td>{{ $v.Twitter }}</td>
|
||||
<td>{{ $v.Email }}</td>
|
||||
<td>
|
||||
<a href="/admin/teams/{{ $v.UUID }}/edit" class="pure-button pure-button-plain"><i class="fa fa-pencil"></i></a>
|
||||
<a href="/admin/teams/{{ $v.UUID }}/delete" class="pure-button pure-button-plain"><i class="fa fa-trash"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
<tr>
|
||||
<td colspan="5" class="center">Add a new member</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><input id="newmembername" name="newmembername" value="" placeholder="Member Name" /></td>
|
||||
<td><input id="newmemberslackid" name="newmemberslackid" value="" placeholder="@SlackID" /></td>
|
||||
<td><input id="newmembertwitter" name="newmembertwitter" value="" placeholder="@Twitter" /></td>
|
||||
<td><input id="newmemberemail" name="newmemberemail" value="" placeholder="user@email.com" /></td>
|
||||
<td><button type="submit" class="pull-right space pure-button pure-button-primary">Add</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
<script>
|
||||
snack.listener(
|
||||
|
@ -5,6 +5,8 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Key</th>
|
||||
<th>Members</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -12,6 +14,8 @@
|
||||
{{ range $i, $v := .TemplateData.Teams }}
|
||||
<tr>
|
||||
<td>{{ $v.Name }}</td>
|
||||
<td>{{ $v.UUID }}</td>
|
||||
<td>{{ len $v.Members }}</td>
|
||||
<td>
|
||||
<a href="/admin/teams/{{ $v.UUID }}/edit" class="pure-button pure-button-plain"><i class="fa fa-pencil"></i></a>
|
||||
<a href="/admin/teams/{{ $v.UUID }}/delete" class="pure-button pure-button-plain"><i class="fa fa-trash"></i></a>
|
||||
|
@ -9,5 +9,5 @@ var clientID = "{{.ClientID}}";
|
||||
devICT Game Jam - {{.CurrentJam}}
|
||||
</div>
|
||||
<div class="header-menu">
|
||||
<h2>{{.SubTitle}}</h2>
|
||||
<h1>{{.SubTitle}}</h1>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user