admin: Add a route and a button to sync the filesystem
This commit is contained in:
parent
a06602a7e8
commit
038abe450d
4 changed files with 27 additions and 6 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"path"
|
"path"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
"srs.epita.fr/fic-server/admin/sync"
|
"srs.epita.fr/fic-server/admin/sync"
|
||||||
"srs.epita.fr/fic-server/libfic"
|
"srs.epita.fr/fic-server/libfic"
|
||||||
|
@ -32,7 +33,8 @@ func getROSettings(_ httprouter.Params, body []byte) (interface{}, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return map[string]interface{}{
|
return map[string]interface{}{
|
||||||
"sync": syncMtd,
|
"sync-type": reflect.TypeOf(sync.GlobalImporter).Name(),
|
||||||
|
"sync": syncMtd,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,11 @@ func init() {
|
||||||
return map[string]interface{}{"progress": sync.DeepSyncProgress}, nil
|
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(
|
router.POST("/api/sync/speed", apiHandler(
|
||||||
func(_ httprouter.Params, _ []byte) (interface{}, error) {
|
func(_ httprouter.Params, _ []byte) (interface{}, error) {
|
||||||
st := sync.SpeedySyncDeep(sync.GlobalImporter)
|
st := sync.SpeedySyncDeep(sync.GlobalImporter)
|
||||||
|
|
|
@ -610,10 +610,10 @@ angular.module("FICApp")
|
||||||
$scope.deepSyncInProgress = true;
|
$scope.deepSyncInProgress = true;
|
||||||
$http.post(url).then(function() {
|
$http.post(url).then(function() {
|
||||||
$scope.deepSyncInProgress = false;
|
$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) {
|
}, function(response) {
|
||||||
$scope.deepSyncInProgress = false;
|
$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;
|
$scope.deepSyncInProgress = true;
|
||||||
$http.post("api/sync/speed").then(function() {
|
$http.post("api/sync/speed").then(function() {
|
||||||
$scope.deepSyncInProgress = false;
|
$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) {
|
}, function(response) {
|
||||||
$scope.deepSyncInProgress = false;
|
$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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -241,7 +241,7 @@
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<dl class="row">
|
<dl class="row">
|
||||||
<dt class="col-3">Synchronisation</dt>
|
<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>
|
</dl>
|
||||||
|
|
||||||
<div class="float-right" ng-if="configro.sync">
|
<div class="float-right" ng-if="configro.sync">
|
||||||
|
@ -251,6 +251,7 @@
|
||||||
Dernier import : {{ syncReport._date[1] }}
|
Dernier import : {{ syncReport._date[1] }}
|
||||||
</div>
|
</div>
|
||||||
<div class="text-left" ng-if="configro.sync">
|
<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">
|
<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" 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">
|
<button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" ng-disabled="deepSyncInProgress">
|
||||||
|
|
Reference in a new issue