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:
@@ -3,6 +3,9 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.golem15.com/golem15/summercms/modules/cabana"
|
||||
"git.golem15.com/golem15/summercms/modules/pact"
|
||||
"git.golem15.com/jakub/sm-bm-plugin/models"
|
||||
)
|
||||
@@ -11,6 +14,10 @@ var (
|
||||
_ pact.AdminController = coursesAdmin{}
|
||||
_ pact.AdminRecordSource = coursesAdmin{}
|
||||
_ pact.AdminPermissioned = coursesAdmin{}
|
||||
|
||||
_ cabana.AdminRelationContractProvider = coursesAdmin{}
|
||||
_ pact.RelationBeforeCreate = coursesAdmin{}
|
||||
_ pact.RelationBeforeUpdate = coursesAdmin{}
|
||||
)
|
||||
|
||||
// coursesAdmin is the admin controller for courses (przedmioty).
|
||||
@@ -28,11 +35,41 @@ func (coursesAdmin) RequiredPermissions() []string {
|
||||
return []string{PermCourses}
|
||||
}
|
||||
|
||||
// TODO: requires SummerCMS change. The course form should embed relation
|
||||
// managers for its readings and class sessions, but cabana relation managers
|
||||
// only link and unlink belongsToMany rows through a pivot; hasMany children
|
||||
// cannot be listed or edited from the parent form. Readings and class
|
||||
// sessions have their own screens, filtered by course.
|
||||
// AdminRelationContracts binds the course form's relation managers for its
|
||||
// readings and class sessions. course_id is nullable, so both work on a
|
||||
// course that is not saved yet.
|
||||
func (coursesAdmin) AdminRelationContracts() []cabana.RelationContract {
|
||||
return []cabana.RelationContract{
|
||||
{
|
||||
Name: "readings",
|
||||
Kind: cabana.RelationHasMany,
|
||||
NewRelated: func() any { return &models.Reading{} },
|
||||
ForeignKey: "course_id",
|
||||
Columns: map[string]string{
|
||||
"title": "title", "author": "author", "is_required": "is_required", "sort_order": "sort_order",
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "sessions",
|
||||
Kind: cabana.RelationHasMany,
|
||||
NewRelated: func() any { return &models.ClassSession{} },
|
||||
ForeignKey: "course_id",
|
||||
Columns: map[string]string{
|
||||
"starts_at": "starts_at", "ends_at": "ends_at", "room": "room", "kind": "kind",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// RelationBeforeCreate and RelationBeforeUpdate check that a class session
|
||||
// ends after it starts, as the class sessions screen does.
|
||||
func (coursesAdmin) RelationBeforeCreate(_ context.Context, _ string, _, child any) error {
|
||||
return checkTemporal(child)
|
||||
}
|
||||
|
||||
func (coursesAdmin) RelationBeforeUpdate(_ context.Context, _ string, _, child any) error {
|
||||
return checkTemporal(child)
|
||||
}
|
||||
|
||||
// CoursesController returns the jz.bm.courses admin controller.
|
||||
func CoursesController() pact.AdminController { return coursesAdmin{} }
|
||||
|
||||
Reference in New Issue
Block a user