working on task tree
This commit is contained in:
parent
f440feb308
commit
6d31b3e4b5
|
@ -15,7 +15,7 @@ class TasksController < ApplicationController
|
|||
# GET /tasks
|
||||
# GET /tasks.xml
|
||||
def index
|
||||
@tasks = Task.all
|
||||
@tasks = Task.parents.paginate(:per_page => 30, :page => params[:page], :include => :project)
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
|
@ -26,11 +26,11 @@ class TasksController < ApplicationController
|
|||
# GET /tasks/1
|
||||
# GET /tasks/1.xml
|
||||
def show
|
||||
@task = Task.find(params[:id])
|
||||
|
||||
@task = Task.find(params[:id], :include => :tasks)
|
||||
@tasks = @task.tasks
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
format.xml { render :xml => @task }
|
||||
format.xml { render :xml => @task, :include => :tasks }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -38,7 +38,7 @@ class TasksController < ApplicationController
|
|||
# GET /tasks/new.xml
|
||||
def new
|
||||
@task = Task.new
|
||||
|
||||
@task.parent = params[:parent].nil? ? nil : params[:parent]
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
format.xml { render :xml => @task }
|
||||
|
|
|
@ -2,6 +2,8 @@ class Task < ActiveRecord::Base
|
|||
belongs_to :project
|
||||
has_many :tasks, :foreign_key => :parent
|
||||
|
||||
named_scope :parents, :conditions => {:parent => nil}
|
||||
|
||||
validates_presence_of :name, :description, :project_id
|
||||
validates_associated :project
|
||||
end
|
||||
|
|
|
@ -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 %>
|
|
@ -1,26 +1,8 @@
|
|||
<h1>Listing tasks</h1>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Project</th>
|
||||
<th>Description</th>
|
||||
<th>Parent</th>
|
||||
</tr>
|
||||
<%= render :partial => 'task_list' %>
|
||||
|
||||
<% @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 />
|
||||
|
||||
<%= will_paginate @tasks %>
|
||||
<%= link_to 'New task', new_project_task_path(@project) %>
|
|
@ -12,10 +12,7 @@
|
|||
<%= f.text_area :description %>
|
||||
</p>
|
||||
<p>
|
||||
<%= f.label :parent %><br />
|
||||
<%= f.text_field :parent %>
|
||||
</p>
|
||||
<p>
|
||||
<%= f.hidden_field :parent %>
|
||||
<%= f.submit 'Create' %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
<%=h @task.parent %>
|
||||
</p>
|
||||
|
||||
<%= render :partial => 'task_list' %>
|
||||
|
||||
|
||||
<%= link_to 'Edit', edit_project_task_path(@project, @task) %> |
|
||||
<%= link_to 'Back', project_tasks_path(@project) %>
|
||||
<%= link_to 'Back', project_tasks_path(@project) %>
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
# SQLite version 3.x
|
||||
# gem install sqlite3-ruby (not necessary on OS X Leopard)
|
||||
development:
|
||||
adapter: sqlite3
|
||||
database: db/development.sqlite3
|
||||
adapter: mysql
|
||||
database: collab_development
|
||||
username: root
|
||||
pool: 5
|
||||
timeout: 5000
|
||||
socket: /tmp/mysql.sock
|
||||
|
||||
# Warning: The database defined as "test" will be erased and
|
||||
# re-generated from your development database when you run "rake".
|
||||
# Do not set this db to the same as development or production.
|
||||
test:
|
||||
adapter: sqlite3
|
||||
database: db/test.sqlite3
|
||||
adapter: mysql
|
||||
encoding: utf8
|
||||
database: collab_test
|
||||
pool: 5
|
||||
timeout: 5000
|
||||
username: root
|
||||
socket: /tmp/mysql.sock
|
||||
|
||||
production:
|
||||
adapter: sqlite3
|
||||
|
|
|
@ -17,9 +17,17 @@ Rails::Initializer.run do |config|
|
|||
# Specify gems that this application depends on and have them installed with rake gems:install
|
||||
# config.gem "bj"
|
||||
# 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 '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).
|
||||
# :all can be used as a placeholder for all plugins not explicitly named
|
||||
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
||||
|
|
|
@ -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
|
|
@ -0,0 +1,5 @@
|
|||
require 'factory_girl'
|
||||
|
||||
Factory.define :project do |f|
|
||||
f.sequence(:name) {|n| "project #{n}"}
|
||||
end
|
|
@ -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
|
|
@ -1,3 +1,7 @@
|
|||
* {
|
||||
margin:0;
|
||||
padding:0;
|
||||
}
|
||||
#flash_error {
|
||||
color:red;
|
||||
}
|
||||
|
@ -8,4 +12,13 @@
|
|||
|
||||
#flash_success {
|
||||
color:green;
|
||||
}
|
||||
|
||||
|
||||
table.task_list tr.odd{
|
||||
background-color:#ddd;
|
||||
}
|
||||
|
||||
table.task_list tr.even{
|
||||
|
||||
}
|
Loading…
Reference in New Issue