Enable setting task duration

This commit is contained in:
Hillel Coren 2017-03-05 22:14:36 +02:00
parent 3302b04efe
commit bdfbea3883

View File

@ -124,8 +124,8 @@
class="form-control time-input time-input-end" placeholder="{{ trans('texts.end_time') }}"/> class="form-control time-input time-input-end" placeholder="{{ trans('texts.end_time') }}"/>
</div> </div>
</td> </td>
<td style="width:100px"> <td style="padding: 0px 12px 12px 0 !important; width:100px">
<div data-bind="text: duration.pretty, visible: !isEmpty()"></div> <input type="text" data-bind="value: duration.pretty, visible: !isEmpty()" class="form-control"></div>
<a href="#" data-bind="click: function() { setNow(), $root.refresh() }, visible: isEmpty()">{{ trans('texts.set_now') }}</a> <a href="#" data-bind="click: function() { setNow(), $root.refresh() }, visible: isEmpty()">{{ trans('texts.set_now') }}</a>
</td> </td>
<td style="width:30px" class="td-icon"> <td style="width:30px" class="td-icon">
@ -350,23 +350,27 @@
self.endTime(moment.tz(timezone).unix()); self.endTime(moment.tz(timezone).unix());
} }
self.duration.pretty = ko.computed(function() { self.duration.pretty = ko.computed({
var duration = false; read: function() {
var start = self.startTime(); var duration = false;
var end = self.endTime(); var start = self.startTime();
var end = self.endTime();
if (start && end) { if (start && end) {
var duration = end - start; var duration = end - start;
}
var duration = moment.duration(duration * 1000);
return Math.floor(duration.asHours()) + moment.utc(duration.asMilliseconds()).format(":mm:ss")
},
write: function(data) {
self.endTime(self.startTime() + convertToSeconds(data));
} }
});
var duration = moment.duration(duration * 1000);
return Math.floor(duration.asHours()) + moment.utc(duration.asMilliseconds()).format(":mm:ss")
}, self);
/* /*
self.isEmpty = function() { self.duration.pretty = ko.computed(function() {
return false; }, self);
};
*/ */
self.hideActions = function() { self.hideActions = function() {
@ -378,6 +382,17 @@
}; };
} }
function convertToSeconds(str) {
if (!str) {
return 0;
}
if (str.indexOf(':') >= 0) {
return moment.duration(str).asSeconds();
} else {
return parseFloat(str) * 60 * 60;
}
}
function loadTimeLog(data) { function loadTimeLog(data) {
model.time_log.removeAll(); model.time_log.removeAll();
data = JSON.parse(data); data = JSON.parse(data);