Merge branch 'master' of ssh://git.bullercodeworks.com:2200/brian/gjvote

This commit is contained in:
Brian Buller 2017-06-22 10:38:04 -05:00
commit 153b869a98
7 changed files with 73 additions and 6 deletions

View File

@ -15,10 +15,22 @@ func handleAdminGames(w http.ResponseWriter, req *http.Request, page *pageData)
teamId := vars["id"] teamId := vars["id"]
if teamId == "" { if teamId == "" {
// Games List // Games List
type gamesPageData struct { type gamePage struct {
Games []Game Game *Game
Team *Team
} }
page.TemplateData = gamesPageData{Games: dbGetAllGames()} type gamesPageData struct {
Games []gamePage
}
gpd := new(gamesPageData)
allGames := dbGetAllGames()
for _, gm := range allGames {
gamePage := new(gamePage)
gamePage.Game = &gm
gamePage.Team = dbGetTeam(gm.TeamId)
gpd.Games = append(gpd.Games, *gamePage)
}
page.TemplateData = gpd
page.SubTitle = "Games" page.SubTitle = "Games"
page.show("admin-games.html", w) page.show("admin-games.html", w)
} else { } else {
@ -39,6 +51,12 @@ func handleAdminGames(w http.ResponseWriter, req *http.Request, page *pageData)
page.session.setFlashMessage("Error updating game: "+err.Error(), "error") page.session.setFlashMessage("Error updating game: "+err.Error(), "error")
} }
redirect("/admin/teams/"+teamId, w, req) redirect("/admin/teams/"+teamId, w, req)
case "screenshotdelete":
ssid := vars["subid"]
if err := dbDeleteTeamGameScreenshot(teamId, ssid); err != nil {
page.session.setFlashMessage("Error deleting screenshot: "+err.Error(), "error")
}
redirect("/admin/teams/"+teamId, w, req)
} }
} }
} }

View File

@ -5,3 +5,7 @@ div.content {
div.bottom-space { div.bottom-space {
margin-bottom: 15px; margin-bottom: 15px;
} }
img.thumbnail {
cursor: pointer;
}

View File

@ -78,7 +78,6 @@ div.horizontal-scroll {
} }
img.thumbnail { img.thumbnail {
width: 100px;
height: 100px; height: 100px;
} }

View File

@ -51,6 +51,7 @@ function showModal(options) {
} }
} }
modal.style.visibility = 'visible'; modal.style.visibility = 'visible';
window.scrollTo(0, 0);
} }
function hideModal() { function hideModal() {

View File

@ -103,6 +103,7 @@ func main() {
admin.HandleFunc("/{category}", handleAdmin) admin.HandleFunc("/{category}", handleAdmin)
admin.HandleFunc("/{category}/{id}", handleAdmin) admin.HandleFunc("/{category}/{id}", handleAdmin)
admin.HandleFunc("/{category}/{id}/{function}", handleAdmin) admin.HandleFunc("/{category}/{id}/{function}", handleAdmin)
admin.HandleFunc("/{category}/{id}/{function}/{subid}", handleAdmin)
http.Handle("/", r) http.Handle("/", r)

View File

@ -16,6 +16,7 @@ type Game struct {
type Screenshot struct { type Screenshot struct {
Description string Description string
Image string Image string
UUID string
} }
func dbUpdateTeamGame(teamId, name, desc string) error { func dbUpdateTeamGame(teamId, name, desc string) error {
@ -101,6 +102,7 @@ func dbGetTeamGameScreenshot(teamId, ssId string) *Screenshot {
var err error var err error
ssPath := []string{"teams", teamId, "game", "screenshots", ssId} ssPath := []string{"teams", teamId, "game", "screenshots", ssId}
ret := new(Screenshot) ret := new(Screenshot)
ret.UUID = ssId
if ret.Description, err = db.GetValue(ssPath, "description"); err != nil { if ret.Description, err = db.GetValue(ssPath, "description"); err != nil {
return nil return nil
} }

View File

@ -23,6 +23,7 @@
<form class="pure-form pure-form-aligned" action="/admin/games/{{ $uuid }}/save" method="POST"> <form class="pure-form pure-form-aligned" action="/admin/games/{{ $uuid }}/save" method="POST">
<fieldset> <fieldset>
<div class="left big-space"> <div class="left big-space">
<a name="game" />
<h3>Team Game</h3> <h3>Team Game</h3>
<div class="pure-control-group"> <div class="pure-control-group">
<label class="control-label" for="gamename">Game Name</label> <label class="control-label" for="gamename">Game Name</label>
@ -34,12 +35,12 @@
</div> </div>
<div class="pure-control-group"> <div class="pure-control-group">
<label class="control-label">Screenshots</label> <label class="control-label">Screenshots</label>
<div class="center-all horizontal-scroll thumbnail-container"> <div class="center-all horizontal-scroll thumbnail-container" id="thumbnail-container">
{{ if not .TemplateData.Game.Screenshots }} {{ if not .TemplateData.Game.Screenshots }}
<a style="margin-top:40px;" class="center-all pure-button pure-button-primary" href="javascript:toggleUploadSSForm();">Upload Screenshot</a> <a style="margin-top:40px;" class="center-all pure-button pure-button-primary" href="javascript:toggleUploadSSForm();">Upload Screenshot</a>
{{ else }} {{ else }}
{{ range $i, $v := .TemplateData.Game.Screenshots }} {{ range $i, $v := .TemplateData.Game.Screenshots }}
<img class="thumbnail" alt="{{ $v.Description }}" src="{{ $v.Image }}" /> <img data-teamid="{{ $uuid }}" data-ssid="{{ $v.UUID }}" class="thumbnail" alt="{{ $v.Description }}" src="data:image/png;base64,{{ $v.Image }}" />
{{ end }} {{ end }}
{{ end }} {{ end }}
</div> </div>
@ -122,6 +123,10 @@
<button type="submit" class="pull-right space-sides pure-button pure-button-primary">Add</button> <button type="submit" class="pull-right space-sides pure-button pure-button-primary">Add</button>
</form> </form>
</div> </div>
<div id="editscreenshotform" style="display:none;">
<div id="editss-container" class="pure-control-group" style="margin-bottom:50px;">
</div>
</div>
<script> <script>
snack.listener( snack.listener(
{node:document.getElementById('btnDeleteTeam'),event:'click'}, {node:document.getElementById('btnDeleteTeam'),event:'click'},
@ -143,6 +148,43 @@
}); });
} }
); );
snack.listener(
{
node:document.getElementById('thumbnail-container'),
event:'click',
delegate: function(node) {
return node.getElementsByTagName('img');
}
},
function() {
showEditScreenShotModal(snack.wrap(this)[0]);
}
);
function showEditScreenShotModal(img) {
var newImg = img.cloneNode();
var editSSForm = document.getElementById('editscreenshotform');
var cont = document.getElementById('editss-container');
while(cont.hasChildNodes()) {
cont.removeChild(cont.lastChild);
}
cont.appendChild(newImg);
showModal({
title: 'Edit Screenshot',
bodyNode: editSSForm,
buttons: [
{ title: 'Delete', class: 'pure-button-error', position: 'right',
click: function() {
window.location = "/admin/games/{{ $uuid }}/screenshotdelete/"+img.dataset.ssid;
}
},
{ title: 'Cancel', class: 'pure-button', position: 'right', click: hideModal }
]
});
editSSForm.style.display="block";
editSSForm.style.height="200px";
}
function toggleUploadSSForm() { function toggleUploadSSForm() {
var uploadForm = document.getElementById('uploadscreenshotform'); var uploadForm = document.getElementById('uploadscreenshotform');
showModal({ showModal({