frontend: interface can open hints

This commit is contained in:
nemunaire 2016-12-09 11:55:58 +01:00
parent f4f55f37ee
commit b132f8d694
2 changed files with 32 additions and 3 deletions

View File

@ -172,7 +172,7 @@ angular.module("FICApp")
} }
$rootScope.refresh(); $rootScope.refresh();
}) })
.controller("ExerciceController", function($scope, $routeParams, $http, $rootScope) { .controller("ExerciceController", function($scope, $routeParams, $http, $rootScope, $timeout) {
$rootScope.current_theme = $routeParams.theme; $rootScope.current_theme = $routeParams.theme;
if ($routeParams.exercice) { if ($routeParams.exercice) {
@ -195,6 +195,35 @@ angular.module("FICApp")
} }
} }
$scope.hsubmit = function(hint) {
hint.submitted = true;
$http({
url: "/openhint/" + $rootScope.current_exercice,
method: "POST",
data: {
id: hint.id
}
}).success(function(data, status, header, config) {
var checkDiffHint = function() {
$http.get("/my.json").success(function(my) {
angular.forEach(my.exercices[$rootScope.current_exercice].hints, function(h,hid){
if (hint.id == h.id) {
if (hint.content != h.content) {
$rootScope.refresh();
} else {
$timeout.cancel($scope.cbh);
$scope.cbh = $timeout(checkDiffHint, 750);
}
}
});
});
};
checkDiffHint();
}).error(function(data, status, header, config) {
hint.submitted = false;
console.error(data.errmsg);
});
};
}) })
.controller("SubmissionController", function($scope, $http, $rootScope, $timeout) { .controller("SubmissionController", function($scope, $http, $rootScope, $timeout) {
$scope.flags = []; $scope.flags = [];

View File

@ -32,8 +32,8 @@
</div> </div>
<ul class="list-group"> <ul class="list-group">
<li class="list-group-item" ng-repeat="hint in my.exercices[current_exercice].hints"> <li class="list-group-item" ng-repeat="hint in my.exercices[current_exercice].hints">
<form class="pull-right" ng-show="!hint.unlocked"> <form class="pull-right" ng-show="!hint.unlocked" ng-submit="hsubmit(hint)">
<button type="submit" class="btn btn-info"><span class="glyphicon glyphicon-lock" aria-hidden="true"></span> Débloquer</button> <button type="submit" class="btn btn-info" ng-class="{disabled: hint.submitted}"><span class="glyphicon glyphicon-lock" aria-hidden="true"></span> Débloquer</button>
</form> </form>
<h4 class="list-group-item-heading">{{ hint.title }}</h4> <h4 class="list-group-item-heading">{{ hint.title }}</h4>
<p class="list-group-item-text" ng-show="hint.unlocked" ng-bind-html="hint.content"></p> <p class="list-group-item-text" ng-show="hint.unlocked" ng-bind-html="hint.content"></p>