123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <%
- # Retrieve widget settings
- metric_ids = []
- (1..10).each do |index|
- metric=widget_properties["metric#{index}"]
- if metric
- metric_ids << metric.id
- end
- end
- if metric_ids.empty?
- # No metric has been selected, it's the first time the widget is displayed: 'ncloc' is the default metric
- ncloc = Metric.find(:first, :conditions => "name = 'ncloc'")
- metric_ids << ncloc.id
- end
- numberOfColumns = widget_properties["numberOfColumns"].to_i == 0 ? 4 : widget_properties["numberOfColumns"].to_i
- displaySparkLine = widget_properties["displaySparkLine"]
-
- # Retrieve the measures for each metric on each snapshot
- options = {}
- from_date = dashboard_configuration.from_datetime
- if from_date
- options[:from] = from_date
- end
- snapshots=Snapshot.for_timemachine_widget(@resource, numberOfColumns, options)
- sids = snapshots.collect{|s| s.id}.uniq
- measures=ProjectMeasure.find(:all, :conditions => {:snapshot_id => sids, :metric_id => metric_ids})
-
- # And prepare the rows to display
- snapshot_by_id={}
- snapshots.each do |s|
- snapshot_by_id[s.id]=s
- end
- rows_by_metric_id={}
- measures.each do |measure|
- next unless measure.metric
-
- if measure.metric.timemachine? && (measure.value || measure.text_value)
- row=rows_by_metric_id[measure.metric_id]
- unless row
- row=Sonar::TimemachineRow.new(measure.metric)
- rows_by_metric_id[measure.metric_id]=row
- end
-
- #optimization : avoid eager loading of snapshots
- measure.snapshot=snapshot_by_id[measure.snapshot_id]
- row.add_measure(measure)
- end
- end
-
- # Create the list of rows to display in the same order as defined by the user
- rows=[]
- metric_ids.each do |metric_id|
- row = rows_by_metric_id[metric_id]
- if row
- rows<<row
- end
- end
- %>
-
- <div class="widget-matrix">
-
- <table class="data">
-
- <thead>
- <tr>
- <th> </th>
- <%
- snapshots.each do |snapshot|
- event = snapshot.event('Version')
- %>
- <th nowrap="nowrap" style="vertical-align:top">
- <%= l snapshot.created_at.to_date -%>
- <br/>
- <%= event.name unless event==nil -%>
- </th>
- <% end %>
- <% if displaySparkLine %>
- <th> </th>
- <% end %>
- </tr>
- </thead>
-
- <tbody>
- <%
- rows.select{|row| row.metric.val_type != Metric::VALUE_TYPE_DISTRIB}.each do |row|
- %>
- <tr class="<%= cycle 'even','odd' -%>">
- <td width="1%" nowrap="nowrap" class="left text">
- <%= row.metric.short_name %>
- </td>
- <%
- snapshots.each do |snapshot|
- measure=row.measure(snapshot)
- %>
- <td width="1%" nowrap="nowrap" class="right"><%= format_measure(measure, :skip_span_id => true) %></td>
- <% end %>
- <%
- sparkline_url=row.sparkline_url
- if displaySparkLine && sparkline_url
- %>
- <td width="1%" >
- <%= image_tag(sparkline_url) %>
- </td>
- <% end %>
- </tr>
- <% end %>
- </tbody>
-
- </table>
-
- </div>
|