Adopt SummerCMS v0.1.1 admin features

Datepickers on native time.Time / lagoon.Date fields, file uploads on
materials, readings and class sessions managed from the course form
(course_id made nullable).
This commit is contained in:
Jakub Zych
2026-10-03 06:03:34 +02:00
parent ac2e2ddd7b
commit 71b848a376
39 changed files with 475 additions and 373 deletions

View File

@@ -37,8 +37,8 @@ func listReadings(db *gorm.DB, userID, courseID uint) ([]readingJSON, error) {
for _, row := range rows {
item := readingJSON{
ID: row.ID,
CourseID: row.CourseID,
Course: newCourseRef(courses[row.CourseID]),
CourseID: idOf(row.CourseID),
Course: newCourseRef(courses[idOf(row.CourseID)]),
Title: row.Title,
Author: row.Author,
Source: row.Source,
@@ -47,7 +47,7 @@ func listReadings(db *gorm.DB, userID, courseID uint) ([]readingJSON, error) {
SortOrder: row.SortOrder,
}
if row.ReadAt != nil {
s := string(models.NewDateTime(*row.ReadAt))
s := models.FormatDateTime(*row.ReadAt)
item.ReadAt = &s
}
out = append(out, item)
@@ -59,9 +59,9 @@ func readingCourseIDs(rows []readingRow) []uint {
seen := map[uint]bool{}
var ids []uint
for _, row := range rows {
if !seen[row.CourseID] {
seen[row.CourseID] = true
ids = append(ids, row.CourseID)
if id := idOf(row.CourseID); !seen[id] {
seen[id] = true
ids = append(ids, id)
}
}
return ids
@@ -121,7 +121,7 @@ func readingFor(w http.ResponseWriter, r *http.Request, db *gorm.DB) (uint, bool
return 0, false
}
var reading models.Reading
res := db.Select("id").Where("id = ?", id).Limit(1).Find(&reading)
res := db.Select("id").Where("id = ? AND course_id IS NOT NULL", id).Limit(1).Find(&reading)
if res.Error != nil {
writeOpaque500(w)
return 0, false
@@ -160,7 +160,7 @@ ON CONFLICT (reading_id, user_id) DO NOTHING`, readingID, userID, now).Error
writeOpaque500(w)
return
}
readAt := string(models.NewDateTime(progress.ReadAt))
readAt := models.FormatDateTime(progress.ReadAt)
writeData(w, progressJSON{ReadingID: readingID, ReadAt: &readAt})
}