admin: interface to synchronize

This commit is contained in:
nemunaire 2017-12-17 15:39:20 +01:00
commit 9abac6e47b
5 changed files with 154 additions and 12 deletions

View file

@ -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) {