Too much things
This commit is contained in:
parent
d35bdca3b1
commit
f3a15b00e9
15 changed files with 640 additions and 17 deletions
136
frontend/static/js/public.js
Normal file
136
frontend/static/js/public.js
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
angular.module("FICApp", ["ngSanitize", "ngAnimate"]);
|
||||
|
||||
String.prototype.capitalize = function() {
|
||||
return this
|
||||
.toLowerCase()
|
||||
.replace(
|
||||
/(^|\s)([a-z])/g,
|
||||
function(m,p1,p2) { return p1+p2.toUpperCase(); }
|
||||
);
|
||||
}
|
||||
|
||||
angular.module("FICApp")
|
||||
.filter("capitalize", function() {
|
||||
return function(input) {
|
||||
return input.capitalize();
|
||||
}
|
||||
})
|
||||
.filter("since", function() {
|
||||
return function(passed) {
|
||||
if (passed < 60000) {
|
||||
return "Il y a " + Math.floor(passed/1000) + " secondes";
|
||||
} else {
|
||||
return "Il y a " + Math.floor(passed/60000) + " minutes";
|
||||
}
|
||||
}
|
||||
})
|
||||
.filter("time", function() {
|
||||
return function(input) {
|
||||
if (input == undefined) {
|
||||
return "--";
|
||||
} else if (input >= 10) {
|
||||
return input;
|
||||
} else {
|
||||
return "0" + input;
|
||||
}
|
||||
}
|
||||
})
|
||||
.controller("TimeController", function($scope, $rootScope, $http, $timeout) {
|
||||
$scope.time = {};
|
||||
var initTime = function() {
|
||||
$timeout.cancel($scope.cbi);
|
||||
$scope.cbi = $timeout(initTime, 10000);
|
||||
$http.get("/time.json").success(function(time) {
|
||||
console.log("upd time");
|
||||
time.he = (new Date()).getTime();
|
||||
sessionStorage.userService = angular.toJson(time);
|
||||
});
|
||||
};
|
||||
initTime();
|
||||
|
||||
function updTime() {
|
||||
$timeout.cancel($scope.cb);
|
||||
$scope.cb = $timeout(updTime, 1000);
|
||||
if (sessionStorage.userService) {
|
||||
var time = angular.fromJson(sessionStorage.userService);
|
||||
var srv_cur = (Date.now() + (time.cu * 1000 - time.he)) / 1000;
|
||||
var remain = time.du;
|
||||
if (time.st == Math.floor(srv_cur)) {
|
||||
$scope.refresh(true);
|
||||
$rootScope.startIn = 0;
|
||||
}
|
||||
if (time.st > 0 && time.st <= srv_cur) {
|
||||
remain = time.st + time.du - srv_cur;
|
||||
} else if (time.st > 0) {
|
||||
$rootScope.startIn = Math.floor(time.st - srv_cur);
|
||||
}
|
||||
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.duration = time.du;
|
||||
$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();
|
||||
})
|
||||
.controller("DataController", function($scope, $http, $rootScope, $timeout) {
|
||||
$rootScope.refresh = function() {
|
||||
$timeout.cancel($scope.cbd);
|
||||
$scope.cbd = $timeout($rootScope.refresh, 4200);
|
||||
$http.get("/demo.json").success(function(demo) {
|
||||
$scope.my = demo;
|
||||
});
|
||||
$http.get("/events.json").success(function(evts) {
|
||||
var events = {};
|
||||
var now = new Date();
|
||||
angular.forEach(evts, function(event, key) {
|
||||
events["e" + event.id] = event;
|
||||
event.since = now.getTime() - now.getTimezoneOffset() * 60000 - Date.parse(event.time);
|
||||
});
|
||||
$scope.events = events;
|
||||
});
|
||||
$http.get("/public.json").success(function(scene) {
|
||||
$scope.scene = scene;
|
||||
});
|
||||
$http.get("/stats.json").success(function(stats) {
|
||||
$scope.stats = stats;
|
||||
});
|
||||
$http.get("/themes.json").success(function(themes) {
|
||||
$scope.themes = themes;
|
||||
$scope.max_gain = 0;
|
||||
angular.forEach(themes, function(theme, key) {
|
||||
this[key].exercice_count = Object.keys(theme.exercices).length;
|
||||
this[key].gain = 0;
|
||||
angular.forEach(theme.exercices, function(ex, k) {
|
||||
this.gain += ex.gain;
|
||||
}, theme);
|
||||
$scope.max_gain += theme.gain;
|
||||
}, themes);
|
||||
});
|
||||
$http.get("/teams.json").success(function(teams) {
|
||||
$scope.teams_count = Object.keys(teams).length
|
||||
$scope.teams = teams;
|
||||
|
||||
$scope.rank = [];
|
||||
angular.forEach($scope.teams, function(team, tid) {
|
||||
team.id = tid;
|
||||
if (team.rank) {
|
||||
this.push(team);
|
||||
}
|
||||
}, $scope.rank);
|
||||
});
|
||||
console.log("refresh!");
|
||||
}
|
||||
$rootScope.refresh();
|
||||
});
|
||||
Reference in a new issue