Theme can be optional: exercices can be standalone

This commit is contained in:
nemunaire 2024-03-12 10:12:40 +01:00
commit a0bc832910
8 changed files with 81 additions and 39 deletions

View file

@ -140,7 +140,7 @@ CREATE TABLE IF NOT EXISTS team_members(
if _, err := db.Exec(`
CREATE TABLE IF NOT EXISTS exercices(
id_exercice INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
id_theme INTEGER NOT NULL,
id_theme INTEGER NULL,
title VARCHAR(255) NOT NULL,
authors TEXT NOT NULL,
image VARCHAR(255) NOT NULL,

View file

@ -22,7 +22,7 @@ var ExerciceCurrentCoefficient = 1.0
// Exercice represents a challenge inside a Theme.
type Exercice struct {
Id int64 `json:"id"`
IdTheme int64 `json:"id_theme"`
IdTheme *int64 `json:"id_theme"`
Language string `json:"lang,omitempty"`
Title string `json:"title"`
Authors string `json:"authors"`

View file

@ -68,7 +68,7 @@ type myTeamMCQJustifiedChoice struct {
Justification myTeamFlag `json:"justification,omitempty"`
}
type myTeamExercice struct {
ThemeId int64 `json:"theme_id"`
ThemeId int64 `json:"theme_id,omitempty"`
Disabled bool `json:"disabled,omitempty"`
WIP bool `json:"wip,omitempty"`
Statement string `json:"statement"`
@ -136,11 +136,11 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
return ret, err
} else if started {
for _, e := range exos {
if t == nil || ((!e.Disabled || !mapthemes[e.IdTheme].Locked) && t.HasAccess(e)) {
if t == nil || ((!e.Disabled || (e.IdTheme != nil && !mapthemes[*e.IdTheme].Locked)) && t.HasAccess(e)) {
exercice := myTeamExercice{}
exercice.Disabled = e.Disabled
exercice.WIP = e.WIP
exercice.ThemeId = e.IdTheme
exercice.ThemeId = *e.IdTheme
exercice.Statement = strings.Replace(e.Statement, "$FILES$", FilesDir, -1)

View file

@ -393,7 +393,9 @@ func (t *Team) MyIssueFile() (ret []teamIssueFile, err error) {
if exo, err := claim.GetExercice(); err == nil && exo != nil {
exercice = &exo.Title
if theme, err := GetTheme(exo.IdTheme); err == nil {
if exo.IdTheme == nil {
url = path.Join("_", exo.URLId)
} else if theme, err := GetTheme(*exo.IdTheme); err == nil {
url = path.Join(theme.URLId, exo.URLId)
}
}