Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use enter to create a new timeline entry
  • Loading branch information
Harm Akkerman committed Jul 23, 2022
commit 4ca39bac2898ed4c47b1db4e31cc00acc53cf1c9
76 changes: 42 additions & 34 deletions js/src/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ require('../../css/style.css');
var dtf = require("./dateformat.js");

(


function() {

$.ajaxSetup({
headers: { 'RequestToken': OC.requestToken }
});
Expand All @@ -25,6 +25,10 @@ function() {


$( function() {
$('#work-input-form').on('submit', function(e) {
e.preventDefault();
createWorkItem();
});
var days='30';
var start = moment().startOf('day').subtract(29, 'days');
var end = moment().endOf('day');
Expand Down Expand Up @@ -70,7 +74,7 @@ function() {
'`': '`',
'=': '='
};

function escapeHtml (string) {
return String(string).replace(/[&<>"'`=\/]/g, function (s) {
return entityMap[s];
Expand Down Expand Up @@ -116,10 +120,10 @@ function() {

validateManualEntryFields();
});

$("#dialog-manual-entry").dialog({
autoOpen: false,
buttons :
buttons :
[ {
id: 'confirm-button',
text: "Confirm",
Expand Down Expand Up @@ -183,7 +187,7 @@ function() {
alert( "error" );
})
.always(function() {

});

}
Expand Down Expand Up @@ -223,7 +227,7 @@ function() {
//contentType: "application/json; charset=utf-8"
});
$.getJSON( baseUrl, function( data ) {

if (data.running.length > 0){
localStorage.setItem('isTimerStarted', true);
localStorage.setItem('timerStartTime', data.running[0].start);
Expand All @@ -246,15 +250,15 @@ function() {
$('#timer').html(secondsToTimer(0));
$('#start-tracking > span').addClass("play-button").removeClass("stop-button");
}


var days = [];
$.each( data.days, function( dayName, dayMap ) {

var dayItems = [];
$.each(dayMap, function (dayItemName, workItem){
var children = [];

$.each(workItem.children, function (ckey, child){
children.push(
"<li>"+
Expand Down Expand Up @@ -302,8 +306,8 @@ function() {
days.push( "<div class='day-work-intervals'>"+
"<ul>"+
"<li class='day-list-item'>" +
"<div class='day-name'>" + dayName +"</div>"+
dayItems.join("") +
"<div class='day-name'>" + dayName +"</div>"+
dayItems.join("") +
"</li>"+
"</ul>"+
"</div>" );
Expand Down Expand Up @@ -348,7 +352,7 @@ function() {
$('.wi-child-name').click(function(e) {
e.preventDefault();
dialogWorkItemEditForm.target = e.target;

var form = dialogWorkItemEditForm.find( "form" )
form.find("#name").val($(e.target).data("name"));
form.find("#details").val($(e.target).data("details"));
Expand All @@ -358,9 +362,7 @@ function() {
})
$('.wi-play').click(function(e) {
e.preventDefault();
$('#work-input').val($(this).data('work-name'));
startTimer($(this).data('projectid'), $(this).data('tagids'));
return false;
createWorkItem();
})
$('.wi-trash').click(function(e) {
$("#dialog-confirm").dialog({
Expand Down Expand Up @@ -425,11 +427,11 @@ function() {
},
ajax: {
url: projectsAjaxUrl,

dataType: 'json',
delay: 250,
processResults: function (data) { //json parse
return {
return {
results: $.map(data.Projects,function(val, i){
return { id: val.id, text:val.name, color: val.color};
}),
Expand All @@ -439,35 +441,35 @@ function() {
};
},
cache: false,

},
});
$(this).data('myid',id);

$(this).val(projectId).trigger('change');
//clearInterval(interval);
//}.bind(this),0);
});

var tagsAjaxUrl = OC.generateUrl('/apps/timetracker/ajax/tags');
$(".set-tag").each(function(){
//var interval = setInterval( function() {


$(this).select2({
tags: true,
containerCssClass:'tags-select',
placeholder: "Select tags...",
allowClear: true,
ajax: {

ajax: {
url: function () { return tagsAjaxUrl+'?workItem='+$(this).data('myid');},
data: function (params){
var query = {
q: params.term,
type: 'public'
}

// Query parameters will be ?search=[term]&type=public
return query;
},
Expand All @@ -478,7 +480,7 @@ function() {
dataType: 'json',
delay: 250,
processResults: function (data) { //json parse
return {
return {
results: $.map(data.Tags,function(val, i){
return { id: val.id, text:val.name};
}),
Expand All @@ -501,8 +503,8 @@ function() {
var myid = $(e.target).data('myid');
var selectedId = $(e.target).val();
var jqxhr = $.post( "ajax/update-work-interval/"+myid,{projectId:selectedId}, function() {


})
.done(function(data, status, jqXHR) {
var response = data;
Expand All @@ -524,7 +526,7 @@ function() {
}, 0);
});

$(".set-tag").on("change", function (e) {
$(".set-tag").on("change", function (e) {
var myid = $(e.target).data('myid');
var selectedTag = $(e.target).val();
var jqxhr = $.post( "ajax/update-work-interval/"+myid,{tagId:selectedTag.join(",")}, function() {
Expand Down Expand Up @@ -553,6 +555,12 @@ function() {
});
}

function createWorkItem() {
$('#work-input').val($(this).data('work-name'));
startTimer($(this).data('projectid'), $(this).data('tagids'));
return false;
}

function startTimer(projectId = null, tags = ""){
if(localStorage.getItem('isTimerStarted') === 'true'){
stopTimer(startTimer, [projectId, tags]);
Expand All @@ -579,10 +587,10 @@ function() {
}).always(function() {
getWorkItems();
});

}
function stopTimer(onStopped = null, args = []){

var workName = $('#work-input').val();
if (workName == ''){
workName = 'no description';
Expand All @@ -608,15 +616,15 @@ function() {
alert( "error" );
})
.always(function() {

});
}



$( "#datepicker-from" ).datepicker();
$( "#datepicker-to" ).datepicker();

if(localStorage.getItem('isTimerStarted') === 'true'){
$('#start-tracking > span').addClass("stop-button").removeClass("play-button");
} else {
Expand All @@ -631,5 +639,5 @@ function() {
return false;
});
} );

}());
4 changes: 2 additions & 2 deletions templates/content/index.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="timetracker-content">
<div id="top-work-bar">
<div id="work-input-container">
<form>
<form id="work-input-form">
<input tabindex="1" type="text" spellcheck="false" autocomplete="off" class="" value="" placeholder="What have you done?" id="work-input">
</form>
</div>
Expand Down Expand Up @@ -66,4 +66,4 @@
<div class="clearfix"> </div>
<div id="work-intervals">
</div>
</div>
</div>