70 lines
2.3 KiB
Plaintext
70 lines
2.3 KiB
Plaintext
package templates
|
|
|
|
import (
|
|
"fmt"
|
|
"gitea.zokki.net/zokki/uni/web43-diary/context"
|
|
"gitea.zokki.net/zokki/uni/web43-diary/internal/database"
|
|
"gitea.zokki.net/zokki/uni/web43-diary/internal/models"
|
|
"gitea.zokki.net/zokki/uni/web43-diary/internal/session"
|
|
"gitea.zokki.net/zokki/uni/web43-diary/web/templates/shared"
|
|
"net/http"
|
|
"strconv"
|
|
)
|
|
|
|
templ ViewDiary(context *context.Context) {
|
|
{{
|
|
idToGet, err := strconv.ParseUint(context.Request.PathValue("diaryID"), 10, 32)
|
|
if err != nil || idToGet == 0 {
|
|
return &models.HTTPError{
|
|
Message: "Malformed Tagebuch ID",
|
|
Code: http.StatusBadRequest,
|
|
}
|
|
}
|
|
|
|
diary, err := database.GetOne(context, &models.Diary{ID: uint32(idToGet)})
|
|
if err != nil {
|
|
return &models.HTTPError{
|
|
Message: "Tagebucheintrag nicht gefunden",
|
|
Code: http.StatusBadRequest,
|
|
Data: err,
|
|
}
|
|
}
|
|
|
|
user := session.GetSession(context).GetUser()
|
|
}}
|
|
@shared.Layout(context) {
|
|
<div class="flex flex-col gap-8 h-full p-6">
|
|
<div class="flex items-center justify-between gap-4 mx-auto">
|
|
<h1>{ diary.Title }</h1>
|
|
if diary.OwnerID == user.ID || user.Role.IsAdminUser() {
|
|
<div class="flex">
|
|
<form method="DELETE" data-redirect-url="/">
|
|
<button class="flex flex-center p-2 rounded-full text-red-600 hover:bg-dark-750">
|
|
<i class="ic--outline-delete size-8"></i>
|
|
</button>
|
|
</form>
|
|
<a href={ templ.URL(fmt.Sprintf("/diary/%d/edit", diary.ID)) } class="flex flex-center p-2 rounded-full hover:bg-dark-750">
|
|
<i class="ic--outline-edit size-8"></i>
|
|
</a>
|
|
</div>
|
|
}
|
|
</div>
|
|
<div class="flex justify-center gap-4 size-full">
|
|
<iframe allowtransparency="true" class="preview size-full max-w-3xl bg-transparent" data-markdown={ diary.Content }></iframe>
|
|
<div class="flex flex-col gap-4">
|
|
<span><strong>Erstellt von</strong>: { diary.Owner.Username }</span>
|
|
<span><strong>Erstellt am</strong>: { diary.CreationTime.Format("02.01.2006 15:04") }Uhr</span>
|
|
<label class="font-medium">Tags</label>
|
|
<div class="flex flex-wrap gap-2">
|
|
for _, tag := range diary.Tags {
|
|
<span class="tag flex flex-center gap-1 w-fit bg-dark-750 text-bright/75 text-xs font-medium px-2.5 py-0.5 rounded hover:bg-dark-650">
|
|
{ tag.Title }
|
|
</span>
|
|
}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
}
|