admin: Add a route and a button to sync the filesystem

This commit is contained in:
nemunaire 2021-11-13 11:06:24 +01:00
parent a06602a7e8
commit 038abe450d
4 changed files with 27 additions and 6 deletions

View file

@ -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
}

View file

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

View file

@ -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.', '<a href="check_import.html">Voir le rapport</a>.', 15000);
$scope.addToast('success', 'Synchronisation intégrale terminée.', '<a href="check_import.html" target="_self">Voir le rapport</a>.', 15000);
}, function(response) {
$scope.deepSyncInProgress = false;
$scope.addToast('warning', 'Synchronisation intégrale terminée.', '<a href="check_import.html">Voir le rapport</a>.', 15000);
$scope.addToast('warning', 'Synchronisation intégrale terminée.', '<a href="check_import.html" target="_self">Voir le rapport</a>.', 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.', '<a href="check_import.html">Voir le rapport</a>.', 15000);
$scope.addToast('success', 'Synchronisation profonde rapide terminée.', '<a href="check_import.html" target="_self">Voir le rapport</a>.', 15000);
}, function(response) {
$scope.deepSyncInProgress = false;
$scope.addToast('warning', 'Synchronisation profinde rapide terminée.', '<a href="check_import.html">Voir le rapport</a>.', 15000);
$scope.addToast('warning', 'Synchronisation profinde rapide terminée.', '<a href="check_import.html" target="_self">Voir le rapport</a>.', 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);
});
});
};

View file

@ -241,7 +241,7 @@
<div class="card-body">
<dl class="row">
<dt class="col-3">Synchronisation</dt>
<dd class="col" ng-bind="configro.sync"></dd>
<dd class="col" title="{{ configro['sync-type'] }}" ng-bind="configro.sync"></dd>
</dl>
<div class="float-right" ng-if="configro.sync">
@ -251,6 +251,7 @@
Dernier import&nbsp;: {{ syncReport._date[1] }}
</div>
<div class="text-left" ng-if="configro.sync">
<button ng-if="configro['sync-type'] === 'GitImporter'" type="button" class="btn btn-info" ng-click="baseSync()" ng-disabled="deepSyncInProgress"><span class="glyphicon glyphicon-repeat" aria-hidden="true"></span> Pull</button>
<div class="btn-group">
<button type="button" class="btn btn-secondary" ng-click="deepSync()" ng-disabled="deepSyncInProgress"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Synchronisation intégrale</button>
<button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" ng-disabled="deepSyncInProgress">