Game Screenshot Upload/Delete is working
This commit is contained in:
parent
b283aacc6a
commit
f4c40a03bb
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,3 +5,7 @@ div.content {
|
|||||||
div.bottom-space {
|
div.bottom-space {
|
||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
img.thumbnail {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
@ -78,7 +78,6 @@ div.horizontal-scroll {
|
|||||||
}
|
}
|
||||||
|
|
||||||
img.thumbnail {
|
img.thumbnail {
|
||||||
width: 100px;
|
|
||||||
height: 100px;
|
height: 100px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +51,7 @@ function showModal(options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
modal.style.visibility = 'visible';
|
modal.style.visibility = 'visible';
|
||||||
|
window.scrollTo(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideModal() {
|
function hideModal() {
|
||||||
|
1
main.go
1
main.go
@ -99,6 +99,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)
|
||||||
|
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
@ -5,45 +5,6 @@
|
|||||||
<label for="teamname">Team Name</label>
|
<label for="teamname">Team Name</label>
|
||||||
<input id="teamname" name="teamname" type="text" placeholder="Team Name" value="" autofocus>
|
<input id="teamname" name="teamname" type="text" placeholder="Team Name" value="" autofocus>
|
||||||
</div>
|
</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>
|
<button type="submit" class="pure-button pure-button-primary">Add Team</button>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
|
@ -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({
|
||||||
|
@ -1,13 +1,19 @@
|
|||||||
<table id="games-table" class="hidden sortable pure-table pure-table-bordered center">
|
<table id="games-table" class="hidden sortable pure-table pure-table-bordered center">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
<th>Team</th>
|
||||||
<th>Game Name</th>
|
<th>Game Name</th>
|
||||||
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{{ range $i, $v := .TemplateData.Games }}
|
{{ range $i, $v := .TemplateData.Games }}
|
||||||
<tr>
|
<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>
|
</tr>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
Loading…
Reference in New Issue
Block a user