Game Screenshot Upload/Delete is working

This commit is contained in:
Brian Buller 2017-06-21 17:09:26 -05:00
parent b283aacc6a
commit f4c40a03bb
9 changed files with 80 additions and 46 deletions

View File

@ -15,10 +15,22 @@ func handleAdminGames(w http.ResponseWriter, req *http.Request, page *pageData)
teamId := vars["id"]
if teamId == "" {
// Games List
type gamesPageData struct {
Games []Game
type gamePage struct {
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.show("admin-games.html", w)
} else {
@ -39,6 +51,12 @@ func handleAdminGames(w http.ResponseWriter, req *http.Request, page *pageData)
page.session.setFlashMessage("Error updating game: "+err.Error(), "error")
}
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 {
margin-bottom: 15px;
}
img.thumbnail {
cursor: pointer;
}

View File

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

View File

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

View File

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

View File

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

View File

@ -5,45 +5,6 @@
<label for="teamname">Team Name</label>
<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>

View File

@ -23,6 +23,7 @@
<form class="pure-form pure-form-aligned" action="/admin/games/{{ $uuid }}/save" method="POST">
<fieldset>
<div class="left big-space">
<a name="game" />
<h3>Team Game</h3>
<div class="pure-control-group">
<label class="control-label" for="gamename">Game Name</label>
@ -34,12 +35,12 @@
</div>
<div class="pure-control-group">
<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 }}
<a style="margin-top:40px;" class="center-all pure-button pure-button-primary" href="javascript:toggleUploadSSForm();">Upload Screenshot</a>
{{ else }}
{{ 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 }}
</div>
@ -122,6 +123,10 @@
<button type="submit" class="pull-right space-sides pure-button pure-button-primary">Add</button>
</form>
</div>
<div id="editscreenshotform" style="display:none;">
<div id="editss-container" class="pure-control-group" style="margin-bottom:50px;">
</div>
</div>
<script>
snack.listener(
{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() {
var uploadForm = document.getElementById('uploadscreenshotform');
showModal({

View File

@ -1,13 +1,19 @@
<table id="games-table" class="hidden sortable pure-table pure-table-bordered center">
<thead>
<tr>
<th>Team</th>
<th>Game Name</th>
<th></th>
</tr>
</thead>
<tbody>
{{ range $i, $v := .TemplateData.Games }}
<tr>
<td>{{ $v.Name }}</td>
<td>{{ $v.Team.Name }}</td>
<td>{{ $v.Game.Name }}</td>
<td>
<a href="/admin/teams/{{ $v.Team.UUID }}/edit#game" class="pure-button pure-button-plain"><i class="fa fa-pencil"></i></a>
</td>
</tr>
{{ end }}
</tbody>