Mutualise some common JS functions
This commit is contained in:
parent
3df8d24e33
commit
e9fd9c4e9a
@ -279,7 +279,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style="box-shadow: 0px -5px 5px 5px #e9ecef; position: fixed; bottom: calc(14vh - 1px); right: 0; width: 33vw;" class="navbar bg-light" ng-controller="TimeController">
|
<div style="box-shadow: 0px -5px 5px 5px #e9ecef; position: fixed; bottom: calc(14vh - 1px); right: 0; width: 33vw;" class="navbar bg-light" ng-controller="CountdownController">
|
||||||
<div class="text-center" ng-if="time.hours === 0 || time.hours" style="margin-top: -5px;">
|
<div class="text-center" ng-if="time.hours === 0 || time.hours" style="margin-top: -5px;">
|
||||||
<div id="clock" ng-class="{expired: time.expired, end: time.end}" style="font-size: 50px" ng-cloak>
|
<div id="clock" ng-class="{expired: time.expired, end: time.end}" style="font-size: 50px" ng-cloak>
|
||||||
<span id="hours">{{ time.hours | time }}</span>
|
<span id="hours">{{ time.hours | time }}</span>
|
||||||
|
@ -1,80 +1,4 @@
|
|||||||
angular.module("FICApp", ["ngSanitize", "ngAnimate"]);
|
angular.module("FICApp", ["ngSanitize", "ngAnimate"])
|
||||||
|
|
||||||
angular.module("FICApp")
|
|
||||||
.filter("objectLength", function() {
|
|
||||||
return function(input) {
|
|
||||||
if (input !== undefined)
|
|
||||||
return Object.keys(input).length;
|
|
||||||
else
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
String.prototype.capitalize = function() {
|
|
||||||
return this
|
|
||||||
.toLowerCase()
|
|
||||||
.replace(
|
|
||||||
/(^|\s)([a-z])/g,
|
|
||||||
function(m,p1,p2) { return p1+p2.toUpperCase(); }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
angular.module("FICApp")
|
|
||||||
.controller("TimeController", function($scope, $rootScope, $http, $timeout) {
|
|
||||||
$rootScope.time = {};
|
|
||||||
$rootScope.recvTime = function(response) {
|
|
||||||
sessionStorage.userService = angular.toJson({
|
|
||||||
"cu": Math.floor(response.headers("x-fic-time") * 1000),
|
|
||||||
"he": (new Date()).getTime(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function updTime() {
|
|
||||||
$timeout.cancel($scope.cb);
|
|
||||||
$scope.cb = $timeout(updTime, 1000);
|
|
||||||
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));
|
|
||||||
|
|
||||||
if (Math.floor(settings.start / 1000) == Math.floor(srv_cur / 1000)) {
|
|
||||||
$rootScope.refresh(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
var remain = 0;
|
|
||||||
if (settings.start == 0) {
|
|
||||||
$rootScope.time = {};
|
|
||||||
return
|
|
||||||
} else if (settings.start > srv_cur) {
|
|
||||||
$rootScope.startIn = Math.floor((settings.start - srv_cur) / 1000);
|
|
||||||
remain = settings.end - settings.start;
|
|
||||||
} else if (settings.end > srv_cur) {
|
|
||||||
$rootScope.startIn = 0;
|
|
||||||
remain = settings.end - srv_cur;
|
|
||||||
}
|
|
||||||
|
|
||||||
remain = remain / 1000;
|
|
||||||
|
|
||||||
if (remain < 0) {
|
|
||||||
remain = 0;
|
|
||||||
$rootScope.time.end = true;
|
|
||||||
$rootScope.time.expired = true;
|
|
||||||
} else if (remain < 60) {
|
|
||||||
$rootScope.time.end = false;
|
|
||||||
$rootScope.time.expired = true;
|
|
||||||
} else {
|
|
||||||
$rootScope.time.end = false;
|
|
||||||
$rootScope.time.expired = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$rootScope.time.remaining = remain;
|
|
||||||
$rootScope.time.hours = Math.floor(remain / 3600);
|
|
||||||
$rootScope.time.minutes = Math.floor((remain % 3600) / 60);
|
|
||||||
$rootScope.time.seconds = Math.floor(remain % 60);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
updTime();
|
|
||||||
})
|
|
||||||
.controller("EventsController", function($scope, $http, $interval) {
|
.controller("EventsController", function($scope, $http, $interval) {
|
||||||
$scope.events = [];
|
$scope.events = [];
|
||||||
var refreshEvents = function() {
|
var refreshEvents = function() {
|
||||||
|
@ -47,64 +47,6 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
|
|||||||
$rootScope.current_exercice = 0;
|
$rootScope.current_exercice = 0;
|
||||||
$rootScope.current_tag = undefined;
|
$rootScope.current_tag = undefined;
|
||||||
})
|
})
|
||||||
.controller("CountdownController", function($scope, $rootScope, $interval) {
|
|
||||||
var time;
|
|
||||||
if (sessionStorage.userService)
|
|
||||||
time = angular.fromJson(sessionStorage.userService);
|
|
||||||
|
|
||||||
$scope.time = {};
|
|
||||||
|
|
||||||
$rootScope.recvTime = function(response) {
|
|
||||||
time = {
|
|
||||||
"cu": Math.floor(response.headers("x-fic-time") * 1000),
|
|
||||||
"he": (new Date()).getTime(),
|
|
||||||
};
|
|
||||||
sessionStorage.userService = angular.toJson(time);
|
|
||||||
}
|
|
||||||
|
|
||||||
function updTime() {
|
|
||||||
if (time && $rootScope.settings) {
|
|
||||||
var srv_cur = new Date(Date.now() + (time.cu - time.he));
|
|
||||||
|
|
||||||
// Refresh on start time reached
|
|
||||||
if (Math.floor($rootScope.settings.start / 1000) == Math.floor(srv_cur / 1000))
|
|
||||||
$rootScope.refresh(true);
|
|
||||||
|
|
||||||
var remain = 0;
|
|
||||||
if ($rootScope.settings.start == 0) {
|
|
||||||
$scope.time = {};
|
|
||||||
return
|
|
||||||
} else if ($rootScope.settings.start > srv_cur) {
|
|
||||||
$rootScope.startIn = Math.floor(($rootScope.settings.start - srv_cur) / 1000);
|
|
||||||
remain = $rootScope.settings.end - $rootScope.settings.start;
|
|
||||||
} else if ($rootScope.settings.end > srv_cur) {
|
|
||||||
$rootScope.startIn = 0;
|
|
||||||
remain = $rootScope.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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
updTime();
|
|
||||||
$interval(updTime, 1000);
|
|
||||||
})
|
|
||||||
.controller("DataController", function($sce, $scope, $http, $rootScope, $interval, $location) {
|
.controller("DataController", function($sce, $scope, $http, $rootScope, $interval, $location) {
|
||||||
var actMenu = function() {
|
var actMenu = function() {
|
||||||
if ($scope.my && $scope.themes) {
|
if ($scope.my && $scope.themes) {
|
||||||
|
@ -110,3 +110,72 @@ angular.module("FICApp")
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
.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;
|
||||||
|
if (sessionStorage.userService)
|
||||||
|
time = angular.fromJson(sessionStorage.userService);
|
||||||
|
|
||||||
|
$scope.time = {};
|
||||||
|
|
||||||
|
$rootScope.recvTime = function(response) {
|
||||||
|
time = {
|
||||||
|
"cu": Math.floor(response.headers("x-fic-time") * 1000),
|
||||||
|
"he": (new Date()).getTime(),
|
||||||
|
};
|
||||||
|
sessionStorage.userService = angular.toJson(time);
|
||||||
|
}
|
||||||
|
|
||||||
|
function updTime() {
|
||||||
|
if (time && $rootScope.settings) {
|
||||||
|
var srv_cur = new Date(Date.now() + (time.cu - time.he));
|
||||||
|
|
||||||
|
// Refresh on start time reached
|
||||||
|
if (Math.floor($rootScope.settings.start / 1000) == Math.floor(srv_cur / 1000))
|
||||||
|
$rootScope.refresh(true);
|
||||||
|
|
||||||
|
var remain = 0;
|
||||||
|
if ($rootScope.settings.start == 0) {
|
||||||
|
$scope.time = {};
|
||||||
|
return
|
||||||
|
} else if ($rootScope.settings.start > srv_cur) {
|
||||||
|
$rootScope.startIn = Math.floor(($rootScope.settings.start - srv_cur) / 1000);
|
||||||
|
remain = $rootScope.settings.end - $rootScope.settings.start;
|
||||||
|
} else if ($rootScope.settings.end > srv_cur) {
|
||||||
|
$rootScope.startIn = 0;
|
||||||
|
remain = $rootScope.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updTime();
|
||||||
|
$interval(updTime, 1000);
|
||||||
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user