diff --git a/admin/static/js/app.js b/admin/static/js/app.js index 9d2b072c..b2f98356 100644 --- a/admin/static/js/app.js +++ b/admin/static/js/app.js @@ -485,15 +485,33 @@ angular.module("FICApp") } }) - .controller("ThemesListController", function($scope, Theme, $location) { + .controller("ThemesListController", function($scope, Theme, $location, $rootScope, $http) { $scope.themes = Theme.query(); $scope.fields = ["id", "name"]; $scope.show = function(id) { $location.url("/themes/" + id); }; + $scope.inSync = false; + $scope.sync = function() { + $scope.inSync = true; + $http({ + url: "/api/sync/themes", + method: "GET" + }).then(function(response) { + $scope.inSync = false; + $scope.themes = Theme.query(); + if (response.data) + $rootScope.newBox('danger', response.data); + else + $rootScope.newBox('success', 'Synchronisation de la liste des thèmes terminée avec succès.'); + }, function(response) { + $scope.inSync = false; + $rootScope.newBox('danger', 'An error occurs when synchronizing theme list:', response.data); + }); + }; }) - .controller("ThemeController", function($scope, Theme, $routeParams, $location) { + .controller("ThemeController", function($scope, Theme, $routeParams, $location, $rootScope, $http) { $scope.theme = Theme.get({ themeId: $routeParams.themeId }); $scope.fields = ["name", "authors"]; @@ -509,15 +527,74 @@ angular.module("FICApp") $scope.deleteTheme = function() { this.theme.$remove(function() { $location.url("/themes/");}); } + $scope.inSync = false; + $scope.syncExo = function() { + $scope.inSync = true; + $http({ + url: "/api/sync/themes/" + $scope.theme.id + "/exercices", + method: "GET" + }).then(function(response) { + $scope.inSync = false; + $scope.theme = Theme.get({ themeId: $routeParams.themeId }); + if (response.data) + $rootScope.newBox('warning', null, response.data, -1); + else + $rootScope.newBox('success', 'Synchronisation de la liste des exercices terminée avec succès.'); + }, function(response) { + $scope.inSync = false; + $rootScope.newBox('danger', 'An error occurs when synchrinizing exercices:', response.data); + }); + }; }) - .controller("AllExercicesListController", function($scope, Exercice, $routeParams, $location) { + .controller("AllExercicesListController", function($scope, Exercice, $routeParams, $location, $rootScope, $http) { $scope.exercices = Exercice.query(); $scope.fields = ["title", "statement", "videoURI"]; $scope.show = function(id) { $location.url("/exercices/" + id); }; + $scope.inSync = false; + $scope.syncFull = function() { + $scope.inSync = true; + $scope.done = -1; + $scope.total = 0; + var work = []; + var go = function() { + if (!work.length) { + $rootScope.newBox('info', "Synchronisation des exercices terminée."); + $scope.inSync = false; + return; + } + var u = work.pop(); + + $http({ + url: u, + method: "GET" + }).then(function(response) { + $scope.done += 1; + go(); + }, function(response) { + $scope.done += 1; + go(); + }); + }; + + angular.forEach($scope.exercices, function(ex) { + if ($scope.syncFiles) + work.push("/api/sync/exercices/" + ex.id + "/files"); + if ($scope.syncHints) + work.push("/api/sync/exercices/" + ex.id + "/hints"); + if ($scope.syncKeys) + work.push("/api/sync/exercices/" + ex.id + "/keys"); + }); + $scope.total = work.length; + go(); + + }; + $scope.syncFiles = true; + $scope.syncHints = true; + $scope.syncKeys = true; }) .controller("ExercicesListController", function($scope, ThemedExercice, $routeParams, $location) { $scope.exercices = ThemedExercice.query({ themeId: $routeParams.themeId }); @@ -547,7 +624,7 @@ angular.module("FICApp") } }) - .controller("ExerciceFilesController", function($scope, ExerciceFile, $routeParams) { + .controller("ExerciceFilesController", function($scope, ExerciceFile, $routeParams, $rootScope, $http) { $scope.files = ExerciceFile.query({ exerciceId: $routeParams.exerciceId }); $scope.deleteFile = function() { @@ -559,9 +636,27 @@ angular.module("FICApp") $scope.saveFile = function() { this.file.$update(); } + $scope.inSync = false; + $scope.syncFiles = function() { + $scope.inSync = true; + $http({ + url: "/api/sync/exercices/" + $routeParams.exerciceId + "/files", + method: "GET" + }).then(function(response) { + $scope.inSync = false; + $scope.files = ExerciceFile.query({ exerciceId: $routeParams.exerciceId }); + if (response.data) + $rootScope.newBox('danger', response.data); + else + $rootScope.newBox('success', "Synchronisation de la liste de drapeaux terminée avec succès."); + }, function(response) { + $scope.inSync = false; + $rootScope.newBox('danger', 'An error occurs when synchronizing flags list:', response.data); + }); + }; }) - .controller("ExerciceHintsController", function($scope, ExerciceHint, $routeParams) { + .controller("ExerciceHintsController", function($scope, ExerciceHint, $routeParams, $rootScope, $http) { $scope.hints = ExerciceHint.query({ exerciceId: $routeParams.exerciceId }); $scope.addHint = function() { @@ -579,9 +674,27 @@ angular.module("FICApp") this.hint.$save({ exerciceId: $routeParams.exerciceId }); } } + $scope.inSync = false; + $scope.syncHints = function() { + $scope.inSync = true; + $http({ + url: "/api/sync/exercices/" + $routeParams.exerciceId + "/hints", + method: "GET" + }).then(function(response) { + $scope.inSync = false; + $scope.hints = ExerciceHint.query({ exerciceId: $routeParams.exerciceId }); + if (response.data) + $rootScope.newBox('danger', response.data); + else + $rootScope.newBox('success', "Synchronisation de la liste d'indices terminée avec succès."); + }, function(response) { + $scope.inSync = false; + $rootScope.newBox('danger', 'An error occurs when synchronizing hints list:', response.data); + }); + }; }) - .controller("ExerciceKeysController", function($scope, ExerciceKey, $routeParams) { + .controller("ExerciceKeysController", function($scope, ExerciceKey, $routeParams, $rootScope, $http) { $scope.keys = ExerciceKey.query({ exerciceId: $routeParams.exerciceId }); $scope.addKey = function() { @@ -599,6 +712,24 @@ angular.module("FICApp") this.key.$save({ exerciceId: $routeParams.exerciceId }); } } + $scope.inSync = false; + $scope.syncKeys = function() { + $scope.inSync = true; + $http({ + url: "/api/sync/exercices/" + $routeParams.exerciceId + "/keys", + method: "GET" + }).then(function(response) { + $scope.inSync = false; + $scope.keys = ExerciceKey.query({ exerciceId: $routeParams.exerciceId }); + if (response.data) + $rootScope.newBox('danger', response.data); + else + $rootScope.newBox('success', "Synchronisation de la liste de drapeaux terminée avec succès."); + }, function(response) { + $scope.inSync = false; + $rootScope.newBox('danger', 'An error occurs when synchronizing flags list:', response.data); + }); + }; }) .controller("TeamsListController", function($scope, Team, $location) { diff --git a/admin/static/views/exercice-list.html b/admin/static/views/exercice-list.html index b8ec8172..2476ad6e 100644 --- a/admin/static/views/exercice-list.html +++ b/admin/static/views/exercice-list.html @@ -1,4 +1,15 @@ -

Exercices

+

Exercices + Synchroner + +
+
+
+
+

+ +
+
+

diff --git a/admin/static/views/exercice.html b/admin/static/views/exercice.html index 155eaf60..9197bbd2 100644 --- a/admin/static/views/exercice.html +++ b/admin/static/views/exercice.html @@ -29,7 +29,7 @@
-

Indices

+

Indices

@@ -61,7 +61,7 @@
-

Téléchargements

+

Téléchargements

@@ -79,7 +79,7 @@
-

Drapeaux

+

Drapeaux

diff --git a/admin/static/views/theme-list.html b/admin/static/views/theme-list.html index 7cef07a6..1a54c0ae 100644 --- a/admin/static/views/theme-list.html +++ b/admin/static/views/theme-list.html @@ -1,4 +1,4 @@ -

Thèmes Ajouter un thème

+

Thèmes Synchroniser Ajouter un thème

diff --git a/admin/static/views/theme.html b/admin/static/views/theme.html index 3469a04a..58cf7340 100644 --- a/admin/static/views/theme.html +++ b/admin/static/views/theme.html @@ -17,7 +17,7 @@