admin: use common.js as well

This commit is contained in:
nemunaire 2018-12-05 04:09:42 +01:00
parent 598f4a5076
commit c8cbbcb84d
5 changed files with 22 additions and 112 deletions

View File

@ -86,6 +86,7 @@ const indextpl = `<!DOCTYPE html>
<script src="/js/angular-route.min.js"></script> <script src="/js/angular-route.min.js"></script>
<script src="/js/angular-sanitize.min.js"></script> <script src="/js/angular-sanitize.min.js"></script>
<script src="{{.urlbase}}js/app.js"></script> <script src="{{.urlbase}}js/app.js"></script>
<script src="{{.urlbase}}js/common.js"></script>
</body> </body>
</html> </html>
` `

View File

@ -84,5 +84,6 @@
<script src="/js/angular-route.min.js"></script> <script src="/js/angular-route.min.js"></script>
<script src="/js/angular-sanitize.min.js"></script> <script src="/js/angular-sanitize.min.js"></script>
<script src="/admin/js/app.js"></script> <script src="/admin/js/app.js"></script>
<script src="/admin/js/common.js"></script>
</body> </body>
</html> </html>

View File

@ -235,15 +235,6 @@ angular.module("FICApp")
}) })
}); });
String.prototype.capitalize = function() {
return this
.toLowerCase()
.replace(
/(^|\s)([a-z])/g,
function(m,p1,p2) { return p1+p2.toUpperCase(); }
);
}
angular.module("FICApp") angular.module("FICApp")
.filter("countHints", function() { .filter("countHints", function() {
return function(input) { return function(input) {
@ -252,12 +243,6 @@ angular.module("FICApp")
return input.reduce(function(sum, n){ return sum + (n.content || n.file) ? 1 : 0; }, 0); return input.reduce(function(sum, n){ return sum + (n.content || n.file) ? 1 : 0; }, 0);
} }
}) })
.filter("capitalize", function() {
return function(input) {
if (input != undefined)
return input.capitalize();
}
})
.filter("toColor", function() { .filter("toColor", function() {
return function(input) { return function(input) {
num >>>= 0; num >>>= 0;
@ -268,28 +253,6 @@ angular.module("FICApp")
return "#" + r.toString(16) + g.toString(16) + b.toString(16); return "#" + r.toString(16) + g.toString(16) + b.toString(16);
} }
}) })
.filter("size", function() {
var units = [
"o",
"kio",
"Mio",
"Gio",
"Tio",
"Pio",
"Eio",
"Zio",
"Yio",
]
return function(input) {
var res = input;
var unit = 0;
while (res > 1024) {
unit += 1;
res = res / 1024;
}
return (Math.round(res * 100) / 100) + " " + units[unit];
}
})
.filter("cksum", function() { .filter("cksum", function() {
return function(input) { return function(input) {
if (input == undefined) if (input == undefined)
@ -303,17 +266,6 @@ angular.module("FICApp")
return hex return hex
} }
}) })
.filter("time", function() {
return function(input) {
if (input == undefined) {
return "--";
} else if (input >= 10) {
return input;
} else {
return "0" + input;
}
}
})
.directive('color', function() { .directive('color', function() {
return { return {
@ -362,6 +314,20 @@ angular.module("FICApp")
}; };
}) })
.run(function($rootScope, $http, $interval) {
function refresh() {
$http.get("/api/settings.json").then(function(response) {
response.data.start = new Date(response.data.start);
response.data.end = new Date(response.data.end);
response.data.generation = new Date(response.data.generation);
$rootScope.settings = response.data;
$rootScope.recvTime(response);
})
}
refresh();
$interval(refresh, 10000);
})
.controller("VersionController", function($scope, Version) { .controller("VersionController", function($scope, Version) {
$scope.v = Version.get(); $scope.v = Version.get();
}) })
@ -1368,67 +1334,6 @@ angular.module("FICApp")
$scope.presence.$promise.then(function(res) { $scope.presence.$promise.then(function(res) {
presenceCal($scope, "#presenceCal", res); presenceCal($scope, "#presenceCal", res);
}); });
})
.controller("CountdownController", function(Settings, $scope, $rootScope, $http, $interval) {
$scope.time = {};
function updTime() {
if (sessionStorage.userService && $rootScope.settings) {
var time = angular.fromJson(sessionStorage.userService);
var settings = $rootScope.settings;
var srv_cur = new Date(Date.now() + (time.cu - time.he));
var remain = 0;
if (settings.start > 0 && settings.start > srv_cur) {
$scope.startIn = Math.floor((settings.start - srv_cur) / 1000);
remain = settings.end - settings.start;
} else if (settings.end > srv_cur) {
$scope.startIn = 0;
remain = settings.end - srv_cur;
}
remain = remain / 1000;
if (remain < 0) {
remain = 0;
$scope.time.end = true;
$scope.time.expired = true;
} else if (remain < 60) {
$scope.time.end = false;
$scope.time.expired = true;
} else {
$scope.time.end = false;
$scope.time.expired = false;
}
$scope.time.remaining = remain;
$scope.time.hours = Math.floor(remain / 3600);
$scope.time.minutes = Math.floor((remain % 3600) / 60);
$scope.time.seconds = Math.floor(remain % 60);
$rootScope.time = $scope.time;
}
};
$interval(updTime, 1000);
$rootScope.updTime = function(response) {
sessionStorage.userService = angular.toJson({
"cu": Math.floor(response.headers("x-fic-time") * 1000),
"he": (new Date()).getTime(),
});
updTime();
}
function refresh() {
$http.get("/api/settings.json").then(function(response) {
response.data.start = new Date(response.data.start);
response.data.end = new Date(response.data.end);
response.data.generation = new Date(response.data.generation);
$rootScope.settings = response.data;
$rootScope.updTime(response);
})
}
refresh();
$interval(refresh, 10000);
}); });
function solvedByLevelPie(location, data) { function solvedByLevelPie(location, data) {

1
admin/static/js/common.js Symbolic link
View File

@ -0,0 +1 @@
../../../frontend/static/js/common.js

View File

@ -32,9 +32,9 @@
<div class="col-sm-10"> <div class="col-sm-10">
<div class="input-group"> <div class="input-group">
<input type="text" class="form-control form-control-sm" id="startTime" ng-model="config.start"> <input type="text" class="form-control form-control-sm" id="startTime" ng-model="config.start">
<span class="input-group-btn"> <div class="input-group-append">
<button ng-click="launchChallenge()" class="btn btn-sm btn-secondary" type="button"><span class="glyphicon glyphicon-play" aria-hidden="true"></span> Lancer le challenge</button> <button ng-click="launchChallenge()" class="btn btn-sm btn-secondary" type="button"><span class="glyphicon glyphicon-play" aria-hidden="true"></span> Lancer le challenge</button>
</span> </div>
</div> </div>
</div> </div>
</div> </div>
@ -50,7 +50,9 @@
<div class="col-sm-2"> <div class="col-sm-2">
<div class="input-group input-group-sm"> <div class="input-group input-group-sm">
<input type="text" class="form-control form-control-sm" id="duration" ng-model="duration" integer> <input type="text" class="form-control form-control-sm" id="duration" ng-model="duration" integer>
<span class="input-group-addon">min</span> <div class="input-group-append">
<span class="input-group-text">min</span>
</div>
</div> </div>
</div> </div>
</div> </div>