Skip to content

Commit

Permalink
basically done status displaying
Browse files Browse the repository at this point in the history
  • Loading branch information
gigix committed Jan 27, 2011
1 parent 49430e1 commit 63c3309
Show file tree
Hide file tree
Showing 14 changed files with 173 additions and 4 deletions.
1 change: 1 addition & 0 deletions rails_root/.rvmrc
@@ -0,0 +1 @@
rvm 1.9.2
2 changes: 1 addition & 1 deletion rails_root/app/helpers/calendars_helper.rb
Expand Up @@ -11,7 +11,7 @@ def draw_plan(plan)
end

plan.executions.each do |execution|
result << %(<div class="date unknown">&nbsp;<br />#{execution.date.day}</div>)
result << %(<div class="date #{execution.status}">&nbsp;<br />#{execution.date.day}</div>)
end
result += %(</div>)

Expand Down
27 changes: 27 additions & 0 deletions rails_root/app/models/execution.rb
@@ -1,4 +1,31 @@
class Execution < ActiveRecord::Base
belongs_to :plan
has_many :activities
has_many :habits, :through => :plan

def act!(habit_id)
self.activities.create!(:habit_id => habit_id)
end

class Status
GREAT = 'great'
GOOD = 'good'
BAD = 'bad'
UNKNOWN = 'unknown'
end

def status
return Status::UNKNOWN if self.date > Date.today
acted_habits = self.habits.select{|habit| acted?(habit) }
if acted_habits.blank?
return self.date == Date.today ? Status::UNKNOWN : Status::BAD
end
return Status::GREAT if acted_habits.size == self.habits.size
return Status::GOOD
end

private
def acted?(habit)
not self.activities.find_by_habit_id(habit).blank?
end
end
2 changes: 1 addition & 1 deletion rails_root/app/models/habit.rb
@@ -1,4 +1,4 @@
class Habit < ActiveRecord::Base
belongs_to :plan
has_many :activities
has_many :activities
end
4 changes: 4 additions & 0 deletions rails_root/app/models/plan.rb
Expand Up @@ -5,6 +5,10 @@ class Plan < ActiveRecord::Base

after_create :create_executions

def execution_on(date)
executions.detect{|execution| execution.date == date}
end

class Status
ACTIVE = 'active'
ABANDONED = 'abandoned'
Expand Down
2 changes: 1 addition & 1 deletion rails_root/db/migrate/20110124121153_insert_test_data.rb
Expand Up @@ -3,7 +3,7 @@ def self.up
return unless RAILS_ENV == 'development'

user = User.create!(:email => 'user@test.com', :password => 'password')
user.create_plan!(Date.today, ['Gym', 'Drawing', 'Djembe'])
user.create_plan!((Date.today - 10), ['Gym', 'Drawing', 'Djembe'])

User.create!(:email => 'empty.user@test.com', :password => 'password')
end
Expand Down
Binary file added rails_root/doc/design.key
Binary file not shown.
Binary file added rails_root/public/images/grid-bad.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rails_root/public/images/grid-good.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rails_root/public/images/grid-great.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions rails_root/public/stylesheets/ohfy.css
Expand Up @@ -63,6 +63,10 @@ a:hover {
background-image: url("/images/grid-unknown.png");
}

.calendar .bad {
background-image: url("/images/grid-bad.png");
}

.sticker {
margin: 0 auto;
overflow: hidden;
Expand Down
40 changes: 39 additions & 1 deletion rails_root/spec/models/execution_spec.rb
@@ -1,5 +1,43 @@
require 'spec_helper'

describe Execution do

before(:each) do
@user = create_test_user
@plan = @user.create_plan!((Date.today - 3), ['Drawing', 'Guitar', 'Gym'])
end

describe :status do
it "returns GREAT if all habits are acted" do
date = Date.today - 3
execution = @plan.execution_on(date)

lambda do
execution.habits.each{|habit| execution.act!(habit.id) }
end.should change(Activity, :count).by(3)

execution.status.should == Execution::Status::GREAT
end

it "returns GOOD if some habits are acted" do
execution = @plan.execution_on(Date.today - 2)
execution.act!(execution.habits.first)
execution.status.should == Execution::Status::GOOD
end

it "returns BAD if no habit is acted" do
@plan.execution_on(Date.today - 1).status.should == Execution::Status::BAD
end

it "returns UNKNOWN for future dates" do
@plan.execution_on(Date.tomorrow).status.should == Execution::Status::UNKNOWN
end

it "returns UNKNOWN if no habit is acted for today" do
execution = @plan.execution_on(Date.today)
execution.status.should == Execution::Status::UNKNOWN

execution.act!(execution.habits.first)
execution.status.should == Execution::Status::GOOD
end
end
end
14 changes: 14 additions & 0 deletions rails_root/spec/models/plan_spec.rb
@@ -1,4 +1,18 @@
require 'spec_helper'

describe Plan do
describe :execution_on do
before(:each) do
@user = create_test_user
@plan = @user.create_plan!((Date.today - 3), ['Drawing', 'Guitar', 'Gym'])
end

it "returns execution on given date" do
@plan.execution_on(Date.today).date.should == Date.today
end

it "returns nil if given date is out of range" do
@plan.execution_on(Date.today - 10).should be_nil
end
end
end
81 changes: 81 additions & 0 deletions rails_root/thoughtworkers-validator.pem
@@ -0,0 +1,81 @@
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript">var _sf_startpt=(new Date()).getTime()</script>
<meta content='text/html; charset=utf-8' http-equiv='content-type' />
<title>Opscode Management</title>
<link rel="Stylesheet" type="text/css" href="/stylesheets/base.css" media="all" charset="utf-8" /><link rel="Stylesheet" type="text/css" href="/stylesheets/themes/opscode/style.css" media="all" charset="utf-8" /><link rel="Stylesheet" type="text/css" href="/stylesheets/chef.css" media="all" charset="utf-8" /><link rel="Stylesheet" type="text/css" href="/facebox/facebox.css" media="all" charset="utf-8" /><link rel="Stylesheet" type="text/css" href="/stylesheets/jquery-ui-1.7.1.custom.css" media="all" charset="utf-8" /><link rel="Stylesheet" type="text/css" href="/stylesheets/jquery.treeTable.css" media="all" charset="utf-8" /><link rel="Stylesheet" type="text/css" href="/stylesheets/jsonedit_main.css" media="all" charset="utf-8" /><link rel="Stylesheet" type="text/css" href="/stylesheets/loading.css" media="all" charset="utf-8" />
<script type="text/javascript" src="/javascripts/jquery-1.3.2.min.js" charset="utf-8"></script><script type="text/javascript" src="/javascripts/jquery.jeditable.mini.js" charset="utf-8"></script><script type="text/javascript" src="/javascripts/jquery.livequery.js" charset="utf-8"></script><script type="text/javascript" src="/javascripts/jquery.localscroll.js" charset="utf-8"></script><script type="text/javascript" src="/javascripts/jquery.scrollTo.js" charset="utf-8"></script><script type="text/javascript" src="/javascripts/jquery.tools.min.js" charset="utf-8"></script>
<script type="text/javascript" src="/facebox/facebox.js" charset="utf-8"></script>
<script type="text/javascript" src="/javascripts/jquery-ui-1.7.1.custom.min.js" charset="utf-8"></script>
<script type="text/javascript" src="/javascripts/jquery.treeTable.min.js" charset="utf-8"></script>
<script type="text/javascript" src="/javascripts/chef.js" charset="utf-8"></script>

</head>
<body>
<div id='container'>
<div id='header'>
<h1>
<a href="http://www.opscode.com"><img src="/images/logo.png" /></a>
<a href="/nodes">thoughtworkers</a>
</h1>
<div id='user-navigation'>
<ul>
<li>Logged in as: <a href="http://cookbooks.opscode.com/users/gigix">gigix</a></li>
<li>|</li>
<li><a href="/organizations">Organizations</a></li>
<li>|</li>
<li><a method="get" href="/logout" confirm="Are you sure you want to logout?">Logout</a></li>
</ul>
<div class='clear'></div>
</div>
<div id='main-navigation'>
<ul>
<li class=''><a href="/search">Search</a></li>
<li class=''><a href="/status">Status</a></li>
<li class=''><a href="/roles">Roles</a></li>
<li class=''><a href="/nodes">Nodes</a></li>
<li class=''><a href="/cookbooks">Cookbooks</a></li>
<li class=''><a href="/databags">Data bags</a></li>
<li class=''><a href="/clients">Clients</a></li>
<li class=''><a href="/groups">Groups</a></li>
<li class=''><a href="/users">Users</a></li>
</ul>
<div class='clear'></div>
</div>
</div>
<div id='wrapper'>
<div id='main'>
<div id="container">

<div id="main-container">
<h3>Page not found.</h3>
</div>
<br />
<br />
</div>
<div id='footer'>
<div class='block'>
<p>Copyright &copy; 2010 Opscode</p>
</div>
</div>
</div>
<div id='sidebar'>
<div class='block notice' id='sidebar_block_notice'>
<h4>Need Help?</h4>
<p>If you have questions, or you're stuck, we're here to help.</p>
<p>
<a href='http://help.opscode.com/home' target='_blank'>Get Help</a>
or
<a href='#'>Leave Feedback</a>
</p>
</div>
<div class='block' id='sidebar_block'></div>
</div>
<div class='clear'></div>
</div>
<script src='/javascripts/tender_widget.js' type='text/javascript'></script>
</div>
</body>
</html>

0 comments on commit 63c3309

Please sign in to comment.