libfic: Can indicate that an exercice is WIP

This commit is contained in:
nemunaire 2022-11-05 15:26:57 +01:00
parent 4b8e447b1b
commit c415e06237
10 changed files with 63 additions and 6 deletions

View File

@ -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."})

View File

@ -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() {

View File

@ -21,7 +21,8 @@
<div class="form-group row" ng-repeat="field in fields">
<label for="{{ field }}" class="col-sm-1 col-form-label-sm">{{ field | capitalize }}</label>
<div class="col-sm-11">
<input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="exercice[field]" ng-if="field != 'statement' && field != 'issue' && field != 'issuekind' && field != 'overview' && field != 'resolution' && field != 'finished' && field != 'depend' && field != 'gain' && field != 'coefficient'">
<input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="exercice[field]" ng-if="field != 'statement' && field != 'issue' && field != 'issuekind' && field != 'overview' && field != 'resolution' && field != 'finished' && field != 'depend' && field != 'gain' && field != 'coefficient' && field != 'wip'">
<input class="form-check-input" type="checkbox" id="{{ field }}" ng-model="exercice[field]" ng-if="field == 'wip'">
<input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="exercice[field]" ng-if="field == 'gain'" integer>
<input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="exercice[field]" ng-if="field == 'coefficient'" float>
<textarea class="form-control form-control-sm" id="{{field}}" ng-model="exercice[field]" ng-if="field == 'statement' || field == 'overview' || field == 'finished' || field == 'resolution' || field == 'issue'"></textarea>

View File

@ -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"`

View File

@ -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 {

View File

@ -36,6 +36,15 @@
{#if !$my || !$my.exercices[$current_exercice.id]}
<p class="lead text-justify">{@html $current_exercice.headline}</p>
{:else}
{#if $my.exercices[$current_exercice.id].wip}
<Alert color="warning">
<Icon name="cone-striped" />
<strong>
Cette étape est marquée comme étant en cours d'élaboration.
</strong>
Elle n'est pas prête à être tentée. Vous devriez directement passer à l'étape suivante.
</Alert>
{/if}
<p class="lead text-justify">{@html $my.exercices[$current_exercice.id].statement}</p>
{#if $my.exercices[$current_exercice.id].issue}
<Alert color="{$my.exercices[$current_exercice.id].issuekind}">

View File

@ -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

View File

@ -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
}

View File

@ -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)

View File

@ -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")