From c7968fb2569b85f45e00f15d5b851bbb5938a4e7 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Mon, 11 Jul 2022 11:11:35 +0200 Subject: [PATCH] admin: Add button to switch from WIP to PROD --- admin/api/settings.go | 13 +++++++++++++ admin/static/js/app.js | 17 ++++++++++++++--- admin/static/views/settings.html | 3 ++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/admin/api/settings.go b/admin/api/settings.go index e66dc4a7..cf0df11c 100644 --- a/admin/api/settings.go +++ b/admin/api/settings.go @@ -47,6 +47,19 @@ func declareSettingsRoutes(router *gin.RouterGroup) { apiNextSettingsRoutes.DELETE("", deleteNextSettings) router.POST("/reset", reset) + + router.GET("/prod", func(c *gin.Context) { + c.JSON(http.StatusOK, IsProductionEnv) + }) + router.PUT("/prod", func(c *gin.Context) { + err := c.ShouldBindJSON(&IsProductionEnv) + if err != nil { + c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": err.Error()}) + return + } + + c.JSON(http.StatusOK, IsProductionEnv) + }) } func NextSettingsHandler(c *gin.Context) { diff --git a/admin/static/js/app.js b/admin/static/js/app.js index 69b3153a..55574e47 100644 --- a/admin/static/js/app.js +++ b/admin/static/js/app.js @@ -455,7 +455,7 @@ angular.module("FICApp") $rootScope.Utils = { keys : Object.keys }; - function refresh() { + $rootScope.refreshSettings = function() { $http.get("api/settings.json").then(function(response) { response.data.start = new Date(response.data.start); response.data.end = new Date(response.data.end); @@ -464,8 +464,8 @@ angular.module("FICApp") $rootScope.recvTime(response); }) } - refresh(); - $interval(refresh, 10000); + $rootScope.refreshSettings(); + $interval($rootScope.refreshSettings, 10000); $rootScope.toasts = []; $rootScope.addToast = function(kind, title, msg, yesFunc, noFunc, tmout) { @@ -655,6 +655,17 @@ angular.module("FICApp") } }); }; + $scope.switchToProd = function() { + $scope.addToast('warning', "Activer le mode challenge ?", "L'activation du mode challenge est temporaire (vous devriez plutôt relancer le daemon avec l'option `-4real`). Ce mode permet d'éviter les mauvaises manipulations et désactive le hook git de synchronisation automatique. Êtes-vous sûr de vouloir continuer ?", + function() { + $http.put("api/prod", true).then(function(time) { + $rootScope.refreshSettings() + $scope.addToast('success', 'Mode challenge activé'); + }, function(response) { + $scope.addToast('danger', 'An error occurs when activating challenge mode:', response.data.errmsg); + }); + }); + }; }) .controller("SyncController", function($scope, $rootScope, ROSettings, $location, $http, $interval) { diff --git a/admin/static/views/settings.html b/admin/static/views/settings.html index 0c65388f..78cda4a9 100644 --- a/admin/static/views/settings.html +++ b/admin/static/views/settings.html @@ -359,6 +359,7 @@
+

Changements anticipés

@@ -402,7 +403,7 @@
- Paramètres de synchronisation + Paramètres de synchronisation