public
Fork of bsag/tracks
Description: Tracks is a GTD(TM) web application, built with Ruby on Rails
Homepage: http://www.rousette.org.uk/projects/
Clone URL: git://github.com/awgy/tracks.git
Make todos sortable.
awgy (author)
Mon Aug 18 22:22:13 -0700 2008
commit  2bc4a1e8e81ccfeb646bfe9afff3daaf95c7f80b
tree    39c2b559d645e1c32340c1581065bdea6d7f31de
parent  666f524b16c847cf8b3d241636e57087097306dc
...
199
200
201
202
 
203
204
205
...
199
200
201
 
202
203
204
205
0
@@ -199,7 +199,7 @@ class ContextsController < ApplicationController
0
       @not_done_todos = @context.todos.find(
0
         :all,
0
         :conditions => ['todos.state = ? AND (todos.project_id IS ? OR projects.state = ?)', 'active', nil, 'active'],
0
- :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC",
0
+ :order => "todos.position, todos.due IS NULL, todos.due ASC, todos.created_at ASC",
0
         :include => [:project, :tags])
0
       @count = @not_done_todos.size
0
       @default_project_context_name_map = build_default_project_context_name_map(@projects).to_json
...
377
378
379
 
 
 
 
 
 
 
 
 
 
 
380
381
382
...
490
491
492
493
 
494
495
496
...
507
508
509
510
 
511
512
513
...
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
...
501
502
503
 
504
505
506
507
...
518
519
520
 
521
522
523
524
0
@@ -377,6 +377,17 @@ class TodosController < ApplicationController
0
     end
0
   end
0
   
0
+ def order
0
+ params.map do |k,v|
0
+ if k =~ /items/
0
+ v.each_with_index do |id, position|
0
+ current_user.todos.update(id, :position => position + 1)
0
+ end
0
+ end
0
+ end
0
+ render :nothing => true
0
+ end
0
+
0
   private
0
   
0
   def get_todo_from_params
0
@@ -490,7 +501,7 @@ class TodosController < ApplicationController
0
             @not_done_todos = Todo.find(:all,
0
               :conditions => ['todos.user_id = ? AND contexts.hide = ? AND (projects.state = ? OR todos.project_id IS NULL)',
0
                 current_user.id, false, 'active'],
0
- :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC",
0
+ :order => "todos.position, todos.due IS NULL, todos.due ASC, todos.created_at ASC",
0
               :include => [ :project, :context, :tags ])
0
           end
0
 
0
@@ -507,7 +518,7 @@ class TodosController < ApplicationController
0
     @not_done_todos = Todo.find(:all,
0
       :conditions => ['todos.user_id = ? AND todos.state = ? AND contexts.hide = ? AND (projects.state = ? OR todos.project_id IS NULL)',
0
         current_user.id, 'active', false, 'active'],
0
- :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC",
0
+ :order => "todo.position, todos.due IS NULL, todos.due ASC, todos.created_at ASC",
0
       :include => [ :project, :context, :tags ])
0
   end
0
     
...
61
62
63
64
 
65
66
67
...
61
62
63
 
64
65
66
67
0
@@ -61,7 +61,7 @@ class User < ActiveRecord::Base
0
            :order => 'position ASC',
0
            :conditions => [ 'hide = ?', 'true' ]
0
   has_many :todos,
0
- :order => 'todos.completed_at DESC, todos.created_at DESC',
0
+ :order => 'todos.position, todos.due IS NULL, todos.due, todos.created_at',
0
            :dependent => :delete_all
0
   has_many :recurring_todos,
0
            :order => 'recurring_todos.completed_at DESC, recurring_todos.created_at DESC',
...
46
47
48
 
 
 
 
 
 
 
 
49
...
46
47
48
49
50
51
52
53
54
55
56
57
0
@@ -46,4 +46,12 @@
0
     end
0
     -%>
0
   </div><!-- [end:items] -->
0
+ <%
0
+ sortable_element "c#{context.id}items",
0
+ :tag => 'div',
0
+ :handle => 'handle',
0
+ :only => 'item-container',
0
+ :complete => visual_effect(:highlight, "c#{context.id}items"),
0
+ :url => order_todos_path(:context_id => context.id)
0
+ -%>
0
 </div><!-- [end:c<%= context.id %>] -->
...
33
34
35
 
 
 
 
 
 
 
 
36
...
33
34
35
36
37
38
39
40
41
42
43
44
0
@@ -33,4 +33,12 @@
0
     end
0
     -%>
0
   </div><!-- [end:items] -->
0
+ <%
0
+ sortable_element "p#{project.id}items",
0
+ :tag => 'div',
0
+ :handle => 'handle',
0
+ :only => 'item-container',
0
+ :complete => visual_effect(:highlight, "p#{project.id}items"),
0
+ :url => order_todos_path
0
+ -%>
0
 </div><!-- [end:p<%= project.id %>] -->
...
5
6
7
 
 
 
8
9
10
...
5
6
7
8
9
10
11
12
13
0
@@ -5,6 +5,9 @@
0
   suppress_edit_button ||= false
0
 %>
0
 <div id="<%= dom_id(todo) %>" class="item-container">
0
+ <div class="position">
0
+ <span class="handle">DRAG</span>
0
+ </div>
0
   <div id="<%= dom_id(todo, 'line') %>">
0
     <%= remote_delete_icon %>
0
     <%= remote_edit_icon unless suppress_edit_button %>
...
30
31
32
33
 
34
35
36
...
30
31
32
 
33
34
35
36
0
@@ -30,7 +30,7 @@ ActionController::Routing::Routes.draw do |map|
0
 
0
   map.resources :todos,
0
                 :member => {:toggle_check => :put, :toggle_star => :put},
0
- :collection => {:check_deferred => :post, :filter_to_context => :post, :filter_to_project => :post}
0
+ :collection => {:check_deferred => :post, :filter_to_context => :post, :filter_to_project => :post, :order => :post}
0
   map.with_options :controller => "todos" do |todos|
0
     todos.home '', :action => "index"
0
     todos.tickler 'tickler', :action => "list_deferred"
...
15
16
17
18
 
19
20
21
...
15
16
17
 
18
19
20
21
0
@@ -15,7 +15,7 @@ module Tracks
0
 
0
     def find_not_done_todos(opts={})
0
       with_not_done_scope(opts) do
0
- self.todos.find(:all, :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC")
0
+ self.todos.find(:all, :order => "todos.position, todos.due IS NULL, todos.due ASC, todos.created_at ASC")
0
       end
0
     end
0
     
...
347
348
349
350
351
352
 
 
 
 
 
353
354
355
...
347
348
349
 
 
 
350
351
352
353
354
355
356
357
0
@@ -347,9 +347,11 @@ div#input_box {
0
 }
0
 
0
 div.item-container {
0
- padding: 2px 0px;
0
- line-height:20px;
0
- clear: both;
0
+ background: #fff;
0
+ _background: transparent; /* the underscore is only used by ie6 and below */
0
+ padding: 4px 4px 4px 8px;
0
+ margin: 2px 2px;
0
+ border: 1px solid #ccc;
0
 }
0
 
0
 a.recurring_icon {

Comments

    No one has commented yet.