settings: Save future changes in a dedicated file

This commit is contained in:
nemunaire 2022-05-26 22:54:46 +02:00
parent 465a48c1c0
commit 3c237819c3
5 changed files with 295 additions and 15 deletions

View file

@ -234,6 +234,11 @@ angular.module("FICApp")
'update': {method: 'PUT'},
})
})
.factory("NextSettings", function($resource) {
return $resource("api/settings-next/:tsId", { tsId: '@id'}, {
'update': {method: 'PUT'},
})
})
.factory("SettingsChallenge", function($resource) {
return $resource("api/challenge.json", null, {
'update': {method: 'PUT'},
@ -510,7 +515,23 @@ angular.module("FICApp")
$scope.monitor = Monitor.get();
})
.controller("SettingsController", function($scope, $rootScope, Settings, SettingsChallenge, $location, $http, $interval) {
.controller("SettingsController", function($scope, $rootScope, NextSettings, Settings, SettingsChallenge, $location, $http, $interval) {
$scope.nextsettings = NextSettings.query();
$scope.erase = false;
$scope.editNextSettings = function(ns) {
$scope.activateTime = ns.date;
$scope.erase = true;
Object.keys(ns.values).forEach(function(k) {
$scope.config[k] = ns.values[k];
});
$scope.config.enableExerciceDepend = $scope.config.unlockedChallengeDepth >= 0;
}
$scope.deleteNextSettings = function(ns) {
ns.$delete().then(function() {
$scope.nextsettings = NextSettings.query();
})
}
$scope.displayDangerousActions = false;
$scope.config = Settings.get();
$scope.dist_config = {};
@ -524,6 +545,7 @@ angular.module("FICApp")
})
$scope.challenge = SettingsChallenge.get();
$scope.duration = 360;
$scope.activateTime = "0001-01-01T00:00:00Z";
$scope.challenge.$promise.then(function(c) {
if (c.duration)
$scope.duration = c.duration;
@ -549,17 +571,24 @@ angular.module("FICApp")
var nStart = this.config.start;
var nEnd = this.config.end;
var nGen = this.config.generation;
var aTime = this.config.activateTime;
var state = this.config.enableExerciceDepend;
this.config.unlockedChallengeDepth = (this.config.enableExerciceDepend?this.config.unlockedChallengeDepth:-1)
this.config.$update(function(response) {
var updateQuery = {};
if (this.activateTime && this.activateTime != '0001-01-01T00:00:00Z') {
updateQuery['t'] = this.activateTime;
}
if (this.erase) {
updateQuery['erase'] = true;
this.erase = false;
}
this.config.$update(updateQuery, function(response) {
$scope.dist_config = Object.assign({}, response);
$scope.addToast('success', msg);
$scope.nextsettings = NextSettings.query();
response.enableExerciceDepend = response.unlockedChallengeDepth >= 0;
$rootScope.settings.start = new Date(nStart);
$rootScope.settings.end = new Date(nEnd);
$rootScope.settings.generation = new Date(nGen);
$rootScope.settings.activateTime = new Date(aTime);
}, function(response) {
$scope.addToast('danger', 'An error occurs when saving settings:', response.data.errmsg);
});
@ -582,12 +611,12 @@ angular.module("FICApp")
});
}
$scope.updateActivateTime = function() {
$rootScope.settings.activateTime = this.config.activateTime;
$rootScope.settings.activateTime = this.activateTime;
}
$scope.updActivateTime = function(modulo) {
var ts = Math.floor((new Date(this.config.end) - Date.now() - (60000 * modulo / 2)) / (60000 * modulo)) * (60000 * modulo);
var d = new Date(this.config.end) - ts;
this.config.activateTime = new Date(d).toISOString();
this.activateTime = new Date(d).toISOString();
this.updateActivateTime();
}
$scope.reset = function(type) {