admin: interface to synchronize

This commit is contained in:
nemunaire 2017-12-17 15:39:20 +01:00
parent 993b83f8e7
commit 9225038ffa
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.themes = Theme.query();
$scope.fields = ["id", "name"]; $scope.fields = ["id", "name"];
$scope.show = function(id) { $scope.show = function(id) {
$location.url("/themes/" + 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.theme = Theme.get({ themeId: $routeParams.themeId });
$scope.fields = ["name", "authors"]; $scope.fields = ["name", "authors"];
@ -509,15 +527,74 @@ angular.module("FICApp")
$scope.deleteTheme = function() { $scope.deleteTheme = function() {
this.theme.$remove(function() { $location.url("/themes/");}); 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.exercices = Exercice.query();
$scope.fields = ["title", "statement", "videoURI"]; $scope.fields = ["title", "statement", "videoURI"];
$scope.show = function(id) { $scope.show = function(id) {
$location.url("/exercices/" + 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) { .controller("ExercicesListController", function($scope, ThemedExercice, $routeParams, $location) {
$scope.exercices = ThemedExercice.query({ themeId: $routeParams.themeId }); $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.files = ExerciceFile.query({ exerciceId: $routeParams.exerciceId });
$scope.deleteFile = function() { $scope.deleteFile = function() {
@ -559,9 +636,27 @@ angular.module("FICApp")
$scope.saveFile = function() { $scope.saveFile = function() {
this.file.$update(); 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.hints = ExerciceHint.query({ exerciceId: $routeParams.exerciceId });
$scope.addHint = function() { $scope.addHint = function() {
@ -579,9 +674,27 @@ angular.module("FICApp")
this.hint.$save({ exerciceId: $routeParams.exerciceId }); 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.keys = ExerciceKey.query({ exerciceId: $routeParams.exerciceId });
$scope.addKey = function() { $scope.addKey = function() {
@ -599,6 +712,24 @@ angular.module("FICApp")
this.key.$save({ exerciceId: $routeParams.exerciceId }); 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) { .controller("TeamsListController", function($scope, Team, $location) {

View File

@ -1,4 +1,15 @@
<h2>Exercices</h2> <h2>Exercices
<a ng-click="syncFull()" ng-class="{'disabled': inSync}" class="pull-right btn btn-default"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Synchroner</a>
<small style="height: 0px;">
<div class="checkbox pull-right"><label><input type="checkbox" ng-model="syncFiles"> Fichiers</label></div>
<div class="checkbox pull-right"><label><input type="checkbox" ng-model="syncHints"> Indices</label></div>
<div class="checkbox pull-right"><label><input type="checkbox" ng-model="syncKeys"> Flags</label></div>
</small>
</h2>
<div class="progress" ng-if="inSync">
<div class="progress-bar" style="width: {{ done * 100 / total }}%;"></div>
</div>
<div> <div>
<p><input type="search" class="form-control" placeholder="Search" ng-model="query"></p> <p><input type="search" class="form-control" placeholder="Search" ng-model="query"></p>

View File

@ -29,7 +29,7 @@
<div class="col-md-4" ng-controller="ExerciceHintsController"> <div class="col-md-4" ng-controller="ExerciceHintsController">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<h3 class="panel-title">Indices<a ng-click="addHint()" class="pull-right btn btn-xs btn-primary"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></a></h3> <h3 class="panel-title">Indices<a ng-click="syncHints()" class="pull-right btn btn-xs btn-default" style="margin-left: 7px"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span></a><a ng-click="addHint()" class="pull-right btn btn-xs btn-primary"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></a></h3>
</div> </div>
<div class="list-group"> <div class="list-group">
<form ng-submit="saveHint()" class="list-group-item form-horizontal" ng-repeat="hint in hints"> <form ng-submit="saveHint()" class="list-group-item form-horizontal" ng-repeat="hint in hints">
@ -61,7 +61,7 @@
<div class="col-md-4" ng-controller="ExerciceFilesController"> <div class="col-md-4" ng-controller="ExerciceFilesController">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<h3 class="panel-title">Téléchargements<a ng-click="addFile()" class="pull-right btn btn-xs btn-primary"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></a></h3> <h3 class="panel-title">Téléchargements<a ng-click="syncFiles()" class="pull-right btn btn-xs btn-default" style="margin-left: 7px"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span></a><a ng-click="addFile()" class="pull-right btn btn-xs btn-primary"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></a></h3>
</div> </div>
<div class="list-group"> <div class="list-group">
<form ng-submit="saveFile()" class="list-group-item form" ng-repeat="file in files"> <form ng-submit="saveFile()" class="list-group-item form" ng-repeat="file in files">
@ -79,7 +79,7 @@
<div class="col-md-4" ng-controller="ExerciceKeysController"> <div class="col-md-4" ng-controller="ExerciceKeysController">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<h3 class="panel-title">Drapeaux<a ng-click="addKey()" class="pull-right btn btn-xs btn-primary"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></a></h3> <h3 class="panel-title">Drapeaux<a ng-click="syncKeys()" class="pull-right btn btn-xs btn-default" style="margin-left: 7px"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span></a><a ng-click="addKey()" class="pull-right btn btn-xs btn-primary"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></a></h3>
</div> </div>
<div class="list-group"> <div class="list-group">
<form ng-submit="saveKey()" class="list-group-item form-horizontal" ng-repeat="key in keys"> <form ng-submit="saveKey()" class="list-group-item form-horizontal" ng-repeat="key in keys">

View File

@ -1,4 +1,4 @@
<h2>Thèmes<a ng-click="show('new')" class="pull-right btn btn-primary"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Ajouter un thème</a></h2> <h2>Thèmes<a ng-click="sync()" ng-class="{'disabled': inSync}" class="pull-right btn btn-default"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Synchroniser</a> <a ng-click="show('new')" class="pull-right btn btn-primary" style="margin-right: 10px;"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Ajouter un thème</a></h2>
<p><input type="search" class="form-control" placeholder="Search" ng-model="query"></p> <p><input type="search" class="form-control" placeholder="Search" ng-model="query"></p>
<table class="table table-hover table-bordered"> <table class="table table-hover table-bordered">

View File

@ -17,7 +17,7 @@
</form> </form>
<div ng-show="theme.id" ng-controller="ExercicesListController"> <div ng-show="theme.id" ng-controller="ExercicesListController">
<h3>Exercices<a ng-click="show('new')" class="pull-right btn btn-sm btn-primary"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Ajouter un exercice</a></h3> <h3>Exercices<a ng-click="syncExo()" ng-class="{'disabled': inSync}" class="pull-right btn btn-sm btn-default"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Synchroniser</a> <a ng-click="show('new')" class="pull-right btn btn-sm btn-primary" style="margin-right: 10px;"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Ajouter un exercice</a></h3>
<p><input type="search" class="form-control" placeholder="Search" ng-model="query"></p> <p><input type="search" class="form-control" placeholder="Search" ng-model="query"></p>
<table class="table table-hover table-bordered"> <table class="table table-hover table-bordered">