mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-01 14:58:50 +01:00
Merge branch 'master' of git@github.com:bsag/tracks
This commit is contained in:
commit
579402ba08
9 changed files with 137 additions and 26 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
|
||||
|
||||
|
|
|
|||
|
|
@ -60,11 +60,21 @@ module TodosHelper
|
|||
url = {:controller => 'todos', :action => 'defer', :id => todo.id, :days => days,
|
||||
:_source_view => (@source_view.underscore.gsub(/\s+/,'_') rescue "")}
|
||||
url[:_tag_name] = @tag_name if @source_view == 'tag'
|
||||
return link_to_remote(
|
||||
image_tag("defer_#{days}_off.png", :mouseover => "defer_#{days}.png", :alt => "", :align => "absmiddle")+" Defer #{pluralize(days, "day")}",
|
||||
:url => url,
|
||||
:before => todo_start_waiting_js(todo),
|
||||
:complete => todo_stop_waiting_js)
|
||||
|
||||
futuredate = (@todo.show_from || @todo.user.date) + days.days
|
||||
puts "DUE: #{@todo.due}, futuredate: #{futuredate}"
|
||||
if @todo.due && futuredate > @todo.due
|
||||
return link_to_function(
|
||||
image_tag("defer_#{days}_off.png", :mouseover => "defer_#{days}.png", :alt => "", :align => "absmiddle")+" Defer #{pluralize(days, "day")}",
|
||||
"alert('Defer date is after due date. Please edit and adjust due date before deferring.')"
|
||||
)
|
||||
else
|
||||
return link_to_remote(
|
||||
image_tag("defer_#{days}_off.png", :mouseover => "defer_#{days}.png", :alt => "", :align => "absmiddle")+" Defer #{pluralize(days, "day")}",
|
||||
:url => url,
|
||||
:before => todo_start_waiting_js(todo),
|
||||
:complete => todo_stop_waiting_js)
|
||||
end
|
||||
end
|
||||
|
||||
def todo_start_waiting_js(todo)
|
||||
|
|
@ -276,13 +286,5 @@ module TodosHelper
|
|||
def image_tag_for_star(todo)
|
||||
class_str = todo.starred? ? "starred_todo" : "unstarred_todo"
|
||||
image_tag("blank.png", :title =>"Star action", :class => class_str)
|
||||
end
|
||||
|
||||
def defer_link(days)
|
||||
url = {:controller => 'todos', :action => 'defer', :id => @todo.id, :days => days,
|
||||
:_source_view => (@source_view.underscore.gsub(/\s+/,'_') rescue "")}
|
||||
url[:_tag_name] = @tag_name if @source_view == 'tag'
|
||||
link_to_remote image_tag("defer_#{days}.png", :alt => "Defer #{pluralize(days, 'day')}"), :url => url
|
||||
end
|
||||
|
||||
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