libfic: handle mcq in team history

This commit is contained in:
nemunaire 2018-12-02 04:52:48 +01:00
parent c5b65289d3
commit 614003a7cd
4 changed files with 26 additions and 3 deletions

View File

@ -17,6 +17,12 @@ const indextpl = `<!DOCTYPE html>
word-wrap: normal; word-wrap: normal;
white-space: nowrap; white-space: nowrap;
} }
.bg-mfound {
background-color: #7bcfd0;
}
.bg-ffound {
background-color: #7bdfc0;
}
</style> </style>
<base href="{{.urlbase}}"> <base href="{{.urlbase}}">
<script src="/js/d3.v3.min.js"></script> <script src="/js/d3.v3.min.js"></script>

View File

@ -15,6 +15,12 @@
word-wrap: normal; word-wrap: normal;
white-space: nowrap; white-space: nowrap;
} }
.bg-mfound {
background-color: #7bcfd0;
}
.bg-ffound {
background-color: #7bdfc0;
}
</style> </style>
<base href="/admin/"> <base href="/admin/">
<script src="/js/d3.v3.min.js"></script> <script src="/js/d3.v3.min.js"></script>

View File

@ -96,7 +96,7 @@
<div class="col-lg-4"> <div class="col-lg-4">
<table ng-controller="TeamHistoryController" class="table table-hover table-striped table-bordered bg-primary text-light"> <table ng-controller="TeamHistoryController" class="table table-hover table-striped table-bordered bg-primary text-light">
<tbody> <tbody>
<tr ng-repeat="row in history" ng-class="{'bg-success': row.kind == 'solved', 'bg-info': row.kind == 'hint', 'bg-warning': row.kind == 'key_found'}"> <tr ng-repeat="row in history" ng-class="{'bg-ffound': row.kind == 'flag_found', 'bg-mfound': row.kind == 'mcq_found', 'bg-success': row.kind == 'solved', 'bg-info': row.kind == 'hint', 'bg-warning': row.kind == 'key_found'}">
<td> <td>
<nobr>{{ row.time | date:"mediumTime" }}</nobr><br>{{ row.kind }} <nobr>{{ row.time | date:"mediumTime" }}</nobr><br>{{ row.kind }}
</td> </td>
@ -106,7 +106,10 @@
</span> </span>
<span ng-if="!row.primary_title">{{ row.primary }}</span> <span ng-if="!row.primary_title">{{ row.primary }}</span>
<span ng-if="row.secondary_title"> <span ng-if="row.secondary_title">
: <a href="exercices/{{ row.primary }}#key-{{ row.secondary }}" ng-if="row.kind == 'key_found'">{{ row.secondary_title }}</a> :
<a href="exercices/{{ row.primary }}#key-{{ row.secondary }}" ng-if="row.kind == 'key_found'">{{ row.secondary_title }}</a>
<a href="exercices/{{ row.primary }}#quizz-{{ row.secondary }}" ng-if="row.kind == 'mcq_found'">{{ row.secondary_title }}</a>
<a href="exercices/{{ row.primary }}#hint-{{ row.secondary }}" ng-if="row.kind == 'hint'">{{ row.secondary_title }}</a>
</span> </span>
<span ng-if="!row.secondary_title && row.secondary && row.kind == 'solved'">(coeff x{{ row.secondary }})</span> <span ng-if="!row.secondary_title && row.secondary && row.kind == 'solved'">(coeff x{{ row.secondary }})</span>
<span ng-if="!row.secondary_title && row.secondary && row.kind != 'solved'">: {{ row.secondary }}</span> <span ng-if="!row.secondary_title && row.secondary && row.kind != 'solved'">: {{ row.secondary }}</span>

View File

@ -8,7 +8,7 @@ import (
func (t Team) GetHistory() ([]map[string]interface{}, error) { func (t Team) GetHistory() ([]map[string]interface{}, error) {
hist := make([]map[string]interface{}, 0) hist := make([]map[string]interface{}, 0)
if rows, err := DBQuery(`SELECT id_team, "tries" AS kind, time, E.id_exercice, E.title, NULL, NULL FROM exercice_tries T INNER JOIN exercices E ON E.id_exercice = T.id_exercice WHERE id_team = ? UNION SELECT id_team, "solved" AS kind, time, E.id_exercice, E.title, coefficient, NULL FROM exercice_solved S INNER JOIN exercices E ON E.id_exercice = S.id_exercice WHERE id_team = ? UNION SELECT id_team, "hint" AS kind, time, E.id_exercice, E.title, H.id_hint, H.title FROM team_hints T INNER JOIN exercice_hints H ON H.id_hint = T.id_hint INNER JOIN exercices E ON E.id_exercice = H.id_exercice WHERE id_team = ? UNION SELECT id_team, "flag_found" AS kind, time, E.id_exercice, E.title, K.id_flag, K.type FROM flag_found F INNER JOIN exercice_flags K ON K.id_flag = F.id_flag INNER JOIN exercices E ON K.id_exercice = E.id_exercice WHERE id_team = ? ORDER BY time DESC`, t.Id, t.Id, t.Id, t.Id); err != nil { if rows, err := DBQuery(`SELECT id_team, "tries" AS kind, time, E.id_exercice, E.title, NULL, NULL FROM exercice_tries T INNER JOIN exercices E ON E.id_exercice = T.id_exercice WHERE id_team = ? UNION SELECT id_team, "solved" AS kind, time, E.id_exercice, E.title, coefficient, NULL FROM exercice_solved S INNER JOIN exercices E ON E.id_exercice = S.id_exercice WHERE id_team = ? UNION SELECT id_team, "hint" AS kind, time, E.id_exercice, E.title, H.id_hint, H.title FROM team_hints T INNER JOIN exercice_hints H ON H.id_hint = T.id_hint INNER JOIN exercices E ON E.id_exercice = H.id_exercice WHERE id_team = ? UNION SELECT id_team, "flag_found" AS kind, time, E.id_exercice, E.title, K.id_flag, K.type FROM flag_found F INNER JOIN exercice_flags K ON K.id_flag = F.id_flag INNER JOIN exercices E ON K.id_exercice = E.id_exercice WHERE id_team = ? UNION SELECT id_team, "mcq_found" AS kind, time, E.id_exercice, E.title, Q.id_mcq, Q.title FROM mcq_found F INNER JOIN exercice_mcq Q ON Q.id_mcq = F.id_mcq INNER JOIN exercices E ON Q.id_exercice = E.id_exercice WHERE id_team = ? ORDER BY time DESC`, t.Id, t.Id, t.Id, t.Id, t.Id); err != nil {
return nil, err return nil, err
} else { } else {
defer rows.Close() defer rows.Close()
@ -72,6 +72,14 @@ func (t Team) DelHistoryItem(kind string, h time.Time, primary *int64, secondary
} else { } else {
return nb, err return nb, err
} }
} else if kind == "mcq_found" && secondary != nil {
if res, err := DBExec("DELETE FROM mcq_found WHERE id_team = ? AND time = ? AND id_mcq = ?", t.Id, h, *secondary); err != nil {
return 0, err
} else if nb, err := res.RowsAffected(); err != nil {
return 0, err
} else {
return nb, err
}
} else if kind == "solved" && primary != nil { } else if kind == "solved" && primary != nil {
if res, err := DBExec("DELETE FROM exercice_solved WHERE id_team = ? AND time = ? AND id_exercice = ?", t.Id, h, *primary); err != nil { if res, err := DBExec("DELETE FROM exercice_solved WHERE id_team = ? AND time = ? AND id_exercice = ?", t.Id, h, *primary); err != nil {
return 0, err return 0, err