diff --git a/admin/api/exercice.go b/admin/api/exercice.go index a219e49b..50ffbfeb 100644 --- a/admin/api/exercice.go +++ b/admin/api/exercice.go @@ -622,7 +622,7 @@ func createExercice(c *gin.Context) { } } - exercice, err := theme.AddExercice(ue.Title, ue.URLId, ue.Path, ue.Statement, ue.Overview, ue.Headline, depend, ue.Gain, ue.VideoURI, ue.Resolution, ue.SeeAlso, ue.Finished) + exercice, err := theme.AddExercice(ue.Title, ue.WIP, ue.URLId, ue.Path, ue.Statement, ue.Overview, ue.Headline, depend, ue.Gain, ue.VideoURI, ue.Resolution, ue.SeeAlso, ue.Finished) if err != nil { log.Println("Unable to createExercice:", err.Error()) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "An error occurs during exercice creation."}) diff --git a/admin/static/js/app.js b/admin/static/js/app.js index 55574e47..56ce3872 100644 --- a/admin/static/js/app.js +++ b/admin/static/js/app.js @@ -1712,7 +1712,7 @@ angular.module("FICApp") }); }); $scope.exercices = Exercice.query(); - $scope.fields = ["title", "urlid", "statement", "headline", "overview", "finished", "depend", "gain", "coefficient", "videoURI", "resolution", "issue", "issuekind"]; + $scope.fields = ["title", "urlid", "statement", "headline", "overview", "finished", "depend", "gain", "coefficient", "videoURI", "resolution", "issue", "issuekind", "wip"]; $scope.inSync = false; $scope.syncExo = function() { diff --git a/admin/static/views/exercice.html b/admin/static/views/exercice.html index 5c60cf42..3be84260 100644 --- a/admin/static/views/exercice.html +++ b/admin/static/views/exercice.html @@ -21,7 +21,8 @@
- + + diff --git a/admin/sync/exercice_defines.go b/admin/sync/exercice_defines.go index 04613471..73a625fb 100644 --- a/admin/sync/exercice_defines.go +++ b/admin/sync/exercice_defines.go @@ -71,6 +71,7 @@ type ExerciceFlagChoice struct { // ExerciceParams contains values parsed from defines.txt. type ExerciceParams struct { + WIP bool `toml:"wip"` Gain int64 Tags []string Files []ExerciceFile `toml:"file"` diff --git a/admin/sync/exercices.go b/admin/sync/exercices.go index 40c3d304..f155d60b 100644 --- a/admin/sync/exercices.go +++ b/admin/sync/exercices.go @@ -16,6 +16,9 @@ import ( "srs.epita.fr/fic-server/libfic" ) +// Set AllowWIPExercice if WIP exercices are accepted. +var AllowWIPExercice bool = false + func fixnbsp(s string) string { return strings.Replace(strings.Replace(strings.Replace(s, " ?", " ?", -1), " !", " !", -1), " :", " :", -1) } @@ -116,6 +119,11 @@ func BuildExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]* } } + // Character reserved for WIP exercices + if len(e.Title) > 0 && e.Title[0] == '%' { + errs = append(errs, NewExerciceError(e, fmt.Errorf("title can't contain start by '%%'"), theme)) + } + e.URLId = fic.ToURLid(e.Title) e.Title = fixnbsp(e.Title) @@ -207,6 +215,11 @@ func BuildExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]* } } + e.WIP = p.WIP + if p.WIP && !AllowWIPExercice { + errs = append(errs, NewExerciceError(e, fmt.Errorf("exercice declared Work In Progress in challenge.txt"), theme)) + } + if p.Gain == 0 { errs = append(errs, NewChallengeTxtError(e, 0, fmt.Errorf("Undefined gain for challenge"), theme)) } else { diff --git a/frontend/ui/src/routes/[theme]/[exercice]/+page.svelte b/frontend/ui/src/routes/[theme]/[exercice]/+page.svelte index f7c0684f..3c9fbb9e 100644 --- a/frontend/ui/src/routes/[theme]/[exercice]/+page.svelte +++ b/frontend/ui/src/routes/[theme]/[exercice]/+page.svelte @@ -36,6 +36,15 @@ {#if !$my || !$my.exercices[$current_exercice.id]}

{@html $current_exercice.headline}

{:else} + {#if $my.exercices[$current_exercice.id].wip} + + + + Cette étape est marquée comme étant en cours d'élaboration. + + Elle n'est pas prête à être tentée. Vous devriez directement passer à l'étape suivante. + + {/if}

{@html $my.exercices[$current_exercice.id].statement}

{#if $my.exercices[$current_exercice.id].issue} diff --git a/libfic/exercice.go b/libfic/exercice.go index edcae96a..23cece3f 100644 --- a/libfic/exercice.go +++ b/libfic/exercice.go @@ -23,6 +23,8 @@ type Exercice struct { Id int64 `json:"id"` IdTheme int64 `json:"id_theme"` Title string `json:"title"` + // WIP indicates if the exercice is in development or not + WIP bool `json:"wip"` // URLid is used to reference the challenge from the URL path URLId string `json:"urlid"` // Path is the relative import location where find challenge data @@ -55,11 +57,21 @@ type Exercice struct { SeeAlso string `json:"seealso"` } +func (e *Exercice) AnalyzeTitle() { + if len(e.Title) > 0 && e.Title[0] == '%' { + e.WIP = true + e.Title = e.Title[1:] + } else { + e.WIP = false + } +} + func getExercice(condition string, args ...interface{}) (*Exercice, error) { var e Exercice if err := DBQueryRow("SELECT id_exercice, id_theme, title, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, resolution, seealso, finished FROM exercices "+condition, args...).Scan(&e.Id, &e.IdTheme, &e.Title, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI, &e.Resolution, &e.SeeAlso, &e.Finished); err != nil { return nil, err } + e.AnalyzeTitle() return &e, nil } @@ -97,6 +109,7 @@ func GetExercices() ([]*Exercice, error) { if err := rows.Scan(&e.Id, &e.IdTheme, &e.Title, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI, &e.Resolution, &e.SeeAlso, &e.Finished); err != nil { return nil, err } + e.AnalyzeTitle() exos = append(exos, e) } if err := rows.Err(); err != nil { @@ -120,6 +133,7 @@ func (t *Theme) GetExercices() ([]*Exercice, error) { if err := rows.Scan(&e.Id, &e.IdTheme, &e.Title, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI, &e.Resolution, &e.SeeAlso, &e.Finished); err != nil { return nil, err } + e.AnalyzeTitle() exos = append(exos, e) } if err := rows.Err(); err != nil { @@ -175,7 +189,11 @@ func (t *Theme) addExercice(e *Exercice) (err error) { cc = fmt.Sprintf("%f", e.Coefficient) } - if res, err := DBExec("INSERT INTO exercices (id_theme, title, url_id, path, statement, overview, finished, headline, issue, depend, gain, video_uri, resolution, seealso, issue_kind, coefficient_cur) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "+ik+", "+cc+")", t.Id, e.Title, e.URLId, e.Path, e.Statement, e.Overview, e.Finished, e.Headline, e.Issue, e.Depend, e.Gain, e.VideoURI, e.Resolution, e.SeeAlso); err != nil { + wip := "" + if e.WIP { + wip = "%" + } + if res, err := DBExec("INSERT INTO exercices (id_theme, title, url_id, path, statement, overview, finished, headline, issue, depend, gain, video_uri, resolution, seealso, issue_kind, coefficient_cur) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "+ik+", "+cc+")", t.Id, wip+e.Title, e.URLId, e.Path, e.Statement, e.Overview, e.Finished, e.Headline, e.Issue, e.Depend, e.Gain, e.VideoURI, e.Resolution, e.SeeAlso); err != nil { return err } else if eid, err := res.LastInsertId(); err != nil { return err @@ -187,7 +205,7 @@ func (t *Theme) addExercice(e *Exercice) (err error) { } // AddExercice creates and fills a new struct Exercice and registers it into the database. -func (t *Theme) AddExercice(title string, urlId string, path string, statement string, overview string, headline string, depend *Exercice, gain int64, videoURI string, resolution string, seealso string, finished string) (e *Exercice, err error) { +func (t *Theme) AddExercice(title string, wip bool, urlId string, path string, statement string, overview string, headline string, depend *Exercice, gain int64, videoURI string, resolution string, seealso string, finished string) (e *Exercice, err error) { var dpd *int64 = nil if depend != nil { dpd = &depend.Id @@ -195,6 +213,7 @@ func (t *Theme) AddExercice(title string, urlId string, path string, statement s e = &Exercice{ Title: title, + WIP: wip, URLId: urlId, Path: path, Statement: statement, @@ -215,7 +234,12 @@ func (t *Theme) AddExercice(title string, urlId string, path string, statement s // Update applies modifications back to the database. func (e *Exercice) Update() (int64, error) { - if res, err := DBExec("UPDATE exercices SET title = ?, url_id = ?, path = ?, statement = ?, overview = ?, headline = ?, issue = ?, issue_kind = ?, depend = ?, gain = ?, coefficient_cur = ?, video_uri = ?, resolution = ?, seealso = ?, finished = ? WHERE id_exercice = ?", e.Title, e.URLId, e.Path, e.Statement, e.Overview, e.Headline, e.Issue, e.IssueKind, e.Depend, e.Gain, e.Coefficient, e.VideoURI, e.Resolution, e.SeeAlso, e.Finished, e.Id); err != nil { + wip := "" + if e.WIP { + wip = "%" + } + + if res, err := DBExec("UPDATE exercices SET title = ?, url_id = ?, path = ?, statement = ?, overview = ?, headline = ?, issue = ?, issue_kind = ?, depend = ?, gain = ?, coefficient_cur = ?, video_uri = ?, resolution = ?, seealso = ?, finished = ? WHERE id_exercice = ?", wip+e.Title, e.URLId, e.Path, e.Statement, e.Overview, e.Headline, e.Issue, e.IssueKind, e.Depend, e.Gain, e.Coefficient, e.VideoURI, e.Resolution, e.SeeAlso, e.Finished, e.Id); err != nil { return 0, err } else if nb, err := res.RowsAffected(); err != nil { return 0, err diff --git a/libfic/team.go b/libfic/team.go index 25c3cffe..bed743f6 100644 --- a/libfic/team.go +++ b/libfic/team.go @@ -146,6 +146,12 @@ func (t *Team) HasAccess(e *Exercice) bool { if err != nil { return false } + + // If our previous exercice is WIP, unlock + if i == UnlockedChallengeDepth && e.WIP { + return true + } + } return false } diff --git a/libfic/team_my.go b/libfic/team_my.go index a09e3b94..05e7cbcc 100644 --- a/libfic/team_my.go +++ b/libfic/team_my.go @@ -65,6 +65,7 @@ type myTeamMCQJustifiedChoice struct { } type myTeamExercice struct { ThemeId int64 `json:"theme_id"` + WIP bool `json:"wip,omitempty"` Statement string `json:"statement"` Overview string `json:"overview,omitempty"` Finished string `json:"finished,omitempty"` @@ -121,6 +122,7 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) { for _, e := range exos { if t == nil || t.HasAccess(e) { exercice := myTeamExercice{} + exercice.WIP = e.WIP exercice.ThemeId = e.IdTheme exercice.Statement = strings.Replace(e.Statement, "$FILES$", FilesDir, -1) diff --git a/repochecker/main.go b/repochecker/main.go index d3a09569..37569f69 100644 --- a/repochecker/main.go +++ b/repochecker/main.go @@ -169,6 +169,7 @@ func main() { "Base directory where to find challenges files to import, cloud part") flag.StringVar(&cloudUsername, "clouduser", cloudUsername, "Username used to sync") flag.StringVar(&cloudPassword, "cloudpass", cloudPassword, "Password used to sync") + flag.BoolVar(&sync.AllowWIPExercice, "allow-wip-exercices", sync.AllowWIPExercice, "Are WIP exercice allowed?") flag.BoolVar(&fic.OptionalDigest, "optionaldigest", fic.OptionalDigest, "Is the digest required when importing files?") flag.BoolVar(&fic.StrongDigest, "strongdigest", fic.StrongDigest, "Are BLAKE2b digests required or is SHA-1 good enough?") flag.BoolVar(&skipFileChecks, "skipfiledigests", skipFileChecks, "Don't perform DIGESTS checks on file to speed up the checks")