Skip to content

Commit

Permalink
show images when edit
Browse files Browse the repository at this point in the history
  • Loading branch information
sxc committed Jul 18, 2023
1 parent 904f4c1 commit 5e3c58c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
25 changes: 22 additions & 3 deletions controllers/galleries.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,32 @@ func (g Galleries) Edit(w http.ResponseWriter, r *http.Request) {
if err != nil {
return
}

type Image struct {
GalleryID int
Filename string
FilenameEscaped string
}
var data struct {
ID int
Title string
ID int
Title string
Images []Image
}
data.ID = gallery.ID
data.Title = gallery.Title
images, err := g.GalleryService.Images(gallery.ID)
if err != nil {
fmt.Println(err)
http.Error(w, "Something went wrong", http.StatusInternalServerError)
return
}
for _, image := range images {
data.Images = append(data.Images, Image{
GalleryID: image.GalleryID,
Filename: image.Filename,
FilenameEscaped: url.PathEscape(image.Filename),
})
}

g.Templates.Edit.Execute(w, r, data)
}

Expand Down
13 changes: 13 additions & 0 deletions templates/galleries/edit.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@
rounded font-bold text-lg">Update</button>
</div>
</form>
<div class="py-4">
<h2 class="p-4 text-sm font-semibold text-gray-800">Current Images</h2>
<div class="py-2 grid grid-cols-8 gap-2">
{{range .Images}}
<div class="h-min w-full relative">
<a href="/galleries/{{.GalleryID}}/images/{{.FilenameEscaped}}">
<img class="w-full" src="/galleries/{{.GalleryID}}/images/{{.FilenameEscaped}}">
</a>
</div>
{{end}}
</div>
</div>

<!-- Danger Actions -->
<div class="py-4">
<h2>Dangerous Acitons</h2>
Expand Down

0 comments on commit 5e3c58c

Please sign in to comment.