Allow to enter countdown time in seconds or 'mm:ss' format.
This commit is contained in:
parent
2af38f75bb
commit
3479a0636e
@ -391,25 +391,24 @@ angular.module('OpenSlidesApp.core', [
|
|||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
/* Converts number of seconds into string "hh:mm:ss" or "mm:ss" */
|
/* Converts number of seconds into string "h:mm:ss" or "mm:ss" */
|
||||||
.filter('osSecondsToTime', [
|
.filter('osSecondsToTime', [
|
||||||
function () {
|
function () {
|
||||||
return function (totalseconds) {
|
return function (totalseconds) {
|
||||||
var time;
|
var time;
|
||||||
// floor returns the largest integer of the absolut value of totalseconds
|
// floor returns the largest integer of the absolut value of totalseconds
|
||||||
var total = Math.floor(Math.abs(totalseconds));
|
var total = Math.floor(Math.abs(totalseconds));
|
||||||
var hh = Math.floor(total / 3600);
|
var h = Math.floor(total / 3600);
|
||||||
var mm = Math.floor(total % 3600 / 60);
|
var mm = Math.floor(total % 3600 / 60);
|
||||||
var ss = Math.floor(total % 60);
|
var ss = Math.floor(total % 60);
|
||||||
var zero = "0";
|
var zero = "0";
|
||||||
// Add leading "0" for double digit values
|
// Add leading "0" for double digit values
|
||||||
hh = (zero+hh).slice(-2);
|
|
||||||
mm = (zero+mm).slice(-2);
|
mm = (zero+mm).slice(-2);
|
||||||
ss = (zero+ss).slice(-2);
|
ss = (zero+ss).slice(-2);
|
||||||
if (hh == "00")
|
if (h == "0")
|
||||||
time = mm + ':' + ss;
|
time = mm + ':' + ss;
|
||||||
else
|
else
|
||||||
time = hh + ":" + mm + ":" + ss;
|
time = h + ":" + mm + ":" + ss;
|
||||||
if (totalseconds < 0)
|
if (totalseconds < 0)
|
||||||
time = "-"+time;
|
time = "-"+time;
|
||||||
return time;
|
return time;
|
||||||
|
@ -1055,6 +1055,48 @@ angular.module('OpenSlidesApp.core.site', [
|
|||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
|
// format time string for model ("s") and view format ("h:mm:ss" or "mm:ss")
|
||||||
|
.directive('minSecFormat', [
|
||||||
|
function () {
|
||||||
|
return {
|
||||||
|
require: 'ngModel',
|
||||||
|
link: function(scope, element, attrs, ngModelController) {
|
||||||
|
ngModelController.$parsers.push(function(data) {
|
||||||
|
//convert data from view format (mm:ss) to model format (s)
|
||||||
|
var time = data.split(':');
|
||||||
|
if (time.length > 1) {
|
||||||
|
data = (+time[0]) * 60 + (+time[1]);
|
||||||
|
if (data < 0) {
|
||||||
|
data = "-"+data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
});
|
||||||
|
|
||||||
|
ngModelController.$formatters.push(function(data) {
|
||||||
|
//convert data from model format (s) to view format (mm:ss)
|
||||||
|
var time;
|
||||||
|
// floor returns the largest integer of the absolut value of totalseconds
|
||||||
|
var total = Math.floor(Math.abs(data));
|
||||||
|
var mm = Math.floor(total / 60);
|
||||||
|
var ss = Math.floor(total % 60);
|
||||||
|
var zero = "0";
|
||||||
|
// Add leading "0" for double digit values
|
||||||
|
if (mm.length < 2) {
|
||||||
|
mm = (zero+mm).slice(-2);
|
||||||
|
}
|
||||||
|
ss = (zero+ss).slice(-2);
|
||||||
|
time = mm + ':' + ss;
|
||||||
|
if (data < 0) {
|
||||||
|
time = "-"+time;
|
||||||
|
}
|
||||||
|
return time;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
.directive('osFocusMe', [
|
.directive('osFocusMe', [
|
||||||
'$timeout',
|
'$timeout',
|
||||||
function ($timeout) {
|
function ($timeout) {
|
||||||
|
@ -136,7 +136,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label translate>Start time</label>
|
<label translate>Start time</label>
|
||||||
<input ng-model="countdown.default" type="number" class="form-control input-sm">
|
<input data-ng-model="countdown.default" min-sec-format
|
||||||
|
type="text" placeholder="mm:ss" class="form-control input-sm">
|
||||||
</div>
|
</div>
|
||||||
<button type="submit"
|
<button type="submit"
|
||||||
title="{{ 'Save' | translate}}"
|
title="{{ 'Save' | translate}}"
|
||||||
|
Loading…
Reference in New Issue
Block a user