| 1 | package DMOSS::Report::HTML; | ||
| 2 | $DMOSS::Report::HTML::VERSION = '0.01_2'; | ||
| 3 | # ABSTRACT: DMOSS HTML report generator | ||
| 4 | use parent qw/DMOSS::Report/; | ||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | sub make_title { | ||
| 9 | my ($self, $plugin, $grade) = (@_); | ||
| 10 | my $name = $plugin->name; | ||
| 11 | my $tag = lc $name; | ||
| 12 | $tag =~ s/\W+/_/g; | ||
| 13 | my $icon = $self->icon($grade); | ||
| 14 | |||
| 15 | my $html =<<"HTML"; | ||
| 16 | <div onclick="javascript: show('#$tag');" style="cursor: pointer;" class="panel-heading"> | ||
| 17 | <div class="panel-title" style="font-size: 22px;"> | ||
| 18 | <i alt="Grade $grade" title="Grade $grade" class="wi-$icon"></i> | ||
| 19 | <span style="padding-left: 15px;">$name</span> | ||
| 20 | <span id="${tag}_icon" class="glyphicon glyphicon-chevron-down pull-right" style="padding-top: 5px;"></span> | ||
| 21 | </div> | ||
| 22 | </div> | ||
| 23 | HTML | ||
| 24 | |||
| 25 | return $html; | ||
| 26 | } | ||
| 27 | |||
| 28 | sub make_plugin_box { | ||
| 29 | my ($self, $content, $grade) = @_; | ||
| 30 | my $class = $self->css_class($grade); | ||
| 31 | |||
| 32 | my $html=<<"HTML"; | ||
| 33 | <div class="panel panel-$class"> | ||
| 34 | $content | ||
| 35 | </div> | ||
| 36 | HTML | ||
| 37 | |||
| 38 | return $html; | ||
| 39 | } | ||
| 40 | |||
| 41 | sub make_more_info { | ||
| 42 | my ($self, $plugin, @results) = @_; | ||
| 43 | my $all = join("\n", @results); | ||
| 44 | my $name = $plugin->name; | ||
| 45 | my $tag = lc $name; | ||
| 46 | $tag =~ s/\W+/_/g; | ||
| 47 | |||
| 48 | my @headers = @{ $plugin->report_headers or [] }; | ||
| 49 | my $hdr = ''; # FIXME better default | ||
| 50 | if (@headers) { | ||
| 51 | $hdr = '<tr><th>'.join('</th><th>',@headers).'</th></tr>'; | ||
| 52 | } | ||
| 53 | |||
| 54 | my $html=<<"HTML"; | ||
| 55 | <div id="$tag" class="panel-body hidden"> | ||
| 56 | <table class="table table-condensed table-hover"> | ||
| 57 | $hdr | ||
| 58 | $all | ||
| 59 | </table> | ||
| 60 | </div> | ||
| 61 | HTML | ||
| 62 | |||
| 63 | return $html; | ||
| 64 | } | ||
| 65 | |||
| 66 | sub make_row { | ||
| 67 | my ($self, @values) = @_; | ||
| 68 | $values[0] = $self->dmoss->{meta}->{dist} unless $values[0]; | ||
| 69 | |||
| 70 | return("<tr><td>".join('</td><td>', @values)."</td></tr>"); | ||
| 71 | } | ||
| 72 | |||
| 73 | sub start_report { | ||
| 74 | my ($self) = @_; | ||
| 75 | my $dist = $self->dmoss->{meta}->{dist}; | ||
| 76 | |||
| 77 | my $html =<<"HTML"; | ||
| 78 | <!DOCTYPE HTML> | ||
| 79 | <html> | ||
| 80 | <head> | ||
| 81 | <meta charset="UTF-8"> | ||
| 82 | <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css"> | ||
| 83 | <link rel="stylesheet" href="http://eremita.di.uminho.pt/~nrc/weather/weather-icons.css"> | ||
| 84 | <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script> | ||
| 85 | <script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script> | ||
| 86 | <title>DMOSS Report - $dist</title> | ||
| 87 | <style>#wrapper { margin: auto; width: 70%; }</style> | ||
| 88 | </head> | ||
| 89 | <body> | ||
| 90 | <div id="wrapper"> | ||
| 91 | <div class="page-header"> | ||
| 92 | <h1>DMOSS Report <small>$dist</small></h1> | ||
| 93 | </div> | ||
| 94 | HTML | ||
| 95 | return $html; | ||
| 96 | } | ||
| 97 | |||
| 98 | sub end_report { | ||
| 99 | my $html =<<'HTML'; | ||
| 100 | </div> | ||
| 101 | <script type="text/javascript"> | ||
| 102 | function show(id) { | ||
| 103 | if ( $(id).hasClass('hidden') ) { | ||
| 104 | $(id).removeClass('hidden'); | ||
| 105 | $(id+'_icon').removeClass('glyphicon-chevron-down'); | ||
| 106 | $(id+'_icon').addClass('glyphicon-chevron-up'); | ||
| 107 | } | ||
| 108 | else { | ||
| 109 | $(id).addClass('hidden'); | ||
| 110 | $(id+'_icon').removeClass('glyphicon-chevron-up'); | ||
| 111 | $(id+'_icon').addClass('glyphicon-chevron-down'); | ||
| 112 | } | ||
| 113 | } | ||
| 114 | </script> | ||
| 115 | </body> | ||
| 116 | </html> | ||
| 117 | HTML | ||
| 118 | return $html; | ||
| 119 | } | ||
| 120 | |||
| 121 | sub css_class { | ||
| 122 | my ($self, $grade) = @_; | ||
| 123 | |||
| 124 | return 'success' if ($grade eq 'A' or $grade eq 'B'); | ||
| 125 | #return 'info' if ($grade eq 'B'); | ||
| 126 | return 'warning' if ($grade eq 'C' or $grade eq 'D' or $grade eq 'E'); | ||
| 127 | return 'danger'; | ||
| 128 | } | ||
| 129 | |||
| 130 | sub icon { | ||
| 131 | my ($self, $grade) = @_; | ||
| 132 | |||
| 133 | return 'day-sunny' if ($grade eq 'A'); | ||
| 134 | return 'day-cloudy' if ($grade eq 'B'); | ||
| 135 | return 'cloudy' if ($grade eq 'C'); | ||
| 136 | return 'cloudy' if ($grade eq 'D'); | ||
| 137 | return 'cloudy' if ($grade eq 'E'); | ||
| 138 | return 'rain' if ($grade eq 'F'); | ||
| 139 | |||
| 140 | return 'unk'; | ||
| 141 | } | ||
| 142 | |||
| 143 | 1; | ||
| 144 | |||
| 145 | __END__ |