admin: add the ability to sync only one exercice

This commit is contained in:
nemunaire 2018-12-05 05:03:21 +01:00
parent dc4a4925e3
commit 2ccc59b4fa
3 changed files with 65 additions and 24 deletions

View File

@ -52,6 +52,11 @@ func init() {
router.PUT("/api/exercices/:eid/tags", apiHandler(exerciceHandler(updateExerciceTags)))
// Synchronize
router.POST("/api/sync/themes/:thid/exercices/:eid", apiHandler(themedExerciceHandler(
func(theme fic.Theme, exercice fic.Exercice, _ []byte) (interface{}, error) {
_, _, errs := sync.SyncExercice(sync.GlobalImporter, theme, exercice.Path, nil)
return errs, nil
})))
router.POST("/api/sync/exercices/:eid/files", apiHandler(exerciceHandler(
func(exercice fic.Exercice, _ []byte) (interface{}, error) {
return sync.SyncExerciceFiles(sync.GlobalImporter, exercice), nil

View File

@ -907,26 +907,12 @@ 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: "POST"
}).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.');
this.theme.$remove(function() {
$location.url("/themes/");
}, function(response) {
$scope.inSync = false;
$rootScope.newBox('danger', 'An error occurs when synchrinizing exercices:', response.data);
$rootScope.newBox('danger', 'An error occurs when trying to delete theme:', response.data.errmsg);
});
};
}
})
.controller("AllExercicesListController", function($scope, Exercice, $routeParams, $location, $rootScope, $http, $filter) {
@ -995,15 +981,34 @@ angular.module("FICApp")
$scope.syncHints = true;
$scope.syncFlags = true;
})
.controller("ExercicesListController", function($scope, ThemedExercice, $routeParams, $location) {
.controller("ExercicesListController", function($scope, ThemedExercice, $routeParams, $location, $rootScope, $http) {
$scope.exercices = ThemedExercice.query({ themeId: $routeParams.themeId });
$scope.fields = ["title", "statement", "overview", "videoURI"];
$scope.show = function(id) {
$location.url("/themes/" + $routeParams.themeId + "/exercices/" + id);
};
$scope.inSync = false;
$scope.syncExo = function() {
$scope.inSync = true;
$http({
url: "/api/sync/themes/" + $scope.theme.id + "/exercices",
method: "POST"
}).then(function(response) {
$scope.inSync = false;
$scope.exercices = ThemedExercice.query({ 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.errmsg);
});
};
})
.controller("ExerciceController", function($scope, Exercice, ThemedExercice, $routeParams, $location) {
.controller("ExerciceController", function($scope, $rootScope, Exercice, ThemedExercice, $routeParams, $location, $http) {
if ($routeParams.themeId && $routeParams.exerciceId == "new") {
$scope.exercice = new ThemedExercice();
} else {
@ -1037,18 +1042,46 @@ angular.module("FICApp")
$scope.showQuizz = val || !$scope.showQuizz;
}
$scope.inSync = false;
$scope.syncExo = function() {
$scope.inSync = true;
$http({
url: "/api/sync/themes/" + $routeParams.themeId + "/exercices/" + $routeParams.exerciceId,
method: "POST"
}).then(function(response) {
$scope.inSync = false;
$scope.exercice = Exercice.get({ exerciceId: $routeParams.exerciceId });
if (response.data)
$rootScope.newBox('danger', response.data);
else
$rootScope.newBox('success', "Synchronisation de l'exercice terminée avec succès.");
}, function(response) {
$scope.inSync = false;
$rootScope.newBox('danger', 'An error occurs when synchronizing exercice:', response.data.errmsg);
});
};
$scope.deleteExercice = function() {
this.exercice.$remove(function() {
$location.url("/themes/" + $routeParams.themeId);
}, function(response) {
$rootScope.newBox('danger', 'An error occurs when trying to delete exercice:', response.data);
});
}
$scope.saveExercice = function() {
if (this.exercice.id) {
this.exercice.$update();
} else if ($routeParams.themeId) {
this.exercice.$save({ themeId: $routeParams.themeId }, function() {
$location.url("/themes/" + $scope.exercice.idTheme + "/exercices/" + $scope.exercice.id);
}, function(response) {
$rootScope.newBox('danger', 'An error occurs when trying to save exercice:', response.data.errmsg);
});
}
}
})
.controller("ExerciceTagsController", function($scope, ExerciceTags, $routeParams, $rootScope, $http) {
.controller("ExerciceTagsController", function($scope, ExerciceTags, $routeParams, $rootScope) {
$scope.tags = ExerciceTags.query({ exerciceId: $routeParams.exerciceId });
$scope.addTag = function() {
@ -1091,7 +1124,7 @@ angular.module("FICApp")
$rootScope.newBox('success', "Synchronisation de la liste de fichiers terminée avec succès.");
}, function(response) {
$scope.inSync = false;
$rootScope.newBox('danger', 'An error occurs when synchronizing flags list:', response.data);
$rootScope.newBox('danger', 'An error occurs when synchronizing flags list:', response.data.errmsg);
});
};
})
@ -1178,7 +1211,7 @@ angular.module("FICApp")
};
})
.controller("ExerciceMCQFlagsController", function($scope, ExerciceMCQFlag, $routeParams, $rootScope, $http) {
.controller("ExerciceMCQFlagsController", function($scope, ExerciceMCQFlag, $routeParams, $rootScope) {
$scope.quiz = ExerciceMCQFlag.query({ exerciceId: $routeParams.exerciceId });
$scope.addQuiz = function() {

View File

@ -1,4 +1,7 @@
<h2>{{exercice.title}}</h2>
<h2>
{{exercice.title}}
<button type="button" ng-click="syncExo()" ng-class="{'disabled': inSync}" class="float-right btn btn-sm btn-light"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Synchroniser</button>
</h2>
<div class="row mb-5">