Permalink
Browse files

Allow the editing of entry start and end times

  • Loading branch information...
David Powell
David Powell committed Oct 21, 2011
1 parent 4574050 commit 964e16475170f4c2dc2a2842a7e9776c740db2be
Showing with 65 additions and 24 deletions.
  1. +10 −2 dashboard.rb
  2. +22 −0 lib/slim_dash.rb
  3. +6 −1 models/time_entry_local.rb
  4. +25 −19 public/javascripts/slim.js
  5. +2 −2 views/slim.haml
View
@@ -215,9 +215,17 @@ def height_for(val, max)
SlimDash.today_entries(username)
end
-post "/slim/activity/comment" do
+post "/slim/activity/edit" do
require_login!
- SlimDash.set_comment(params["entry_id"], params["value"])
+ if params['comment_id']
+ SlimDash.set_comment(params["comment_id"], params["value"])
+ end
+ if params['start_id']
+ SlimDash.set_time(params["start_id"], params["value"], true)
+ end
+ if params['end_id']
+ SlimDash.set_time(params["end_id"], params["value"], false)
+ end
SlimDash.today_entries(request.env['REMOTE_USER'])
end
View
@@ -76,12 +76,34 @@ def entry_start(task_id, user_email)
:in_progress => true).save
end
+ # Allow the setting of a comment on an entry
def set_comment(entry_id, comment)
entry = TimeEntryLocal.get(entry_id)
entry.comments = comment
entry.save
end
+ # Allow the setting of the start/end time on an entry
+ def set_time(entry_id, value, start)
+ entry = TimeEntryLocal.get(entry_id)
+ v = Time.parse(value, entry.start_time)
+ return if v.to_date != entry.start_time.to_date # Only allow setting of time, not changing the day
+ if start
+ entry.start_time = v
+ else
+ entry.end_time = v
+ entry.in_progress = false
+ end
+
+ # Ensure it starts *before* it ends
+ if entry.end_time && entry.start_time > entry.end_time
+ entry.end_time = entry.start_time + 1
+ end
+
+ entry.update_duration
+ entry.save
+ end
+
def autocomplete(term)
max_autocomplete = 50
@@ -51,10 +51,15 @@ def self.update_or_create(slimtimer_entry)
end
end
+ def update_duration
+ return if in_progress
+ self.duration_in_seconds = self.end_time - self.start_time
+ end
+
def stop(time)
self.end_time = time
- self.duration_in_seconds = self.end_time - self.start_time
self.in_progress = false
+ update_duration
self.save
end
View
@@ -8,36 +8,34 @@ $(function() {
this.list = [];
this.total_work_time = 0;
- this.add = function(item) {
+ var add = function(item) {
self.list.push(parse_item(item));
- redraw();
}
this.set = function(list) {
self.list = []
- $.each(list, function(idx, item) { self.add(item); });
+ $.each(list, function(idx, item) { add(item); });
redraw();
}
- parse_item = function(item) {
+ var parse_item = function(item) {
item.start = new Date(item.start);
item.end = item.end ? new Date(item.end) : null;
item.active = item.end==null;
return item;
}
- format_entry = function(e) {
+ var format_entry = function(e) {
var li = $('li.task-item.template').clone();
li.removeClass('template');
if (!e.synced) {
$('.synced',li).text("*").attr('title', 'This entry is not synced with slimtimer');
}
- $('.start-time',li).text(e.start.toLocaleTimeString());
- $('.end-time',li).text(e.end ? e.end.toLocaleTimeString() : '');
+ $('.start-time',li).attr('id', e.id).text(e.start.toLocaleTimeString());
+ $('.end-time',li).attr('id', e.id).text(e.end ? e.end.toLocaleTimeString() : '');
$('.duration',li).text(e.duration ? fmt_duration(e.duration) : '');
$('.task-name',li).text(e.task_name + (e.story_name ? (" : " + e.story_name) : ""));
- $('.comments',li).text(e.comments ? e.comments : "");
- $('.comments',li).attr('id', e.id);
+ $('.comments',li).attr('id', e.id).text(e.comments ? e.comments : "");
if (e.story_name) {
$('.total-time',li).text(e.total_time ? fmt_duration_no_secs(e.total_time) : '');
if (e.estimate)
@@ -57,7 +55,7 @@ $(function() {
return li;
}
- redraw = function() {
+ var redraw = function() {
$(self.elem).empty();
this.total_work_time = 0
for(i=0; i<self.list.length; i++) {
@@ -68,20 +66,28 @@ $(function() {
}
}
- /* Enable editing */
- $('.comments.edit').editable('/slim/activity/comment', {
+ enable_editing();
+ };
+
+ var enable_editing = function() {
+ edit_field(".comments.edit", 'comment_id', '<div class="placeholder">Click to enter a comment...</div>');
+ edit_field(".start-time.edit", 'start_id', '');
+ edit_field(".end-time.edit", 'end_id', '');
+ }
+
+ var edit_field = function(sel, param_id, placeholder) {
+ $(sel).editable('/slim/activity/edit', {
tooltip : 'Click to edit...',
- placeholder: '<div class="placeholder">Click to enter a comment...</div>',
- id : 'entry_id',
+ placeholder: placeholder,
+ id : param_id,
indicator : '<img src="images/busy.gif">',
ajaxoptions: {
success: function(data) { self.slimcomplete.handle_success(data); }
}
});
-
}
- fmt_duration = function(d) {
+ var fmt_duration = function(d) {
var h = Math.floor(d/3600);
var m = Math.floor((d%3600)/60);
var s = Math.floor(d%60);
@@ -92,13 +98,13 @@ $(function() {
}
}
- fmt_duration_no_secs = function(d) {
+ var fmt_duration_no_secs = function(d) {
var h = Math.floor(d/3600);
var m = Math.floor((d%3600)/60);
return h+":"+(m<10?"0":"")+m;
}
- update_active_time = function () {
+ var update_active_time = function () {
var last = self.list[self.list.length-1];
var last_duration = 0;
if (last && last.active) {
@@ -113,7 +119,7 @@ $(function() {
set_timer();
}
- set_timer = function() {
+ var set_timer = function() {
setTimeout(update_active_time, 200);
}
set_timer();
View
@@ -48,10 +48,10 @@
Estimate
.estimate
0
- .start-time
+ .start-time.edit
0
\-
- .end-time
+ .end-time.edit
0
.duration
0

0 comments on commit 964e164

Please sign in to comment.