admin: add a progression indicator for the deep synchronization
This commit is contained in:
parent
d9fb261232
commit
7227c7109e
|
@ -44,6 +44,14 @@ func init() {
|
||||||
router.GET("/api/remote/themes/:thid/exercices", apiHandler(themeHandler(sync.ApiListRemoteExercices)))
|
router.GET("/api/remote/themes/:thid/exercices", apiHandler(themeHandler(sync.ApiListRemoteExercices)))
|
||||||
|
|
||||||
// Synchronize
|
// 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(
|
router.POST("/api/sync/deep", apiHandler(
|
||||||
func(_ httprouter.Params, _ []byte) (interface{}, error) {
|
func(_ httprouter.Params, _ []byte) (interface{}, error) {
|
||||||
return sync.SyncDeep(sync.GlobalImporter), nil
|
return sync.SyncDeep(sync.GlobalImporter), nil
|
||||||
|
|
|
@ -422,7 +422,7 @@ angular.module("FICApp")
|
||||||
$interval(updBox, 750);
|
$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 = Settings.get();
|
||||||
$scope.config.$promise.then(function(response) {
|
$scope.config.$promise.then(function(response) {
|
||||||
$rootScope.settings.start = new Date(response.start);
|
$rootScope.settings.start = new Date(response.start);
|
||||||
|
@ -433,6 +433,21 @@ angular.module("FICApp")
|
||||||
$scope.configro = ROSettings.get();
|
$scope.configro = ROSettings.get();
|
||||||
$scope.duration = 240;
|
$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) {
|
$scope.saveSettings = function(msg) {
|
||||||
if (msg === undefined) { msg = 'New settings saved!'; }
|
if (msg === undefined) { msg = 'New settings saved!'; }
|
||||||
var nStart = this.config.start;
|
var nStart = this.config.start;
|
||||||
|
|
|
@ -161,6 +161,9 @@
|
||||||
<dd class="col" ng-bind="configro.sync"></dd>
|
<dd class="col" ng-bind="configro.sync"></dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
|
<div class="float-right" ng-if="configro.sync">
|
||||||
|
{{ syncProgress }}
|
||||||
|
</div>
|
||||||
<div class="text-left" ng-if="configro.sync">
|
<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>
|
<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>
|
</div>
|
||||||
|
|
|
@ -18,10 +18,14 @@ var DeepReportPath = "full_import_report.json"
|
||||||
// oneDeepSync ensure there is no more than one running deep sync.
|
// oneDeepSync ensure there is no more than one running deep sync.
|
||||||
var oneDeepSync sync.Mutex
|
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.
|
// SyncDeep performs a recursive synchronisation: from themes to challenge items.
|
||||||
func SyncDeep(i Importer) (errs map[string][]string) {
|
func SyncDeep(i Importer) (errs map[string][]string) {
|
||||||
oneDeepSync.Lock()
|
oneDeepSync.Lock()
|
||||||
defer oneDeepSync.Unlock()
|
defer oneDeepSync.Unlock()
|
||||||
|
DeepSyncProgress = 1
|
||||||
|
|
||||||
errs = map[string][]string{}
|
errs = map[string][]string{}
|
||||||
|
|
||||||
|
@ -29,19 +33,28 @@ func SyncDeep(i Importer) (errs map[string][]string) {
|
||||||
errs["_themes"] = SyncThemes(i)
|
errs["_themes"] = SyncThemes(i)
|
||||||
|
|
||||||
if themes, err := fic.GetThemes(); err == nil {
|
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)
|
errs[theme.Name] = SyncExercices(i, theme)
|
||||||
|
|
||||||
if exercices, err := theme.GetExercices(); err == nil {
|
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)...)
|
errs[theme.Name] = append(errs[theme.Name], SyncExerciceFiles(i, exercice)...)
|
||||||
|
DeepSyncProgress += exerciceStep / 3
|
||||||
errs[theme.Name] = append(errs[theme.Name], SyncExerciceFlags(i, exercice)...)
|
errs[theme.Name] = append(errs[theme.Name], SyncExerciceFlags(i, exercice)...)
|
||||||
|
DeepSyncProgress += exerciceStep / 3
|
||||||
errs[theme.Name] = append(errs[theme.Name], SyncExerciceHints(i, exercice)...)
|
errs[theme.Name] = append(errs[theme.Name], SyncExerciceHints(i, exercice)...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeepSyncProgress = 254
|
||||||
errs["_date"] = append(errs["_date"], fmt.Sprintf("%v", time.Now()))
|
errs["_date"] = append(errs["_date"], fmt.Sprintf("%v", time.Now()))
|
||||||
|
|
||||||
errs["_regeneration"] = []string{}
|
errs["_regeneration"] = []string{}
|
||||||
|
@ -66,5 +79,6 @@ func SyncDeep(i Importer) (errs map[string][]string) {
|
||||||
errs["_regeneration"] = append(errs["_regeneration"], err.Error())
|
errs["_regeneration"] = append(errs["_regeneration"], err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeepSyncProgress = 255
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user