Skip to content

Commit f96a234

Browse files
committed
added timelines to email feature. fix #31
1 parent 6bd1e5a commit f96a234

File tree

5 files changed

+175
-30
lines changed

5 files changed

+175
-30
lines changed

appinfo/routes.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
['name' => 'dashboard#index', 'url' => '/dashboard', 'verb' => 'GET'],
1919
['name' => 'reports#index', 'url' => '/reports', 'verb' => 'GET'],
2020
['name' => 'timelines#index', 'url' => '/timelines', 'verb' => 'GET'],
21+
2122
['name' => 'timelinesAdmin#index', 'url' => '/timelines-admin', 'verb' => 'GET'],
2223

2324
['name' => 'tags#index', 'url' => '/tags', 'verb' => 'GET'],
@@ -55,5 +56,6 @@
5556
['name' => 'ajax#download_timeline', 'url' => '/ajax/download-timeline/{id}', 'verb' => 'GET'],
5657
['name' => 'ajax#edit_timeline', 'url' => '/ajax/edit-timeline/{id}', 'verb' => 'POST'],
5758
['name' => 'ajax#delete_timeline', 'url' => '/ajax/delete-timeline/{id}', 'verb' => 'POST'],
59+
['name' => 'ajax#email_timeline', 'url' => '/ajax/email-timeline/{id}', 'verb' => 'POST'],
5860
]
5961
];

js/src/clients.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11

22
var $ = require("jquery");
33
require("jquery-migrate");
4-
54
// var moment = require("moment");
65
require("jqueryui");
76
require("jqueryui/jquery-ui.css");

js/src/timelines.js

Lines changed: 93 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,23 @@ require('select2/dist/css/select2.css');
220220
});
221221
return false;
222222
});
223+
$("#timeline-csv-email").off().click(function(){
224+
var baseUrl = OC.generateUrl('/apps/timetracker/ajax/email-timeline');
225+
$.post(baseUrl, // url
226+
{
227+
from: start.unix(),
228+
to: end.unix(),
229+
group1: group1,
230+
group2: group2,
231+
timegroup: group3,
232+
filterProjectId: filterProjectId,
233+
filterClientId: filterClientId
234+
}, // data to be submit
235+
function(data, status, jqXHR) {// success callback
236+
getTimelines();
237+
});
238+
return false;
239+
});
223240

224241
}
225242

@@ -277,38 +294,87 @@ require('select2/dist/css/select2.css');
277294
return '<a href="'+baseUrl+'">'+"Download"+'</a>';
278295

279296
}},
297+
{title:"Email", field:"", formatter:"rownum",formatter:function(cell, formatterParams, onRendered){
298+
//cell - the cell component
299+
//formatterParams - parameters set for the column
300+
//onRendered - function to call when the formatter has been rendered
301+
302+
303+
return '<a href=# data-id="'+cell.getRow().getData()["id"]+'">Email</a>';
304+
305+
},cellClick:function(e, cell){
306+
$("#dialog-send-email-form").dialog({
307+
buttons : {
308+
"Confirm" : {
309+
click: function() {
310+
var baseUrl = OC.generateUrl('/apps/timetracker/ajax/email-timeline/'+cell.getRow().getData().id);
311+
312+
var jqxhr = $.post( baseUrl, {
313+
email:$('#email-address').val(),
314+
subject:$('#email-subject').val(),
315+
content:$('#email-content').val(),
316+
}, function() {
317+
$("#dialog-send-email-form").dialog("close");
318+
debugger;
319+
})
320+
.done(function(data, status, jqXHR) {
321+
var response = data;
322+
if ('Error' in response){
323+
alert(response.Error);
324+
}
325+
})
326+
.fail(function() {
327+
alert( "error" );
328+
})
329+
return false;
330+
},
331+
text: 'Confirm',
332+
class:'primary'
333+
},
334+
"Cancel" : function() {
335+
$(this).dialog("close");
336+
}
337+
}
338+
});
339+
$("#dialog-send-email-form").dialog('open');
340+
341+
//cell.getRow().delete();
342+
}
343+
},
280344
{formatter:"buttonCross", width:40, align:"center", cellClick:function(e, cell){
281-
$("#dialog-confirm").dialog({
282-
buttons : {
283-
"Confirm" : {click: function() {
284-
var baseUrl = OC.generateUrl('/apps/timetracker/ajax/delete-timeline/'+cell.getRow().getData().id);
285-
var jqxhr = $.post( baseUrl, function() {
345+
$("#dialog-confirm").dialog({
346+
buttons : {
347+
"Confirm" : {
348+
click: function() {
349+
var baseUrl = OC.generateUrl('/apps/timetracker/ajax/delete-timeline/'+cell.getRow().getData().id);
350+
var jqxhr = $.post( baseUrl, function() {
286351
getTimelines();
287352
$("#dialog-confirm").dialog("close");
288-
})
289-
.done(function(data, status, jqXHR) {
290-
var response = data;
291-
if ('Error' in response){
292-
alert(response.Error);
293-
}
294-
})
295-
.fail(function() {
296-
alert( "error" );
297-
})
298-
return false;
299-
},
300-
text: 'Confirm',
301-
class:'primary'
302-
},
303-
"Cancel" : function() {
304-
$(this).dialog("close");
305-
}
306-
}
307-
});
308-
$("#dialog-confirm").dialog('open');
353+
})
354+
.done(function(data, status, jqXHR) {
355+
var response = data;
356+
if ('Error' in response){
357+
alert(response.Error);
358+
}
359+
})
360+
.fail(function() {
361+
alert( "error" );
362+
})
363+
return false;
364+
},
365+
text: 'Confirm',
366+
class:'primary'
367+
},
368+
"Cancel" : function() {
369+
$(this).dialog("close");
370+
}
371+
}
372+
});
373+
$("#dialog-confirm").dialog('open');
309374

310375
//cell.getRow().delete();
311-
}},
376+
}
377+
},
312378

313379
],
314380
ajaxResponse:function(url, params, response){

lib/Controller/AjaxController.php

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,14 +976,15 @@ public function secondsToTime($seconds){
976976
$timeFormat = sprintf('%02d:%02d:%02d', $hours, $mins, $secs);
977977
return $timeFormat;
978978
}
979+
979980
/**
980981
*
981982
* @NoAdminRequired
982983
* @NoCSRFRequired
983984
*/
984985
public function downloadTimeline($id){
985986
$te = $this->timelineEntryMapper->findTimelineEntries($id);
986-
if (count($te) == 0){
987+
if (count($te) == 0){ // nothing to send
987988
exit(0);
988989
}
989990

@@ -1036,5 +1037,60 @@ public function deleteTimeline($id) {
10361037
return new JSONResponse(["Timeline" => $timeline]);
10371038
}
10381039

1040+
/**
1041+
*
1042+
* @NoAdminRequired
1043+
*/
1044+
1045+
public function emailTimeline($id) {
1046+
1047+
$te = $this->timelineEntryMapper->findTimelineEntries($id);
1048+
if (count($te) == 0){ // nothing to send
1049+
exit(0);
1050+
}
1051+
$user = $te[0]->userUid;
1052+
1053+
$email = $this->request->email;
1054+
$emails = explode(';',$email);
1055+
$subject = $this->request->subject;
1056+
$content = $this->request->content;
1057+
1058+
// output headers so that the file is downloaded rather than displayed
1059+
header('Content-Type: text/csv; charset=utf-8');
1060+
header('Content-Disposition: attachment; filename=timeline-'.$user.'-'.$id.'.csv');
1061+
1062+
// create a file pointer connected to the output stream
1063+
$id = (int)$id;
1064+
$path = sys_get_temp_dir() . DIRECTORY_SEPARATOR. 'timeline-'.$user.'-'.$id.'.csv';
1065+
$output = fopen($path, "w");
1066+
//$path = stream_get_meta_data($output)['uri'];
1067+
// output the column headings
1068+
fputcsv($output, array('id', 'User Uid', 'Name', 'Project Name', 'Client Name', 'Time Interval', 'Total Duration'));
1069+
$totalDuration = 0;
1070+
foreach($te as $t){
1071+
1072+
fputcsv($output, [$t->id, $t->userUid, $t->name, $t->projectName, $t->clientName, $t->timeInterval, $this->secondsToTime($t->totalDuration)]);
1073+
$totalDuration += $t->totalDuration;
1074+
}
1075+
fputcsv($output, ['TOTAL', '', '', '', '', '', $this->secondsToTime($totalDuration)]);
1076+
1077+
1078+
1079+
$mailer = \OC::$server->getMailer();
1080+
$message = $mailer->createMessage();
1081+
$attach = $mailer->createAttachmentFromPath($path);
1082+
$message->setSubject($subject);
1083+
//$message->setTo([$email => 'Recipient']);
1084+
$message->setTo($emails);
1085+
$message->setPlainBody($content);
1086+
//$message->setHtmlBody($content);
1087+
$message->attach($attach);
1088+
$mailer->send($message);
1089+
1090+
fclose($output);
1091+
unlink($path);
1092+
return new JSONResponse([]);
1093+
}
1094+
10391095

10401096
}

templates/content/timelines.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
<div id="timetracker-projects" class='theme-white'>
32
<h1 class='page-title'>Timelines</h1>
43

@@ -13,6 +12,29 @@
1312
<label for="name">Name</label>
1413
<input type="text" name="name" id="name" value="" class="text ui-widget-content ui-corner-all">
1514
15+
<!-- Allow form submission with keyboard without duplicating the dialog button -->
16+
<input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
17+
</fieldset>
18+
</form>
19+
</div>
20+
<div id="dialog-send-email-form" title="Send timeline to email" class='hidden'>
21+
<p class="validateTips">All form fields are required. Please make sure that your email settings are correct in your Nextcloud configuration.</p>
22+
<br/>
23+
<form>
24+
<fieldset>
25+
<label for="email">Destination Email addresses (; separated):</label>
26+
<div class="clearfix"> </div>
27+
<input type="text" name="email" id="email-address" value="" class="text ui-widget-content ui-corner-all" style="width:250px;">
28+
<div class="clearfix"> </div>
29+
<label for="subject">Subject:</label>
30+
<div class="clearfix"> </div>
31+
<input type="text" name="subject" id="email-subject" value="" placehoder="Subject line" style="width:250px;" class="text ui-widget-content ui-corner-all">
32+
<div class="clearfix"> </div>
33+
<label for="content">Email Content:</label>
34+
<div class="clearfix"> </div>
35+
<textarea id="email-content" name="content" rows="4" cols="50" class="text ui-widget-content ui-corner-all" style="width:250px;"></textarea>
36+
37+
1638
<!-- Allow form submission with keyboard without duplicating the dialog button -->
1739
<input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
1840
</fieldset>

0 commit comments

Comments
 (0)