From 76effdd1fd46e822cba8d1dcb9014be097f9017c Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Sat, 14 Jan 2017 14:57:39 +0100 Subject: [PATCH] frontend: use a common JS file to contain common features between challenger and public interface --- frontend/static/index.html | 3 +- frontend/static/js/{app.js => challenge.js} | 49 -------------- frontend/static/js/common.js | 71 +++++++++++++++++++++ frontend/static/js/public.js | 25 -------- frontend/static/public.html | 1 + 5 files changed, 74 insertions(+), 75 deletions(-) rename frontend/static/js/{app.js => challenge.js} (92%) create mode 100644 frontend/static/js/common.js diff --git a/frontend/static/index.html b/frontend/static/index.html index 7268f504..da559577 100644 --- a/frontend/static/index.html +++ b/frontend/static/index.html @@ -126,6 +126,7 @@ - + + diff --git a/frontend/static/js/app.js b/frontend/static/js/challenge.js similarity index 92% rename from frontend/static/js/app.js rename to frontend/static/js/challenge.js index 0317e8b2..1b7e9b00 100644 --- a/frontend/static/js/app.js +++ b/frontend/static/js/challenge.js @@ -68,55 +68,6 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"]) } } updTime(); - }); - -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("time", function() { - return function(input) { - if (input == undefined) { - return "--"; - } else if (input >= 10) { - return input; - } else { - return "0" + input; - } - } - }) - .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]; - } }) .controller("DataController", function($sce, $scope, $http, $rootScope, $timeout) { var actMenu = function() { diff --git a/frontend/static/js/common.js b/frontend/static/js/common.js new file mode 100644 index 00000000..8156d436 --- /dev/null +++ b/frontend/static/js/common.js @@ -0,0 +1,71 @@ +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("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) { + 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]; + } + }) diff --git a/frontend/static/js/public.js b/frontend/static/js/public.js index 3c1b6245..6409e204 100644 --- a/frontend/static/js/public.js +++ b/frontend/static/js/public.js @@ -10,31 +10,6 @@ String.prototype.capitalize = function() { } angular.module("FICApp") - .filter("capitalize", function() { - return function(input) { - return input.capitalize(); - } - }) - .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("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() { diff --git a/frontend/static/public.html b/frontend/static/public.html index 3587e2aa..f3c5411f 100644 --- a/frontend/static/public.html +++ b/frontend/static/public.html @@ -200,5 +200,6 @@ +