public
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/bsag/tracks.git
Click here to lend your support to: tracks and make a donation at www.pledgie.com !
clean up export controller a bit. also some cleanups in the view
lrbalt (author)
Fri Sep 05 08:53:18 -0700 2008
commit  3a56d2bdd2ad86718f263bc5d1263757d844bbaa
tree    033849ac220ac977a6105c787e2e6b41e0720aa8
parent  88159d3f6ad4b0d0aa4d6b69c94b75d645cd2ecc
...
3
4
5
6
 
7
8
9
...
35
36
37
38
39
 
 
40
41
42
 
 
43
44
45
46
47
48
49
50
51
52
 
 
 
 
 
 
 
 
 
53
54
55
...
59
60
61
62
63
64
 
 
 
 
65
66
67
 
 
68
69
70
71
 
 
 
72
73
74
...
104
105
106
107
108
109
110
...
153
154
155
156
157
158
159
160
161
 
 
 
 
 
 
162
163
164
165
166
167
 
168
169
170
...
182
183
184
185
186
 
 
187
188
189
...
198
199
200
201
202
203
204
 
 
205
...
3
4
5
 
6
7
8
9
...
35
36
37
 
 
38
39
40
 
 
41
42
43
 
 
 
 
 
 
 
 
 
44
45
46
47
48
49
50
51
52
53
54
55
...
59
60
61
 
 
 
62
63
64
65
66
 
 
67
68
69
 
 
 
70
71
72
73
74
75
...
105
106
107
 
108
109
110
...
153
154
155
 
 
 
 
 
 
156
157
158
159
160
161
162
163
164
165
166
 
167
168
169
170
...
182
183
184
 
 
185
186
187
188
189
...
198
199
200
 
201
 
 
202
203
204
0
@@ -3,7 +3,7 @@ class DataController < ApplicationController
0
   require 'csv'
0
   
0
   def index
0
-        @page_title = "TRACKS::Export"
0
+    @page_title = "TRACKS::Export"
0
   end
0
 
0
   def import
0
@@ -35,21 +35,21 @@ class DataController < ApplicationController
0
     content_type = 'text/csv'
0
     CSV::Writer.generate(result = "") do |csv|
0
       csv << ["id", "Context", "Project", "Description", "Notes", "Tags",
0
-              "Created at", "Due", "Completed at", "User ID", "Show from",
0
-              "state"]
0
+        "Created at", "Due", "Completed at", "User ID", "Show from",
0
+        "state"]
0
       current_user.todos.find(:all, :include => [:context, :project]).each do |todo|
0
-        # Format dates in ISO format for easy sorting in spreadsheet
0
-        # Print context and project names for easy viewing
0
+        # Format dates in ISO format for easy sorting in spreadsheet Print
0
+        # context and project names for easy viewing
0
         csv << [todo.id, todo.context.name, 
0
-                todo.project_id = todo.project_id.nil? ? "" : todo.project.name,
0
-                todo.description, 
0
-                todo.notes, todo.tags.collect{|t| t.name}.join(', '),
0
-                todo.created_at.to_formatted_s(:db),
0
-                todo.due = todo.due? ? todo.due.to_formatted_s(:db) : "",
0
-                todo.completed_at = todo.completed_at? ? todo.completed_at.to_formatted_s(:db) : "", 
0
-                todo.user_id, 
0
-                todo.show_from = todo.show_from? ? todo.show_from.to_formatted_s(:db) : "",
0
-                todo.state] 
0
+          todo.project_id = todo.project_id.nil? ? "" : todo.project.name,
0
+          todo.description, 
0
+          todo.notes, todo.tags.collect{|t| t.name}.join(', '),
0
+          todo.created_at.to_formatted_s(:db),
0
+          todo.due = todo.due? ? todo.due.to_formatted_s(:db) : "",
0
+          todo.completed_at = todo.completed_at? ? todo.completed_at.to_formatted_s(:db) : "", 
0
+          todo.user_id, 
0
+          todo.show_from = todo.show_from? ? todo.show_from.to_formatted_s(:db) : "",
0
+          todo.state] 
0
       end
0
     end
0
     send_data(result, :filename => "todos.csv", :type => content_type)
0
@@ -59,16 +59,17 @@ class DataController < ApplicationController
0
     content_type = 'text/csv'
0
     CSV::Writer.generate(result = "") do |csv|
0
       csv << ["id", "User ID", "Project", "Note",
0
-              "Created at", "Updated at"]
0
-      # had to remove project include because it's association order is leaking through
0
-      # and causing an ambiguous column ref even with_exclusive_scope didn't seem to help -JamesKebinger 
0
+        "Created at", "Updated at"]
0
+      # had to remove project include because it's association order is leaking
0
+      # through and causing an ambiguous column ref even with_exclusive_scope
0
+      # didn't seem to help -JamesKebinger
0
       current_user.notes.find(:all,:order=>"notes.created_at").each do |note|
0
-        # Format dates in ISO format for easy sorting in spreadsheet
0
-        # Print context and project names for easy viewing
0
+        # Format dates in ISO format for easy sorting in spreadsheet Print
0
+        # context and project names for easy viewing
0
         csv << [note.id, note.user_id, 
0
-                note.project_id = note.project_id.nil? ? "" : note.project.name,
0
-                note.body, note.created_at.to_formatted_s(:db),
0
-                note.updated_at.to_formatted_s(:db)] 
0
+          note.project_id = note.project_id.nil? ? "" : note.project.name,
0
+          note.body, note.created_at.to_formatted_s(:db),
0
+          note.updated_at.to_formatted_s(:db)] 
0
       end
0
     end
0
     send_data(result, :filename => "notes.csv", :type => content_type)
0
@@ -104,7 +105,6 @@ class DataController < ApplicationController
0
     @inarray = YAML::load(params['import']['yaml'])
0
     # arrays to handle id translations
0
 
0
-
0
     # contexts
0
     translate_context = Hash.new
0
     translate_context[nil] = nil
0
@@ -153,18 +153,18 @@ class DataController < ApplicationController
0
 
0
       # state + dates
0
       case item.ivars['attributes']['state']
0
-        when 'active' : newitem.activate!
0
-        when 'project_hidden' : newitem.hide!
0
-        when 'completed' 
0
-          newitem.complete!
0
-          newitem.completed_at = adjust_time(item.ivars['attributes']['completed_at'])
0
-        when 'deferred' : newitem.defer!
0
+      when 'active' then newitem.activate!
0
+      when 'project_hidden' then newitem.hide!
0
+      when 'completed' 
0
+        newitem.complete!
0
+        newitem.completed_at = adjust_time(item.ivars['attributes']['completed_at'])
0
+      when 'deferred' then newitem.defer!
0
       end
0
       newitem.created_at = adjust_time(item.ivars['attributes']['created_at'])
0
       newitem.save(false)
0
     }
0
 
0
-    #tags
0
+    # tags
0
     translate_tag = Hash.new
0
     translate_tag[nil] = nil
0
     current_user.tags.each { |item| item.destroy }
0
@@ -182,8 +182,8 @@ class DataController < ApplicationController
0
       newitem.user_id = current_user.id
0
       newitem.tag_id = translate_tag[newitem.tag_id]
0
       case newitem.taggable_type
0
-        when 'Todo' : newitem.taggable_id = translate_todo[newitem.taggable_id]
0
-        else newitem.taggable_id = 0
0
+      when 'Todo' then newitem.taggable_id = translate_todo[newitem.taggable_id]
0
+      else newitem.taggable_id = 0
0
       end
0
       newitem.save
0
     }
0
@@ -198,7 +198,6 @@ class DataController < ApplicationController
0
       newitem.created_at = adjust_time(item.ivars['attributes']['created_at'])
0
       newitem.save
0
     }
0
-
0
   end
0
0
-end
0
+  
0
+end
0
\ No newline at end of file
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
43
44
 
 
 
 
 
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
 
45
46
47
48
49
0
@@ -1,44 +1,49 @@
0
-<div id="feeds">
0
-  <div id="feedlegend">
0
-    <h3>Exporting data</h3>
0
-    <p>You can choose between the following formats:</p>
0
-    <ul>
0
-            <li><strong>YAML: </strong>Best for exporting data. <br/><i>Please note that  importing YAML files is currently supported only in experimentally. Do not rely on it for backing up critical data.</i></li>
0
-      <li><strong>CSV: </strong>Best for importing into spreadsheet or data analysis software</li>
0
-      <li><strong>XML: </strong>Best for importing or repurposing the data</li>
0
-          </ul>
0
-  </div>
0
-
0
-<p>
0
-<table class="export_table">
0
-<tr>
0
-  <th>Description</th>
0
-  <th>Download link</th>
0
-</tr>
0
-<tr>
0
-<td>YAML file containing all your actions, contexts, projects, tags and notes</td>
0
-<td><%= link_to "YAML file", :controller => 'data', :action => 'yaml_export' %></td>
0
-</tr>
0
-<tr>
0
-<td>CSV file containing all of your actions, with named contexts and projects</td>
0
-<td><%= link_to "CSV file (actions, contexts and projects)", :controller => 'data', :action => 'csv_actions' %></td>
0
-</tr>
0
-<tr>
0
-  <td>CSV file containing all your notes</td>
0
-  <td><%= link_to "CSV file (notes only)", :controller => 'data', :action => 'csv_notes' %></td>
0
-</tr>
0
-<tr>
0
-  <td>XML file containing all your actions, contexts, projects, tags and notes</td>
0
-  <td><%= link_to "XML file (actions only)", :controller => 'data', :action => 'xml_export' %></td>
0
-</tr>
0
-</table>
0
-</p>
0
-
0
-<div id="feeds">
0
-  <div id="feedlegend">
0
-   <h3>Importing data</h3>
0
-<p>Curently there is a experimental support for importing YAML files. Beware: all your current data will be destroyed before importing the YAML file, so if you have access to the database, we strongly reccoment backing up the database right now in case that anything goes wrong.</p>
0
-<p><%= link_to "Start import", :controller => 'data', :action => 'yaml_form' %>.</p>
0
+<div id="display_box">
0
+  <div id="feeds">
0
+    <div id="feedlegend">
0
+      <h3>Importing data</h3>
0
+      <p>Curently there is a experimental support for importing YAML files. 
0
+        Beware: all your current data will be destroyed before importing the YAML 
0
+        file, so if you have access to the database, we strongly recomment backing up 
0
+        the database right now in case that anything goes wrong.
0
+      </p>
0
+      <p><%= link_to "Start import", :controller => 'data', :action => 'yaml_form' %>.</p>
0
+      <br/><br/><h3>Exporting data</h3>
0
+      <p>You can choose between the following formats:</p>
0
+      <ul>
0
+        <li><strong>YAML: </strong>Best for exporting data. <br/><i>Please note that  importing YAML files is currently supported only in experimentally. Do not rely on it for backing up critical data.</i></li>
0
+        <li><strong>CSV: </strong>Best for importing into spreadsheet or data analysis software</li>
0
+        <li><strong>XML: </strong>Best for importing or repurposing the data</li>
0
+      </ul>
0
+    </div>
0
+    <br/><br/>
0
+    <table class="export_table">
0
+      <tr>
0
+        <th>Description</th>
0
+        <th>Download link</th>
0
+      </tr>
0
+      <tr>
0
+        <td>YAML file containing all your actions, contexts, projects, tags and notes</td>
0
+        <td><%= link_to "YAML file", :controller => 'data', :action => 'yaml_export' %></td>
0
+      </tr>
0
+      <tr>
0
+        <td>CSV file containing all of your actions, with named contexts and projects</td>
0
+        <td><%= link_to "CSV file (actions, contexts and projects)", :controller => 'data', :action => 'csv_actions' %></td>
0
+      </tr>
0
+      <tr>
0
+        <td>CSV file containing all your notes</td>
0
+        <td><%= link_to "CSV file (notes only)", :controller => 'data', :action => 'csv_notes' %></td>
0
+      </tr>
0
+      <tr>
0
+        <td>XML file containing all your actions, contexts, projects, tags and notes</td>
0
+        <td><%= link_to "XML file (actions only)", :controller => 'data', :action => 'xml_export' %></td>
0
+      </tr>
0
+    </table>  
0
+  </div><!-- End of feeds -->
0
 </div>
0
 
0
-</div><!-- End of feeds -->
0
+<script type="text/javascript">
0
+    window.onload=function(){
0
+        Nifty("div#feedlegend","normal");
0
+    }
0
+</script>
...
1
2
3
4
5
6
7
8
9
10
11
12
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
15
16
17
 
 
 
 
 
...
1
 
 
 
 
 
 
 
 
 
 
 
 
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
 
19
20
21
22
23
0
@@ -1,17 +1,23 @@
0
 <div id="display_box">
0
- <div id="feeds">
0
-  <div id="feedlegend">
0
-   <p><b>Beware</b>: all your current data will be destroyed before importing the YAML file, so if you have access to the database, we strongly reccoment backing up the database right now in case that anything goes wrong.</p>
0
-   <p>Paste the contents of the YAML file you exported into the text box below:</p>
0
-  </div>
0
-  <p>
0
-  <% form_for :import, @import, :url => {:controller => 'data', :action => 'yaml_import'} do |f| %>
0
-   <%= f.text_area :yaml %><br />
0
-   <input type="submit" value="Import data">
0
-  <% end %>
0
-  </p>
0
- </div><!-- End of feeds -->
0
+  <div id="feeds">
0
+    <div id="feedlegend">
0
+      <p><b>Beware</b>: all your current data will be destroyed before importing 
0
+        the YAML file, so if you have access to the database, we strongly recommend 
0
+        backing up the database right now in case that anything goes wrong.
0
+      </p>
0
+      <p>Paste the contents of the YAML file you exported into the text box below:</p>
0
+    </div>
0
+    <p>
0
+      <% form_for :import, @import, :url => {:controller => 'data', :action => 'yaml_import'} do |f| %>
0
+        <%= f.text_area :yaml %><br />
0
+        <input type="submit" value="Import data">
0
+      <% end %>
0
+    </p>
0
+  </div><!-- End of feeds -->
0
 </div><!-- End of display_box -->
0
 
0
-<div id="input_box">
0
-</div><!-- End of input box -->
0
+<script type="text/javascript">
0
+    window.onload=function(){
0
+        Nifty("div#feedlegend","normal");
0
+    }
0
+</script>

Comments