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).
76 lines
2.5 KiB
Go
76 lines
2.5 KiB
Go
// Code generated by summer make. DO NOT EDIT.
|
|
|
|
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"
|
|
)
|
|
|
|
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).
|
|
type coursesAdmin struct{}
|
|
|
|
func (coursesAdmin) ID() string { return "jz.bm.courses" }
|
|
func (coursesAdmin) ModelName() string { return "Course" }
|
|
func (coursesAdmin) ConfigDir() string { return "controllers/courses" }
|
|
|
|
// NewRecord returns the model the generic admin handlers query and fill.
|
|
func (coursesAdmin) NewRecord() any { return &models.Course{} }
|
|
|
|
// RequiredPermissions is checked before any schema or record is served.
|
|
func (coursesAdmin) RequiredPermissions() []string {
|
|
return []string{PermCourses}
|
|
}
|
|
|
|
// 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{} }
|