#4 Update Gallery Name
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Kekskurse 2022-01-15 12:43:27 +01:00
parent cdb7122a30
commit 6611640a35
Signed by: kekskurse
GPG key ID: 728ACCB59341E7E4
6 changed files with 111 additions and 7 deletions

View file

@ -100,6 +100,78 @@ func galleryNew(t template.Template, data template.Data, s session.Session, c fl
}
func galleryEdit(t template.Template) {
func galleryEditList(t template.Template, data template.Data, s session.Session, c flamego.Context) {
if s.Get("user_id") == nil {
c.Redirect("/login", http.StatusTemporaryRedirect)
return
}
galleries := []Gallery{}
err := sqlConnection.Select(&galleries, "SELECT * FROM gallery WHERE owner_id = ? ORDER BY id DESC", s.Get("user_id"))
if err != nil {
panic(err)
}
data["galleries"] = galleries
var list [][]Gallery
var tmp []Gallery
for _, g := range galleries {
if len(tmp) == 6 {
list = append(list, tmp)
tmp = []Gallery{}
}
tmp = append(tmp, g)
}
list = append(list, tmp)
data["list"] = list
t.HTML(http.StatusOK, "gallery_list")
return
}
func galleryEditSave(c flamego.Context, s session.Session) {
if s.Get("user_id") == nil {
c.Redirect("/login", http.StatusTemporaryRedirect)
return
}
galleries := []Gallery{}
err := sqlConnection.Select(&galleries, "SELECT * FROM gallery WHERE id = ? ORDER BY id DESC", c.Param("id"))
if err != nil {
log.Warn().Err(err).Msg("Cant find Gallery")
return
}
if galleries[0].OwnerId != int64(s.Get("user_id").(int)) {
c.ResponseWriter().Write([]byte("No Access"))
c.ResponseWriter().WriteHeader(http.StatusNotAcceptable)
return
}
_, err = sqlConnection.NamedExec("UPDATE gallery SET `name` = :name WHERE `id` = :id LIMIT 1", map[string]interface{}{
"name": c.Request().FormValue("name"),
"id": c.Param("id"),
})
if err != nil {
log.Error().Err(err).Msg("Cant update Gallery")
}
c.Redirect("/gallery/edit/"+c.Param("id"))
}
func galleryEdit(t template.Template,data template.Data, c flamego.Context) {
galleries := []Gallery{}
err := sqlConnection.Select(&galleries, "SELECT * FROM gallery WHERE id = ? ORDER BY id DESC", c.Param("id"))
if err != nil {
log.Warn().Err(err).Msg("Cant find Gallery")
return
}
data["gallery"] = galleries[0]
t.HTML(http.StatusOK, "gallery_edit")
}

View file

@ -182,7 +182,9 @@ func main() {
f.Get("/gallery/new", galleryNewForm)
f.Post("/gallery/new", galleryNew)
f.Get("/gallery/edit", galleryEdit)
f.Get("/gallery/edit", galleryEditList)
f.Get("/gallery/edit/{id}", galleryEdit)
f.Post("/gallery/edit/{id}", galleryEditSave)
f.Get("/file/upload", uploadImageForm)
f.Post("/file/upload", uploadImage)

View file

@ -22,26 +22,29 @@
<a class="list-group-item list-group-item-action disabled">A disabled link item</a>!-->
</div>
</div>
<div class="col-md-9">
<form method="post">
<div class="row">
<div class="col-md-2">
<img src="http://localhost:2830/image?path=%2fgallery%2f1%2f2%2fmain%2f1642166578549090734-crop.png" style="max-width: 80%;" ></img>
<img src="/image?path={{ .gallery.MainImage }}" style="max-width: 80%;" ></img>
</div>
<div class="col-md-10">
<a href="/settings/profile/image">[Change Image]</a>
<a href="/gallery/edit/{{.gallery.Id}}/image">[Change Image]</a>
</div>
</div>
</div>
<div class="row" style="margin-top: 20px;">
<div class="col-md-12">
<div class="form-floating mb-3">
<input type="text" name="name" class="form-control" id="floatingInput" placeholder="Name" value="{{ if .user.Name}}{{ .user.Name }}{{ end }}">
<input type="text" name="name" class="form-control" id="floatingInput" placeholder="Name" value="{{ .gallery.Name }}">
<label for="floatingInput">Name</label>
</div>
<input type="submit" class="btn btn-success" value="Save" style="width: 100%;"></input>
</div>
</div>
</form>
</div>
</div>
</div>
{{template "bottom" .}}

View file

@ -0,0 +1,24 @@
{{template "top" .}}
<div class="container" style="margin-top: 100px;">
<div class="col-12">
<h1>Select Gallery</h1>
{{ range .list }}
<div class="row">
{{ range . }}
<div class="col-md-2">
<div class="card border-secondary mb-3" style="max-width: 20rem;">
<div class="card-header">{{ .Name }}</div>
<div class="card-body">
<p class="card-text"> <a href="/gallery/edit/{{ .Id }}"><img src="/image?path={{ .MainImage }}&width=170" style="max-width: 100%"></img></a></p>
</div>
</div>
</div>
{{ end }}
</div>
{{ end }}
</div>
</div>
{{template "bottom" .}}

View file

@ -17,6 +17,9 @@
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav me-auto mb-2 mb-md-0">
<li class="nav-item">
<a class="nav-link" href="/gallery/edit">Gallerys</a>
</li>
<!--<li class="nav-item">
<a class="nav-link" href="/">Home</a>
</li>

View file

@ -4,7 +4,7 @@
<div class="container" style="margin-top: 100px;">
<div class="row">
<div class="col-md-3">
<img src="/image?path={{ .user.Image }}&width=200" style="border-radius: 50%;max-width: 80%;" ></img>
<a href="/u/{{ .user.Username }}"><img src="/image?path={{ .user.Image }}&width=200" style="border-radius: 50%;max-width: 80%;" ></img></a>
</div>
<div class="col-9">
<h1>{{ if not .user.Name }}