working on task tree

This commit is contained in:
Scott Davis 2010-03-04 17:42:09 -05:00
parent f440feb308
commit 6d31b3e4b5
12 changed files with 117 additions and 40 deletions

View File

@ -15,7 +15,7 @@ class TasksController < ApplicationController
# GET /tasks # GET /tasks
# GET /tasks.xml # GET /tasks.xml
def index def index
@tasks = Task.all @tasks = Task.parents.paginate(:per_page => 30, :page => params[:page], :include => :project)
respond_to do |format| respond_to do |format|
format.html # index.html.erb format.html # index.html.erb
@ -26,11 +26,11 @@ class TasksController < ApplicationController
# GET /tasks/1 # GET /tasks/1
# GET /tasks/1.xml # GET /tasks/1.xml
def show def show
@task = Task.find(params[:id]) @task = Task.find(params[:id], :include => :tasks)
@tasks = @task.tasks
respond_to do |format| respond_to do |format|
format.html # show.html.erb format.html # show.html.erb
format.xml { render :xml => @task } format.xml { render :xml => @task, :include => :tasks }
end end
end end
@ -38,7 +38,7 @@ class TasksController < ApplicationController
# GET /tasks/new.xml # GET /tasks/new.xml
def new def new
@task = Task.new @task = Task.new
@task.parent = params[:parent].nil? ? nil : params[:parent]
respond_to do |format| respond_to do |format|
format.html # new.html.erb format.html # new.html.erb
format.xml { render :xml => @task } format.xml { render :xml => @task }

View File

@ -2,6 +2,8 @@ class Task < ActiveRecord::Base
belongs_to :project belongs_to :project
has_many :tasks, :foreign_key => :parent has_many :tasks, :foreign_key => :parent
named_scope :parents, :conditions => {:parent => nil}
validates_presence_of :name, :description, :project_id validates_presence_of :name, :description, :project_id
validates_associated :project validates_associated :project
end end

View File

@ -0,0 +1,25 @@
<% unless @tasks.empty? %>
<table class='task_list'>
<tr>
<th>Name</th>
<th>Project</th>
<th>Description</th>
<th>Children</th>
</tr>
<% @tasks.each do |task| %>
<tr class="<%= cycle(:even, :odd)%>">
<td><%=h task.name %></td>
<td><%= link_to h(task.project.name), project_path(task.project) %></td>
<td><%=h task.description %></td>
<td><%=h task.tasks.size %></td>
<td><%= link_to 'Show', project_task_path(@project, task) %></td>
<td><%= link_to 'Edit', edit_project_task_path(@project, task) %></td>
<td><%= link_to 'Destroy', project_task_path(@project, task), :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>
<% else %>
<p> No Dependet Tasks </p>
<p><%= link_to 'Create One', new_project_task_path(@project, :parent => @task.id) %>
<% end %>

View File

@ -1,26 +1,8 @@
<h1>Listing tasks</h1> <h1>Listing tasks</h1>
<table> <%= render :partial => 'task_list' %>
<tr>
<th>Name</th>
<th>Project</th>
<th>Description</th>
<th>Parent</th>
</tr>
<% @tasks.each do |task| %>
<tr>
<td><%=h task.name %></td>
<td><%= link_to h(task.project.name), project_path(task.project) %></td>
<td><%=h task.description %></td>
<td><%=h task.parent %></td>
<td><%= link_to 'Show', project_task_path(@project, task) %></td>
<td><%= link_to 'Edit', edit_project_task_path(@project, task) %></td>
<td><%= link_to 'Destroy', project_task_path(@project, task), :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>
<br /> <br />
<%= will_paginate @tasks %>
<%= link_to 'New task', new_project_task_path(@project) %> <%= link_to 'New task', new_project_task_path(@project) %>

View File

@ -12,10 +12,7 @@
<%= f.text_area :description %> <%= f.text_area :description %>
</p> </p>
<p> <p>
<%= f.label :parent %><br /> <%= f.hidden_field :parent %>
<%= f.text_field :parent %>
</p>
<p>
<%= f.submit 'Create' %> <%= f.submit 'Create' %>
</p> </p>
<% end %> <% end %>

View File

@ -18,6 +18,8 @@
<%=h @task.parent %> <%=h @task.parent %>
</p> </p>
<%= render :partial => 'task_list' %>
<%= link_to 'Edit', edit_project_task_path(@project, @task) %> | <%= link_to 'Edit', edit_project_task_path(@project, @task) %> |
<%= link_to 'Back', project_tasks_path(@project) %> <%= link_to 'Back', project_tasks_path(@project) %>

View File

@ -1,19 +1,20 @@
# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
development: development:
adapter: sqlite3 adapter: mysql
database: db/development.sqlite3 database: collab_development
username: root
pool: 5 pool: 5
timeout: 5000 socket: /tmp/mysql.sock
# Warning: The database defined as "test" will be erased and # Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake". # re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production. # Do not set this db to the same as development or production.
test: test:
adapter: sqlite3 adapter: mysql
database: db/test.sqlite3 encoding: utf8
database: collab_test
pool: 5 pool: 5
timeout: 5000 username: root
socket: /tmp/mysql.sock
production: production:
adapter: sqlite3 adapter: sqlite3

View File

@ -19,6 +19,14 @@ Rails::Initializer.run do |config|
# config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net" # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
#config.gem "sqlite3-ruby", :lib => "sqlite3" #config.gem "sqlite3-ruby", :lib => "sqlite3"
# config.gem "aws-s3", :lib => "aws/s3" # config.gem "aws-s3", :lib => "aws/s3"
config.gem 'clearance'
config.gem 'will_paginate'
config.gem 'factory_girl'
config.gem 'paperclip'
config.gem 'formtastic'
config.gem 'faker'
config.gem 'postgres'
config.gem 'mysql'
# Only load the plugins named here, in the order given (default is alphabetical). # Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named # :all can be used as a placeholder for all plugins not explicitly named

View File

@ -0,0 +1,36 @@
path = File.join(RAILS_ROOT, 'factories')
require 'factory_girl'
require File.join(path, 'task_factory')
require File.join(path, 'project_factory')
class FactoryLoader
def self.up
self.create_projects
end
def self.down
[Task, Project].each {|klass| klass.delete_all}
end
def self.create_projects
101.times do |i|
p = Factory.create(:project)
self.create_tasks(p)
end
end
def self.create_tasks(project)
5.times do |i|
task = Factory.create(:task, :project => project)
5.times do |n|
t = Factory.create(:task, :project => project, :parent => task.id)
2.times do |nn|
Factory.create(:task, :project => project, :parent => t.id)
end
end
end
end
end

View File

@ -0,0 +1,5 @@
require 'factory_girl'
Factory.define :project do |f|
f.sequence(:name) {|n| "project #{n}"}
end

View File

@ -0,0 +1,6 @@
require 'factory_girl'
require 'faker'
Factory.define :task do |f|
f.sequence(:name) {|n| "task #{n}"}
f.description Faker::Lorem.paragraphs(1)
end

View File

@ -1,3 +1,7 @@
* {
margin:0;
padding:0;
}
#flash_error { #flash_error {
color:red; color:red;
} }
@ -9,3 +13,12 @@
#flash_success { #flash_success {
color:green; color:green;
} }
table.task_list tr.odd{
background-color:#ddd;
}
table.task_list tr.even{
}