mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-09 10:48:50 +01:00
Fix #592 be able to set default tags for a project. Default tags can now be specified when creating or editing a project, and they will be applied to any new todos created in that project.
This commit is contained in:
parent
3d3b658763
commit
42bea2490b
8 changed files with 122 additions and 13 deletions
|
|
@ -49,6 +49,7 @@ class TodosController < ApplicationController
|
|||
@source_view = params['_source_view'] || 'todo'
|
||||
p = TodoCreateParamsHelper.new(params, prefs)
|
||||
p.parse_dates() unless mobile?
|
||||
tag_list = p.tag_list
|
||||
|
||||
@todo = current_user.todos.build(p.attributes)
|
||||
|
||||
|
|
@ -56,6 +57,11 @@ class TodosController < ApplicationController
|
|||
project = current_user.projects.find_or_create_by_name(p.project_name)
|
||||
@new_project_created = project.new_record_before_save?
|
||||
@todo.project_id = project.id
|
||||
if tag_list.blank?
|
||||
tag_list = project.default_tags unless project.default_tags.blank?
|
||||
else
|
||||
tag_list += ','+project.default_tags unless project.default_tags.blank?
|
||||
end
|
||||
end
|
||||
|
||||
if p.context_specified_by_name?
|
||||
|
|
@ -67,8 +73,8 @@ class TodosController < ApplicationController
|
|||
|
||||
@todo.update_state_from_project
|
||||
@saved = @todo.save
|
||||
unless (@saved == false) || p.tag_list.blank?
|
||||
@todo.tag_with(p.tag_list)
|
||||
unless (@saved == false) || tag_list.blank?
|
||||
@todo.tag_with(tag_list)
|
||||
@todo.tags.reload
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,10 @@
|
|||
<%= render :partial => 'default_context_autocomplete' %>
|
||||
<br/>
|
||||
|
||||
<label for="project[default_tags]">Default Tags</label><br/>
|
||||
<%= text_field_tag("project[default_tags]", project.default_tags, {:tabindex=>2,:size=> 25}) %>
|
||||
<br/>
|
||||
|
||||
<input type="hidden" name="wants_render" value="true" />
|
||||
<div class="submit_box">
|
||||
<div class="widgets" id="<%= dom_id(project, 'widgets') %>">
|
||||
|
|
|
|||
|
|
@ -44,6 +44,10 @@
|
|||
<br />
|
||||
<% end -%>
|
||||
|
||||
<label for="default_tags">Default Tags (optional):</label><br />
|
||||
<%= text_field_tag("project[default_tags]", @project.default_tags, :tabindex => 4) %>
|
||||
<br />
|
||||
|
||||
<br/>
|
||||
|
||||
<div class="submit_box">
|
||||
|
|
|
|||
|
|
@ -57,20 +57,41 @@
|
|||
<h2>Default Context</h2>
|
||||
<div>
|
||||
<% form_remote_tag( :url => project_path(@project), :method => :put,
|
||||
:html=> { :id => 'set-default-context-action',
|
||||
:name => 'default_context',
|
||||
:class => 'inline-form' }) do -%>
|
||||
<%= hidden_field_tag("update_default_context", true) %>
|
||||
<%= text_field_tag("project[default_context_name]",
|
||||
@project.default_context.name,
|
||||
{ :tabindex => 9,:size => 25 }) %>
|
||||
<%= submit_tag "Set Default Context for this Project", { :tabindex => 10 } %>
|
||||
<%= render :partial => 'default_context_autocomplete' %>
|
||||
<% end -%>
|
||||
:html=> { :id => 'set-default-context-action',
|
||||
:name => 'default_context',
|
||||
:class => 'inline-form' }) do -%>
|
||||
<%= hidden_field_tag("update_default_context", true) %>
|
||||
<%= text_field_tag("project[default_context_name]",
|
||||
@project.default_context.name,
|
||||
{ :tabindex => 9,:size => 25 }) %>
|
||||
<%= submit_tag "Set Default Context for this Project", { :tabindex => 10 } %>
|
||||
<%= render :partial => 'default_context_autocomplete' %>
|
||||
<% end -%>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- [end:display_box] -->
|
||||
|
||||
<div class="container">
|
||||
<div id="default_tags">
|
||||
<h2>Default Tags</h2>
|
||||
<div>
|
||||
<% form_remote_tag( :url => project_path(@project), :method => :put,
|
||||
:html=> { :id => 'set-default-tags-action',
|
||||
:name => 'default_tags',
|
||||
:class => 'inline-form' }) do -%>
|
||||
<%= hidden_field_tag("update_default_tags", true) %>
|
||||
<%= text_field_tag("project[default_tags]",
|
||||
@project.default_tags,
|
||||
{ :tabindex => 11,:size => 25 }) %>
|
||||
<%= submit_tag "Set Default Tags for this Project", { :tabindex => 12 } %>
|
||||
<% end -%>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div id="input_box">
|
||||
<%= render :partial => "shared/add_new_item_form" %>
|
||||
|
|
|
|||
9
db/migrate/20090301154745_add_default_tags_to_project.rb
Normal file
9
db/migrate/20090301154745_add_default_tags_to_project.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
class AddDefaultTagsToProject < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column :projects, :default_tags, :string
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :projects, :default_tags
|
||||
end
|
||||
end
|
||||
|
|
@ -480,6 +480,9 @@ div#project_status > div {
|
|||
div#default_context > div{
|
||||
padding:10px;
|
||||
}
|
||||
div#default_tags > div{
|
||||
padding:10px;
|
||||
}
|
||||
a.footer_link {color: #cc3334; font-style: normal;}
|
||||
a.footer_link:hover {color: #fff; background-color: #cc3334 !important;}
|
||||
|
||||
|
|
|
|||
21
spec/controllers/projects_controller_spec.rb
Normal file
21
spec/controllers/projects_controller_spec.rb
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
require File.dirname(__FILE__) + '/../spec_helper'
|
||||
|
||||
describe ProjectsController do
|
||||
it "should save default tags" do
|
||||
project = Project.new
|
||||
|
||||
projects = mock(:project_list, :build => project,
|
||||
:active => mock(:meh, :count => 0), :size => 0)
|
||||
|
||||
user = mock_model(User, :projects => projects, :prefs => {},
|
||||
:contexts => mock(:context_list, :find => []))
|
||||
controller.stub!(:current_user).and_return(user)
|
||||
controller.stub!(:login_required).and_return(true)
|
||||
controller.stub!(:set_time_zone).and_return(true)
|
||||
controller.stub!(:mobile?).and_return(true)
|
||||
|
||||
get 'create', :project => {:name => "fooproject", :default_tags => "a,b"}
|
||||
|
||||
project.default_tags.should == 'a,b'
|
||||
end
|
||||
end
|
||||
41
spec/controllers/todos_controller_spec.rb
Normal file
41
spec/controllers/todos_controller_spec.rb
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
require File.dirname(__FILE__) + '/../spec_helper'
|
||||
|
||||
describe TodosController do
|
||||
it "should add project's default tags to todos" do
|
||||
p = mock_model(Project, :new_record_before_save? => false)
|
||||
p.should_receive(:default_tags).twice.and_return('abcd,efgh')
|
||||
todo = mock_model(Todo, :save => true, :update_state_from_project => nil,
|
||||
:tags => mock(:tag_list, :reload => nil))
|
||||
todo.stub!(:project_id=)
|
||||
todo.should_receive(:tag_with).with('abcd,efgh')
|
||||
projects = mock(:project_list, :find_or_create_by_name => p, :find => [p])
|
||||
todos = mock(:todo_list, :build => todo)
|
||||
|
||||
user = mock_model(User, :todos => todos, :projects => projects, :prefs => {},
|
||||
:contexts => mock(:context_list, :find => []))
|
||||
controller.stub!(:current_user).and_return(user)
|
||||
controller.stub!(:login_required).and_return(true)
|
||||
controller.stub!(:set_time_zone).and_return(true)
|
||||
controller.stub!(:mobile?).and_return(true)
|
||||
get 'create', :project_name => "zzzz", :tag_list => '', :todo => {}
|
||||
end
|
||||
|
||||
it "should append project's default tags to todos" do
|
||||
p = mock_model(Project, :new_record_before_save? => false)
|
||||
p.should_receive(:default_tags).twice.and_return('abcd,efgh')
|
||||
todo = mock_model(Todo, :save => true, :update_state_from_project => nil,
|
||||
:tags => mock(:tag_list, :reload => nil))
|
||||
todo.stub!(:project_id=)
|
||||
todo.should_receive(:tag_with).with('111,222,abcd,efgh')
|
||||
projects = mock(:project_list, :find_or_create_by_name => p, :find => [p])
|
||||
todos = mock(:todo_list, :build => todo)
|
||||
|
||||
user = mock_model(User, :todos => todos, :projects => projects, :prefs => {},
|
||||
:contexts => mock(:context_list, :find => []))
|
||||
controller.stub!(:current_user).and_return(user)
|
||||
controller.stub!(:login_required).and_return(true)
|
||||
controller.stub!(:set_time_zone).and_return(true)
|
||||
controller.stub!(:mobile?).and_return(true)
|
||||
get 'create', :project_name => "zzzz", :tag_list => '111,222', :todo => {}
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue