Skip to content

Commit

Permalink
add task model
Browse files Browse the repository at this point in the history
  • Loading branch information
amesel committed Apr 29, 2012
1 parent ed11e03 commit 5135444
Show file tree
Hide file tree
Showing 21 changed files with 425 additions and 6 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/tasks.js.coffee
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
56 changes: 56 additions & 0 deletions app/assets/stylesheets/scaffolds.css.scss
@@ -0,0 +1,56 @@
body {
background-color: #fff;
color: #333;
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px; }

p, ol, ul, td {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px; }

pre {
background-color: #eee;
padding: 10px;
font-size: 11px; }

a {
color: #000;
&:visited {
color: #666; }
&:hover {
color: #fff;
background-color: #000; } }

div {
&.field, &.actions {
margin-bottom: 10px; } }

#notice {
color: green; }

.field_with_errors {
padding: 2px;
background-color: red;
display: table; }

#error_explanation {
width: 450px;
border: 2px solid red;
padding: 7px;
padding-bottom: 0;
margin-bottom: 20px;
background-color: #f0f0f0;
h2 {
text-align: left;
font-weight: bold;
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px;
margin-bottom: 0px;
background-color: #c00;
color: #fff; }
ul li {
font-size: 12px;
list-style: square; } }
3 changes: 3 additions & 0 deletions app/assets/stylesheets/tasks.css.scss
@@ -0,0 +1,3 @@
// Place all the styles related to the Tasks controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
101 changes: 101 additions & 0 deletions app/controllers/tasks_controller.rb
@@ -0,0 +1,101 @@
class TasksController < ApplicationController
before_filter :authenticate_user!, :except => [:index, :show]

# GET /tasks
# GET /tasks.json
def index
@tasks = Task.all

respond_to do |format|
format.html # index.html.erb
format.json { render json: @tasks }
end
end

# GET /tasks/1
# GET /tasks/1.json
def show
@task = Task.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.json { render json: @task }
end
end

# GET /tasks/new
# GET /tasks/new.json
def new
@task = Task.new

respond_to do |format|
format.html # new.html.erb
format.json { render json: @task }
end
end

# GET /tasks/1/edit
def edit
@task = Task.find(params[:id])
end

# POST /tasks
# POST /tasks.json
def create
@task = Task.new(params[:task])
@task.user_id = current_user.id
@task.party_id = params[:party_id]
@task.state = "backlog"

respond_to do |format|
if @task.save
format.html { redirect_to @task.party, notice: 'Task was successfully created.' }
format.json { render json: @task, status: :created, location: @task }
else
format.html { render action: "new" }
format.json { render json: @task.errors, status: :unprocessable_entity }
end
end
end

# PUT /tasks/1
# PUT /tasks/1.json
def update
@task = Task.find(params[:id])

respond_to do |format|
if @task.update_attributes(params[:task])
format.html { redirect_to @task, notice: 'Task was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @task.errors, status: :unprocessable_entity }
end
end
end

# DELETE /tasks/1
# DELETE /tasks/1.json
def destroy
@task = Task.find(params[:id])
@task.destroy

respond_to do |format|
format.html { redirect_to tasks_url }
format.json { head :no_content }
end
end

def start
raise params
end

def hold
raise params
end

def finish
raise params
end

end
2 changes: 2 additions & 0 deletions app/helpers/tasks_helper.rb
@@ -0,0 +1,2 @@
module TasksHelper
end
9 changes: 9 additions & 0 deletions app/models/task.rb
@@ -0,0 +1,9 @@
class Task < ActiveRecord::Base
attr_accessible :content, :end_time, :start_time, :state, :user_id
belongs_to :user
belongs_to :party

scope :current, where(state: "current")
scope :backlog, where(state: "backlog").order("created_at desc")
scope :done, where(state: "done").order("created_at desc")
end
3 changes: 2 additions & 1 deletion app/models/user.rb
Expand Up @@ -3,7 +3,8 @@ class User < ActiveRecord::Base

has_many :joins
has_many :parties
has_many :invited_parties, :through => :joins
# has_many :invited_parties, :through => :joins
has_many :tasks

def self.create_with_omniauth(auth)
create! do |user|
Expand Down
34 changes: 32 additions & 2 deletions app/views/parties/show.html.erb
Expand Up @@ -15,11 +15,41 @@
<%= @party.end_at %>
</p>

<hr />

<p>
<b>Member:</b>
<ul>
<% @party.users.each do |user| %>
<li><%= user.name %></li>
<%= div_for user do %>
<%= user.name %>
user tasks

<div id="current">
<h2>current</h2>
</div>

<% if user.id == current_user.id %>
<%= form_for [@party, user.tasks.build] do |f| -%>
<%= f.text_area :content, :rows => 3, :cols => 30 %>
<%= f.submit %>
<% end -%>
<% end %>

<div id="backlog">
<h2>backlog</h2>
<% user.tasks.backlog.each do |task| %>
<%= div_for task do %>
<%= task.content %>
<%= link_to "start", start_party_task_path(@party, task) %>
<% end %>
<% end %>
</div>

<div id="done">
<h2>done</h2>
</div>

<% end %>
<% end %>
</ul>
</p>
Expand Down
37 changes: 37 additions & 0 deletions app/views/tasks/_form.html.erb
@@ -0,0 +1,37 @@
<%= form_for(@task) do |f| %>
<% if @task.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@task.errors.count, "error") %> prohibited this task from being saved:</h2>

<ul>
<% @task.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= f.label :user_id %><br />
<%= f.number_field :user_id %>
</div>
<div class="field">
<%= f.label :content %><br />
<%= f.text_area :content %>
</div>
<div class="field">
<%= f.label :state %><br />
<%= f.text_field :state %>
</div>
<div class="field">
<%= f.label :start_time %><br />
<%= f.time_select :start_time %>
</div>
<div class="field">
<%= f.label :end_time %><br />
<%= f.time_select :end_time %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/tasks/edit.html.erb
@@ -0,0 +1,6 @@
<h1>Editing task</h1>

<%= render 'form' %>
<%= link_to 'Show', @task %> |
<%= link_to 'Back', tasks_path %>
31 changes: 31 additions & 0 deletions app/views/tasks/index.html.erb
@@ -0,0 +1,31 @@
<h1>Listing tasks</h1>

<table>
<tr>
<th>User</th>
<th>Content</th>
<th>State</th>
<th>Start time</th>
<th>End time</th>
<th></th>
<th></th>
<th></th>
</tr>

<% @tasks.each do |task| %>
<tr>
<td><%= task.user_id %></td>
<td><%= task.content %></td>
<td><%= task.state %></td>
<td><%= task.start_time %></td>
<td><%= task.end_time %></td>
<td><%= link_to 'Show', task %></td>
<td><%= link_to 'Edit', edit_task_path(task) %></td>
<td><%= link_to 'Destroy', task, confirm: 'Are you sure?', method: :delete %></td>
</tr>
<% end %>
</table>

<br />

<%= link_to 'New Task', new_task_path %>
5 changes: 5 additions & 0 deletions app/views/tasks/new.html.erb
@@ -0,0 +1,5 @@
<h1>New task</h1>

<%= render 'form' %>
<%= link_to 'Back', tasks_path %>
30 changes: 30 additions & 0 deletions app/views/tasks/show.html.erb
@@ -0,0 +1,30 @@
<p id="notice"><%= notice %></p>

<p>
<b>User:</b>
<%= @task.user_id %>
</p>

<p>
<b>Content:</b>
<%= @task.content %>
</p>

<p>
<b>State:</b>
<%= @task.state %>
</p>

<p>
<b>Start time:</b>
<%= @task.start_time %>
</p>

<p>
<b>End time:</b>
<%= @task.end_time %>
</p>


<%= link_to 'Edit', edit_task_path(@task) %> |
<%= link_to 'Back', tasks_path %>
8 changes: 7 additions & 1 deletion config/routes.rb
Expand Up @@ -2,7 +2,13 @@

resources :joins

resources :parties
resources :parties do
resources :tasks do
get "start", :on => :member
get "hold", :on => :member
get "finish", :on => :member
end
end

get "sessions/create"

Expand Down
14 changes: 14 additions & 0 deletions db/migrate/20120429045006_create_tasks.rb
@@ -0,0 +1,14 @@
class CreateTasks < ActiveRecord::Migration
def change
create_table :tasks do |t|
t.integer :user_id
t.integer :party_id
t.text :content
t.string :state
t.time :start_time
t.time :end_time

t.timestamps
end
end
end

0 comments on commit 5135444

Please sign in to comment.