From 038abe450d07e69f4b3f524f271b248967a5ccfb Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Sat, 13 Nov 2021 11:06:24 +0100 Subject: [PATCH] admin: Add a route and a button to sync the filesystem --- admin/api/settings.go | 4 +++- admin/api/theme.go | 5 +++++ admin/static/js/app.js | 21 +++++++++++++++++---- admin/static/views/settings.html | 3 ++- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/admin/api/settings.go b/admin/api/settings.go index c63bf31c..dc3e3562 100644 --- a/admin/api/settings.go +++ b/admin/api/settings.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "path" + "reflect" "srs.epita.fr/fic-server/admin/sync" "srs.epita.fr/fic-server/libfic" @@ -32,7 +33,8 @@ func getROSettings(_ httprouter.Params, body []byte) (interface{}, error) { } return map[string]interface{}{ - "sync": syncMtd, + "sync-type": reflect.TypeOf(sync.GlobalImporter).Name(), + "sync": syncMtd, }, nil } diff --git a/admin/api/theme.go b/admin/api/theme.go index 9be6bf34..2d446d3c 100644 --- a/admin/api/theme.go +++ b/admin/api/theme.go @@ -56,6 +56,11 @@ func init() { return map[string]interface{}{"progress": sync.DeepSyncProgress}, nil } })) + router.POST("/api/sync/base", apiHandler( + func(_ httprouter.Params, _ []byte) (interface{}, error) { + err := sync.GlobalImporter.Sync() + return true, err + })) router.POST("/api/sync/speed", apiHandler( func(_ httprouter.Params, _ []byte) (interface{}, error) { st := sync.SpeedySyncDeep(sync.GlobalImporter) diff --git a/admin/static/js/app.js b/admin/static/js/app.js index 6e10de92..d45f17a4 100644 --- a/admin/static/js/app.js +++ b/admin/static/js/app.js @@ -610,10 +610,10 @@ angular.module("FICApp") $scope.deepSyncInProgress = true; $http.post(url).then(function() { $scope.deepSyncInProgress = false; - $scope.addToast('success', 'Synchronisation intégrale terminée.', 'Voir le rapport.', 15000); + $scope.addToast('success', 'Synchronisation intégrale terminée.', 'Voir le rapport.', 15000); }, function(response) { $scope.deepSyncInProgress = false; - $scope.addToast('warning', 'Synchronisation intégrale terminée.', 'Voir le rapport.', 15000); + $scope.addToast('warning', 'Synchronisation intégrale terminée.', 'Voir le rapport.', 15000); }); }); }; @@ -623,10 +623,23 @@ angular.module("FICApp") $scope.deepSyncInProgress = true; $http.post("api/sync/speed").then(function() { $scope.deepSyncInProgress = false; - $scope.addToast('success', 'Synchronisation profonde rapide terminée.', 'Voir le rapport.', 15000); + $scope.addToast('success', 'Synchronisation profonde rapide terminée.', 'Voir le rapport.', 15000); }, function(response) { $scope.deepSyncInProgress = false; - $scope.addToast('warning', 'Synchronisation profinde rapide terminée.', 'Voir le rapport.', 15000); + $scope.addToast('warning', 'Synchronisation profinde rapide terminée.', 'Voir le rapport.', 15000); + }); + }); + }; + $scope.baseSync = function() { + $scope.addToast('warning', 'Tirer les mises à jour du dépôt ?', '', + function() { + $scope.deepSyncInProgress = true; + $http.post("api/sync/base").then(function() { + $scope.deepSyncInProgress = false; + $scope.addToast('success', 'Mise à jour terminée.'); + }, function(response) { + $scope.deepSyncInProgress = false; + $scope.addToast('danger', 'Mise à jour terminée.', response.data.errmsg); }); }); }; diff --git a/admin/static/views/settings.html b/admin/static/views/settings.html index 202a112b..483ea536 100644 --- a/admin/static/views/settings.html +++ b/admin/static/views/settings.html @@ -241,7 +241,7 @@
Synchronisation
-
+
@@ -251,6 +251,7 @@ Dernier import : {{ syncReport._date[1] }}
+