Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Filter Reports (index page) by status #112

Merged
merged 1 commit into from Dec 19, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/controllers/reports_controller.rb
Expand Up @@ -13,12 +13,21 @@ def index
if params[:kind] == "inspect"
@reports = paginate_scope Report.inspections
else
@controller_action = 'all'
@reports = paginate_scope Report.applies
end
end
end
end

[:all, :failed, :changed, :unchanged, :pending].each do |action|
define_method(action) {
@reports = paginate_scope Report.send(action)
@controller_action = action.to_s
render :index
}
end

def create
if SETTINGS.disable_legacy_report_upload_url
render :text => "Access Denied, this url has been disabled, try /reports/upload", :status => 403
Expand Down
9 changes: 7 additions & 2 deletions app/models/report.rb
Expand Up @@ -20,8 +20,13 @@ def self.per_page; SETTINGS.reports_per_page end # Pagination

default_scope :order => 'time DESC', :include => :node

named_scope :inspections, :conditions => {:kind => "inspect"}, :include => :metrics
named_scope :applies, :conditions => {:kind => "apply" }, :include => :metrics
named_scope :inspections, :conditions => {:kind => "inspect" }, :include => :metrics
named_scope :applies, :conditions => {:kind => "apply" }, :include => :metrics
named_scope :all, :conditions => {:kind => "apply" }, :include => :metrics
named_scope :changed, :conditions => {:kind => "apply", :status => 'changed' }, :include => :metrics
named_scope :unchanged, :conditions => {:kind => "apply", :status => 'unchanged' }, :include => :metrics
named_scope :failed, :conditions => {:kind => "apply", :status => 'failed' }, :include => :metrics
named_scope :pending, :conditions => {:kind => "apply", :status => 'pending' }, :include => :metrics

def total_resources
metric_value("resources", "total")
Expand Down
5 changes: 5 additions & 0 deletions app/views/reports/index.html.haml
@@ -1,3 +1,4 @@
- tab_statuses = Node.possible_statuses.unshift("all")
#sidebar= render 'shared/node_manager_sidebar'
#main
.header
Expand All @@ -9,4 +10,8 @@
%span.count== (#{@reports.total_entries})

.item
%ul#report-tabs.tabbed
- tab_statuses.each do |tab_status|
%li{:id => "#{tab_status}-tab", :class => (tab_status == @controller_action ? 'active' : '') }
%a{:href => "/reports/#{tab_status}"}= h tab_status.humanize
= render 'reports/reports_table', :reports => @reports, :node => @node
7 changes: 6 additions & 1 deletion config/routes.rb
Expand Up @@ -28,7 +28,12 @@

map.resources :reports,
:collection => {
:search => :get,
:search => :get,
:all => :get,
:failed => :get,
:pending => :get,
:changed => :get,
:unchanged => :get
}

map.resources :node_group_memberships, :as => :memberships
Expand Down
81 changes: 80 additions & 1 deletion spec/controllers/reports_controller_spec.rb
Expand Up @@ -5,6 +5,10 @@
describe ReportsController do
before :each do
@yaml = File.read(Rails.root.join('spec', 'fixtures', 'sample_report.yml'))
@failed = Report.create!(:host => "failed", :time => 1.week.ago.to_date, :status => "failed", :kind => "apply")
@unchanged = Report.create!(:host => "unchanged", :time => 1.week.ago.to_date, :status => "unchanged", :kind => "apply")
@pending = Report.create!(:host => "pending", :time => 1.week.ago.to_date, :status => "pending", :kind => "apply")
@changed = Report.create!(:host => "changed", :time => 1.week.ago.to_date, :status => "changed", :kind => "apply")
end

def model; Report end
Expand Down Expand Up @@ -86,6 +90,82 @@ def model; Report end
end
end

describe "#index" do
it "should render the index template and show all reports" do
get('index')
response.code.should == '200'
response.should render_template("reports/index")
assigns[:controller_action].should == 'all'
assigns[:reports].should include @failed
assigns[:reports].should include @pending
assigns[:reports].should include @changed
assigns[:reports].should include @unchanged
end
end

describe "#all" do
it "should render the index template and show all reports" do
get('all')
response.code.should == '200'
response.should render_template("reports/index")
assigns[:controller_action].should == 'all'
assigns[:reports].should include @failed
assigns[:reports].should include @pending
assigns[:reports].should include @changed
assigns[:reports].should include @unchanged
end
end

describe "#failed" do
it "should render the index template and show only failed reports" do
get('failed')
response.code.should == '200'
response.should render_template("reports/index")
assigns[:controller_action].should == 'failed'
assigns[:reports].should include @failed
assigns[:reports].should_not include @pending
assigns[:reports].should_not include @changed
assigns[:reports].should_not include @unchanged
end
end
describe "#pending" do
it "should render the index template and show only pending reports" do
get('pending')
response.code.should == '200'
response.should render_template("reports/index")
assigns[:controller_action].should == 'pending'
assigns[:reports].should_not include @failed
assigns[:reports].should include @pending
assigns[:reports].should_not include @changed
assigns[:reports].should_not include @unchanged
end
end
describe "#changed" do
it "should render the index template and show only changed reports" do
get('changed')
response.code.should == '200'
response.should render_template("reports/index")
assigns[:controller_action].should == 'changed'
assigns[:reports].should_not include @failed
assigns[:reports].should_not include @pending
assigns[:reports].should include @changed
assigns[:reports].should_not include @unchanged
end
end

describe "#unchanged" do
it "should render the index template and show only unchanged reports" do
get('unchanged')
response.code.should == '200'
response.should render_template("reports/index")
assigns[:controller_action].should == 'unchanged'
assigns[:reports].should_not include @failed
assigns[:reports].should_not include @pending
assigns[:reports].should_not include @changed
assigns[:reports].should include @unchanged
end
end

describe "#search" do
it "should render the search form if there are no parameters" do
get('search')
Expand Down Expand Up @@ -153,5 +233,4 @@ def post_with_body(action, body, headers)
@request.env.delete('RAW_POST_DATA')
response
end

end