You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

time_machine.html.erb 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <%
  2. # Retrieve widget settings
  3. metric_ids = []
  4. (1..10).each do |index|
  5. metric=widget_properties["metric#{index}"]
  6. if metric
  7. metric_ids << metric.id
  8. end
  9. end
  10. if metric_ids.empty?
  11. # No metric has been selected, it's the first time the widget is displayed: 'ncloc' is the default metric
  12. ncloc = Metric.find(:first, :conditions => "name = 'ncloc'")
  13. metric_ids << ncloc.id
  14. end
  15. numberOfColumns = widget_properties["numberOfColumns"].to_i == 0 ? 4 : widget_properties["numberOfColumns"].to_i
  16. displaySparkLine = widget_properties["displaySparkLine"]
  17. # Retrieve the measures for each metric on each snapshot
  18. options = {}
  19. from_date = dashboard_configuration.from_datetime
  20. if from_date
  21. options[:from] = from_date
  22. end
  23. snapshots=Snapshot.for_timemachine_widget(@resource, numberOfColumns, options)
  24. sids = snapshots.collect{|s| s.id}.uniq
  25. measures=ProjectMeasure.find(:all, :conditions => {:snapshot_id => sids, :metric_id => metric_ids})
  26. # And prepare the rows to display
  27. snapshot_by_id={}
  28. snapshots.each do |s|
  29. snapshot_by_id[s.id]=s
  30. end
  31. rows_by_metric_id={}
  32. measures.each do |measure|
  33. next unless measure.metric
  34. if measure.metric.timemachine? && (measure.value || measure.text_value)
  35. row=rows_by_metric_id[measure.metric_id]
  36. unless row
  37. row=Sonar::TimemachineRow.new(measure.metric)
  38. rows_by_metric_id[measure.metric_id]=row
  39. end
  40. #optimization : avoid eager loading of snapshots
  41. measure.snapshot=snapshot_by_id[measure.snapshot_id]
  42. row.add_measure(measure)
  43. end
  44. end
  45. # Create the list of rows to display in the same order as defined by the user
  46. rows=[]
  47. metric_ids.each do |metric_id|
  48. row = rows_by_metric_id[metric_id]
  49. if row
  50. rows<<row
  51. end
  52. end
  53. %>
  54. <div class="widget-matrix">
  55. <table class="data">
  56. <thead>
  57. <tr>
  58. <th> </th>
  59. <%
  60. snapshots.each do |snapshot|
  61. event = snapshot.event('Version')
  62. %>
  63. <th nowrap="nowrap" style="vertical-align:top">
  64. <%= l snapshot.created_at.to_date -%>
  65. <br/>
  66. <%= event.name unless event==nil -%>
  67. </th>
  68. <% end %>
  69. <% if displaySparkLine %>
  70. <th> </th>
  71. <% end %>
  72. </tr>
  73. </thead>
  74. <tbody>
  75. <%
  76. rows.select{|row| row.metric.val_type != Metric::VALUE_TYPE_DISTRIB}.each do |row|
  77. %>
  78. <tr class="<%= cycle 'even','odd' -%>">
  79. <td width="1%" nowrap="nowrap" class="left text">
  80. <%= row.metric.short_name %>
  81. </td>
  82. <%
  83. snapshots.each do |snapshot|
  84. measure=row.measure(snapshot)
  85. %>
  86. <td width="1%" nowrap="nowrap" class="right"><%= format_measure(measure, :skip_span_id => true) %></td>
  87. <% end %>
  88. <%
  89. sparkline_url=row.sparkline_url
  90. if displaySparkLine && sparkline_url
  91. %>
  92. <td width="1%" >
  93. <%= image_tag(sparkline_url) %>
  94. </td>
  95. <% end %>
  96. </tr>
  97. <% end %>
  98. </tbody>
  99. </table>
  100. </div>