2017-01-14 13:57:39 +00:00
|
|
|
String.prototype.capitalize = function() {
|
|
|
|
return this
|
|
|
|
.toLowerCase()
|
|
|
|
.replace(
|
2018-12-05 04:23:36 +00:00
|
|
|
/(^|\s|-)([a-z])/g,
|
2017-01-14 13:57:39 +00:00
|
|
|
function(m,p1,p2) { return p1+p2.toUpperCase(); }
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-01-23 01:26:55 +00:00
|
|
|
Array.prototype.inArray = function(v) {
|
|
|
|
return this.reduce(function(presence, current) {
|
|
|
|
return presence || current == v;
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
2018-01-16 23:05:50 +00:00
|
|
|
angular.module("FICApp")
|
|
|
|
.directive('autofocus', ['$timeout', function($timeout) {
|
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
link : function($scope, $element) {
|
|
|
|
$timeout(function() {
|
|
|
|
$element[0].focus();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2018-01-23 02:49:23 +00:00
|
|
|
}])
|
2018-02-02 20:10:31 +00:00
|
|
|
.directive('autocarousel', ['$timeout', function($timeout) {
|
2018-01-23 02:49:23 +00:00
|
|
|
return {
|
|
|
|
restrict: 'A',
|
2018-02-02 20:10:31 +00:00
|
|
|
link : function($scope, $element) {
|
|
|
|
$timeout(function() {
|
|
|
|
$($element[0]).carousel();
|
|
|
|
});
|
2018-01-23 02:49:23 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-16 23:05:50 +00:00
|
|
|
}]);
|
|
|
|
|
2017-01-14 13:57:39 +00:00
|
|
|
angular.module("FICApp")
|
2018-12-05 03:09:59 +00:00
|
|
|
.filter("stripHTML", function() {
|
|
|
|
return function(input) {
|
|
|
|
if (!input)
|
|
|
|
return input;
|
|
|
|
return input.replace(
|
|
|
|
/(<([^>]+)>)/ig,
|
|
|
|
""
|
|
|
|
);
|
|
|
|
}
|
|
|
|
})
|
2017-01-14 13:57:39 +00:00
|
|
|
.filter("capitalize", function() {
|
|
|
|
return function(input) {
|
|
|
|
return input.capitalize();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.filter("rankTitle", function() {
|
|
|
|
var itms = {
|
|
|
|
"rank": "Rang",
|
|
|
|
"name": "Équipe",
|
|
|
|
"score": "Score",
|
|
|
|
};
|
|
|
|
return function(input) {
|
|
|
|
if (itms[input] != undefined) {
|
|
|
|
return itms[input];
|
|
|
|
} else {
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.filter("time", function() {
|
|
|
|
return function(input) {
|
2017-12-17 19:44:23 +00:00
|
|
|
input = Math.floor(input);
|
2017-01-14 13:57:39 +00:00
|
|
|
if (input == undefined) {
|
|
|
|
return "--";
|
|
|
|
} else if (input >= 10) {
|
|
|
|
return input;
|
|
|
|
} else {
|
|
|
|
return "0" + input;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.filter("since", function() {
|
|
|
|
return function(passed) {
|
|
|
|
if (passed < 120000) {
|
|
|
|
return "Il y a " + Math.floor(passed/1000) + " secondes";
|
|
|
|
} else {
|
|
|
|
return "Il y a " + Math.floor(passed/60000) + " minutes";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.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];
|
|
|
|
}
|
|
|
|
})
|
2017-01-16 12:09:31 +00:00
|
|
|
|
|
|
|
.filter("coeff", function() {
|
|
|
|
return function(input) {
|
|
|
|
if (input > 1) {
|
|
|
|
return "+" + Math.floor((input - 1) * 100) + " %"
|
|
|
|
} else if (input < 1) {
|
|
|
|
return "-" + Math.floor((1 - input) * 100) + " %"
|
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2018-12-04 03:13:01 +00:00
|
|
|
|
|
|
|
.filter("objectLength", function() {
|
|
|
|
return function(input) {
|
|
|
|
if (input !== undefined)
|
|
|
|
return Object.keys(input).length;
|
|
|
|
else
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
angular.module("FICApp")
|
|
|
|
.controller("CountdownController", function($scope, $rootScope, $interval) {
|
|
|
|
var time;
|
2019-01-19 07:04:54 +00:00
|
|
|
if (sessionStorage.time)
|
|
|
|
time = angular.fromJson(sessionStorage.time);
|
2018-12-04 03:13:01 +00:00
|
|
|
|
|
|
|
$scope.time = {};
|
|
|
|
|
2018-12-01 17:15:03 +00:00
|
|
|
$rootScope.getSrvTime = function() {
|
2019-01-18 13:44:56 +00:00
|
|
|
if (time && time.cu && time.he)
|
2018-12-01 17:15:03 +00:00
|
|
|
return new Date(Date.now() + (time.cu - time.he));
|
|
|
|
else
|
|
|
|
return undefined;
|
|
|
|
}
|
2018-12-04 03:13:01 +00:00
|
|
|
$rootScope.recvTime = function(response) {
|
|
|
|
time = {
|
|
|
|
"cu": Math.floor(response.headers("x-fic-time") * 1000),
|
|
|
|
"he": (new Date()).getTime(),
|
|
|
|
};
|
2019-01-19 07:04:54 +00:00
|
|
|
sessionStorage.time = angular.toJson(time);
|
2019-01-17 12:03:15 +00:00
|
|
|
return time;
|
2018-12-04 03:13:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function updTime() {
|
|
|
|
if (time && $rootScope.settings) {
|
|
|
|
var srv_cur = new Date(Date.now() + (time.cu - time.he));
|
|
|
|
|
2019-01-17 12:03:15 +00:00
|
|
|
// Refresh on start/activate time reached
|
|
|
|
if (Math.floor($rootScope.settings.start / 1000) == Math.floor(srv_cur / 1000) ||Math.floor($rootScope.settings.activateTime / 1000) == Math.floor(srv_cur / 1000))
|
|
|
|
$rootScope.refresh(true, true);
|
2018-12-04 03:13:01 +00:00
|
|
|
|
|
|
|
var remain = 0;
|
2019-02-18 17:00:54 +00:00
|
|
|
if ($rootScope.settings.start === undefined || $rootScope.settings.start == 0) {
|
2018-12-04 03:13:01 +00:00
|
|
|
$scope.time = {};
|
|
|
|
return
|
|
|
|
} else if ($rootScope.settings.start > srv_cur) {
|
2018-12-04 04:34:34 +00:00
|
|
|
$scope.startIn = Math.floor(($rootScope.settings.start - srv_cur) / 1000);
|
2018-12-04 03:13:01 +00:00
|
|
|
remain = $rootScope.settings.end - $rootScope.settings.start;
|
|
|
|
} else if ($rootScope.settings.end > srv_cur) {
|
2018-12-04 04:34:34 +00:00
|
|
|
$scope.startIn = 0;
|
2018-12-04 03:13:01 +00:00
|
|
|
remain = $rootScope.settings.end - srv_cur;
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:56:09 +00:00
|
|
|
$rootScope.timeProgression = 1 - remain / ($rootScope.settings.end - $rootScope.settings.start);
|
|
|
|
|
2018-12-04 03:13:01 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updTime();
|
|
|
|
$interval(updTime, 1000);
|
|
|
|
})
|