Skip to content

Commit e67bc4f

Browse files
committed
Increased work items name length to 256 characters, improved displaying of long work items names and client error reporing.
1 parent 48fefe6 commit e67bc4f

File tree

4 files changed

+70
-26
lines changed

4 files changed

+70
-26
lines changed

appinfo/database.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@
194194
<name>name</name>
195195
<type>text</type>
196196
<notnull>true</notnull>
197-
<length>64</length>
197+
<length>256</length>
198198
</field>
199199
<field>
200200
<name>project_id</name>

appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<name>Time Tracker</name>
66
<summary>Time Tracker App</summary>
77
<description><![CDATA[Time Tracker App]]></description>
8-
<version>0.0.35</version>
8+
<version>0.0.36</version>
99
<licence>agpl</licence>
1010
<author mail="[email protected]" >MTier Ltd.</author>
1111
<namespace>TimeTracker</namespace>

js/timer.js

Lines changed: 58 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
autoOpen: false,
5050
buttons :
5151
[ {
52-
id: 'confirm-button',
52+
id: 'confirm-button',
5353
text: "Confirm",
5454
click: function() {
5555
var baseUrl = OC.generateUrl('/apps/timetracker/ajax/add-work-interval/'+$('#name-manual-entry').val());
@@ -58,9 +58,12 @@
5858
getWorkItems();
5959
$("#dialog-manual-entry").dialog("close");
6060
})
61-
.done(function() {
62-
63-
})
61+
.done(function(data, status, jqXHR) {
62+
var response = data;
63+
if ('Error' in response){
64+
alert(response.Error);
65+
}
66+
})
6467
.fail(function() {
6568
alert( "error" );
6669
})
@@ -90,9 +93,12 @@
9093
getWorkItems();
9194
$(dialogWorkItemEditForm).dialog("close");
9295
})
93-
.done(function() {
94-
95-
})
96+
.done(function(data, status, jqXHR) {
97+
var response = data;
98+
if ('Error' in response){
99+
alert(response.Error);
100+
}
101+
})
96102
.fail(function() {
97103
alert( "error" );
98104
})
@@ -101,7 +107,12 @@
101107
});
102108

103109
}
104-
110+
function cutString(s, n){
111+
if (s.length < n) {
112+
return s;
113+
}
114+
return s.substring(0, n - 4) + ' ...';
115+
}
105116
function secondsToTimer(s){
106117
function pad(num, size) {
107118
var s = num+"";
@@ -184,7 +195,7 @@
184195

185196
$.each(workItem.children, function (ckey, child){
186197
//debugger;
187-
children.push("<div class='wi-child'><li><div class='wi-child-element'><div class='wi-child-name clickable' data-myid="+child.id+" data-name='"+child.name+"'>"+child.name+"</div>"+
198+
children.push("<div class='wi-child'><li><div class='wi-child-element'><div class='wi-child-name clickable' data-myid="+child.id+" data-name='"+child.name+"'>"+cutString(child.name,64)+"</div>"+
188199
"<span class='fas clickable fa-trash wi-trash' id="+child.id+"></span><span class='set-project' data-myid="+child.id+" data-projectid="+child.projectId+" data-projectname='"+child.projectName+"'></span>"+
189200
"<span class='set-tag' data-myid="+child.id+" data-tagids='"+child.tags.map(function(tag) {return tag.id}).join(',')+"' data-tagnames='"+child.tags.map(function(tag) {return tag.name}).join(',')+"'></span>"+
190201
"<div class='wi-child-hours' data-myid="+child.id+" data-start-date='"+child.start+"' data-end-date='"+(child.start+child.duration)+"'>"+tsToHour(child.start)+"&nbsp;-&nbsp;"+
@@ -198,7 +209,7 @@
198209
dayItems.push("<div class='work-item'>"+"<ul><li class=''><div class='work-item-element'>"+
199210
((children.length == 1)?"<div class='wi-len-empty'>&nbsp;</div>":"<div class='wi-len'>"+children.length+"</div>")+
200211
"<div class='wi-name'>"+
201-
dayItemName+"</div><div class='wi-duration'>"+secondsToTimer(workItem.totalTime)+
212+
cutString(dayItemName,128)+"</div><div class='wi-duration'>"+secondsToTimer(workItem.totalTime)+
202213
"</div>"+
203214
"</div></li>"+children.join("")+"</ul>"+"</div>");
204215
});
@@ -227,9 +238,13 @@
227238
var id = $(this).data('myid');
228239
var jqxhr = $.post( "ajax/update-work-interval/"+id,{start:picker.startDate.format('DD/MM/YY HH:mm'), end:picker.endDate.format('DD/MM/YY HH:mm'), tzoffset: new Date().getTimezoneOffset()}, function() {
229240
})
230-
.done(function() {
231-
getWorkItems();
232-
})
241+
.done(function(data, status, jqXHR) {
242+
var response = data;
243+
if ('Error' in response){
244+
alert(response.Error);
245+
}
246+
getWorkItems();
247+
})
233248
.fail(function() {
234249
alert( "error" );
235250
})
@@ -262,8 +277,11 @@
262277
getWorkItems();
263278
$("#dialog-confirm").dialog("close");
264279
})
265-
.done(function() {
266-
280+
.done(function(data, status, jqXHR) {
281+
var response = data;
282+
if ('Error' in response){
283+
alert(response.Error);
284+
}
267285
})
268286
.fail(function() {
269287
alert( "error" );
@@ -383,9 +401,13 @@
383401

384402

385403
})
386-
.done(function() {
404+
.done(function(data, status, jqXHR) {
405+
var response = data;
406+
if ('Error' in response){
407+
alert(response.Error);
408+
}
387409
getWorkItems();
388-
})
410+
})
389411
.fail(function() {
390412
alert( "error" );
391413
})
@@ -398,7 +420,11 @@
398420
var selectedTag = $(e.target).val();
399421
var jqxhr = $.post( "ajax/update-work-interval/"+myid,{tagId:selectedTag}, function() {
400422
})
401-
.done(function() {
423+
.done(function(data, status, jqXHR) {
424+
var response = data;
425+
if ('Error' in response){
426+
alert(response.Error);
427+
}
402428
getWorkItems();
403429
})
404430
.fail(function() {
@@ -426,11 +452,15 @@
426452
$('#start-tracking > span').addClass("stop-button").removeClass("play-button");
427453
getWorkItems();
428454
})
429-
.done(function() {
430-
})
431-
.fail(function() {
455+
.done(function(data, status, jqXHR) {
456+
var response = data;
457+
if ('Error' in response){
458+
alert(response.Error);
459+
}
460+
})
461+
.fail(function() {
432462
alert( "error" );
433-
})
463+
});
434464

435465
}
436466
function stopTimer(){
@@ -444,8 +474,12 @@
444474
$('#start-tracking > span').addClass("play-button").removeClass("stop-button");
445475
getWorkItems();
446476
})
447-
.done(function() {
448-
})
477+
.done(function(data, status, jqXHR) {
478+
var response = data;
479+
if ('Error' in response){
480+
alert(response.Error);
481+
}
482+
})
449483
.fail(function() {
450484
alert( "error" );
451485
})

lib/Controller/AjaxController.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ public function index() {
145145

146146
public function startTimer($name) {
147147
//$this->endTimer();
148+
if (strlen($name) > 255){
149+
return new JSONResponse(["Error" => "Name too long"]);
150+
}
148151
$winterval = new WorkInterval();
149152
$winterval->setStart(time());
150153
$winterval->setRunning(1);
@@ -184,6 +187,10 @@ public function startTimer($name) {
184187
*/
185188

186189
public function stopTimer($name) {
190+
if (strlen($name) > 255){
191+
return new JSONResponse(["Error" => "Name too long"]);
192+
}
193+
187194
$running = $this->workIntervalMapper->findAllRunning($this->userId);
188195

189196
$now = time();
@@ -219,6 +226,9 @@ public function updateWorkInterval($id) {
219226
$wi = $this->workIntervalMapper->find($id);
220227

221228
if (isset($this->request->name)) {
229+
if (strlen($this->request->name) > 255){
230+
return new JSONResponse(["Error" => "Name too long"]);
231+
}
222232
$wi->setName($this->request->name);
223233
}
224234
if (isset($this->request->projectId)) {

0 commit comments

Comments
 (0)