1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

Working on time tracker

This commit is contained in:
Hillel Coren 2017-09-24 20:58:10 +03:00
parent 3347f14392
commit 27813567b2
3 changed files with 50 additions and 32 deletions

View File

@ -154,6 +154,14 @@ class TaskRepository extends BaseRepository
}
}
/*
if ($count = count($timeLog)) {
$lastTime = $timeLog[$count - 1];
$task->is_running = count($lastTime) == 2 && $lastTime[1];
\Log::info('is running: ' . $task->is_running);
}
*/
$task->time_log = json_encode($timeLog);
$task->save();

View File

@ -95,13 +95,15 @@
<div style="height:74px"></div>
<!--
Client: <span data-bind="text: ko.toJSON(model.selectedClient().public_id)"></span>
Project: <span data-bind="text: ko.toJSON(model.selectedProject().public_id)"></span>
<div data-bind="text: ko.toJSON(model.selectedTask().client_id)"></div>
<div data-bind="text: ko.toJSON(model.selectedTask().client)"></div>
<div data-bind="text: ko.toJSON(model.selectedTask().project_id)"></div>
<div data-bind="text: ko.toJSON(model.selectedTask().project)"></div>
<div data-bind="text: ko.toJSON(model.selectedClient().public_id)"></div>
<div data-bind="text: ko.toJSON(model.selectedProject().public_id)"></div>
-->
<div class="container" style="margin: 0 auto;width: 100%;">

View File

@ -15,38 +15,10 @@
if (! model.selectedTask() || ! model.formChanged()) {
return;
}
var data = $('#taskForm').serialize();
var task = model.selectedTask();
var data = $('#taskForm').serialize();
data += '&time_log=' + JSON.stringify(task.times());
var url = '{{ url('/tasks') }}';
var method = 'post';
if (task.public_id()) {
method = 'put';
url += '/' + task.public_id();
}
$.ajax({
dataType: 'json',
type: method,
data: data,
url: url,
accepts: {
json: 'application/json'
},
success: function(response) {
console.log(response);
var task = self.selectedTask();
var projectId = $('input[name=project_id]').val();
if (projectId == -1) {
var project = response.project;
project.client = response.client;
projects.push(project);
addProjectToMaps(project);
refreshProjectList();
}
task.update(response);
self.formChanged(false);
},
});
task.save(data, true);
}
self.submitBulkAction = function(action, task) {
@ -144,12 +116,14 @@
self.viewClient = function(task) {
self.filter(task.client().displayName());
self.selectedProject(false);
self.selectedClient(task.client());
return false;
}
self.viewProject = function(task) {
self.filter(task.project().name());
self.selectedClient(false);
self.selectedProject(task.project());
return false;
}
@ -348,6 +322,39 @@
]
}
self.save = function(data, isSelected) {
var url = '{{ url('/tasks') }}';
var method = 'post';
if (self.public_id()) {
method = 'put';
url += '/' + self.public_id();
}
$.ajax({
dataType: 'json',
type: method,
data: data,
url: url,
accepts: {
json: 'application/json'
},
success: function(response) {
console.log(response);
if (isSelected) {
var projectId = $('input[name=project_id]').val();
if (projectId == -1) {
var project = response.project;
project.client = response.client;
projects.push(project);
addProjectToMaps(project);
refreshProjectList();
}
self.update(response);
model.formChanged(false);
}
},
});
}
self.update = function(data) {
self.data = data;
var times = JSON.parse(data.time_log);
@ -431,6 +438,7 @@
time.startTime(moment().unix());
self.addTime(time);
}
self.save('time_log=' + JSON.stringify(self.times()));
}
self.listItemState = ko.computed(function() {