diff --git a/tracks/app/controllers/application.rb b/tracks/app/controllers/application.rb
index 6b42a528..52d4b533 100644
--- a/tracks/app/controllers/application.rb
+++ b/tracks/app/controllers/application.rb
@@ -111,6 +111,10 @@ class ApplicationController < ActionController::Base
def markdown(text)
RedCloth.new(text).to_html
end
+
+ def build_default_project_context_name_map(projects)
+ Hash[*projects.reject{ |p| p.default_context.nil? }.map{ |p| [p.name, p.default_context.name] }.flatten].to_json
+ end
protected
diff --git a/tracks/app/controllers/contexts_controller.rb b/tracks/app/controllers/contexts_controller.rb
index bbdfc5da..cc5464fc 100644
--- a/tracks/app/controllers/contexts_controller.rb
+++ b/tracks/app/controllers/contexts_controller.rb
@@ -162,6 +162,7 @@ class ContextsController < ApplicationController
# Hides actions in hidden projects from context.
@not_done_todos = @context.todos.find(:all, :conditions => ['todos.state = ?', 'active'], :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC", :include => :project)
@count = @not_done_todos.size
+ @default_project_context_name_map = build_default_project_context_name_map(@projects).to_json
end
end
diff --git a/tracks/app/controllers/projects_controller.rb b/tracks/app/controllers/projects_controller.rb
index 5ed1149c..4fd22e59 100644
--- a/tracks/app/controllers/projects_controller.rb
+++ b/tracks/app/controllers/projects_controller.rb
@@ -3,6 +3,7 @@ class ProjectsController < ApplicationController
helper :application, :todos, :notes
before_filter :init, :except => [:create, :destroy, :order]
before_filter :check_user_set_project, :only => [:update, :destroy, :show]
+ before_filter :default_context_filter, :only => [:create,:update]
skip_before_filter :login_required, :only => [:index]
prepend_before_filter :login_or_feed_token_required, :only => [:index]
session :off, :only => :index, :if => Proc.new { |req| ['rss','atom','txt'].include?(req.parameters[:format]) }
@@ -28,6 +29,7 @@ class ProjectsController < ApplicationController
@count = @not_done.size
@next_project = @user.projects.next_from(@project)
@previous_project = @user.projects.previous_from(@project)
+ @default_project_context_name_map = build_default_project_context_name_map(@projects).to_json
end
# Example XML usage: curl -H 'Accept: application/xml' -H 'Content-Type: application/xml'
@@ -50,6 +52,7 @@ class ProjectsController < ApplicationController
@saved = @project.save
@project_not_done_counts = { @project.id => 0 }
@active_projects_count = @user.projects.count(:conditions => "state = 'active'")
+ @contexts = @user.contexts
respond_to do |wants|
wants.js
wants.xml do
@@ -93,6 +96,8 @@ class ProjectsController < ApplicationController
render
elsif boolean_param('update_status')
render :action => 'update_status'
+ elsif boolean_param('update_default_context')
+ render :action => 'update_default_context'
else
render :text => success_text || 'Success'
end
@@ -181,6 +186,19 @@ class ProjectsController < ApplicationController
@done = @user.todos.find_in_state(:all, :completed, :order => "completed_at DESC")
init_data_for_sidebar
end
+
+ def default_context_filter
+ p = params['project']
+ p = params['request']['project'] if p.nil? && params['request']
+ p = {} if p.nil?
+ default_context_name = p['default_context_name']
+ p.delete('default_context_name')
+
+ unless default_context_name.blank?
+ default_context = Context.find_or_create_by_name(default_context_name)
+ p['default_context_id'] = default_context.id
+ end
+ end
def summary(project)
project_description = ''
diff --git a/tracks/app/controllers/todos_controller.rb b/tracks/app/controllers/todos_controller.rb
index e837418d..391b7dec 100644
--- a/tracks/app/controllers/todos_controller.rb
+++ b/tracks/app/controllers/todos_controller.rb
@@ -224,6 +224,7 @@ class TodosController < ApplicationController
@page_title = "TRACKS::Tickler"
@tickles = @user.deferred_todos
@count = @tickles.size
+ @default_project_context_name_map = build_default_project_context_name_map(@projects).to_json
end
# Check for any due tickler items, activate them
@@ -262,6 +263,7 @@ class TodosController < ApplicationController
@done = @user.completed_todos.find(:all, :limit => max_completed, :include => [ :context, :project, :tags ]) unless max_completed == 0
# Set count badge to number of items with this tag
@not_done_todos.empty? ? @count = 0 : @count = @not_done_todos.size
+ @default_project_context_name_map = build_default_project_context_name_map(@projects).to_json
end
@@ -421,7 +423,9 @@ class TodosController < ApplicationController
# Set count badge to number of not-done, not hidden context items
@count = @todos.reject { |x| !x.active? || x.context.hide? }.size
-
+
+ @default_project_context_name_map = build_default_project_context_name_map(@projects).to_json
+
render
end
end
diff --git a/tracks/app/helpers/projects_helper.rb b/tracks/app/helpers/projects_helper.rb
index 55360243..09be149f 100644
--- a/tracks/app/helpers/projects_helper.rb
+++ b/tracks/app/helpers/projects_helper.rb
@@ -23,7 +23,7 @@ module ProjectsHelper
project_name = truncate(@previous_project.name, 40, "...")
html << link_to_project(@previous_project, "« #{project_name}")
end
- html << '|' if @previous_project && @next_project
+ html << ' | ' if @previous_project && @next_project
unless @next_project.nil?
project_name = truncate(@next_project.name, 40, "...")
html << link_to_project(@next_project, "#{project_name} »")
diff --git a/tracks/app/models/context.rb b/tracks/app/models/context.rb
index 25012d35..22912120 100644
--- a/tracks/app/models/context.rb
+++ b/tracks/app/models/context.rb
@@ -22,6 +22,10 @@ class Context < ActiveRecord::Base
:description => "Lists all the contexts for #{user.display_name}"
}
end
+
+ def self.null_object
+ NullContext.new
+ end
def hidden?
self.hide == true || self.hide == 1
@@ -43,3 +47,19 @@ class Context < ActiveRecord::Base
end
end
+
+class NullContext
+
+ def nil?
+ true
+ end
+
+ def id
+ nil
+ end
+
+ def name
+ ''
+ end
+
+end
\ No newline at end of file
diff --git a/tracks/app/models/project.rb b/tracks/app/models/project.rb
index 46519b37..2d91a940 100644
--- a/tracks/app/models/project.rb
+++ b/tracks/app/models/project.rb
@@ -1,6 +1,7 @@
class Project < ActiveRecord::Base
has_many :todos, :dependent => :delete_all, :include => :context
has_many :notes, :dependent => :delete_all, :order => "created_at DESC"
+ belongs_to :default_context, :dependent => :nullify, :class_name => "Context", :foreign_key => "default_context_id"
belongs_to :user
validates_presence_of :name, :message => "project must have a name"
@@ -65,7 +66,13 @@ class Project < ActiveRecord::Base
end
end
end
+
+ alias_method :original_default_context, :default_context
+ def default_context
+ original_default_context.nil? ? Context.null_object : original_default_context
+ end
+
# would prefer to call this method state=(), but that causes an endless loop
# as a result of acts_as_state_machine calling state=() to update the attribute
def transition_to(candidate_state)
@@ -96,5 +103,5 @@ class NullProject
def id
nil
end
-
+
end
\ No newline at end of file
diff --git a/tracks/app/views/projects/_default_context_autocomplete.rhtml b/tracks/app/views/projects/_default_context_autocomplete.rhtml
new file mode 100644
index 00000000..65977467
--- /dev/null
+++ b/tracks/app/views/projects/_default_context_autocomplete.rhtml
@@ -0,0 +1,6 @@
+
+
\ No newline at end of file
diff --git a/tracks/app/views/projects/_project_form.rhtml b/tracks/app/views/projects/_project_form.rhtml
index f3917ee3..b783aa28 100644
--- a/tracks/app/views/projects/_project_form.rhtml
+++ b/tracks/app/views/projects/_project_form.rhtml
@@ -17,3 +17,10 @@
<% end %>
+