Display read-only settings for information purpose

This commit is contained in:
nemunaire 2017-12-11 02:56:26 +01:00 committed by Pierre-Olivier Mercier
parent 6ef91a92e5
commit a1c6eadbe5
3 changed files with 25 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import (
"path" "path"
"time" "time"
"srs.epita.fr/fic-server/admin/sync"
"srs.epita.fr/fic-server/libfic" "srs.epita.fr/fic-server/libfic"
"srs.epita.fr/fic-server/settings" "srs.epita.fr/fic-server/settings"
@ -13,12 +14,24 @@ import (
) )
func init() { func init() {
router.GET("/api/settings-ro.json", apiHandler(getROSettings))
router.GET("/api/settings.json", apiHandler(getSettings)) router.GET("/api/settings.json", apiHandler(getSettings))
router.PUT("/api/settings.json", apiHandler(saveSettings)) router.PUT("/api/settings.json", apiHandler(saveSettings))
router.POST("/api/reset", apiHandler(reset)) router.POST("/api/reset", apiHandler(reset))
} }
func getROSettings(_ httprouter.Params, body []byte) (interface{}, error) {
syncMtd := "Disabled"
if sync.GlobalImporter != nil {
syncMtd = sync.GlobalImporter.Kind()
}
return map[string]interface{}{
"sync": syncMtd,
}, nil
}
func getSettings(_ httprouter.Params, body []byte) (interface{}, error) { func getSettings(_ httprouter.Params, body []byte) (interface{}, error) {
if settings.ExistsSettings(path.Join(settings.SettingsDir, settings.SettingsFile)) { if settings.ExistsSettings(path.Join(settings.SettingsDir, settings.SettingsFile)) {
return settings.ReadSettings(path.Join(settings.SettingsDir, settings.SettingsFile)) return settings.ReadSettings(path.Join(settings.SettingsDir, settings.SettingsFile))

View File

@ -68,6 +68,9 @@ angular.module("FICApp")
'update': {method: 'PUT'}, 'update': {method: 'PUT'},
}) })
}) })
.factory("ROSettings", function($resource) {
return $resource("/api/settings-ro.json")
})
.factory("Settings", function($resource) { .factory("Settings", function($resource) {
return $resource("/api/settings.json", null, { return $resource("/api/settings.json", null, {
'update': {method: 'PUT'}, 'update': {method: 'PUT'},
@ -328,8 +331,9 @@ angular.module("FICApp")
$interval(updBox, 750); $interval(updBox, 750);
}) })
.controller("SettingsController", function($scope, $rootScope, Settings, $location, $http) { .controller("SettingsController", function($scope, $rootScope, Settings, ROSettings, $location, $http) {
$scope.config = Settings.get(); $scope.config = Settings.get();
$scope.configro = ROSettings.get();
$scope.duration = 240; $scope.duration = 240;
$scope.saveSettings = function(msg) { $scope.saveSettings = function(msg) {

View File

@ -112,6 +112,13 @@
</div> </div>
</div> </div>
<hr>
<div class="form-group">
<label class="col-sm-2 control-label">Synchronisation</label>
<div class="col-sm-10">{{ configro.sync }}</div>
</div>
<div class="text-right"> <div class="text-right">
<button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-save" aria-hidden="true"></span> Propager ces paramètres</button> <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-save" aria-hidden="true"></span> Propager ces paramètres</button>
</div> </div>