Working on the time tracker

This commit is contained in:
Hillel Coren 2017-10-01 16:16:27 +03:00
parent dea460e0a9
commit 6f76cb1686
2 changed files with 52 additions and 11 deletions

View File

@ -226,16 +226,20 @@
->raw() !!} ->raw() !!}
</td> </td>
<td style="padding: 0 6px 10px 6px"> <td style="padding: 0 6px 10px 6px">
{!! Former::text('start_time') <div data-bind="css: { 'has-error': !isStartValid() }">
->placeholder('start_time') {!! Former::text('start_time')
->data_bind("timepicker: startTimeOfDay, timepickerOptions: {scrollDefault: 'now', timeFormat: '" . ($account->military_time ? 'H:i:s' : 'g:i:s A') . "'}") ->placeholder('start_time')
->raw() !!} ->data_bind("timepicker: startTimeOfDay, timepickerOptions: {scrollDefault: 'now', timeFormat: '" . ($account->military_time ? 'H:i:s' : 'g:i:s A') . "'}")
->raw() !!}
</div>
</td> </td>
<td style="padding: 0 6px 10px 6px"> <td style="padding: 0 6px 10px 6px">
{!! Former::text('end_time') <div data-bind="css: { 'has-error': !isEndValid() }">
->placeholder('end_time') {!! Former::text('end_time')
->data_bind("timepicker: endTimeOfDay, timepickerOptions: {scrollDefault: 'now', timeFormat: '" . ($account->military_time ? 'H:i:s' : 'g:i:s A') . "'}") ->placeholder('end_time')
->raw() !!} ->data_bind("timepicker: endTimeOfDay, timepickerOptions: {scrollDefault: 'now', timeFormat: '" . ($account->military_time ? 'H:i:s' : 'g:i:s A') . "'}")
->raw() !!}
</div>
</td> </td>
<td style="padding: 0 0 10px 6px"> <td style="padding: 0 0 10px 6px">
{!! Former::text('duration') {!! Former::text('duration')

View File

@ -303,6 +303,10 @@
if (self.selectedTask()) { if (self.selectedTask()) {
self.selectedTask().onStartClick(); self.selectedTask().onStartClick();
} else { } else {
if (! task.checkForOverlaps()) {
swal("{{ trans('texts.task_errors') }}");
return;
}
var time = new TimeModel(); var time = new TimeModel();
time.startTime(moment().unix()); time.startTime(moment().unix());
var task = new TaskModel(); var task = new TaskModel();
@ -560,6 +564,10 @@
} }
self.save = function(isSelected) { self.save = function(isSelected) {
if (! self.checkForOverlaps()) {
swal("{{ trans('texts.task_errors') }}");
return;
}
if (self.isValid() !== true) { if (self.isValid() !== true) {
toastr.error("{{ trans('texts.error_refresh_page') }}"); toastr.error("{{ trans('texts.error_refresh_page') }}");
throw self.isValid(); throw self.isValid();
@ -658,6 +666,33 @@
} }
} }
self.checkForOverlaps = function() {
var lastTime = 0;
var isValid = true;
for (var i=0; i<self.time_log().length; i++) {
var timeLog = self.time_log()[i];
var startValid = true;
var endValid = true;
if (!timeLog.isEmpty()) {
if (timeLog.startTime() < lastTime || (timeLog.endTime() && timeLog.startTime() > timeLog.endTime())) {
startValid = false;
}
if (timeLog.endTime() && timeLog.endTime() < Math.min(timeLog.startTime(), lastTime)) {
endValid = false;
}
lastTime = Math.max(lastTime, timeLog.endTime());
}
timeLog.isStartValid(startValid);
timeLog.isEndValid(endValid);
if (! startValid || ! endValid) {
isValid = false;
}
}
return isValid;
}
self.checkForEmpty = function() { self.checkForEmpty = function() {
setTimeout(function() { setTimeout(function() {
var hasEmpty = false; var hasEmpty = false;
@ -708,6 +743,7 @@
}); });
self.onChange = function() { self.onChange = function() {
self.checkForOverlaps();
self.checkForEmpty(); self.checkForEmpty();
} }
@ -780,17 +816,18 @@
if (! model.isStartEnabled()) { if (! model.isStartEnabled()) {
return false; return false;
} }
if (! self.checkForOverlaps()) {
swal("{{ trans('texts.task_errors') }}");
return;
}
if (self.isRunning()) { if (self.isRunning()) {
var time = self.lastTime(); var time = self.lastTime();
time.endTime(moment().unix()); time.endTime(moment().unix());
} else { } else {
var lastTime = self.lastTime(); var lastTime = self.lastTime();
if (lastTime && ! lastTime.startTime()) { if (lastTime && ! lastTime.startTime()) {
console.log('using time');
var time = lastTime; var time = lastTime;
} else { } else {
console.log('adding time');
var time = new TimeModel(); var time = new TimeModel();
self.addTime(time); self.addTime(time);
} }