admin: new button in navbar to regenerate static files

This commit is contained in:
nemunaire 2018-12-05 06:54:50 +01:00
parent f2e1268398
commit 07dcc1804b
3 changed files with 43 additions and 5 deletions

View file

@ -51,6 +51,7 @@ const indextpl = `<!DOCTYPE html>
</div> </div>
<span id="clock" class="navbar-text" ng-controller="CountdownController" ng-cloak> <span id="clock" class="navbar-text" ng-controller="CountdownController" ng-cloak>
<button type="button" class="mr-2 btn btn-sm" ng-class="{'btn-info':staticFilesNeedUpdate,'btn-secondary':!staticFilesNeedUpdate}" ng-click="regenerateStaticFiles()"><span class="glyphicon glyphicon-refresh" aria-hidden="true" title="Regénérer les fichiers statiques"></span><span ng-if="staticFilesNeedUpdate"> {{ "{{ staticFilesNeedUpdate }}" }}</span></button>
<span ng-show="startIn > 0"> <span ng-show="startIn > 0">
Démarrage dans : Démarrage dans :
<span>{{"{{ startIn }}"}}</span>" <span>{{"{{ startIn }}"}}</span>"

View file

@ -49,6 +49,7 @@
</div> </div>
<span id="clock" class="navbar-text" ng-controller="CountdownController" ng-cloak> <span id="clock" class="navbar-text" ng-controller="CountdownController" ng-cloak>
<button type="button" class="mr-2 btn btn-sm" ng-class="{'btn-info':staticFilesNeedUpdate,'btn-secondary':!staticFilesNeedUpdate}" ng-click="regenerateStaticFiles()"><span class="glyphicon glyphicon-refresh" aria-hidden="true" title="Regénérer les fichiers statiques"></span><span ng-if="staticFilesNeedUpdate"> {{ staticFilesNeedUpdate }}</span></button>
<span ng-show="startIn > 0"> <span ng-show="startIn > 0">
Démarrage dans : Démarrage dans :
<span>{{ startIn }}</span>" <span>{{ startIn }}</span>"

View file

@ -314,7 +314,7 @@ angular.module("FICApp")
}; };
}) })
.run(function($rootScope, $http, $interval) { .run(function($rootScope, $http, $interval, Settings) {
function refresh() { function refresh() {
$http.get("/api/settings.json").then(function(response) { $http.get("/api/settings.json").then(function(response) {
response.data.start = new Date(response.data.start); response.data.start = new Date(response.data.start);
@ -326,6 +326,19 @@ angular.module("FICApp")
} }
refresh(); refresh();
$interval(refresh, 10000); $interval(refresh, 10000);
$rootScope.staticFilesNeedUpdate = 0;
$rootScope.regenerateStaticFiles = function() {
Settings.get().$promise.then(function(config) {
config.generation = (new Date()).toISOString();
config.$update(function() {
$rootScope.staticFilesNeedUpdate = 0;
$rootScope.newBox('success', "Regeneration in progress...");
}, function (response) {
$rootScope.newBox('success', 'An error occurs when saving settings:', response.data.errmsg);
})
})
}
}) })
.controller("VersionController", function($scope, Version) { .controller("VersionController", function($scope, Version) {
@ -686,6 +699,7 @@ angular.module("FICApp")
$scope.clearFiles = function(id) { $scope.clearFiles = function(id) {
File.delete(function() { File.delete(function() {
$rootScope.staticFilesNeedUpdate++;
$scope.files = []; $scope.files = [];
}); });
}; };
@ -897,6 +911,7 @@ angular.module("FICApp")
}).then(function(response) { }).then(function(response) {
$scope.inSync = false; $scope.inSync = false;
$scope.themes = Theme.query(); $scope.themes = Theme.query();
$rootScope.staticFilesNeedUpdate++;
if (response.data) if (response.data)
$rootScope.newBox('danger', response.data); $rootScope.newBox('danger', response.data);
else else
@ -919,9 +934,11 @@ angular.module("FICApp")
$location.url("/themes/" + $scope.theme.id); $location.url("/themes/" + $scope.theme.id);
}); });
} }
$rootScope.staticFilesNeedUpdate++;
} }
$scope.deleteTheme = function() { $scope.deleteTheme = function() {
this.theme.$remove(function() { this.theme.$remove(function() {
$rootScope.staticFilesNeedUpdate++;
$location.url("/themes/"); $location.url("/themes/");
}, function(response) { }, function(response) {
$rootScope.newBox('danger', 'An error occurs when trying to delete theme:', response.data.errmsg); $rootScope.newBox('danger', 'An error occurs when trying to delete theme:', response.data.errmsg);
@ -947,6 +964,7 @@ angular.module("FICApp")
} }
}) })
$scope.exercice = {}; $scope.exercice = {};
$rootScope.staticFilesNeedUpdate++;
$rootScope.newBox('success', 'Édition de masse terminée avec succès'); $rootScope.newBox('success', 'Édition de masse terminée avec succès');
} }
@ -971,6 +989,7 @@ angular.module("FICApp")
url: u, url: u,
method: "GET" method: "GET"
}).then(function(response) { }).then(function(response) {
$rootScope.staticFilesNeedUpdate++;
$scope.done += 1; $scope.done += 1;
go(); go();
}, function(response) { }, function(response) {
@ -1012,6 +1031,7 @@ angular.module("FICApp")
}).then(function(response) { }).then(function(response) {
$scope.inSync = false; $scope.inSync = false;
$scope.exercices = ThemedExercice.query({ themeId: $routeParams.themeId }); $scope.exercices = ThemedExercice.query({ themeId: $routeParams.themeId });
$rootScope.staticFilesNeedUpdate++;
if (response.data) if (response.data)
$rootScope.newBox('warning', null, response.data, -1); $rootScope.newBox('warning', null, response.data, -1);
else else
@ -1065,6 +1085,7 @@ angular.module("FICApp")
}).then(function(response) { }).then(function(response) {
$scope.inSync = false; $scope.inSync = false;
$scope.exercice = Exercice.get({ exerciceId: $routeParams.exerciceId }); $scope.exercice = Exercice.get({ exerciceId: $routeParams.exerciceId });
$rootScope.staticFilesNeedUpdate++;
if (response.data) if (response.data)
$rootScope.newBox('danger', response.data); $rootScope.newBox('danger', response.data);
else else
@ -1077,6 +1098,7 @@ angular.module("FICApp")
$scope.deleteExercice = function() { $scope.deleteExercice = function() {
this.exercice.$remove(function() { this.exercice.$remove(function() {
$rootScope.staticFilesNeedUpdate++;
$location.url("/themes/" + $routeParams.themeId); $location.url("/themes/" + $routeParams.themeId);
}, function(response) { }, function(response) {
$rootScope.newBox('danger', 'An error occurs when trying to delete exercice:', response.data); $rootScope.newBox('danger', 'An error occurs when trying to delete exercice:', response.data);
@ -1085,8 +1107,10 @@ angular.module("FICApp")
$scope.saveExercice = function() { $scope.saveExercice = function() {
if (this.exercice.id) { if (this.exercice.id) {
this.exercice.$update(); this.exercice.$update();
$rootScope.staticFilesNeedUpdate++;
} else if ($routeParams.themeId) { } else if ($routeParams.themeId) {
this.exercice.$save({ themeId: $routeParams.themeId }, function() { this.exercice.$save({ themeId: $routeParams.themeId }, function() {
$rootScope.staticFilesNeedUpdate++;
$location.url("/themes/" + $scope.exercice.idTheme + "/exercices/" + $scope.exercice.id); $location.url("/themes/" + $scope.exercice.idTheme + "/exercices/" + $scope.exercice.id);
}, function(response) { }, function(response) {
$rootScope.newBox('danger', 'An error occurs when trying to save exercice:', response.data.errmsg); $rootScope.newBox('danger', 'An error occurs when trying to save exercice:', response.data.errmsg);
@ -1108,6 +1132,7 @@ angular.module("FICApp")
} }
$scope.saveTags = function() { $scope.saveTags = function() {
ExerciceTags.update({ exerciceId: $routeParams.exerciceId }, this.tags); ExerciceTags.update({ exerciceId: $routeParams.exerciceId }, this.tags);
$rootScope.staticFilesNeedUpdate++;
} }
}) })
@ -1118,10 +1143,12 @@ angular.module("FICApp")
this.file.$delete(function() { this.file.$delete(function() {
$scope.files.splice($scope.files.indexOf(this.file), 1); $scope.files.splice($scope.files.indexOf(this.file), 1);
}); });
$rootScope.staticFilesNeedUpdate++;
return false; return false;
} }
$scope.saveFile = function() { $scope.saveFile = function() {
this.file.$update(); this.file.$update();
$rootScope.staticFilesNeedUpdate++;
} }
$scope.inSync = false; $scope.inSync = false;
$scope.syncFiles = function() { $scope.syncFiles = function() {
@ -1131,6 +1158,7 @@ angular.module("FICApp")
method: "POST" method: "POST"
}).then(function(response) { }).then(function(response) {
$scope.inSync = false; $scope.inSync = false;
$rootScope.staticFilesNeedUpdate++;
$scope.files = ExerciceFile.query({ exerciceId: $routeParams.exerciceId }); $scope.files = ExerciceFile.query({ exerciceId: $routeParams.exerciceId });
if (response.data) if (response.data)
$rootScope.newBox('danger', response.data); $rootScope.newBox('danger', response.data);
@ -1147,12 +1175,12 @@ angular.module("FICApp")
$scope.hints = ExerciceHint.query({ exerciceId: $routeParams.exerciceId }); $scope.hints = ExerciceHint.query({ exerciceId: $routeParams.exerciceId });
$scope.addHint = function() { $scope.addHint = function() {
$scope.toggleHints(true);
$scope.hints.push(new ExerciceHint()); $scope.hints.push(new ExerciceHint());
} }
$scope.deleteHint = function() { $scope.deleteHint = function() {
this.hint.$delete(function() { this.hint.$delete(function() {
$scope.hints.splice($scope.hints.indexOf(this.hint), 1); $scope.hints.splice($scope.hints.indexOf(this.hint), 1);
$rootScope.staticFilesNeedUpdate++;
}, function(response) { }, function(response) {
$rootScope.newBox('danger', 'An error occurs when trying to delete hint:', response.data); $rootScope.newBox('danger', 'An error occurs when trying to delete hint:', response.data);
}); });
@ -1163,6 +1191,7 @@ angular.module("FICApp")
} else { } else {
this.hint.$save({ exerciceId: $routeParams.exerciceId }); this.hint.$save({ exerciceId: $routeParams.exerciceId });
} }
$rootScope.staticFilesNeedUpdate++;
} }
$scope.inSync = false; $scope.inSync = false;
$scope.syncHints = function() { $scope.syncHints = function() {
@ -1173,6 +1202,7 @@ angular.module("FICApp")
}).then(function(response) { }).then(function(response) {
$scope.inSync = false; $scope.inSync = false;
$scope.hints = ExerciceHint.query({ exerciceId: $routeParams.exerciceId }); $scope.hints = ExerciceHint.query({ exerciceId: $routeParams.exerciceId });
$rootScope.staticFilesNeedUpdate++;
if (response.data) if (response.data)
$rootScope.newBox('danger', response.data); $rootScope.newBox('danger', response.data);
else else
@ -1188,12 +1218,12 @@ angular.module("FICApp")
$scope.flags = ExerciceFlag.query({ exerciceId: $routeParams.exerciceId }); $scope.flags = ExerciceFlag.query({ exerciceId: $routeParams.exerciceId });
$scope.addFlag = function() { $scope.addFlag = function() {
$scope.toggleFlags(true);
$scope.flags.push(new ExerciceFlag()); $scope.flags.push(new ExerciceFlag());
} }
$scope.deleteFlag = function() { $scope.deleteFlag = function() {
this.flag.$delete(function() { this.flag.$delete(function() {
$scope.flags.splice($scope.flags.indexOf(this.flag), 1); $scope.flags.splice($scope.flags.indexOf(this.flag), 1);
$rootScope.staticFilesNeedUpdate++;
}, function(response) { }, function(response) {
$rootScope.newBox('danger', 'An error occurs when trying to delete flag:', response.data); $rootScope.newBox('danger', 'An error occurs when trying to delete flag:', response.data);
}); });
@ -1204,6 +1234,7 @@ angular.module("FICApp")
} else { } else {
this.flag.$save({ exerciceId: $routeParams.exerciceId }); this.flag.$save({ exerciceId: $routeParams.exerciceId });
} }
$rootScope.staticFilesNeedUpdate++;
} }
$scope.inSync = false; $scope.inSync = false;
$scope.syncFlags = function() { $scope.syncFlags = function() {
@ -1214,6 +1245,7 @@ angular.module("FICApp")
}).then(function(response) { }).then(function(response) {
$scope.inSync = false; $scope.inSync = false;
$scope.flags = ExerciceFlag.query({ exerciceId: $routeParams.exerciceId }); $scope.flags = ExerciceFlag.query({ exerciceId: $routeParams.exerciceId });
$rootScope.staticFilesNeedUpdate++;
if (response.data) if (response.data)
$rootScope.newBox('danger', response.data); $rootScope.newBox('danger', response.data);
else else
@ -1229,12 +1261,12 @@ angular.module("FICApp")
$scope.quiz = ExerciceMCQFlag.query({ exerciceId: $routeParams.exerciceId }); $scope.quiz = ExerciceMCQFlag.query({ exerciceId: $routeParams.exerciceId });
$scope.addQuiz = function() { $scope.addQuiz = function() {
$scope.toggleQuizz(true);
$scope.quiz.push(new ExerciceMCQFlag()); $scope.quiz.push(new ExerciceMCQFlag());
} }
$scope.deleteQuiz = function() { $scope.deleteQuiz = function() {
this.q.$delete(function() { this.q.$delete(function() {
$scope.quiz.splice($scope.quiz.indexOf(this.q), 1); $scope.quiz.splice($scope.quiz.indexOf(this.q), 1);
$rootScope.staticFilesNeedUpdate++;
}, function(response) { }, function(response) {
$rootScope.newBox('danger', 'An error occurs when trying to delete flag:', response.data); $rootScope.newBox('danger', 'An error occurs when trying to delete flag:', response.data);
}); });
@ -1245,6 +1277,7 @@ angular.module("FICApp")
} else { } else {
this.q.$save({ exerciceId: $routeParams.exerciceId }); this.q.$save({ exerciceId: $routeParams.exerciceId });
} }
$rootScope.staticFilesNeedUpdate++;
} }
$scope.addChoice = function() { $scope.addChoice = function() {
@ -1310,15 +1343,17 @@ angular.module("FICApp")
$scope.saveTeam = function() { $scope.saveTeam = function() {
if (this.team.id) { if (this.team.id) {
this.team.$update(); this.team.$update();
$rootScope.staticFilesNeedUpdate++;
} else { } else {
this.team.$save(function() { this.team.$save(function() {
$rootScope.staticFilesNeedUpdate++;
$location.url("/teams/" + $scope.team.id); $location.url("/teams/" + $scope.team.id);
}); });
} }
} }
$scope.deleteTeam = function() { $scope.deleteTeam = function() {
backName = this.team.name; backName = this.team.name;
this.team.$remove(function() { $rootScope.newBox('success', 'Team ' + backName + ' successfully removed.'); $location.url("/teams/"); }, this.team.$remove(function() { $rootScope.newBox('success', 'Team ' + backName + ' successfully removed.'); $location.url("/teams/"); $rootScope.staticFilesNeedUpdate++; },
function(response) { $rootScope.newBox('danger', 'An error occurs during suppression of the team:', response.data); }); function(response) { $rootScope.newBox('danger', 'An error occurs during suppression of the team:', response.data); });
} }
$scope.showStats = function() { $scope.showStats = function() {
@ -1333,6 +1368,7 @@ angular.module("FICApp")
method: "DELETE", method: "DELETE",
data: row data: row
}).then(function(response) { }).then(function(response) {
$rootScope.staticFilesNeedUpdate++;
$scope.history = TeamHistory.query({ teamId: $routeParams.teamId }); $scope.history = TeamHistory.query({ teamId: $routeParams.teamId });
}, function(response) { }, function(response) {
$rootScope.newBox('danger', 'An error occurs when removing history item: ', response.data); $rootScope.newBox('danger', 'An error occurs when removing history item: ', response.data);