[admin] Add exercices related pages

This commit is contained in:
nemunaire 2016-12-26 01:23:31 +01:00 committed by Pierre-Olivier Mercier
parent f9c053397a
commit f0f39e4905
3 changed files with 233 additions and 9 deletions

View file

@ -9,7 +9,15 @@ angular.module("FICApp", ["ngRoute", "ngResource", "ngSanitize"])
controller: "ThemeController",
templateUrl: "views/theme.html"
})
.when("/themes/:themeId/:exerciceId", {
.when("/themes/:themeId/exercices/:exerciceId", {
controller: "ExerciceController",
templateUrl: "views/exercice.html"
})
.when("/exercices", {
controller: "AllExercicesListController",
templateUrl: "views/exercice-list.html"
})
.when("/exercices/:exerciceId", {
controller: "ExerciceController",
templateUrl: "views/exercice.html"
})
@ -65,10 +73,30 @@ angular.module("FICApp")
'get': {method: 'GET'},
})
})
.factory("ThemedExercice", function($resource) {
return $resource("/api/themes/:themeId/exercices/:exerciceId", { exerciceId: '@id' }, {
update: {method: 'PUT'}
})
})
.factory("Exercice", function($resource) {
return $resource("/api/exercices/:exerciceId", { exerciceId: '@id' }, {
update: {method: 'PUT'}
})
})
.factory("ExerciceFile", function($resource) {
return $resource("/api/exercices/:exerciceId/files", { exerciceId: '@idExercice' }, {
update: {method: 'PATCH'}
})
})
.factory("ExerciceHint", function($resource) {
return $resource("/api/exercices/:exerciceId/hints", { exerciceId: '@idExercice' }, {
update: {method: 'PATCH'}
})
})
.factory("ExerciceKey", function($resource) {
return $resource("/api/exercices/:exerciceId/keys", { exerciceId: '@idExercice' }, {
update: {method: 'PATCH'}
})
});
String.prototype.capitalize = function() {
@ -87,6 +115,41 @@ angular.module("FICApp")
return input.capitalize();
}
})
.filter("size", function() {
var units = [
"o",
"kio",
"Mio",
"Gio",
"Tio",
"Pio",
"Eio",
"Zio",
"Yio",
]
return function(input) {
var res = input;
var unit = 0;
while (res > 1024) {
unit += 1;
res = res / 1024;
}
return (Math.round(res * 100) / 100) + " " + units[unit];
}
})
.filter("cksum", function() {
return function(input) {
if (input == undefined)
return input;
var raw = atob(input).toString(16);
var hex = '';
for (var i = 0; i < raw.length; i++ ) {
var _hex = raw.charCodeAt(i).toString(16)
hex += (_hex.length == 2 ? _hex : '0' + _hex);
}
return hex
}
})
.filter("time", function() {
return function(input) {
if (input == undefined) {
@ -123,20 +186,62 @@ angular.module("FICApp")
}
})
.controller("ExercicesListController", function($scope, Exercice, $routeParams, $location) {
$scope.exercices = Exercice.query({ themeId: $routeParams.themeId });
.controller("AllExercicesListController", function($scope, Exercice, $routeParams, $location) {
$scope.exercices = Exercice.query();
$scope.fields = ["id", "title", "statement", "videoURI"];
$scope.show = function(id) {
$location.url("/themes/" + $routeParams.themeId + "/" + id);
$location.url("/exercices/" + id);
};
})
.controller("ExerciceController", function($scope, Theme, $routeParams) {
$scope.exercice = Exercice.get({ themeId: $routeParams.themeId });
$scope.fields = ["name", "statement", "hint", "videoURI"];
.controller("ExercicesListController", function($scope, ThemedExercice, $routeParams, $location) {
$scope.exercices = ThemedExercice.query({ themeId: $routeParams.themeId });
$scope.fields = ["id", "title", "statement", "videoURI"];
$scope.saveTheme = function() {
this.exercice.$save({ themeId: this.exercice.themeId, exerciceId: this.exercice.exerciceId});
$scope.show = function(id) {
$location.url("/themes/" + $routeParams.themeId + "/exercices/" + id);
};
})
.controller("ExerciceController", function($scope, Exercice, $routeParams) {
$scope.exercice = Exercice.get({ exerciceId: $routeParams.exerciceId });
$scope.exercices = Exercice.query();
$scope.fields = ["title", "statement", "depend", "gain", "videoURI"];
$scope.saveExercice = function() {
this.exercice.$update();
}
})
.controller("ExerciceFilesController", function($scope, ExerciceFile, $routeParams) {
$scope.files = ExerciceFile.query({ exerciceId: $routeParams.exerciceId });
$scope.deleteFile = function() {
this.file.$delete();
}
$scope.saveFile = function() {
this.file.$update();
}
})
.controller("ExerciceHintsController", function($scope, ExerciceHint, $routeParams) {
$scope.hints = ExerciceHint.query({ exerciceId: $routeParams.exerciceId });
$scope.deleteHint = function() {
this.hint.$delete();
}
$scope.saveHint = function() {
this.hint.$update();
}
})
.controller("ExerciceKeysController", function($scope, ExerciceKey, $routeParams) {
$scope.keys = ExerciceKey.query({ exerciceId: $routeParams.exerciceId });
$scope.deleteKey = function() {
this.key.$delete();
}
$scope.saveKey = function() {
this.key.$update();
}
})