mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2026-02-04 02:25:30 +00:00
FIX: delete button and layout in baende vendpoint
This commit is contained in:
@@ -46,7 +46,7 @@ func (p *AlmanachEditPage) Setup(router *router.Router[*core.RequestEvent], ia p
|
||||
rg.BindFunc(middleware.IsAdminOrEditor())
|
||||
rg.GET(URL_ALMANACH_EDIT, p.GET(engine, app))
|
||||
rg.POST(URL_ALMANACH_EDIT+"save", p.POSTSave(engine, app, ia))
|
||||
rg.POST(URL_ALMANACH_EDIT+"delete", p.POSTDelete(engine, app))
|
||||
rg.POST(URL_ALMANACH_EDIT+"delete", p.POSTDelete(engine, app, ia))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ func (p *AlmanachEditPage) POSTSave(engine *templating.Engine, app core.App, ma
|
||||
}
|
||||
}
|
||||
|
||||
func (p *AlmanachEditPage) POSTDelete(engine *templating.Engine, app core.App) HandleFunc {
|
||||
func (p *AlmanachEditPage) POSTDelete(engine *templating.Engine, app core.App, ma pagemodels.IApp) HandleFunc {
|
||||
return func(e *core.RequestEvent) error {
|
||||
id := e.Request.PathValue("id")
|
||||
req := templating.NewRequest(e)
|
||||
@@ -302,6 +302,9 @@ func (p *AlmanachEditPage) POSTDelete(engine *templating.Engine, app core.App) H
|
||||
// Invalidate sorted entries cache since entry was deleted
|
||||
InvalidateSortedEntriesCache()
|
||||
|
||||
// Invalidate Bände cache since entry was deleted
|
||||
ma.ResetBaendeCache()
|
||||
|
||||
// Delete from FTS5 index asynchronously
|
||||
go func(appInstance core.App, entryID string) {
|
||||
if err := dbmodels.DeleteFTS5Entry(appInstance, entryID); err != nil {
|
||||
@@ -333,8 +336,8 @@ type almanachEditPayload struct {
|
||||
}
|
||||
|
||||
type almanachDeletePayload struct {
|
||||
CSRFToken string `json:"csrf_token"`
|
||||
LastEdited string `json:"last_edited"`
|
||||
CSRFToken string `json:"csrf_token" form:"csrf_token"`
|
||||
LastEdited string `json:"last_edited" form:"last_edited"`
|
||||
}
|
||||
|
||||
type almanachEntryPayload struct {
|
||||
|
||||
@@ -24,6 +24,7 @@ const (
|
||||
URL_BAENDE = "/baende/"
|
||||
URL_BAENDE_RESULTS = "/baende/results/"
|
||||
URL_BAENDE_MORE = "/baende/more/"
|
||||
URL_BAENDE_DELETE = "/baende/delete-info/{id}"
|
||||
TEMPLATE_BAENDE = "/baende/"
|
||||
URL_BAENDE_DETAILS = "/baende/details/{id}"
|
||||
BAENDE_PAGE_SIZE = 150
|
||||
@@ -77,6 +78,7 @@ func (p *BaendePage) Setup(router *router.Router[*core.RequestEvent], ia pagemod
|
||||
rg.GET("more/", p.handleMore(engine, app, ia))
|
||||
rg.GET("details/{id}", p.handleDetails(engine, app))
|
||||
rg.GET("row/{id}", p.handleRow(engine, app))
|
||||
rg.GET("delete-info/{id}", p.handleDeleteInfo(engine, app))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -221,6 +223,45 @@ func (p *BaendePage) handleDetails(engine *templating.Engine, app core.App) Hand
|
||||
}
|
||||
}
|
||||
|
||||
func (p *BaendePage) handleDeleteInfo(engine *templating.Engine, app core.App) HandleFunc {
|
||||
return func(e *core.RequestEvent) error {
|
||||
req := templating.NewRequest(e)
|
||||
if req.User() == nil {
|
||||
return e.Redirect(303, "/login/")
|
||||
}
|
||||
|
||||
id := e.Request.PathValue("id")
|
||||
if id == "" {
|
||||
return engine.Response404(e, nil, nil)
|
||||
}
|
||||
|
||||
entry, err := dbmodels.Entries_MusenalmID(app, id)
|
||||
if err != nil {
|
||||
return engine.Response404(e, err, nil)
|
||||
}
|
||||
|
||||
items, err := dbmodels.Items_Entry(app, entry.Id)
|
||||
if err != nil {
|
||||
app.Logger().Error("Failed to get items for delete dialog", "error", err)
|
||||
}
|
||||
|
||||
contents, err := dbmodels.Contents_Entry(app, entry.Id)
|
||||
if err != nil {
|
||||
app.Logger().Error("Failed to get contents for delete dialog", "error", err)
|
||||
}
|
||||
|
||||
dbmodels.Sort_Contents_Numbering(contents)
|
||||
|
||||
data := map[string]any{
|
||||
"entry": entry,
|
||||
"items": items,
|
||||
"contents": contents,
|
||||
}
|
||||
|
||||
return engine.Response200(e, "/baende/delete_info/", data, "fragment")
|
||||
}
|
||||
}
|
||||
|
||||
func (p *BaendePage) buildResultData(app core.App, ma pagemodels.IApp, e *core.RequestEvent, req *templating.Request, showAggregated bool) (map[string]any, error) {
|
||||
data := map[string]any{}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user