From 653c0de31f784475e4d8695b7933f5c336b9b9f6 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sun, 3 Jun 2012 15:47:22 +1200 Subject: [PATCH] Hide repo, tracker and deploy columns on apps#index page if no apps have any of those attributes --- app/assets/stylesheets/errbit.css | 16 +++++++--------- app/controllers/apps_controller.rb | 16 ++++++++++------ app/helpers/apps_helper.rb | 26 ++++++++++++++++++++++++++ app/views/apps/index.html.haml | 35 +++++++++++++++++------------------ 4 files changed, 60 insertions(+), 33 deletions(-) diff --git a/app/assets/stylesheets/errbit.css b/app/assets/stylesheets/errbit.css index 4c45ebf..bc6cfb2 100644 --- a/app/assets/stylesheets/errbit.css +++ b/app/assets/stylesheets/errbit.css @@ -576,17 +576,15 @@ div.issue_tracker.nested label.r_on, div.issue_tracker.nested label.r_on:hover { /* Apps Table */ table.apps tbody tr:hover td ,table.errs tbody tr:hover td { background-color: #F2F2F2;} -table.apps td.name, table.errs td.message { - width: 100%; -} -table.apps td { - padding-top: 16px; - padding-bottom: 16px; +table.apps td.name, table.errs td.message { width: 100%; } +table.apps td { padding: 16px 25px; } +table.apps th { padding: 10px 25px; } + +table.apps td.issue_tracker, table.apps td.count, table.apps td.deploy { + text-align: center; } table.apps td.issue_tracker, table.apps td.count { - padding-top: 10px; - padding-bottom: 10px; - text-align: center; + padding: 10px 8px; } table.apps td.issue_tracker img { vertical-align: top; } diff --git a/app/controllers/apps_controller.rb b/app/controllers/apps_controller.rb index db96bdd..4fb7e8c 100644 --- a/app/controllers/apps_controller.rb +++ b/app/controllers/apps_controller.rb @@ -8,10 +8,10 @@ class AppsController < InheritedResources::Base format.html do @all_errs = !!params[:all_errs] - @sort = params[:sort] + @sort = params[:sort] @order = params[:order] - @sort = "last_notice_at" unless %w{message app last_deploy_at count}.member?(@sort) - @order = "desc" unless (@order == "asc") + @sort = "last_notice_at" unless %w{message app last_deploy_at last_notice_at count}.member?(@sort) + @order = "desc" unless %w{asc desc}.member?(@order) @problems = resource.problems @problems = @problems.unresolved unless @all_errs @@ -52,10 +52,14 @@ class AppsController < InheritedResources::Base def collection # Sort apps by number of unresolved errs, descending. # Caches the unresolved err counts while performing the sort. - @unresolved_counts = {} + @unresolved_counts, @problem_counts = {}, {} @apps ||= end_of_association_chain.all.sort{|a,b| - [a,b].each{|app| @unresolved_counts[app.id] ||= app.problems.unresolved.count } - @unresolved_counts[b.id] <=> @unresolved_counts[a.id] + [a,b].each do |app| + @unresolved_counts[app.id] ||= app.problems.unresolved.count + @problem_counts[app.id] ||= app.problems.count + end + unresolved = @unresolved_counts[b.id] <=> @unresolved_counts[a.id] + unresolved != 0 ? unresolved : @problem_counts[b.id] <=> @problem_counts[a.id] } end diff --git a/app/helpers/apps_helper.rb b/app/helpers/apps_helper.rb index 789ae38..c9ed6d2 100644 --- a/app/helpers/apps_helper.rb +++ b/app/helpers/apps_helper.rb @@ -10,5 +10,31 @@ module AppsHelper return html end end + + def any_github_repos? + detect_any_apps_with_attributes unless @any_github_repos + @any_github_repos + end + + def any_issue_trackers? + detect_any_apps_with_attributes unless @any_issue_trackers + @any_issue_trackers + end + + def any_deploys? + detect_any_apps_with_attributes unless @any_deploys + @any_deploys + end + + private + + def detect_any_apps_with_attributes + @any_github_repos = @any_issue_trackers = @any_deploys = false + @apps.each do |app| + @any_github_repos ||= app.github_repo? + @any_issue_trackers ||= app.issue_tracker_configured? + @any_deploys ||= !!app.last_deploy_at + end + end end diff --git a/app/views/apps/index.html.haml b/app/views/apps/index.html.haml index 25e423a..dc9923b 100644 --- a/app/views/apps/index.html.haml +++ b/app/views/apps/index.html.haml @@ -2,43 +2,42 @@ - content_for :action_bar do %span= link_to('Add a New App', new_app_path, :class => 'add') if current_user.admin? -- any_github_repos = @apps.any? {|a| a.github_repo? } -- any_issue_trackers = @apps.any? {|a| a.issue_tracker_configured? } - %table.apps %thead %tr %th Name - - if any_github_repos + - if any_github_repos? %th GitHub Repo - - if any_issue_trackers + - if any_issue_trackers? %th Tracker - %th Last Deploy + - if any_deploys? + %th Last Deploy %th Errors %tbody - @apps.each do |app| %tr %td.name= link_to app.name, app_path(app) - - if any_github_repos + - if any_github_repos? %td.github_repo - if app.github_repo? = link_to(app.github_repo, app.github_url, :target => '_blank') - - if any_issue_trackers + - if any_issue_trackers? %td.issue_tracker - if app.issue_tracker_configured? - = image_tag("#{app.issue_tracker.class::Label}_create.png") - %td.deploy - - if app.last_deploy_at - - revision = app.deploys.last.short_revision - = link_to( app.last_deploy_at.to_s(:micro) << (revision.present? ? " (#{revision})" : ""), app_deploys_path(app)) - - else - n/a + - tracker_img = image_tag("#{app.issue_tracker.class::Label}_goto.png") + - if app.issue_tracker.url + = link_to( tracker_img, app.issue_tracker.url ) + - else + = tracker_img + - if any_deploys? + %td.deploy + - if app.last_deploy_at + - revision = app.deploys.last.short_revision + = link_to( app.last_deploy_at.to_s(:micro) << (revision.present? ? " (#{revision})" : ""), app_deploys_path(app)) %td.count - - if app.problems.count > 0 + - if @problem_counts[app.id] > 0 - unresolved = @unresolved_counts[app.id] || app.problems.unresolved.count = link_to unresolved, app_path(app), :class => (unresolved == 0 ? "resolved" : nil) - - else - \- - if @apps.none? %tr %td{:colspan => 3} -- libgit2 0.21.2