Working on the time tracker

This commit is contained in:
Hillel Coren 2017-10-01 14:01:37 +03:00
parent 43cbb7e3cd
commit 026d440831
2 changed files with 25 additions and 25 deletions

View File

@ -215,7 +215,7 @@
<label>{{ trans('texts.times') }}</label> <label>{{ trans('texts.times') }}</label>
<table class="table times-table" style="margin-bottom: 0px !important;"> <table class="table times-table" data-bind="event: { change: selectedTask().onChange }" style="margin-bottom: 0px !important;">
<tbody data-bind="foreach: selectedTask().time_log"> <tbody data-bind="foreach: selectedTask().time_log">
<tr data-bind="event: { mouseover: onMouseOver, mouseout: onMouseOut }"> <tr data-bind="event: { mouseover: onMouseOver, mouseout: onMouseOut }">
<td style="padding: 0 6px 10px 0"> <td style="padding: 0 6px 10px 0">

View File

@ -50,19 +50,6 @@
var value = valueAccessor(); var value = valueAccessor();
var seconds = $(element).timepicker('getSecondsFromMidnight'); var seconds = $(element).timepicker('getSecondsFromMidnight');
value(seconds); value(seconds);
/*
var field = $(element).attr('name');
var time = 0;
if (field == 'duration') {
time = $(element).timepicker('getSecondsFromMidnight');
} else {
var dateTime = $(element).timepicker('getTime');
if (dateTime) {
time = dateTime.getTime() / 1000;
}
}
value(time);
*/
}); });
}, },
update: function (element, valueAccessor) { update: function (element, valueAccessor) {
@ -75,6 +62,8 @@
} else { } else {
$(element).timepicker('setTime', new Date(value * 1000)); $(element).timepicker('setTime', new Date(value * 1000));
} }
} else {
$(element).val('');
} }
if (field == 'start_time') { if (field == 'start_time') {
@ -661,24 +650,31 @@
var times = data.time_log instanceof Array ? data.time_log : JSON.parse(data.time_log); var times = data.time_log instanceof Array ? data.time_log : JSON.parse(data.time_log);
ko.mapping.fromJS(data, self.mapping, this); ko.mapping.fromJS(data, self.mapping, this);
self.time_log.removeAll(); self.time_log.removeAll();
console.log('removing all...');
for (var i=0; i<times.length; i++) { for (var i=0; i<times.length; i++) {
self.time_log.push(new TimeModel(times[i])); self.time_log.push(new TimeModel(times[i]));
} }
//self.addTime();
self.checkForEmpty(); self.checkForEmpty();
} }
self.checkForEmpty = function() { self.checkForEmpty = function() {
var hasEmpty = false; setTimeout(function() {
var lastTime = 0; console.log('checking..');
for (var i=0; i<self.time_log().length; i++) { var hasEmpty = false;
var timeLog = self.time_log()[i]; var times = self.time_log();
if (timeLog.isEmpty() || timeLog.isRunning()) { for (var i=0; i<times.length; i++) {
hasEmpty = true; var timeLog = times[i];
console.log('end time: ' + timeLog.endTime());
if (! timeLog.endTime()) {
hasEmpty = true;
}
} }
} if (! hasEmpty) {
if (!hasEmpty) { console.log('addng blank');
self.addTime(); self.addTime();
} }
}, 1);
} }
self.sortValue = function(field) { self.sortValue = function(field) {
@ -714,6 +710,10 @@
return self.isHovered(); return self.isHovered();
}); });
self.onChange = function() {
self.checkForEmpty();
}
self.onMouseOver = function() { self.onMouseOver = function() {
self.isHovered(true); self.isHovered(true);
} }
@ -880,6 +880,7 @@
}); });
self.seconds = function(total) { self.seconds = function(total) {
//model.clock(); // bind to the clock
if (! self.time_log().length) { if (! self.time_log().length) {
return moment.duration(0); return moment.duration(0);
} }
@ -913,7 +914,6 @@
self.removeTime = function(time) { self.removeTime = function(time) {
model.formChanged(true); model.formChanged(true);
self.time_log.remove(time); self.time_log.remove(time);
self.checkForEmpty();
} }
if (data) { if (data) {