admin: Refactor synchronization status report + display last git error

This commit is contained in:
nemunaire 2025-01-13 18:00:27 +01:00
parent c1924c0e92
commit 03d02669ea
6 changed files with 81 additions and 49 deletions

View file

@ -230,9 +230,6 @@ angular.module("FICApp")
.factory("File", function ($resource) {
return $resource("api/files/:fileId", { fileId: '@id' })
})
.factory("ROSettings", function ($resource) {
return $resource("api/settings-ro.json")
})
.factory("Settings", function ($resource) {
return $resource("api/settings.json", null, {
'update': { method: 'PUT' },
@ -787,9 +784,8 @@ angular.module("FICApp")
template: `<span class="badge {{ $ctrl.color }}">{{ $ctrl.status.hash }}</span> <small>{{ $ctrl.status.text }}</small>`
})
.controller("SyncController", function ($scope, $rootScope, ROSettings, $location, $http, $interval) {
.controller("SyncController", function ($scope, $rootScope, $location, $http, $interval) {
$scope.displayDangerousActions = false;
$scope.configro = ROSettings.get();
var needRefreshSyncReportWhenReady = false;
var refreshSyncReport = function () {
@ -800,30 +796,28 @@ angular.module("FICApp")
};
refreshSyncReport()
$scope.deepSyncInProgress = false;
var progressInterval = $interval(function () {
$http.get("api/sync/deep").then(function (response) {
$http.get("api/sync/status").then(function (response) {
if (response.data.progress && response.data.progress != 255)
needRefreshSyncReportWhenReady = true;
else if (needRefreshSyncReportWhenReady)
refreshSyncReport();
if (response.data && response.data.progress) {
$scope.syncPercent = Math.floor(response.data.progress * 100 / 255);
$scope.syncProgress = Math.floor(response.data.progress * 100 / 255) + " %";
$scope.deepSyncInProgress = response.data.pullMutex && response.data.syncMutex;
} else {
$scope.syncProgress = response.data;
$scope.syncPercent = 0;
}
$scope.syncStatus = response.data;
}, function (response) {
$scope.syncPercent = 0;
if (response.data && response.data.errmsg)
$scope.syncProgress = response.data.errmsg;
else
$scope.syncProgress = response.data;
$scope.syncStatus = response.data;
})
}, 1500);
$scope.$on('$destroy', function () { $interval.cancel(progressInterval); });
$scope.deepSyncInProgress = false;
$scope.deepSync = function (theme) {
if (theme) {
question = 'Faire une synchronisation intégrale du thème ' + theme.name + ' ?'

View file

@ -32,17 +32,25 @@
<div class="card-body">
<dl class="row">
<dt class="col-2">Type</dt>
<dd class="col-10" ng-bind="configro['sync-type']"></dd>
<dd class="col-10" ng-bind="syncStatus['sync-type']"></dd>
<dt class="col-2">Synchronisation</dt>
<dd class="col-10" title="{{ configro['sync'] }}" ng-bind="configro.sync"></dd>
<dt class="col-2" ng-if="configro['sync-id']">ID</dt>
<dd class="col-10" ng-if="configro['sync-id']">{{ configro['sync-id'] }}</dd>
<dt class="col-2" ng-if="configro['sync']">Statut</dt>
<dd class="col-10" ng-if="configro['sync']">{{ syncProgress }}</dd>
<dd class="col-10" title="{{ syncStatus['sync'] }}" ng-bind="syncStatus.sync"></dd>
<dt class="col-2" ng-if="syncStatus['sync-id']">ID</dt>
<dd class="col-10" ng-if="syncStatus['sync-id']">
{{ syncStatus['sync-id'] }}
<button ng-if="syncStatus['sync-type'] === 'GitImporter'" type="button" class="btn btn-sm btn-dark" ng-click="baseSync()" ng-disabled="deepSyncInProgress"><span class="glyphicon glyphicon-repeat" aria-hidden="true"></span> Pull</button>
</dd>
<dt class="col-2" ng-if="syncStatus['sync']">Statut</dt>
<dd class="col-10" ng-if="syncStatus['sync']">
<span ng-if="(syncStatus.syncMutex !== undefined && syncStatus.syncMutex) || (syncPercent > 0 && syncPercent < 100)">{{ syncPercent }}&nbsp;%</span>
<span class="badge badge-pill" ng-class="{'badge-success': !syncStatus.pullMutex, 'badge-danger': syncStatus.pullMutex}" ng-if="syncStatus.pullMutex !== undefined">Pull</span>
<span class="badge badge-pill" ng-class="{'badge-success': !syncStatus.syncMutex, 'badge-danger': syncStatus.syncMutex}" ng-if="syncStatus.syncMutex !== undefined">Synchronisation</span>
</dd>
</dl>
<div class="d-flex justify-content-around" 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>
<pre style="background: black; color: white;" class="p-2" ng-if="syncStatus.lastError">{{ syncStatus.lastError }}</pre>
<div class="d-flex justify-content-around" ng-if="syncStatus.sync">
<div class="btn-group dropright">
<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">