The report view is now composed entirely of widgets that register themselves using the plug-in registry. This will allow future plug-ins to add themselves at any point in the view.
Paired-with: Nick Lewis <[email protected]> Signed-off-by: Paul Berry <[email protected]> --- Local-branch: maint/next/refactor_report_view app/views/reports/_log.html.haml | 18 +++++++ app/views/reports/_metrics.html.haml | 10 ++++ app/views/reports/_report.html.haml | 64 +++-------------------- app/views/reports/_resource_statuses.html.haml | 25 +++++++++ lib/core_callbacks.rb | 14 +++++ 5 files changed, 76 insertions(+), 55 deletions(-) create mode 100644 app/views/reports/_log.html.haml create mode 100644 app/views/reports/_metrics.html.haml create mode 100644 app/views/reports/_resource_statuses.html.haml diff --git a/app/views/reports/_log.html.haml b/app/views/reports/_log.html.haml new file mode 100644 index 0000000..9c814a8 --- /dev/null +++ b/app/views/reports/_log.html.haml @@ -0,0 +1,18 @@ +.section + %h3 Log + .section + %table.inspector + %thead + %tr + %th Level + %th Message + %th Source + %th File + %th Line + %th Time + %tbody + - if report.logs.present? + = render :partial => 'puppet/util/logs/log', :collection => puppet_log_sorter(report.logs.compact) + - else + %td.empty{:colspan => 6} + = describe_no_matches_for 'log messages', :report diff --git a/app/views/reports/_metrics.html.haml b/app/views/reports/_metrics.html.haml new file mode 100644 index 0000000..5430a1e --- /dev/null +++ b/app/views/reports/_metrics.html.haml @@ -0,0 +1,10 @@ +.section + %h3 Metrics + - if report.metrics.present? + - report.metrics.group_by(&:category).sort.each do |category, metrics_in_category| + .section + %h4= category.titleize + %table.inspector + = render :partial => 'metrics/metrics_table', :locals => {:metrics => metrics_in_category} + - else + — No metrics in this report — diff --git a/app/views/reports/_report.html.haml b/app/views/reports/_report.html.haml index 41b539d..5a3fc77 100644 --- a/app/views/reports/_report.html.haml +++ b/app/views/reports/_report.html.haml @@ -8,58 +8,12 @@ %li= link_to 'Destroy', report, :confirm => 'Are you sure?', :method => :delete, :class => "delete button" .item - - Registry.each_callback :core, :report_view_widgets do |thing| - = thing.call self, report - - if report.resource_statuses.present? - .section - %h3 - Events - %a{ :href => '#', :class => 'expand-all' } (expand all) - .section - %dl.expandable-list - - report.resource_statuses.sort_by(&:time).each_with_index do |status, index| - %dt{:class => cycle( 'odd', 'even' )} - %div.expandable-list-item - - if status.events.empty? - %span{:class => 'non-expandable-bullet'}= status.name - - else - = link_to h(status.name), {}, {:class => 'expandable-link collapsed-link', :id => "expand-#{index}"} - - if status.file or status.line - = "(#{status.file}:#{status.line})" - %dd.expandable.collapsed{:id => "expandable-#{index}"} - %table - %tr - %th Property - %th Message - - status.events.each do |event| - %tr{:class => "status #{event.status}"} - %td= event.property - %td= popup_md5s( h event.message ) - .section - %h3 Log - .section - %table.inspector - %thead - %tr - %th Level - %th Message - %th Source - %th File - %th Line - %th Time - %tbody - - if report.logs.present? - = render :partial => 'puppet/util/logs/log', :collection => puppet_log_sorter(report.logs.compact) - - else - %td.empty{:colspan => 6} - = describe_no_matches_for 'log messages', :report - .section - %h3 Metrics - - if report.metrics.present? - - report.metrics.group_by(&:category).sort.each do |category, metrics_in_category| - .section - %h4= category.titleize - %table.inspector - = render :partial => 'metrics/metrics_table', :locals => {:metrics => metrics_in_category} - - else - — No metrics in this report — + - Registry.each_callback :core, :report_view_widgets do |widget| + = widget.call self, report + - # 500_baseline + + - # 600_resource_statuses + + - # 700_log + + - # 800_metrics diff --git a/app/views/reports/_resource_statuses.html.haml b/app/views/reports/_resource_statuses.html.haml new file mode 100644 index 0000000..f828596 --- /dev/null +++ b/app/views/reports/_resource_statuses.html.haml @@ -0,0 +1,25 @@ +- if report.resource_statuses.present? + .section + %h3 + Events + %a{ :href => '#', :class => 'expand-all' } (expand all) + .section + %dl.expandable-list + - report.resource_statuses.sort_by(&:time).each_with_index do |status, index| + %dt{:class => cycle( 'odd', 'even' )} + %div.expandable-list-item + - if status.events.empty? + %span{:class => 'non-expandable-bullet'}= status.name + - else + = link_to h(status.name), {}, {:class => 'expandable-link collapsed-link', :id => "expand-#{index}"} + - if status.file or status.line + = "(#{status.file}:#{status.line})" + %dd.expandable.collapsed{:id => "expandable-#{index}"} + %table + %tr + %th Property + %th Message + - status.events.each do |event| + %tr{:class => "status #{event.status}"} + %td= event.property + %td= popup_md5s( h event.message ) diff --git a/lib/core_callbacks.rb b/lib/core_callbacks.rb index bb7eda4..a575af1 100644 --- a/lib/core_callbacks.rb +++ b/lib/core_callbacks.rb @@ -1,3 +1,4 @@ +# Node view widgets Registry.add_callback :core, :node_view_widgets, "100_description" do |view_renderer, node| view_renderer.render 'nodes/description', :node => node end @@ -21,3 +22,16 @@ end Registry.add_callback :core, :node_view_widgets, "700_activity" do |view_renderer, node| view_renderer.render 'nodes/activity', :node => node end + +# Report view widgets +Registry.add_callback :core, :report_view_widgets, "600_resource_statuses" do |view_renderer, report| + view_renderer.render 'reports/resource_statuses', :report => report +end + +Registry.add_callback :core, :report_view_widgets, "700_log" do |view_renderer, report| + view_renderer.render 'reports/log', :report => report +end + +Registry.add_callback :core, :report_view_widgets, "800_metrics" do |view_renderer, report| + view_renderer.render 'reports/metrics', :report => report +end -- 1.7.2 -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
