feat: add admin controllers, permissions and navigation for quizzes and attempts
This commit is contained in:
46
controllers/answers.go
Normal file
46
controllers/answers.go
Normal file
@@ -0,0 +1,46 @@
|
||||
// Code generated by summer make. DO NOT EDIT.
|
||||
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"git.golem15.com/golem15/sm-quizzes-plugin/models"
|
||||
"git.golem15.com/golem15/summercms/modules/cabana"
|
||||
"git.golem15.com/golem15/summercms/modules/pact"
|
||||
)
|
||||
|
||||
var (
|
||||
_ pact.AdminController = answersAdmin{}
|
||||
_ pact.AdminRecordSource = answersAdmin{}
|
||||
_ pact.AdminPermissioned = answersAdmin{}
|
||||
_ cabana.FieldRelationProvider = answersAdmin{}
|
||||
)
|
||||
|
||||
// answersAdmin lists and edits the answers of single and multiple
|
||||
// questions; the list filters by quiz.
|
||||
type answersAdmin struct{}
|
||||
|
||||
func (answersAdmin) ID() string { return "golem15.quizzes.answers" }
|
||||
func (answersAdmin) ModelName() string { return "Answer" }
|
||||
func (answersAdmin) ConfigDir() string { return "controllers/answers" }
|
||||
|
||||
// NewRecord returns the model the generic admin handlers query and fill.
|
||||
func (answersAdmin) NewRecord() any { return &models.Answer{} }
|
||||
|
||||
// RequiredPermissions is checked before any schema or record is served.
|
||||
func (answersAdmin) RequiredPermissions() []string {
|
||||
return []string{"golem15.quizzes.access_quizzes"}
|
||||
}
|
||||
|
||||
// AdminFieldRelations binds the question picker to question_id.
|
||||
func (answersAdmin) AdminFieldRelations() []cabana.FieldRelationContract {
|
||||
return []cabana.FieldRelationContract{{
|
||||
Field: "question",
|
||||
Kind: "belongsTo",
|
||||
NewRelated: func() any { return &models.Question{} },
|
||||
ForeignKey: "question_id",
|
||||
LabelColumn: "text",
|
||||
}}
|
||||
}
|
||||
|
||||
// AnswersController returns the golem15.quizzes.answers admin controller.
|
||||
func AnswersController() pact.AdminController { return answersAdmin{} }
|
||||
10
controllers/answers/config_filter.yaml
Normal file
10
controllers/answers/config_filter.yaml
Normal file
@@ -0,0 +1,10 @@
|
||||
scopes:
|
||||
quiz:
|
||||
label: golem15.quizzes::lang.questions.quiz
|
||||
modelClass: Quiz
|
||||
nameFrom: title
|
||||
scope: filterByQuiz
|
||||
is_correct:
|
||||
label: golem15.quizzes::lang.answers.is_correct
|
||||
type: switch
|
||||
column: is_correct
|
||||
12
controllers/answers/config_form.yaml
Normal file
12
controllers/answers/config_form.yaml
Normal file
@@ -0,0 +1,12 @@
|
||||
name: golem15.quizzes::lang.answers.answer
|
||||
form: ~/plugins/golem15/quizzes/models/answers/fields.yaml
|
||||
modelClass: Answer
|
||||
defaultRedirect: golem15/quizzes/answers
|
||||
|
||||
create:
|
||||
redirect: golem15/quizzes/answers/update/:id
|
||||
redirectClose: golem15/quizzes/answers
|
||||
|
||||
update:
|
||||
redirect: golem15/quizzes/answers
|
||||
redirectClose: golem15/quizzes/answers
|
||||
15
controllers/answers/config_list.yaml
Normal file
15
controllers/answers/config_list.yaml
Normal file
@@ -0,0 +1,15 @@
|
||||
list: ~/plugins/golem15/quizzes/models/answers/columns.yaml
|
||||
modelClass: Answer
|
||||
title: golem15.quizzes::lang.answers.title
|
||||
recordUrl: golem15/quizzes/answers/update/:id
|
||||
recordsPerPage: 50
|
||||
perPageOptions: [20, 50, 100]
|
||||
showCheckboxes: true
|
||||
defaultSort:
|
||||
column: sort_order
|
||||
direction: asc
|
||||
filter: config_filter.yaml
|
||||
toolbar:
|
||||
buttons: [create, delete]
|
||||
search:
|
||||
prompt: backend::lang.list.search_prompt
|
||||
33
controllers/attempts.go
Normal file
33
controllers/attempts.go
Normal file
@@ -0,0 +1,33 @@
|
||||
// Code generated by summer make. DO NOT EDIT.
|
||||
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"git.golem15.com/golem15/sm-quizzes-plugin/models"
|
||||
"git.golem15.com/golem15/summercms/modules/pact"
|
||||
)
|
||||
|
||||
var (
|
||||
_ pact.AdminController = attemptsAdmin{}
|
||||
_ pact.AdminRecordSource = attemptsAdmin{}
|
||||
_ pact.AdminPermissioned = attemptsAdmin{}
|
||||
)
|
||||
|
||||
// attemptsAdmin is a read-only list of attempts: it has no form, so the
|
||||
// admin API refuses every create, update and delete.
|
||||
type attemptsAdmin struct{}
|
||||
|
||||
func (attemptsAdmin) ID() string { return "golem15.quizzes.attempts" }
|
||||
func (attemptsAdmin) ModelName() string { return "Attempt" }
|
||||
func (attemptsAdmin) ConfigDir() string { return "controllers/attempts" }
|
||||
|
||||
// NewRecord returns the model the generic admin handlers query.
|
||||
func (attemptsAdmin) NewRecord() any { return &models.Attempt{} }
|
||||
|
||||
// RequiredPermissions is checked before any schema or record is served.
|
||||
func (attemptsAdmin) RequiredPermissions() []string {
|
||||
return []string{"golem15.quizzes.access_attempts"}
|
||||
}
|
||||
|
||||
// AttemptsController returns the golem15.quizzes.attempts admin controller.
|
||||
func AttemptsController() pact.AdminController { return attemptsAdmin{} }
|
||||
10
controllers/attempts/config_filter.yaml
Normal file
10
controllers/attempts/config_filter.yaml
Normal file
@@ -0,0 +1,10 @@
|
||||
scopes:
|
||||
quiz:
|
||||
label: golem15.quizzes::lang.attempts.quiz
|
||||
modelClass: Quiz
|
||||
nameFrom: title
|
||||
scope: filterByQuiz
|
||||
started_at:
|
||||
label: golem15.quizzes::lang.attempts.started_at
|
||||
type: daterange
|
||||
column: started_at
|
||||
13
controllers/attempts/config_list.yaml
Normal file
13
controllers/attempts/config_list.yaml
Normal file
@@ -0,0 +1,13 @@
|
||||
list: ~/plugins/golem15/quizzes/models/attempts/columns.yaml
|
||||
modelClass: Attempt
|
||||
title: golem15.quizzes::lang.attempts.title
|
||||
recordsPerPage: 50
|
||||
perPageOptions: [20, 50, 100]
|
||||
defaultSort:
|
||||
column: started_at
|
||||
direction: desc
|
||||
filter: config_filter.yaml
|
||||
toolbar:
|
||||
buttons: []
|
||||
search:
|
||||
prompt: backend::lang.list.search_prompt
|
||||
46
controllers/questions.go
Normal file
46
controllers/questions.go
Normal file
@@ -0,0 +1,46 @@
|
||||
// Code generated by summer make. DO NOT EDIT.
|
||||
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"git.golem15.com/golem15/sm-quizzes-plugin/models"
|
||||
"git.golem15.com/golem15/summercms/modules/cabana"
|
||||
"git.golem15.com/golem15/summercms/modules/pact"
|
||||
)
|
||||
|
||||
var (
|
||||
_ pact.AdminController = questionsAdmin{}
|
||||
_ pact.AdminRecordSource = questionsAdmin{}
|
||||
_ pact.AdminPermissioned = questionsAdmin{}
|
||||
_ cabana.FieldRelationProvider = questionsAdmin{}
|
||||
)
|
||||
|
||||
// questionsAdmin lists and edits questions of every quiz; the list filters
|
||||
// by quiz, category and type.
|
||||
type questionsAdmin struct{}
|
||||
|
||||
func (questionsAdmin) ID() string { return "golem15.quizzes.questions" }
|
||||
func (questionsAdmin) ModelName() string { return "Question" }
|
||||
func (questionsAdmin) ConfigDir() string { return "controllers/questions" }
|
||||
|
||||
// NewRecord returns the model the generic admin handlers query and fill.
|
||||
func (questionsAdmin) NewRecord() any { return &models.Question{} }
|
||||
|
||||
// RequiredPermissions is checked before any schema or record is served.
|
||||
func (questionsAdmin) RequiredPermissions() []string {
|
||||
return []string{"golem15.quizzes.access_quizzes"}
|
||||
}
|
||||
|
||||
// AdminFieldRelations binds the quiz picker to quiz_id.
|
||||
func (questionsAdmin) AdminFieldRelations() []cabana.FieldRelationContract {
|
||||
return []cabana.FieldRelationContract{{
|
||||
Field: "quiz",
|
||||
Kind: "belongsTo",
|
||||
NewRelated: func() any { return &models.Quiz{} },
|
||||
ForeignKey: "quiz_id",
|
||||
LabelColumn: "title",
|
||||
}}
|
||||
}
|
||||
|
||||
// QuestionsController returns the golem15.quizzes.questions admin controller.
|
||||
func QuestionsController() pact.AdminController { return questionsAdmin{} }
|
||||
16
controllers/questions/config_filter.yaml
Normal file
16
controllers/questions/config_filter.yaml
Normal file
@@ -0,0 +1,16 @@
|
||||
scopes:
|
||||
quiz:
|
||||
label: golem15.quizzes::lang.questions.quiz
|
||||
modelClass: Quiz
|
||||
nameFrom: title
|
||||
scope: filterByQuiz
|
||||
category:
|
||||
label: golem15.quizzes::lang.questions.category
|
||||
modelClass: Question
|
||||
nameFrom: category
|
||||
scope: filterByCategory
|
||||
type:
|
||||
label: golem15.quizzes::lang.questions.type
|
||||
modelClass: Question
|
||||
nameFrom: type
|
||||
scope: filterByType
|
||||
12
controllers/questions/config_form.yaml
Normal file
12
controllers/questions/config_form.yaml
Normal file
@@ -0,0 +1,12 @@
|
||||
name: golem15.quizzes::lang.questions.question
|
||||
form: ~/plugins/golem15/quizzes/models/questions/fields.yaml
|
||||
modelClass: Question
|
||||
defaultRedirect: golem15/quizzes/questions
|
||||
|
||||
create:
|
||||
redirect: golem15/quizzes/questions/update/:id
|
||||
redirectClose: golem15/quizzes/questions
|
||||
|
||||
update:
|
||||
redirect: golem15/quizzes/questions
|
||||
redirectClose: golem15/quizzes/questions
|
||||
15
controllers/questions/config_list.yaml
Normal file
15
controllers/questions/config_list.yaml
Normal file
@@ -0,0 +1,15 @@
|
||||
list: ~/plugins/golem15/quizzes/models/questions/columns.yaml
|
||||
modelClass: Question
|
||||
title: golem15.quizzes::lang.questions.title
|
||||
recordUrl: golem15/quizzes/questions/update/:id
|
||||
recordsPerPage: 50
|
||||
perPageOptions: [20, 50, 100]
|
||||
showCheckboxes: true
|
||||
defaultSort:
|
||||
column: sort_order
|
||||
direction: asc
|
||||
filter: config_filter.yaml
|
||||
toolbar:
|
||||
buttons: [create, delete]
|
||||
search:
|
||||
prompt: backend::lang.list.search_prompt
|
||||
37
controllers/quizzes.go
Normal file
37
controllers/quizzes.go
Normal file
@@ -0,0 +1,37 @@
|
||||
// Code generated by summer make. DO NOT EDIT.
|
||||
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"git.golem15.com/golem15/sm-quizzes-plugin/models"
|
||||
"git.golem15.com/golem15/summercms/modules/pact"
|
||||
)
|
||||
|
||||
var (
|
||||
_ pact.AdminController = quizzesAdmin{}
|
||||
_ pact.AdminRecordSource = quizzesAdmin{}
|
||||
_ pact.AdminPermissioned = quizzesAdmin{}
|
||||
)
|
||||
|
||||
// quizzesAdmin lists and edits quizzes. Questions have their own controller
|
||||
// filtered by quiz.
|
||||
//
|
||||
// TODO: requires SummerCMS change. cabana's relation manager only links and
|
||||
// unlinks belongsToMany records through a pivot; it cannot create or edit
|
||||
// hasMany children inline, so the quiz form cannot embed its questions.
|
||||
type quizzesAdmin struct{}
|
||||
|
||||
func (quizzesAdmin) ID() string { return "golem15.quizzes.quizzes" }
|
||||
func (quizzesAdmin) ModelName() string { return "Quiz" }
|
||||
func (quizzesAdmin) ConfigDir() string { return "controllers/quizzes" }
|
||||
|
||||
// NewRecord returns the model the generic admin handlers query and fill.
|
||||
func (quizzesAdmin) NewRecord() any { return &models.Quiz{} }
|
||||
|
||||
// RequiredPermissions is checked before any schema or record is served.
|
||||
func (quizzesAdmin) RequiredPermissions() []string {
|
||||
return []string{"golem15.quizzes.access_quizzes"}
|
||||
}
|
||||
|
||||
// QuizzesController returns the golem15.quizzes.quizzes admin controller.
|
||||
func QuizzesController() pact.AdminController { return quizzesAdmin{} }
|
||||
5
controllers/quizzes/config_filter.yaml
Normal file
5
controllers/quizzes/config_filter.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
scopes:
|
||||
is_published:
|
||||
label: golem15.quizzes::lang.quizzes.is_published
|
||||
type: switch
|
||||
column: is_published
|
||||
12
controllers/quizzes/config_form.yaml
Normal file
12
controllers/quizzes/config_form.yaml
Normal file
@@ -0,0 +1,12 @@
|
||||
name: golem15.quizzes::lang.quizzes.quiz
|
||||
form: ~/plugins/golem15/quizzes/models/quizzes/fields.yaml
|
||||
modelClass: Quiz
|
||||
defaultRedirect: golem15/quizzes/quizzes
|
||||
|
||||
create:
|
||||
redirect: golem15/quizzes/quizzes/update/:id
|
||||
redirectClose: golem15/quizzes/quizzes
|
||||
|
||||
update:
|
||||
redirect: golem15/quizzes/quizzes
|
||||
redirectClose: golem15/quizzes/quizzes
|
||||
14
controllers/quizzes/config_list.yaml
Normal file
14
controllers/quizzes/config_list.yaml
Normal file
@@ -0,0 +1,14 @@
|
||||
list: ~/plugins/golem15/quizzes/models/quizzes/columns.yaml
|
||||
modelClass: Quiz
|
||||
title: golem15.quizzes::lang.quizzes.title
|
||||
recordUrl: golem15/quizzes/quizzes/update/:id
|
||||
recordsPerPage: 20
|
||||
showCheckboxes: true
|
||||
defaultSort:
|
||||
column: title
|
||||
direction: asc
|
||||
filter: config_filter.yaml
|
||||
toolbar:
|
||||
buttons: [create, delete]
|
||||
search:
|
||||
prompt: backend::lang.list.search_prompt
|
||||
Reference in New Issue
Block a user