Compare commits

...

1 Commits

Author SHA1 Message Date
nemunaire 0ddd6c4899 Export themes as array 2018-05-13 14:16:16 +02:00
3 changed files with 83 additions and 70 deletions

View File

@ -41,6 +41,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
.run(function($rootScope, $interval) { .run(function($rootScope, $interval) {
$rootScope.current_theme = 0; $rootScope.current_theme = 0;
$rootScope.current_exercice = 0; $rootScope.current_exercice = 0;
$rootScope.current_exercice_my = 0;
$rootScope.time = {}; $rootScope.time = {};
$('[data-toggle="popover"]').popover(); $('[data-toggle="popover"]').popover();
@ -170,29 +171,30 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
$rootScope.current_exercice = $scope.exercicesUrl[$routeParams.exercice]; $rootScope.current_exercice = $scope.exercicesUrl[$routeParams.exercice];
} else { } else {
if ($scope.themes && $scope.my && $scope.themes[$scope.current_theme]) { if ($scope.themes && $scope.my && $scope.themes[$scope.current_theme]) {
var exos = Object.keys($scope.themes[$scope.current_theme].exercices); var exos = $scope.themes[$scope.current_theme].exercices;
var i = 0; var i = 0;
for (; i < exos.length; i++) { for (; i < exos.length; i++) {
if (!$scope.my.exercices || !$scope.my.exercices[exos[i]] || !$scope.my.exercices[exos[i]].solved) if (!$scope.my.exercices || !$scope.my.exercices[exos[i].id] || !$scope.my.exercices[exos[i].id].solved)
break; break;
} }
if (i < exos.length) { if (i < exos.length) {
$rootScope.current_exercice = exos[i]; $rootScope.current_exercice = i;
} else { } else {
$rootScope.current_exercice = exos[0]; $rootScope.current_exercice = 0;
} }
} else { } else {
$rootScope.current_exercice = 0; $rootScope.current_exercice = 0;
} }
} }
$rootScope.current_exercice_my = $scope.themes[$scope.current_theme].exercices[$rootScope.current_exercice].id;
$scope.hsubmit = function(hint) { $scope.hsubmit = function(hint) {
hint.submitted = true; hint.submitted = true;
$http({ url: "/openhint/" + $rootScope.current_exercice, method: "POST", data: { id: hint.id } }).then(function(response, status, header, config) { $http({ url: "/openhint/" + $rootScope.current_exercice_my, method: "POST", data: { id: hint.id } }).then(function(response, status, header, config) {
var checkDiffHint = function() { var checkDiffHint = function() {
$http.get("/my.json").then(function(response) { $http.get("/my.json").then(function(response) {
var my = response.data; var my = response.data;
angular.forEach(my.exercices[$rootScope.current_exercice].hints, function(h,hid){ angular.forEach(my.exercices[$rootScope.current_exercice_my].hints, function(h,hid){
if (hint.id == h.id) { if (hint.id == h.id) {
if (hint.content != h.content) { if (hint.content != h.content) {
$rootScope.refresh(); $rootScope.refresh();
@ -216,24 +218,24 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
$rootScope.sberr = ""; $rootScope.sberr = "";
var waitMy = function() { var waitMy = function() {
if (!$scope.my || !$scope.my.exercices || !$scope.my.exercices[$rootScope.current_exercice]) { if (!$scope.my || !$scope.my.exercices || !$scope.my.exercices[$rootScope.current_exercice_my]) {
$timeout.cancel($scope.cbs); $timeout.cancel($scope.cbs);
$scope.cbs = $timeout(waitMy, 420); $scope.cbs = $timeout(waitMy, 420);
} else { } else {
$scope.flags = []; $scope.flags = [];
angular.forEach($scope.my.exercices[$rootScope.current_exercice].keys, function(key,kid) { angular.forEach($scope.my.exercices[$rootScope.current_exercice_my].keys, function(key,kid) {
var o = { var o = {
id: kid, id: kid,
name: key, name: key,
value: "" value: ""
}; };
if ($scope.my.exercices[$rootScope.current_exercice].solved_matrix != null) if ($scope.my.exercices[$rootScope.current_exercice_my].solved_matrix != null)
o.found = $scope.my.exercices[$rootScope.current_exercice].solved_matrix[kid]; o.found = $scope.my.exercices[$rootScope.current_exercice_my].solved_matrix[kid];
this.push(o); this.push(o);
}, $scope.flags); }, $scope.flags);
$scope.mcqs = []; $scope.mcqs = [];
angular.forEach($scope.my.exercices[$rootScope.current_exercice].mcqs, function(mcq,qid) { angular.forEach($scope.my.exercices[$rootScope.current_exercice_my].mcqs, function(mcq,qid) {
var o = { var o = {
title: mcq.title, title: mcq.title,
kind: mcq.kind, kind: mcq.kind,
@ -273,7 +275,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
}); });
} }
$http({ url: "/submit/" + $rootScope.current_exercice, method: "POST", data: resp }).then(function(response, status, header, config) { $http({ url: "/submit/" + $rootScope.current_exercice_my, method: "POST", data: resp }).then(function(response, status, header, config) {
$rootScope.messageClass = {"text-success": true}; $rootScope.messageClass = {"text-success": true};
$rootScope.message = response.data.errmsg; $rootScope.message = response.data.errmsg;
$rootScope.sberr = ""; $rootScope.sberr = "";
@ -285,7 +287,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
var checkDiff = function() { var checkDiff = function() {
$http.get("/my.json").then(function(response) { $http.get("/my.json").then(function(response) {
var my = response.data; var my = response.data;
if ($scope.my.exercices[$rootScope.current_exercice].tries != my.exercices[$rootScope.current_exercice].tries || $scope.my.exercices[$rootScope.current_exercice].solved_time != my.exercices[$rootScope.current_exercice].solved_time) { if ($scope.my.exercices[$rootScope.current_exercice_my].tries != my.exercices[$rootScope.current_exercice_my].tries || $scope.my.exercices[$rootScope.current_exercice_my].solved_time != my.exercices[$rootScope.current_exercice_my].solved_time) {
$rootScope.refresh(); $rootScope.refresh();
$scope.my = my; $scope.my = my;
waitMy(); waitMy();
@ -298,7 +300,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
checkDiff(); checkDiff();
}, function(response, status, header, config) { }, function(response, status, header, config) {
if (status >= 500) { if (status >= 500) {
$scope.my.exercices[$rootScope.current_exercice].submitted = false; $scope.my.exercices[$rootScope.current_exercice_my].submitted = false;
} }
$rootScope.messageClass = {"text-danger": true}; $rootScope.messageClass = {"text-danger": true};
$rootScope.message = response.data.errmsg; $rootScope.message = response.data.errmsg;
@ -306,12 +308,13 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
$rootScope.sberr = "Une erreur est survenue lors de l'envoi. Veuillez réessayer dans quelques instants."; $rootScope.sberr = "Une erreur est survenue lors de l'envoi. Veuillez réessayer dans quelques instants.";
} }
}); });
$scope.my.exercices[$rootScope.current_exercice].submitted = true; $scope.my.exercices[$rootScope.current_exercice_my].submitted = true;
}; };
}) })
.controller("MyTeamController", function($scope, $http, $rootScope, $timeout) { .controller("MyTeamController", function($scope, $http, $rootScope, $timeout) {
$rootScope.current_theme = 0; $rootScope.current_theme = 0;
$rootScope.current_exercice = 0; $rootScope.current_exercice = 0;
$rootScope.current_exercice_my = 0;
if ($scope.my) { if ($scope.my) {
$rootScope.title = $scope.my.name; $rootScope.title = $scope.my.name;
$rootScope.authors = $scope.my.members.map(function (cur) { $rootScope.authors = $scope.my.members.map(function (cur) {
@ -373,6 +376,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
.controller("RegisterController", function($scope, $rootScope, $location, $http) { .controller("RegisterController", function($scope, $rootScope, $location, $http) {
$rootScope.current_theme = 0; $rootScope.current_theme = 0;
$rootScope.current_exercice = 0; $rootScope.current_exercice = 0;
$rootScope.current_exercice_my = 0;
$rootScope.title = "Bienvenue au challenge forensic !"; $rootScope.title = "Bienvenue au challenge forensic !";
$rootScope.authors = null; $rootScope.authors = null;
@ -443,6 +447,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
.controller("RankController", function($scope, $rootScope) { .controller("RankController", function($scope, $rootScope) {
$rootScope.current_theme = 0; $rootScope.current_theme = 0;
$rootScope.current_exercice = 0; $rootScope.current_exercice = 0;
$rootScope.current_exercice_my = 0;
$rootScope.title = "Classement général"; $rootScope.title = "Classement général";
$rootScope.authors = ""; $rootScope.authors = "";
@ -461,12 +466,14 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
.controller("VideosController", function($scope, $rootScope) { .controller("VideosController", function($scope, $rootScope) {
$rootScope.current_theme = 0; $rootScope.current_theme = 0;
$rootScope.current_exercice = 0; $rootScope.current_exercice = 0;
$rootScope.current_exercice_my = 0;
$rootScope.title = "Vidéos de résolution"; $rootScope.title = "Vidéos de résolution";
$rootScope.authors = ""; $rootScope.authors = "";
}) })
.controller("HomeController", function($scope, $rootScope) { .controller("HomeController", function($scope, $rootScope) {
$rootScope.current_theme = 0; $rootScope.current_theme = 0;
$rootScope.current_exercice = 0; $rootScope.current_exercice = 0;
$rootScope.current_exercice_my = 0;
$rootScope.title = ""; $rootScope.title = "";
$rootScope.authors = ""; $rootScope.authors = "";
}); });

View File

@ -12,15 +12,15 @@
</ol> </ol>
</nav> </nav>
<div class="alert alert-warning" style="margin-top:15px;" ng-if="!(my.exercices[current_exercice])"> <div class="alert alert-warning" style="margin-top:15px;" ng-if="!(my.exercices[current_exercice_my])">
Vous n'avez pas encore accès à cet exercice. Vous n'avez pas encore accès à cet exercice.
</div> </div>
<div class="jumbotron text-indent" style="margin-top: 15px" class="well well-lg" ng-if="!(my.exercices[current_exercice])"> <div class="jumbotron text-indent" style="margin-top: 15px" class="well well-lg" ng-if="!(my.exercices[current_exercice_my])">
<p class="lead text-justify" ng-bind-html="themes[current_theme].intro"></p> <p class="lead text-justify" ng-bind-html="themes[current_theme].intro"></p>
</div> </div>
<div class="jumbotron text-indent" style="margin-top: 15px" class="well well-lg" ng-if="(my.exercices[current_exercice])"> <div class="jumbotron text-indent" style="margin-top: 15px" class="well well-lg" ng-if="(my.exercices[current_exercice_my])">
<h3 class="display-4">{{ themes[current_theme].exercices[current_exercice].title }}</h3> <h3 class="display-4">{{ themes[current_theme].exercices[current_exercice].title }}</h3>
<p class="lead text-justify" ng-bind-html="my.exercices[current_exercice].statement"></p> <p class="lead text-justify" ng-bind-html="my.exercices[current_exercice_my].statement"></p>
<hr class="my-3"> <hr class="my-3">
<ul> <ul>
<li><strong>Gain&nbsp;:</strong> <ng-pluralize count="themes[current_theme].exercices[current_exercice].gain" when="{'one': '{} point', 'other': '{} points'}"></ng-pluralize> <em ng-if="settings.firstBlood && themes[current_theme].exercices[current_exercice].solved < 1">{{ 1 + settings.firstBlood | coeff }} prem's</em> <em ng-if="themes[current_theme].exercices[current_exercice].curcoeff != 1.0">{{ themes[current_theme].exercices[current_exercice].curcoeff | coeff }} bonus</em></li> <li><strong>Gain&nbsp;:</strong> <ng-pluralize count="themes[current_theme].exercices[current_exercice].gain" when="{'one': '{} point', 'other': '{} points'}"></ng-pluralize> <em ng-if="settings.firstBlood && themes[current_theme].exercices[current_exercice].solved < 1">{{ 1 + settings.firstBlood | coeff }} prem's</em> <em ng-if="themes[current_theme].exercices[current_exercice].curcoeff != 1.0">{{ themes[current_theme].exercices[current_exercice].curcoeff | coeff }} bonus</em></li>
@ -30,13 +30,13 @@
<div class="row"> <div class="row">
<div class="col-xl" ng-if="(my.exercices[current_exercice] && my.exercices[current_exercice].files.length)" style="margin-bottom: 15px"> <div class="col-xl" ng-if="(my.exercices[current_exercice_my] && my.exercices[current_exercice_my].files.length)" style="margin-bottom: 15px">
<div class="card" style="margin-bottom: 15px"> <div class="card" style="margin-bottom: 15px">
<div class="card-header text-white"> <div class="card-header text-white">
<span class="glyphicon glyphicon-download-alt" aria-hidden="true"></span> Téléchargements <span class="glyphicon glyphicon-download-alt" aria-hidden="true"></span> Téléchargements
</div> </div>
<div class="list-group"> <div class="list-group">
<a ng-href="{{ file.path }}" target="_self" class="list-group-item" ng-repeat="file in my.exercices[current_exercice].files"> <a ng-href="{{ file.path }}" target="_self" class="list-group-item" ng-repeat="file in my.exercices[current_exercice_my].files">
<h1 class="float-left" style="margin: 7px 7px 5px -5px"><span class="glyphicon glyphicon-download" aria-hidden="true"></span></h1> <h1 class="float-left" style="margin: 7px 7px 5px -5px"><span class="glyphicon glyphicon-download" aria-hidden="true"></span></h1>
<h4 class="list-group-item-heading"><strong><samp>{{ file.name }}</samp></strong></h4> <h4 class="list-group-item-heading"><strong><samp>{{ file.name }}</samp></strong></h4>
<p class="list-group-item-text"><nobr>Taille&nbsp;: <span title="{{ file.size }} octets">{{ file.size | size }}</span></nobr> &ndash; <nobr><span title="blake2.net">b2sum</span>&nbsp;: <samp class="cksum" title="{{ file.checksum }}">{{ file.checksum }}</samp></nobr></p> <p class="list-group-item-text"><nobr>Taille&nbsp;: <span title="{{ file.size }} octets">{{ file.size | size }}</span></nobr> &ndash; <nobr><span title="blake2.net">b2sum</span>&nbsp;: <samp class="cksum" title="{{ file.checksum }}">{{ file.checksum }}</samp></nobr></p>
@ -45,13 +45,13 @@
</div> </div>
</div> </div>
<div class="col-xl" ng-if="(my.exercices[current_exercice] && my.exercices[current_exercice].hints.length)" style="margin-bottom: 15px"> <div class="col-xl" ng-if="(my.exercices[current_exercice_my] && my.exercices[current_exercice_my].hints.length)" style="margin-bottom: 15px">
<div class="card border-info" style="margin-bottom: 15px"> <div class="card border-info" style="margin-bottom: 15px">
<div class="card-header bg-info text-white"> <div class="card-header bg-info text-white">
<span class="glyphicon glyphicon-lamp" aria-hidden="true"></span> Indices <span class="glyphicon glyphicon-lamp" aria-hidden="true"></span> Indices
</div> </div>
<div class="list-group"> <div class="list-group">
<a target="_self" class="list-group-item text-light" ng-repeat="hint in my.exercices[current_exercice].hints" ng-href="{{ hint.file }}"> <a target="_self" class="list-group-item text-light" ng-repeat="hint in my.exercices[current_exercice_my].hints" ng-href="{{ hint.file }}">
<button ng-click="hsubmit(hint)" class="float-right btn btn-info" ng-if="!(hint.content || hint.file)" ng-class="{disabled: hint.submitted}"><span class="glyphicon glyphicon-lock" aria-hidden="true"></span> Débloquer</button> <button ng-click="hsubmit(hint)" class="float-right btn btn-info" ng-if="!(hint.content || hint.file)" ng-class="{disabled: hint.submitted}"><span class="glyphicon glyphicon-lock" aria-hidden="true"></span> Débloquer</button>
<button ng-click="hint.hidden = false;" class="float-right btn btn-info" ng-if="!hint.file && hint.hidden"><span class="glyphicon glyphicon-lock" aria-hidden="true"></span> Afficher</button> <button ng-click="hint.hidden = false;" class="float-right btn btn-info" ng-if="!hint.file && hint.hidden"><span class="glyphicon glyphicon-lock" aria-hidden="true"></span> Afficher</button>
<h1 class="float-left" style="margin: 5px 7px 5px -5px" ng-if="hint.file"><span class="glyphicon glyphicon-download" aria-hidden="true"></span></h1> <h1 class="float-left" style="margin: 5px 7px 5px -5px" ng-if="hint.file"><span class="glyphicon glyphicon-download" aria-hidden="true"></span></h1>
@ -65,15 +65,15 @@
</div> </div>
<div class="col-xl" style="margin-bottom: 25px"> <div class="col-xl" style="margin-bottom: 25px">
<div class="card border-danger" ng-if="my.team_id && my.exercices[current_exercice] && !(my.exercices[current_exercice].solved)" style="margin-bottom: 15px"> <div class="card border-danger" ng-if="my.team_id && my.exercices[current_exercice_my] && !(my.exercices[current_exercice_my].solved)" style="margin-bottom: 15px">
<div class="card-header bg-danger text-white"> <div class="card-header bg-danger text-white">
<span class="glyphicon glyphicon-flag" aria-hidden="true"></span> Faire son rapport <span class="glyphicon glyphicon-flag" aria-hidden="true"></span> Faire son rapport
</div> </div>
<ul class="list-group" ng-if="(my.exercices[current_exercice].tries || my.exercices[current_exercice].submitted || sberr)"> <ul class="list-group" ng-if="(my.exercices[current_exercice_my].tries || my.exercices[current_exercice_my].submitted || sberr)">
<li class="list-group-item text-warning" ng-if="my.exercices[current_exercice].tries"><ng-pluralize count="my.exercices[current_exercice].tries" when="{'one': '{} tentative effectuée', 'other': '{} tentatives effectuées'}"></ng-pluralize>. Dernière solution envoyée à {{ my.exercices[current_exercice].solved_time | date:"mediumTime" }}. <span ng-if="my.exercices[current_exercice].solve_dist"><ng-pluralize count="my.exercices[current_exercice].solve_dist" when="{'one': '{} réponse erronée', 'other': '{} réponses erronées'}"></ng-pluralize>.</span></li> <li class="list-group-item text-warning" ng-if="my.exercices[current_exercice_my].tries"><ng-pluralize count="my.exercices[current_exercice_my].tries" when="{'one': '{} tentative effectuée', 'other': '{} tentatives effectuées'}"></ng-pluralize>. Dernière solution envoyée à {{ my.exercices[current_exercice_my].solved_time | date:"mediumTime" }}. <span ng-if="my.exercices[current_exercice_my].solve_dist"><ng-pluralize count="my.exercices[current_exercice_my].solve_dist" when="{'one': '{} réponse erronée', 'other': '{} réponses erronées'}"></ng-pluralize>.</span></li>
<li class="list-group-item" ng-class="messageClass" ng-if="my.exercices[current_exercice].submitted || sberr"><strong ng-if="!sberr">Votre solution a bien été envoyée !</strong><strong ng-if="sberr">{{ sberr }}</strong> {{ message }}</li> <li class="list-group-item" ng-class="messageClass" ng-if="my.exercices[current_exercice_my].submitted || sberr"><strong ng-if="!sberr">Votre solution a bien été envoyée !</strong><strong ng-if="sberr">{{ sberr }}</strong> {{ message }}</li>
</ul> </ul>
<div class="card-body" ng-if="!my.exercices[current_exercice].submitted || sberr"> <div class="card-body" ng-if="!my.exercices[current_exercice_my].submitted || sberr">
<form ng-controller="SubmissionController" ng-submit="ssubmit()"> <form ng-controller="SubmissionController" ng-submit="ssubmit()">
<div class="form-group" ng-repeat="key in flags"> <div class="form-group" ng-repeat="key in flags">
<label for="sol_{{ key.id }}">{{ key.name }}&nbsp;:</label> <label for="sol_{{ key.id }}">{{ key.name }}&nbsp;:</label>
@ -97,19 +97,19 @@
</div> </div>
</div> </div>
<div class="card border-success" ng-if="(my.team_id && my.exercices[current_exercice].solved)"> <div class="card border-success" ng-if="(my.team_id && my.exercices[current_exercice_my].solved)">
<div class="card-header bg-success text-white"> <div class="card-header bg-success text-white">
<span class="glyphicon glyphicon-flag" aria-hidden="true"></span> Challenge réussi ! <span class="glyphicon glyphicon-flag" aria-hidden="true"></span> Challenge réussi !
</div> </div>
<div class="card-body"> <div class="card-body">
<p class="card-text"> <p class="card-text">
Vous êtes la {{ my.exercices[current_exercice].solved_rank }}<sup><ng-pluralize count="my.exercices[current_exercice].solved_rank" when="{'one': 're', 'other': 'e'}"></ng-pluralize></sup> équipe à avoir résolu ce challenge à {{ my.exercices[current_exercice].solved_time | date:"mediumTime" }}. Vous avez marqué <ng-pluralize count="my.exercices[current_exercice].gain" when="{'one': '{} point', 'other': '{} points'}"></ng-pluralize> ! Vous êtes la {{ my.exercices[current_exercice_my].solved_rank }}<sup><ng-pluralize count="my.exercices[current_exercice_my].solved_rank" when="{'one': 're', 'other': 'e'}"></ng-pluralize></sup> équipe à avoir résolu ce challenge à {{ my.exercices[current_exercice_my].solved_time | date:"mediumTime" }}. Vous avez marqué <ng-pluralize count="my.exercices[current_exercice_my].gain" when="{'one': '{} point', 'other': '{} points'}"></ng-pluralize> !
</p> </p>
<a href="/{{ themes[current_theme].urlid }}" class="btn btn-success">Passer au challenge suivant</a> <a href="/{{ themes[current_theme].urlid }}" class="btn btn-success">Passer au challenge suivant</a>
</div> </div>
</div> </div>
<div class="card border-success" ng-if="(!my.team_id && my.exercices[current_exercice].keys)"> <div class="card border-success" ng-if="(!my.team_id && my.exercices[current_exercice_my].keys)">
<div class="card-header bg-success text-white"> <div class="card-header bg-success text-white">
<span class="glyphicon glyphicon-flag" aria-hidden="true"></span> Solution du challenge <span class="glyphicon glyphicon-flag" aria-hidden="true"></span> Solution du challenge
</div> </div>
@ -117,13 +117,13 @@
<p> <p>
Vérifiez les clefs que vous trouvez en comparant leur <a href="https://blake2.net/">BLAKE2b</a>&nbsp;: Vérifiez les clefs que vous trouvez en comparant leur <a href="https://blake2.net/">BLAKE2b</a>&nbsp;:
</p> </p>
<dl class="dl-horizontal" ng-repeat="key in my.exercices[current_exercice].keys"> <dl class="dl-horizontal" ng-repeat="key in my.exercices[current_exercice_my].keys">
<dt title="{{ key.slice(128) }}">{{ key.slice(128) }}</dt> <dt title="{{ key.slice(128) }}">{{ key.slice(128) }}</dt>
<dd><samp class="cksum">{{ key.slice(0, 128) }}</samp></dd> <dd><samp class="cksum">{{ key.slice(0, 128) }}</samp></dd>
</dl> </dl>
<div class="embed-responsive embed-responsive-16by9"> <div class="embed-responsive embed-responsive-16by9">
<iframe type="text/html" ng-if="my.exercices[current_exercice].video_uri" ng-src="{{ my.exercices[current_exercice].video_uri }}" class="embed-responsive-item"> <iframe type="text/html" ng-if="my.exercices[current_exercice_my].video_uri" ng-src="{{ my.exercices[current_exercice_my].video_uri }}" class="embed-responsive-item">
Regardez la vidéo de résolution de cet exercice&nbsp;: <a ng-href="{{ my.exercices[current_exercice].video_uri }}">{{ my.exercices[current_exercice].video_uri }}</a>. Regardez la vidéo de résolution de cet exercice&nbsp;: <a ng-href="{{ my.exercices[current_exercice_my].video_uri }}">{{ my.exercices[current_exercice_my].video_uri }}</a>.
</iframe> </iframe>
</div> </div>
</div> </div>

View File

@ -2,10 +2,12 @@ package fic
import ( import (
"fmt" "fmt"
"strings"
) )
// exportedExercice is a structure representing a challenge, as exposed to players. // ExportedExercice is a structure representing a challenge, as exposed to players.
type exportedExercice struct { type ExportedExercice struct {
Id int64 `json:"id"`
Title string `json:"title"` Title string `json:"title"`
URLId string `json:"urlid"` URLId string `json:"urlid"`
Gain int64 `json:"gain"` Gain int64 `json:"gain"`
@ -16,44 +18,48 @@ type exportedExercice struct {
// exportedTheme is a structure representing a Theme, as exposed to players. // exportedTheme is a structure representing a Theme, as exposed to players.
type exportedTheme struct { type exportedTheme struct {
Name string `json:"name"` Name string `json:"name"`
URLId string `json:"urlid"` URLId string `json:"urlid"`
Authors string `json:"authors"` Authors string `json:"authors"`
Intro string `json:"intro"` Intro string `json:"intro"`
Exercices map[string]exportedExercice `json:"exercices"` Exercices []ExportedExercice `json:"exercices"`
} }
// Exportedthemes exports themes from the database, to be displayed to players. // Exportedthemes exports themes from the database, to be displayed to players.
func ExportThemes() (interface{}, error) { func ExportThemes() (ret map[string]exportedTheme, err error) {
if themes, err := GetThemes(); err != nil { var themes []Theme
return nil, err
} else { if themes, err = GetThemes(); err != nil {
ret := map[string]exportedTheme{} return
for _, theme := range themes { }
if exercices, err := theme.GetExercices(); err != nil {
return nil, err ret = map[string]exportedTheme{}
} else { for _, theme := range themes {
exos := map[string]exportedExercice{} var exercices []Exercice
for _, exercice := range exercices { if exercices, err = theme.GetExercices(); err != nil {
exos[fmt.Sprintf("%d", exercice.Id)] = exportedExercice{ return
exercice.Title,
exercice.URLId,
exercice.Gain,
exercice.Coefficient,
exercice.SolvedCount(),
exercice.TriedTeamCount(),
}
}
ret[fmt.Sprintf("%d", theme.Id)] = exportedTheme{
theme.Name,
theme.URLId,
theme.Authors,
theme.Intro,
exos,
}
}
} }
return ret, nil var exos []ExportedExercice
for _, exercice := range exercices {
exos = append(exos, ExportedExercice{
exercice.Id,
exercice.Title,
exercice.URLId,
exercice.Gain,
exercice.Coefficient,
exercice.SolvedCount(),
exercice.TriedTeamCount(),
})
}
ret[fmt.Sprintf("%d", theme.Id)] = exportedTheme{
theme.Name[strings.Index(theme.Name, "-")+1:],
theme.URLId,
theme.Authors,
theme.Intro,
exos,
}
} }
return
} }