Exercice: add overview field
This field is use as a high level description of the exercice. It will be displayed on the public interface only: not to players.
This commit is contained in:
parent
48e6ba7861
commit
838918da66
@ -558,7 +558,7 @@ angular.module("FICApp")
|
||||
|
||||
.controller("AllExercicesListController", function($scope, Exercice, $routeParams, $location, $rootScope, $http) {
|
||||
$scope.exercices = Exercice.query();
|
||||
$scope.fields = ["title", "statement", "videoURI"];
|
||||
$scope.fields = ["title", "statement", "overview", "videoURI"];
|
||||
|
||||
$scope.show = function(id) {
|
||||
$location.url("/exercices/" + id);
|
||||
@ -607,7 +607,7 @@ angular.module("FICApp")
|
||||
})
|
||||
.controller("ExercicesListController", function($scope, ThemedExercice, $routeParams, $location) {
|
||||
$scope.exercices = ThemedExercice.query({ themeId: $routeParams.themeId });
|
||||
$scope.fields = ["title", "statement", "videoURI"];
|
||||
$scope.fields = ["title", "statement", "overview", "videoURI"];
|
||||
|
||||
$scope.show = function(id) {
|
||||
$location.url("/themes/" + $routeParams.themeId + "/exercices/" + id);
|
||||
@ -620,7 +620,7 @@ angular.module("FICApp")
|
||||
$scope.exercice = Exercice.get({ exerciceId: $routeParams.exerciceId });
|
||||
}
|
||||
$scope.exercices = Exercice.query();
|
||||
$scope.fields = ["title", "statement", "depend", "gain", "coefficient", "videoURI"];
|
||||
$scope.fields = ["title", "statement", "overview", "depend", "gain", "coefficient", "videoURI"];
|
||||
|
||||
$scope.saveExercice = function() {
|
||||
if (this.exercice.id) {
|
||||
|
@ -4,10 +4,10 @@
|
||||
<div class="form-group" ng-repeat="field in fields">
|
||||
<label for="{{ field }}" class="col-xs-1 control-label">{{ field | capitalize }}</label>
|
||||
<div class="col-xs-11">
|
||||
<input type="text" class="form-control" id="{{ field }}" ng-model="exercice[field]" ng-show="field != 'statement' && field != 'depend' && field != 'gain' && field != 'coefficient'">
|
||||
<input type="text" class="form-control" id="{{ field }}" ng-model="exercice[field]" ng-show="field != 'statement' && field != 'overview' && field != 'depend' && field != 'gain' && field != 'coefficient'">
|
||||
<input type="text" class="form-control" id="{{ field }}" ng-model="exercice[field]" ng-show="field == 'gain'" integer>
|
||||
<input type="text" class="form-control" id="{{ field }}" ng-model="exercice[field]" ng-show="field == 'coefficient'" float>
|
||||
<textarea class="form-control" id="{{field}}" ng-model="exercice[field]" ng-show="field == 'statement'"></textarea>
|
||||
<textarea class="form-control" id="{{field}}" ng-model="exercice[field]" ng-show="field == 'statement' || field == 'overview'"></textarea>
|
||||
<select class="form-control" id="{{field}}" ng-model="exercice[field]" ng-options="ex.id as ex.title for ex in exercices" ng-show="field == 'depend'">
|
||||
<option value="">Aucune</option>
|
||||
</select>
|
||||
|
@ -49,6 +49,12 @@ func SyncExercices(i Importer, theme fic.Theme) []string {
|
||||
|
||||
emap[ename] = eid
|
||||
|
||||
// Overview and scenario
|
||||
overview, err := getFileContent(i, path.Join(theme.Name, edir, "introduction.txt"))
|
||||
if err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: introduction.txt: %s", edir, err))
|
||||
}
|
||||
|
||||
statement, err := getFileContent(i, path.Join(theme.Name, edir, "scenario.txt"))
|
||||
if err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: scenario.txt: %s", edir, err))
|
||||
@ -65,13 +71,14 @@ func SyncExercices(i Importer, theme fic.Theme) []string {
|
||||
videoURI := ""
|
||||
|
||||
if e, err := theme.GetExerciceByTitle(ename); err != nil {
|
||||
if _, err := theme.AddExercice(ename, path.Join(theme.Name, edir), statement, depend, gain, videoURI); err != nil {
|
||||
if _, err := theme.AddExercice(ename, path.Join(theme.Name, edir), statement, overview, nil, gain, videoURI); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: error on exercice add: %s", edir, err))
|
||||
continue
|
||||
}
|
||||
} else if e.Title != ename || e.Statement != statement || (depend == nil && e.Depend != nil) || (depend != nil && e.Depend == nil) || (depend != nil && e.Depend != nil && *e.Depend != depend.Id) || e.Gain != gain || e.VideoURI != videoURI {
|
||||
} else if e.Title != ename || e.Statement != statement || e.Overview != overview || (depend == nil && e.Depend != nil) || (depend != nil && e.Depend == nil) || (depend != nil && e.Depend != nil && *e.Depend != depend.Id) || e.Gain != gain || e.VideoURI != videoURI {
|
||||
e.Title = ename
|
||||
e.Statement = statement
|
||||
e.Overview = overview
|
||||
if depend != nil {
|
||||
e.Depend = &depend.Id
|
||||
} else {
|
||||
|
@ -94,6 +94,7 @@ CREATE TABLE IF NOT EXISTS exercices(
|
||||
title VARCHAR(255) NOT NULL,
|
||||
path VARCHAR(255) NOT NULL,
|
||||
statement TEXT NOT NULL,
|
||||
overview TEXT NOT NULL,
|
||||
depend INTEGER,
|
||||
gain INTEGER NOT NULL,
|
||||
coefficient_cur FLOAT NOT NULL DEFAULT 1.0,
|
||||
|
@ -13,6 +13,7 @@ type Exercice struct {
|
||||
Title string `json:"title"`
|
||||
Path string `json:"path"`
|
||||
Statement string `json:"statement"`
|
||||
Overview string `json:"overview"`
|
||||
Depend *int64 `json:"depend"`
|
||||
Gain int64 `json:"gain"`
|
||||
Coefficient float64 `json:"coefficient"`
|
||||
@ -21,7 +22,7 @@ type Exercice struct {
|
||||
|
||||
func GetExercice(id int64) (Exercice, error) {
|
||||
var e Exercice
|
||||
if err := DBQueryRow("SELECT id_exercice, title, path, statement, depend, gain, coefficient_cur, video_uri FROM exercices WHERE id_exercice = ?", id).Scan(&e.Id, &e.Title, &e.Path, &e.Statement, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI); err != nil {
|
||||
if err := DBQueryRow("SELECT id_exercice, title, path, statement, overview, depend, gain, coefficient_cur, video_uri FROM exercices WHERE id_exercice = ?", id).Scan(&e.Id, &e.Title, &e.Path, &e.Statement, &e.Overview, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI); err != nil {
|
||||
return Exercice{}, err
|
||||
}
|
||||
|
||||
@ -30,7 +31,7 @@ func GetExercice(id int64) (Exercice, error) {
|
||||
|
||||
func (t Theme) GetExercice(id int) (Exercice, error) {
|
||||
var e Exercice
|
||||
if err := DBQueryRow("SELECT id_exercice, title, path, statement, depend, gain, coefficient_cur, video_uri FROM exercices WHERE id_theme = ? AND id_exercice = ?", t.Id, id).Scan(&e.Id, &e.Title, &e.Path, &e.Statement, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI); err != nil {
|
||||
if err := DBQueryRow("SELECT id_exercice, title, path, statement, overview, depend, gain, coefficient_cur, video_uri FROM exercices WHERE id_theme = ? AND id_exercice = ?", t.Id, id).Scan(&e.Id, &e.Title, &e.Path, &e.Statement, &e.Overview, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI); err != nil {
|
||||
return Exercice{}, err
|
||||
}
|
||||
|
||||
@ -39,7 +40,7 @@ func (t Theme) GetExercice(id int) (Exercice, error) {
|
||||
|
||||
func (t Theme) GetExerciceByTitle(title string) (Exercice, error) {
|
||||
var e Exercice
|
||||
if err := DBQueryRow("SELECT id_exercice, title, path, statement, depend, gain, coefficient_cur, video_uri FROM exercices WHERE id_theme = ? AND title = ?", t.Id, title).Scan(&e.Id, &e.Title, &e.Path, &e.Statement, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI); err != nil {
|
||||
if err := DBQueryRow("SELECT id_exercice, title, path, statement, overview, depend, gain, coefficient_cur, video_uri FROM exercices WHERE id_theme = ? AND title = ?", t.Id, title).Scan(&e.Id, &e.Title, &e.Path, &e.Statement, &e.Overview, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI); err != nil {
|
||||
return Exercice{}, err
|
||||
}
|
||||
|
||||
@ -47,7 +48,7 @@ func (t Theme) GetExerciceByTitle(title string) (Exercice, error) {
|
||||
}
|
||||
|
||||
func GetExercices() ([]Exercice, error) {
|
||||
if rows, err := DBQuery("SELECT id_exercice, title, path, statement, depend, gain, coefficient_cur, video_uri FROM exercices"); err != nil {
|
||||
if rows, err := DBQuery("SELECT id_exercice, title, path, statement, overview, depend, gain, coefficient_cur, video_uri FROM exercices"); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer rows.Close()
|
||||
@ -55,7 +56,7 @@ func GetExercices() ([]Exercice, error) {
|
||||
var exos = make([]Exercice, 0)
|
||||
for rows.Next() {
|
||||
var e Exercice
|
||||
if err := rows.Scan(&e.Id, &e.Title, &e.Path, &e.Statement, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI); err != nil {
|
||||
if err := rows.Scan(&e.Id, &e.Title, &e.Path, &e.Statement, &e.Overview, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
exos = append(exos, e)
|
||||
@ -69,7 +70,7 @@ func GetExercices() ([]Exercice, error) {
|
||||
}
|
||||
|
||||
func (t Theme) GetExercices() ([]Exercice, error) {
|
||||
if rows, err := DBQuery("SELECT id_exercice, title, path, statement, depend, gain, coefficient_cur, video_uri FROM exercices WHERE id_theme = ?", t.Id); err != nil {
|
||||
if rows, err := DBQuery("SELECT id_exercice, title, path, statement, overview, depend, gain, coefficient_cur, video_uri FROM exercices WHERE id_theme = ?", t.Id); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer rows.Close()
|
||||
@ -77,7 +78,7 @@ func (t Theme) GetExercices() ([]Exercice, error) {
|
||||
var exos = make([]Exercice, 0)
|
||||
for rows.Next() {
|
||||
var e Exercice
|
||||
if err := rows.Scan(&e.Id, &e.Title, &e.Path, &e.Statement, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI); err != nil {
|
||||
if err := rows.Scan(&e.Id, &e.Title, &e.Path, &e.Statement, &e.Overview, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
exos = append(exos, e)
|
||||
@ -90,28 +91,28 @@ func (t Theme) GetExercices() ([]Exercice, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (t Theme) AddExercice(title string, path string, statement string, depend *Exercice, gain int64, videoURI string) (Exercice, error) {
|
||||
func (t Theme) AddExercice(title string, path string, statement string, overview string, depend *Exercice, gain int64, videoURI string) (Exercice, error) {
|
||||
var dpd interface{}
|
||||
if depend == nil {
|
||||
dpd = nil
|
||||
} else {
|
||||
dpd = depend.Id
|
||||
}
|
||||
if res, err := DBExec("INSERT INTO exercices (id_theme, title, path, statement, depend, gain, video_uri) VALUES (?, ?, ?, ?, ?, ?, ?)", t.Id, title, path, statement, dpd, gain, videoURI); err != nil {
|
||||
if res, err := DBExec("INSERT INTO exercices (id_theme, title, path, statement, overview, depend, gain, video_uri) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", t.Id, title, path, statement, overview, dpd, gain, videoURI); err != nil {
|
||||
return Exercice{}, err
|
||||
} else if eid, err := res.LastInsertId(); err != nil {
|
||||
return Exercice{}, err
|
||||
} else {
|
||||
if depend == nil {
|
||||
return Exercice{eid, title, path, statement, nil, gain, 1.0, videoURI}, nil
|
||||
return Exercice{eid, title, path, statement, overview, nil, gain, 1.0, videoURI}, nil
|
||||
} else {
|
||||
return Exercice{eid, title, path, statement, &depend.Id, gain, 1.0, videoURI}, nil
|
||||
return Exercice{eid, title, path, statement, overview, &depend.Id, gain, 1.0, videoURI}, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (e Exercice) Update() (int64, error) {
|
||||
if res, err := DBExec("UPDATE exercices SET title = ?, path = ?, statement = ?, depend = ?, gain = ?, coefficient_cur = ?, video_uri = ? WHERE id_exercice = ?", e.Title, e.Path, e.Statement, e.Depend, e.Gain, e.Coefficient, e.VideoURI, e.Id); err != nil {
|
||||
if res, err := DBExec("UPDATE exercices SET title = ?, path = ?, statement = ?, overview = ?, depend = ?, gain = ?, coefficient_cur = ?, video_uri = ? WHERE id_exercice = ?", e.Title, e.Path, e.Statement, e.Overview, e.Depend, e.Gain, e.Coefficient, e.VideoURI, e.Id); err != nil {
|
||||
return 0, err
|
||||
} else if nb, err := res.RowsAffected(); err != nil {
|
||||
return 0, err
|
||||
|
Loading…
Reference in New Issue
Block a user