admin: add a progression indicator for the deep synchronization

This commit is contained in:
nemunaire 2019-01-18 15:39:58 +01:00
parent d9fb261232
commit 7227c7109e
4 changed files with 43 additions and 3 deletions

View File

@ -44,6 +44,14 @@ func init() {
router.GET("/api/remote/themes/:thid/exercices", apiHandler(themeHandler(sync.ApiListRemoteExercices)))
// Synchronize
router.GET("/api/sync/deep", apiHandler(
func(_ httprouter.Params, _ []byte) (interface{}, error) {
if sync.DeepSyncProgress == 0 {
return nil, errors.New("Pas de synchronisation en cours")
} else {
return map[string]interface{}{"progress": sync.DeepSyncProgress}, nil
}
}))
router.POST("/api/sync/deep", apiHandler(
func(_ httprouter.Params, _ []byte) (interface{}, error) {
return sync.SyncDeep(sync.GlobalImporter), nil

View File

@ -422,7 +422,7 @@ angular.module("FICApp")
$interval(updBox, 750);
})
.controller("SettingsController", function($scope, $rootScope, Settings, ROSettings, $location, $http) {
.controller("SettingsController", function($scope, $rootScope, Settings, ROSettings, $location, $http, $interval) {
$scope.config = Settings.get();
$scope.config.$promise.then(function(response) {
$rootScope.settings.start = new Date(response.start);
@ -433,6 +433,21 @@ angular.module("FICApp")
$scope.configro = ROSettings.get();
$scope.duration = 240;
var progressInterval = $interval(function() {
$http.get("/api/sync/deep").then(function(response) {
if (response.data && response.data.progress)
$scope.syncProgress = Math.floor(response.data.progress * 100 / 255) + " %";
else
$scope.syncProgress = response.data;
}, function(response) {
if (response.data && response.data.errmsg)
$scope.syncProgress = response.data.errmsg;
else
$scope.syncProgress = response.data;
})
}, 1500);
$scope.$on('$destroy', function () { $interval.cancel(progressInterval); });
$scope.saveSettings = function(msg) {
if (msg === undefined) { msg = 'New settings saved!'; }
var nStart = this.config.start;

View File

@ -161,6 +161,9 @@
<dd class="col" ng-bind="configro.sync"></dd>
</dl>
<div class="float-right" ng-if="configro.sync">
{{ syncProgress }}
</div>
<div class="text-left" ng-if="configro.sync">
<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>
</div>

View File

@ -18,10 +18,14 @@ var DeepReportPath = "full_import_report.json"
// oneDeepSync ensure there is no more than one running deep sync.
var oneDeepSync sync.Mutex
// DeepSyncProgress expose the progression of the depp synchronization (0 = 0%, 255 = 100%).
var DeepSyncProgress uint8
// SyncDeep performs a recursive synchronisation: from themes to challenge items.
func SyncDeep(i Importer) (errs map[string][]string) {
oneDeepSync.Lock()
defer oneDeepSync.Unlock()
DeepSyncProgress = 1
errs = map[string][]string{}
@ -29,19 +33,28 @@ func SyncDeep(i Importer) (errs map[string][]string) {
errs["_themes"] = SyncThemes(i)
if themes, err := fic.GetThemes(); err == nil {
for _, theme := range themes {
DeepSyncProgress = 2
var themeStep uint8 = uint8(250) / uint8(len(themes))
for tid, theme := range themes {
DeepSyncProgress = 3 + uint8(tid) * themeStep
errs[theme.Name] = SyncExercices(i, theme)
if exercices, err := theme.GetExercices(); err == nil {
for _, exercice := range exercices {
var exerciceStep uint8 = themeStep / uint8(len(exercices))
for eid, exercice := range exercices {
DeepSyncProgress = 3 + uint8(tid) * themeStep + uint8(eid) * exerciceStep
errs[theme.Name] = append(errs[theme.Name], SyncExerciceFiles(i, exercice)...)
DeepSyncProgress += exerciceStep / 3
errs[theme.Name] = append(errs[theme.Name], SyncExerciceFlags(i, exercice)...)
DeepSyncProgress += exerciceStep / 3
errs[theme.Name] = append(errs[theme.Name], SyncExerciceHints(i, exercice)...)
}
}
}
}
DeepSyncProgress = 254
errs["_date"] = append(errs["_date"], fmt.Sprintf("%v", time.Now()))
errs["_regeneration"] = []string{}
@ -66,5 +79,6 @@ func SyncDeep(i Importer) (errs map[string][]string) {
errs["_regeneration"] = append(errs["_regeneration"], err.Error())
}
DeepSyncProgress = 255
return
}