diff --git a/app/controllers/data_controller.rb b/app/controllers/data_controller.rb index 884c1496..ba997607 100644 --- a/app/controllers/data_controller.rb +++ b/app/controllers/data_controller.rb @@ -3,7 +3,7 @@ class DataController < ApplicationController require 'csv' def index - @page_title = "TRACKS::Export" + @page_title = "TRACKS::Export" end def import @@ -35,21 +35,21 @@ class DataController < ApplicationController content_type = 'text/csv' CSV::Writer.generate(result = "") do |csv| csv << ["id", "Context", "Project", "Description", "Notes", "Tags", - "Created at", "Due", "Completed at", "User ID", "Show from", - "state"] + "Created at", "Due", "Completed at", "User ID", "Show from", + "state"] current_user.todos.find(:all, :include => [:context, :project]).each do |todo| - # Format dates in ISO format for easy sorting in spreadsheet - # Print context and project names for easy viewing + # Format dates in ISO format for easy sorting in spreadsheet Print + # context and project names for easy viewing csv << [todo.id, todo.context.name, - todo.project_id = todo.project_id.nil? ? "" : todo.project.name, - todo.description, - todo.notes, todo.tags.collect{|t| t.name}.join(', '), - todo.created_at.to_formatted_s(:db), - todo.due = todo.due? ? todo.due.to_formatted_s(:db) : "", - todo.completed_at = todo.completed_at? ? todo.completed_at.to_formatted_s(:db) : "", - todo.user_id, - todo.show_from = todo.show_from? ? todo.show_from.to_formatted_s(:db) : "", - todo.state] + todo.project_id = todo.project_id.nil? ? "" : todo.project.name, + todo.description, + todo.notes, todo.tags.collect{|t| t.name}.join(', '), + todo.created_at.to_formatted_s(:db), + todo.due = todo.due? ? todo.due.to_formatted_s(:db) : "", + todo.completed_at = todo.completed_at? ? todo.completed_at.to_formatted_s(:db) : "", + todo.user_id, + todo.show_from = todo.show_from? ? todo.show_from.to_formatted_s(:db) : "", + todo.state] end end send_data(result, :filename => "todos.csv", :type => content_type) @@ -59,16 +59,17 @@ class DataController < ApplicationController content_type = 'text/csv' CSV::Writer.generate(result = "") do |csv| csv << ["id", "User ID", "Project", "Note", - "Created at", "Updated at"] - # had to remove project include because it's association order is leaking through - # and causing an ambiguous column ref even with_exclusive_scope didn't seem to help -JamesKebinger + "Created at", "Updated at"] + # had to remove project include because it's association order is leaking + # through and causing an ambiguous column ref even with_exclusive_scope + # didn't seem to help -JamesKebinger current_user.notes.find(:all,:order=>"notes.created_at").each do |note| - # Format dates in ISO format for easy sorting in spreadsheet - # Print context and project names for easy viewing + # Format dates in ISO format for easy sorting in spreadsheet Print + # context and project names for easy viewing csv << [note.id, note.user_id, - note.project_id = note.project_id.nil? ? "" : note.project.name, - note.body, note.created_at.to_formatted_s(:db), - note.updated_at.to_formatted_s(:db)] + note.project_id = note.project_id.nil? ? "" : note.project.name, + note.body, note.created_at.to_formatted_s(:db), + note.updated_at.to_formatted_s(:db)] end end send_data(result, :filename => "notes.csv", :type => content_type) @@ -104,7 +105,6 @@ class DataController < ApplicationController @inarray = YAML::load(params['import']['yaml']) # arrays to handle id translations - # contexts translate_context = Hash.new translate_context[nil] = nil @@ -153,18 +153,18 @@ class DataController < ApplicationController # state + dates case item.ivars['attributes']['state'] - when 'active' : newitem.activate! - when 'project_hidden' : newitem.hide! - when 'completed' - newitem.complete! - newitem.completed_at = adjust_time(item.ivars['attributes']['completed_at']) - when 'deferred' : newitem.defer! + when 'active' then newitem.activate! + when 'project_hidden' then newitem.hide! + when 'completed' + newitem.complete! + newitem.completed_at = adjust_time(item.ivars['attributes']['completed_at']) + when 'deferred' then newitem.defer! end newitem.created_at = adjust_time(item.ivars['attributes']['created_at']) newitem.save(false) } - #tags + # tags translate_tag = Hash.new translate_tag[nil] = nil current_user.tags.each { |item| item.destroy } @@ -182,8 +182,8 @@ class DataController < ApplicationController newitem.user_id = current_user.id newitem.tag_id = translate_tag[newitem.tag_id] case newitem.taggable_type - when 'Todo' : newitem.taggable_id = translate_todo[newitem.taggable_id] - else newitem.taggable_id = 0 + when 'Todo' then newitem.taggable_id = translate_todo[newitem.taggable_id] + else newitem.taggable_id = 0 end newitem.save } @@ -198,7 +198,6 @@ class DataController < ApplicationController newitem.created_at = adjust_time(item.ivars['attributes']['created_at']) newitem.save } - end - -end + +end \ No newline at end of file diff --git a/app/views/data/index.html.erb b/app/views/data/index.html.erb index 8f7aec2c..5ed8adaf 100644 --- a/app/views/data/index.html.erb +++ b/app/views/data/index.html.erb @@ -1,44 +1,49 @@ -
-
-

Exporting data

-

You can choose between the following formats:

- -
- -

- - - - - - - - - - - - - - - - - - - - - -
DescriptionDownload link
YAML file containing all your actions, contexts, projects, tags and notes<%= link_to "YAML file", :controller => 'data', :action => 'yaml_export' %>
CSV file containing all of your actions, with named contexts and projects<%= link_to "CSV file (actions, contexts and projects)", :controller => 'data', :action => 'csv_actions' %>
CSV file containing all your notes<%= link_to "CSV file (notes only)", :controller => 'data', :action => 'csv_notes' %>
XML file containing all your actions, contexts, projects, tags and notes<%= link_to "XML file (actions only)", :controller => 'data', :action => 'xml_export' %>
-

- -
-
-

Importing data

-

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.

-

<%= link_to "Start import", :controller => 'data', :action => 'yaml_form' %>.

+
+
+
+

Importing data

+

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 recomment backing up + the database right now in case that anything goes wrong. +

+

<%= link_to "Start import", :controller => 'data', :action => 'yaml_form' %>.

+

Exporting data

+

You can choose between the following formats:

+
    +
  • YAML: Best for exporting data.
    Please note that importing YAML files is currently supported only in experimentally. Do not rely on it for backing up critical data.
  • +
  • CSV: Best for importing into spreadsheet or data analysis software
  • +
  • XML: Best for importing or repurposing the data
  • +
+
+

+ + + + + + + + + + + + + + + + + + + + + +
DescriptionDownload link
YAML file containing all your actions, contexts, projects, tags and notes<%= link_to "YAML file", :controller => 'data', :action => 'yaml_export' %>
CSV file containing all of your actions, with named contexts and projects<%= link_to "CSV file (actions, contexts and projects)", :controller => 'data', :action => 'csv_actions' %>
CSV file containing all your notes<%= link_to "CSV file (notes only)", :controller => 'data', :action => 'csv_notes' %>
XML file containing all your actions, contexts, projects, tags and notes<%= link_to "XML file (actions only)", :controller => 'data', :action => 'xml_export' %>
+
-
+ diff --git a/app/views/data/yaml_form.html.erb b/app/views/data/yaml_form.html.erb index d3be8c1e..edc13098 100644 --- a/app/views/data/yaml_form.html.erb +++ b/app/views/data/yaml_form.html.erb @@ -1,17 +1,23 @@
-
-
-

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.

-

Paste the contents of the YAML file you exported into the text box below:

-
-

- <% form_for :import, @import, :url => {:controller => 'data', :action => 'yaml_import'} do |f| %> - <%= f.text_area :yaml %>
- - <% end %> -

-
+
+
+

Beware: all your current data will be destroyed before importing + the YAML file, so if you have access to the database, we strongly recommend + backing up the database right now in case that anything goes wrong. +

+

Paste the contents of the YAML file you exported into the text box below:

+
+

+ <% form_for :import, @import, :url => {:controller => 'data', :action => 'yaml_import'} do |f| %> + <%= f.text_area :yaml %>
+ + <% end %> +

+
-
-
+