libfic: Can indicate that an exercice is WIP
This commit is contained in:
parent
4b8e447b1b
commit
c415e06237
10 changed files with 63 additions and 6 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Reference in a new issue