diff --git a/app/helpers/submittals_helper.rb b/app/helpers/submittals_helper.rb
index 75ed617..e09b039 100755
--- a/app/helpers/submittals_helper.rb
+++ b/app/helpers/submittals_helper.rb
@@ -1,2 +1,11 @@
module SubmittalsHelper
+
+ def owner_review_status(submittal)
+ if submittal.owner_reviewed?
+ "Reviewed by #{submittal.reviewing_owner.display_name} on #{submittal.owner_reviewed_at}"
+ else
+ "An Authorized Owner has yet to review this Submittal"
+ end
+ end
+
end
diff --git a/app/models/job.rb b/app/models/job.rb
index ea3a30d..77e3dc7 100755
--- a/app/models/job.rb
+++ b/app/models/job.rb
@@ -528,6 +528,11 @@ class Job < ActiveRecord::Base
!child_number.nil?
end
+ # See if this Job has any assigned Authorized Owners
+ def has_authorized_owner?
+ @val ||= assigned_users.any?{|u| u.is_a?(AuthorizedOwner)}
+ end
+
protected
diff --git a/app/models/poll.rb b/app/models/poll.rb
index 7676eae..9031680 100644
--- a/app/models/poll.rb
+++ b/app/models/poll.rb
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 20090109155322
+# Schema version: 20090210165710
#
# Table name: polls
#
@@ -8,6 +8,7 @@
# description :text
# options :text
# ends_at :date
+# string :text
# created_at :datetime
# updated_at :datetime
# created_by_id :integer(4)
@@ -132,4 +133,4 @@ class Poll < ActiveRecord::Base
total_votes > 0
end
-end
\ No newline at end of file
+end
diff --git a/app/models/submittal.rb b/app/models/submittal.rb
index 6786833..93ae695 100755
--- a/app/models/submittal.rb
+++ b/app/models/submittal.rb
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 20081202211758
+# Schema version: 20090210165710
#
# Table name: submittals
#
@@ -17,6 +17,8 @@
# reviewed_by_id :integer(4)
# reviewed_at :datetime
# delivered_to_id :integer(4)
+# owner_reviewed_at :datetime
+# reviewing_owner_id :integer(4)
#
class Submittal < ActiveRecord::Base
@@ -32,6 +34,7 @@ class Submittal < ActiveRecord::Base
belongs_to :receiver, :foreign_key => 'delivered_to_id', :class_name => 'User'
belongs_to :design_professional, :foreign_key => 'design_professional_id', :class_name => 'User'
belongs_to :reviewing_engineer, :foreign_key => 'reviewed_by_id', :class_name => 'User'
+ belongs_to :reviewing_owner, :foreign_key => 'reviewing_owner_id', :class_name => 'User'
belongs_to :author, :foreign_key => 'created_by_id', :class_name => 'User'
belongs_to :spec_section
@@ -157,6 +160,14 @@ class Submittal < ActiveRecord::Base
all(:include => [:response], :conditions => ["design_professional_id = ?", user.id]).select{|r| r.is_open?}
end
+ def owner_reviewed?
+ owner_reviewed_at != nil
+ end
+
+ def owner_reviewable?(user)
+ (user.is_a?(AuthorizedOwner) || user.is_admin?) && !owner_reviewed?
+ end
+
protected
diff --git a/app/views/submittals/_submittal.html.haml b/app/views/submittals/_submittal.html.haml
index 59dadb0..ba6da3d 100755
--- a/app/views/submittals/_submittal.html.haml
+++ b/app/views/submittals/_submittal.html.haml
@@ -4,6 +4,9 @@
%td.capitalize= h truncate(submittal.spec_section.name, :length => 25)
%td= submittal.response.name if submittal.response
+ - if @job.has_authorized_owner?
+ %td= submittal.owner_reviewed? ? "Reviewed" : ""
+
- if @current_user.is_employee?
%td= submittal.receiver.display_name rescue ""
diff --git a/app/views/submittals/index.html.haml b/app/views/submittals/index.html.haml
index 21d65db..2e5da87 100755
--- a/app/views/submittals/index.html.haml
+++ b/app/views/submittals/index.html.haml
@@ -9,22 +9,25 @@
%table#sortable.sortable
%thead
%tr
- %th== Name
- %th== Discipline
- %th== Spec Section
- %th== Status
+ %th Name
+ %th Discipline
+ %th Spec Section
+ %th Engineer Status
+
+ - if @job.has_authorized_owner?
+ %th Owner Status
- if @current_user.is_employee?
- %th== Receiver
+ %th Receiver
- %th== Reviewer
- %th== Received
+ %th Reviewer
+ %th Received
- if @current_user.is_employee?
- %th== Due
+ %th Due
- %th== Returned
- %th== Days<br/>Open
+ %th Returned
+ %th Days<br/>Open
%tbody#submittal_list
= render :partial => 'submittal', :collection => @submittals
\ No newline at end of file
diff --git a/app/views/submittals/show.html.haml b/app/views/submittals/show.html.haml
index 0b60663..9f7f47a 100755
--- a/app/views/submittals/show.html.haml
+++ b/app/views/submittals/show.html.haml
@@ -9,10 +9,13 @@
- if @submittal.is_respondable_by(@current_user)
= link_to_function 'Respond', toggle('response_div')
+ - if @submittal.owner_reviewable?(@current_user)
+ = link_to 'Mark as Reviewed', owner_review_job_submittal_path(@job, @submittal)
+
- if @submittal.is_respondable_by(@current_user)
#response_div{ :style => "display: none;" }
= render :partial => 'submittal_responses/new'
-
+
= box("Name:") do
= h @submittal.display_short_name
@@ -58,6 +61,12 @@
= render :partial => 'comments/index', :locals => {:obj => @submittal}
+- if @job.has_authorized_owner?
+ .subsection_header Owner Review:
+ = box do
+ = owner_review_status(@submittal)
+
+
- if @submittal.response
.subsection_header== Response:
= box do
@@ -68,6 +77,6 @@
- if @submittal.has_been_reviewed?
- .subsection_header== Review
+ .subsection_header== Review
= box("Review Status:") do
- = h @submittal.review_status
\ No newline at end of file
+ = h @submittal.review_status
diff --git a/db/migrate/20090210165710_add_owner_reviewed_flag_to_submittals.rb b/db/migrate/20090210165710_add_owner_reviewed_flag_to_submittals.rb
new file mode 100644
index 0000000..cf4b496
--- /dev/null
+++ b/db/migrate/20090210165710_add_owner_reviewed_flag_to_submittals.rb
@@ -0,0 +1,11 @@
+class AddOwnerReviewedFlagToSubmittals < ActiveRecord::Migration
+ def self.up
+ add_column :submittals, :owner_reviewed_at, :datetime
+ add_column :submittals, :reviewing_owner_id, :integer
+ end
+
+ def self.down
+ remove_column :submittals, :reviewing_owner_id
+ remove_column :submittals, :owner_reviewed_at
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index acffdf8..8ec70a0 100755
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20090209181517) do
+ActiveRecord::Schema.define(:version => 20090210165710) do
create_table "announcements", :force => true do |t|
t.string "message"
@@ -826,6 +826,8 @@ ActiveRecord::Schema.define(:version => 20090209181517) do
t.integer "reviewed_by_id"
t.datetime "reviewed_at"
t.integer "delivered_to_id"
+ t.datetime "owner_reviewed_at"
+ t.integer "reviewing_owner_id"
end
add_index "submittals", ["design_professional_id"], :name => "index_submittals_on_design_professional_id"
diff --git a/spec/helpers/submittals_helper_spec.rb b/spec/helpers/submittals_helper_spec.rb
index 4cc2013..bb559a4 100755
--- a/spec/helpers/submittals_helper_spec.rb
+++ b/spec/helpers/submittals_helper_spec.rb
@@ -2,5 +2,22 @@ require File.dirname(__FILE__) + '/../spec_helper'
describe SubmittalsHelper do
+ describe " -- the owner_review_status method" do
+ describe "when the submittal has been reviewd" do
+ it "should show this blurb" do
+ user = mock_model(User, :display_name => "foo bar")
+ submittal = mock_model(Submittal, :owner_reviewed? => true, :reviewing_owner => user, :owner_reviewed_at => Date.today)
+ helper.owner_review_status(submittal).should == "Reviewed by #{submittal.reviewing_owner.display_name} on #{submittal.owner_reviewed_at}"
+ end
+ end
+
+ describe "when the submittal has not been reviewed" do
+ it "should show this blurb" do
+ submittal = mock_model(Submittal, :owner_reviewed? => false)
+ helper.owner_review_status(submittal).should == "An Authorized Owner has yet to review this Submittal"
+ end
+ end
+
+ end
-end
+end
\ No newline at end of file
diff --git a/spec/models/job_spec.rb b/spec/models/job_spec.rb
index d9afd97..24fd9ee 100755
--- a/spec/models/job_spec.rb
+++ b/spec/models/job_spec.rb
@@ -231,6 +231,13 @@ describe "Job" do
@job.is_subjob?.should be_false
end
+ it "should know if it has any assigned Authorized Owners" do
+ user_1 = mock_model(AuthorizedOwner)
+ user_2 = mock_model(HvacEngineer)
+ @job.stub!(:assigned_users => [user_1, user_2])
+ @job.has_authorized_owner?.should be_true
+ end
+
describe " - Subjob" do
before do
diff --git a/spec/models/submittal_spec.rb b/spec/models/submittal_spec.rb
index 7af55ac..b15de84 100755
--- a/spec/models/submittal_spec.rb
+++ b/spec/models/submittal_spec.rb
@@ -34,6 +34,10 @@ describe "A Submittal" do
@submittal.should be_valid
end
+ it "should respond to :reviewing_owner" do
+ @submittal.should respond_to(:reviewing_owner)
+ end
+
it "should have a name" do
@submittal.name = nil
@submittal.should_not be_valid
@@ -223,4 +227,45 @@ describe "A Submittal" do
end
end
+ describe " in a Job with an Authorized Owner" do
+ describe "without an existing owner review" do
+ before do
+ @submittal.stub!(:owner_reviewed? => false)
+ end
+
+ it "should be owner reviewable by an Authorized Owner" do
+ @submittal.owner_reviewable?(@authed_owner).should be_true
+ end
+
+ it "should not be reviewable by anyone else" do
+ @submittal.owner_reviewable?(@user).should be_false
+ @submittal.owner_reviewable?(@employee).should be_false
+ end
+
+ it "should know that it hasn't been reviewed" do
+ @submittal.owner_reviewed?.should be_false
+ end
+ end
+
+ describe "with an existing owner review" do
+ before do
+ @submittal.stub!(:owner_reviewed_at => Date.today, :reviewing_owner => @authed_owner)
+ end
+
+ it "should not be reviewable by an Authorized Owner" do
+ @submittal.owner_reviewable?(@authed_owner).should be_false
+ end
+
+ it "should know that it has been reviewed" do
+ @submittal.owner_reviewed?.should be_true
+ end
+ end
+ end
+
+ describe " in a Job without an Authorized Owner" do
+ it "should not allow owner reviews" do
+ @submittal.owner_reviewable?(@employee).should be_false
+ end
+ end
+
end
\ No newline at end of file
diff --git a/spec/views/submittals/_submittal.html.haml_spec.rb b/spec/views/submittals/_submittal.html.haml_spec.rb
index 0fa58c6..a642d3c 100644
--- a/spec/views/submittals/_submittal.html.haml_spec.rb
+++ b/spec/views/submittals/_submittal.html.haml_spec.rb
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
describe "/submittals/_submittal.html.haml" do
before do
- @job = mock_model(Job, :is_fasttrack? => false, :bulletins => [], :submittals => [])
+ @job = mock_model(Job, :is_fasttrack? => false, :bulletins => [], :submittals => [], :has_authorized_owner? => false)
@spec_section = mock_model(SpecSection, :name => "foo")
@sub_response = mock_model(SubmittalResponse, :name => "foo", :created_at => Time.now)
@@ -119,4 +119,16 @@ describe "/submittals/_submittal.html.haml" do
end
end
+ describe " with a Job that has an Authorized Owner" do
+ before do
+ @job.stub!(:has_authorized_owner? => true)
+ @submittal.stub!(:owner_reviewed? => true)
+ end
+
+ it "should show the owner review table cell" do
+ do_get
+ response.should have_tag("td", "Reviewed")
+ end
+ end
+
end
\ No newline at end of file
diff --git a/spec/views/submittals/index.html.haml_spec.rb b/spec/views/submittals/index.html.haml_spec.rb
index ea7a945..f22fba7 100644
--- a/spec/views/submittals/index.html.haml_spec.rb
+++ b/spec/views/submittals/index.html.haml_spec.rb
@@ -5,17 +5,18 @@ describe "/submittals/index.html.haml" do
it_should_behave_like "it has the job_nav"
before do
- @job = mock_model(Job, :submittals => [])
+ @job = mock_model(Job, :submittals => [], :has_authorized_owner? => false)
@job.stub!(:submittals => [])
@job.stub!(:plain_display_name => "foo")
@job.stub!(:is_fasttrack? => false)
@job.stub!(:bulletins => [])
@submittal = Factory(:submittal, :job => @job)
- @employee = mock_model(User, :is_employee? => true)
+ @user = mock_model(User, :is_employee? => false)
assigns[:job] = @job
assigns[:submittals] = [@submittal]
+ assigns[:current_user] = @user
template.stub!(:render).with(:partial => "submittal", :collection => [@submittal])
template.stub!(:creatable => false)
@@ -28,7 +29,7 @@ describe "/submittals/index.html.haml" do
describe " when an employee is logged in" do
before do
- assigns[:current_user].stub!(:is_employee? => true)
+ @user.stub!(:is_employee? => true)
end
it "should have a sortable table" do
@@ -43,7 +44,7 @@ describe "/submittals/index.html.haml" do
with_tag("th", "Name")
with_tag("th", "Discipline")
with_tag("th", "Spec Section")
- with_tag("th", "Status")
+ with_tag("th", "Engineer Status")
with_tag("th", "Receiver")
with_tag("th", "Reviewer")
with_tag("th", "Received")
@@ -56,7 +57,7 @@ describe "/submittals/index.html.haml" do
describe " when a non-employee is logged in" do
before do
- assigns[:current_user].stub!(:is_employee? => false)
+ @user.stub!(:is_employee? => false)
end
it "should have a sortable table sans the Receiver & Due columns" do
@@ -66,7 +67,7 @@ describe "/submittals/index.html.haml" do
with_tag("th", "Name")
with_tag("th", "Discipline")
with_tag("th", "Spec Section")
- with_tag("th", "Status")
+ with_tag("th", "Engineer Status")
with_tag("th", "Reviewer")
with_tag("th", "Received")
with_tag("th", "Returned")
@@ -75,4 +76,15 @@ describe "/submittals/index.html.haml" do
end
end
+ describe " in a Job that has an Authorized Owner" do
+ before do
+ @job.stub!(:has_authorized_owner? => true)
+ end
+
+ it "should the owner review table header" do
+ do_get
+ response.should have_tag("th", "Owner Status")
+ end
+ end
+
end
\ No newline at end of file
diff --git a/spec/views/submittals/show.html.haml_spec.rb b/spec/views/submittals/show.html.haml_spec.rb
index 993ea4b..ed351f5 100644
--- a/spec/views/submittals/show.html.haml_spec.rb
+++ b/spec/views/submittals/show.html.haml_spec.rb
@@ -17,6 +17,9 @@ describe "/submittals/show.html.haml" do
@submittal.stub!(:response => nil)
@submittal.stub!(:is_updatable_by => false)
@submittal.stub!(:has_been_reviewed? => false)
+ @submittal.stub!(:owner_reviewable? => false)
+
+ @job.stub!(:has_authorized_owner? => false)
assigns[:job] = @job
assigns[:submittal] = @submittal
@@ -25,6 +28,7 @@ describe "/submittals/show.html.haml" do
assigns[:current_user].stub!(:is_admin? => false)
assigns[:current_user].stub!(:is_tim_allen? => false)
+ template.stub!(:owner_review_status)
template.stub!(:render).with(:partial => "submittal_responses/new")
template.stub!(:render).with(:partial => "attachments/index", :locals => {:obj => @submittal})
template.stub!(:render).with(:partial => "comments/index", :locals => {:obj => @submittal})
@@ -172,4 +176,44 @@ describe "/submittals/show.html.haml" do
end
+ describe "in a Job with an Authorized Owner" do
+ before do
+ @job.stub!(:has_authorized_owner? => true)
+ end
+
+ it "should shwo the Owner Review subsection" do
+ do_get
+ response.should have_tag("div[class=?]", "subsection_header")
+ end
+
+ it "should call the #owner_review_status helper" do
+ template.should_receive(:owner_review_status).with(@submittal)
+ do_get
+ end
+
+
+ describe " that has yet to be reviewed" do
+ before do
+ @submittal.stub!(:owner_reviewable? => true)
+ end
+
+ it "should show a review link" do
+ do_get
+ response.should have_tag("a[href=?]", owner_review_job_submittal_path(@job, @submittal))
+ end
+ end
+
+ describe " that has been reviewed" do
+ before do
+ @submittal.stub!(:owner_reviewable? => false)
+ end
+
+ it "should not show a review link" do
+ do_get
+ response.should_not have_tag("a[href=?]", owner_review_job_submittal_path(@job, @submittal))
+ end
+ end
+
+ end
+
end
\ No newline at end of file