implement choices_cost

This commit is contained in:
nemunaire 2018-12-02 23:18:32 +01:00
commit 476f0f553c
18 changed files with 180 additions and 24 deletions

19
frontend/choices.go Normal file
View file

@ -0,0 +1,19 @@
package main
import (
"net/http"
"path"
"time"
)
func WantChoicesHandler(w http.ResponseWriter, r *http.Request, team string, sURL []string) {
if time.Now().Sub(challengeEnd) > 0 {
http.Error(w, "{\"errmsg\":\"Le challenge est terminé, trop tard !\"}", http.StatusGone)
return
}
// Enqueue file for backend treatment
if saveTeamFile(path.Join(team, "choices"), w, r) {
http.Error(w, "{\"errmsg\":\"Demande de choix acceptée...\"}", http.StatusAccepted)
}
}

View file

@ -47,6 +47,7 @@ func main() {
// Register handlers
http.Handle(fmt.Sprintf("%s/chname/", *prefix), http.StripPrefix(fmt.Sprintf("%s/chname/", *prefix), submissionTeamChecker{"name change", ChNameHandler, *teamsDir}))
http.Handle(fmt.Sprintf("%s/openhint/", *prefix), http.StripPrefix(fmt.Sprintf("%s/openhint/", *prefix), submissionTeamChecker{"opening hint", HintHandler, *teamsDir}))
http.Handle(fmt.Sprintf("%s/wantchoices/", *prefix), http.StripPrefix(fmt.Sprintf("%s/wantchoices/", *prefix), submissionTeamChecker{"wantint choices", WantChoicesHandler, *teamsDir}))
http.Handle(fmt.Sprintf("%s/registration/", *prefix), http.StripPrefix(fmt.Sprintf("%s/registration/", *prefix), submissionChecker{"registration", RegistrationHandler}))
http.Handle(fmt.Sprintf("%s/resolution/", *prefix), http.StripPrefix(fmt.Sprintf("%s/resolution/", *prefix), ResolutionHandler{}))
http.Handle(fmt.Sprintf("%s/submission/", *prefix), http.StripPrefix(fmt.Sprintf("%s/submission/", *prefix), submissionTeamChecker{"submission", SubmissionHandler, *teamsDir}))

View file

@ -426,6 +426,30 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
});
$scope.my.exercices[$rootScope.current_exercice].submitted = true;
};
$scope.wantchoices = function(kid) {
$scope.my.exercices[$rootScope.current_exercice].flags[kid].wcsubmitted = true;
$http({ url: "/wantchoices/" + $rootScope.current_exercice, method: "POST", data: { id: Math.floor(kid) } }).then(function(response) {
var checkDiffWC = function() {
$http.get("/my.json").then(function(response) {
var my = response.data;
if (my.exercices[$rootScope.current_exercice].flags[kid].choices)
$rootScope.recvMy(my);
else {
if (cbd)
$timeout.cancel(cbd);
cbd = $timeout(checkDiffWC, 750);
}
});
};
checkDiffWC();
}, function(response) {
$scope.messageClass = {"text-danger": true};
$scope.sberr = "Oups !";
$scope.message = response.data.errmsg;
$scope.my.exercices[$rootScope.current_exercice].flags[kid].wcsubmitted = false;
});
}
})
.controller("MyTeamController", function($scope, $http, $rootScope, $timeout) {
$rootScope.current_theme = 0;

View file

@ -88,8 +88,16 @@
<div class="form-group" ng-repeat="(kid,key) in my.exercices[current_exercice].flags">
<label for="sol_{{ kid }}">{{ key.label }}&nbsp;:</label>
<span ng-if="key.found && key.value" ng-bind="key.value"></span>
<input type="text" class="form-control" id="sol_{{ kid }}" autocomplete="off" name="sol_{{ kid }}" ng-model="key.value" ng-if="!key.found && !key.choices">
<select class="custom-select" id="sol_{{ kid }}" name="sol_{{ kid }}" ng-model="key.value" ng-if="!key.found && key.choices" ng-options="l as v for (l, v) in key.choices"></select>
<div class="input-group">
<input type="text" class="form-control" id="sol_{{ kid }}" autocomplete="off" name="sol_{{ kid }}" ng-model="key.value" ng-if="!key.found && !key.choices">
<select class="custom-select" id="sol_{{ kid }}" name="sol_{{ kid }}" ng-model="key.value" ng-if="!key.found && key.choices" ng-options="l as v for (l, v) in key.choices"></select>
<div class="input-group-append" ng-if="key.choices_cost">
<button class="btn btn-success" type="button" ng-click="wantchoices(kid)" ng-class="{disabled: key.wcsubmitted}" title="Cliquez pour échanger ce champ de texte par une liste de choix. L'opération vous coûtera {{ key.choices_cost }} points.">
<span class="glyphicon glyphicon-tasks" aria-hidden="true"></span>
Liste de propositions ({{ key.choices_cost }} points)
</button>
</div>
</div>
<small class="form-text text-muted" ng-if="!key.found && key.help.length > 0" ng-bind="key.help"></small>
<span class="glyphicon glyphicon-ok form-control-feedback text-success" aria-hidden="true" ng-if="key.found" title="Flag trouvé à {{ key.found | date:'mediumTime'}}"></span>
</div>

View file

@ -23,9 +23,9 @@
<div class="col-sm-10">
<div class="input-group">
<input type="text" class="form-control" id="newName" ng-model="newName" placeholder="{{ my.name }}">
<span class="input-group-btn">
<div class="input-group-append">
<button type="submit" class="btn btn-info">Valider</button>
</span>
</div>
</div>
</div>
</div>