From 863070c0377239478f907a59d973211631ad4253 Mon Sep 17 00:00:00 2001 From: nemunaire Date: Mon, 26 Dec 2016 01:23:31 +0100 Subject: [PATCH] [admin] Add exercices related pages --- admin/static/js/app.js | 123 ++++++++++++++++++++++++-- admin/static/views/exercice-list.html | 21 +++++ admin/static/views/exercice.html | 98 ++++++++++++++++++++ 3 files changed, 233 insertions(+), 9 deletions(-) create mode 100644 admin/static/views/exercice-list.html create mode 100644 admin/static/views/exercice.html diff --git a/admin/static/js/app.js b/admin/static/js/app.js index 44ae020b..c59a8a53 100644 --- a/admin/static/js/app.js +++ b/admin/static/js/app.js @@ -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(); } }) diff --git a/admin/static/views/exercice-list.html b/admin/static/views/exercice-list.html new file mode 100644 index 00000000..b8ec8172 --- /dev/null +++ b/admin/static/views/exercice-list.html @@ -0,0 +1,21 @@ +

Exercices

+ +
+

+ + + + + + + + + + + +
+ {{ field }} +
+ {{ exercice[field] }} +
+
diff --git a/admin/static/views/exercice.html b/admin/static/views/exercice.html new file mode 100644 index 00000000..8a94cf5f --- /dev/null +++ b/admin/static/views/exercice.html @@ -0,0 +1,98 @@ +

{{exercice.title}}

+ +
+
+ +
+ + + +
+
+
+ + +
+
+ +
+ +
+ +
+
+
+

Indices

+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ + +
+
+
+
+ +
+
+
+

Téléchargements

+
+
+
+ + + +
+ Taille : {{ file.size | size }}
+ SHA-1 : {{ file.checksum | cksum }} +
+
+
+
+ +
+
+
+

Drapeaux

+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+
+ +