Commit 653c0de31f784475e4d8695b7933f5c336b9b9f6

Authored by Nathan Broadbent
1 parent baef45e9
Exists in master and in 1 other branch production

Hide repo, tracker and deploy columns on apps#index page if no apps have any of those attributes

app/assets/stylesheets/errbit.css
... ... @@ -576,17 +576,15 @@ div.issue_tracker.nested label.r_on, div.issue_tracker.nested label.r_on:hover {
576 576 /* Apps Table */
577 577 table.apps tbody tr:hover td ,table.errs tbody tr:hover td { background-color: #F2F2F2;}
578 578  
579   -table.apps td.name, table.errs td.message {
580   - width: 100%;
581   -}
582   -table.apps td {
583   - padding-top: 16px;
584   - padding-bottom: 16px;
  579 +table.apps td.name, table.errs td.message { width: 100%; }
  580 +table.apps td { padding: 16px 25px; }
  581 +table.apps th { padding: 10px 25px; }
  582 +
  583 +table.apps td.issue_tracker, table.apps td.count, table.apps td.deploy {
  584 + text-align: center;
585 585 }
586 586 table.apps td.issue_tracker, table.apps td.count {
587   - padding-top: 10px;
588   - padding-bottom: 10px;
589   - text-align: center;
  587 + padding: 10px 8px;
590 588 }
591 589 table.apps td.issue_tracker img { vertical-align: top; }
592 590  
... ...
app/controllers/apps_controller.rb
... ... @@ -8,10 +8,10 @@ class AppsController < InheritedResources::Base
8 8 format.html do
9 9 @all_errs = !!params[:all_errs]
10 10  
11   - @sort = params[:sort]
  11 + @sort = params[:sort]
12 12 @order = params[:order]
13   - @sort = "last_notice_at" unless %w{message app last_deploy_at count}.member?(@sort)
14   - @order = "desc" unless (@order == "asc")
  13 + @sort = "last_notice_at" unless %w{message app last_deploy_at last_notice_at count}.member?(@sort)
  14 + @order = "desc" unless %w{asc desc}.member?(@order)
15 15  
16 16 @problems = resource.problems
17 17 @problems = @problems.unresolved unless @all_errs
... ... @@ -52,10 +52,14 @@ class AppsController < InheritedResources::Base
52 52 def collection
53 53 # Sort apps by number of unresolved errs, descending.
54 54 # Caches the unresolved err counts while performing the sort.
55   - @unresolved_counts = {}
  55 + @unresolved_counts, @problem_counts = {}, {}
56 56 @apps ||= end_of_association_chain.all.sort{|a,b|
57   - [a,b].each{|app| @unresolved_counts[app.id] ||= app.problems.unresolved.count }
58   - @unresolved_counts[b.id] <=> @unresolved_counts[a.id]
  57 + [a,b].each do |app|
  58 + @unresolved_counts[app.id] ||= app.problems.unresolved.count
  59 + @problem_counts[app.id] ||= app.problems.count
  60 + end
  61 + unresolved = @unresolved_counts[b.id] <=> @unresolved_counts[a.id]
  62 + unresolved != 0 ? unresolved : @problem_counts[b.id] <=> @problem_counts[a.id]
59 63 }
60 64 end
61 65  
... ...
app/helpers/apps_helper.rb
... ... @@ -10,5 +10,31 @@ module AppsHelper
10 10 return html
11 11 end
12 12 end
  13 +
  14 + def any_github_repos?
  15 + detect_any_apps_with_attributes unless @any_github_repos
  16 + @any_github_repos
  17 + end
  18 +
  19 + def any_issue_trackers?
  20 + detect_any_apps_with_attributes unless @any_issue_trackers
  21 + @any_issue_trackers
  22 + end
  23 +
  24 + def any_deploys?
  25 + detect_any_apps_with_attributes unless @any_deploys
  26 + @any_deploys
  27 + end
  28 +
  29 + private
  30 +
  31 + def detect_any_apps_with_attributes
  32 + @any_github_repos = @any_issue_trackers = @any_deploys = false
  33 + @apps.each do |app|
  34 + @any_github_repos ||= app.github_repo?
  35 + @any_issue_trackers ||= app.issue_tracker_configured?
  36 + @any_deploys ||= !!app.last_deploy_at
  37 + end
  38 + end
13 39 end
14 40  
... ...
app/views/apps/index.html.haml
... ... @@ -2,43 +2,42 @@
2 2 - content_for :action_bar do
3 3 %span= link_to('Add a New App', new_app_path, :class => 'add') if current_user.admin?
4 4  
5   -- any_github_repos = @apps.any? {|a| a.github_repo? }
6   -- any_issue_trackers = @apps.any? {|a| a.issue_tracker_configured? }
7   -
8 5 %table.apps
9 6 %thead
10 7 %tr
11 8 %th Name
12   - - if any_github_repos
  9 + - if any_github_repos?
13 10 %th GitHub Repo
14   - - if any_issue_trackers
  11 + - if any_issue_trackers?
15 12 %th Tracker
16   - %th Last Deploy
  13 + - if any_deploys?
  14 + %th Last Deploy
17 15 %th Errors
18 16 %tbody
19 17 - @apps.each do |app|
20 18 %tr
21 19 %td.name= link_to app.name, app_path(app)
22   - - if any_github_repos
  20 + - if any_github_repos?
23 21 %td.github_repo
24 22 - if app.github_repo?
25 23 = link_to(app.github_repo, app.github_url, :target => '_blank')
26   - - if any_issue_trackers
  24 + - if any_issue_trackers?
27 25 %td.issue_tracker
28 26 - if app.issue_tracker_configured?
29   - = image_tag("#{app.issue_tracker.class::Label}_create.png")
30   - %td.deploy
31   - - if app.last_deploy_at
32   - - revision = app.deploys.last.short_revision
33   - = link_to( app.last_deploy_at.to_s(:micro) << (revision.present? ? " (#{revision})" : ""), app_deploys_path(app))
34   - - else
35   - n/a
  27 + - tracker_img = image_tag("#{app.issue_tracker.class::Label}_goto.png")
  28 + - if app.issue_tracker.url
  29 + = link_to( tracker_img, app.issue_tracker.url )
  30 + - else
  31 + = tracker_img
  32 + - if any_deploys?
  33 + %td.deploy
  34 + - if app.last_deploy_at
  35 + - revision = app.deploys.last.short_revision
  36 + = link_to( app.last_deploy_at.to_s(:micro) << (revision.present? ? " (#{revision})" : ""), app_deploys_path(app))
36 37 %td.count
37   - - if app.problems.count > 0
  38 + - if @problem_counts[app.id] > 0
38 39 - unresolved = @unresolved_counts[app.id] || app.problems.unresolved.count
39 40 = link_to unresolved, app_path(app), :class => (unresolved == 0 ? "resolved" : nil)
40   - - else
41   - \-
42 41 - if @apps.none?
43 42 %tr
44 43 %td{:colspan => 3}
... ...