class ComparisonController < ApplicationController
SECTION=Navigation::SECTION_HOME
-
+
def index
snapshots = []
resource_key = params[:resource]
project = Project.by_key(resource_key)
return render_not_found('Project not found') unless project
- snapshots = project.events.select { |event| !event.snapshot_id.nil? && event.category==EventCategory::KEY_VERSION }[0..5].reverse.map {|e| e.snapshot}
+ snapshots = project.events.select { |event| !event.snapshot.nil? && event.category==EventCategory::KEY_VERSION }[0..5].reverse.map {|e| e.snapshot}
# if last snapshot is not in the list, add it at the end (=> might be the case for views or developers which do not have events)
last_snapshot = project.last_snapshot
unless snapshots.last == last_snapshot
sids.each do |id|
selected_snapshots.each do |s|
snapshots << s if id==s.id.to_s
- end
+ end
end
end
- end
+ end
@snapshots = select_authorized(:user, snapshots)
-
+
metrics = get_params_as_array(:metrics)
if metrics.empty?
- metrics = [
+ metrics = [
'ncloc',
'complexity',
'comment_lines_density',
]
end
@metrics = Metric.by_keys(metrics)
-
+
@metric_to_choose = Metric.all.select {|m| m.display? && !m.on_new_code? && !@metrics.include?(m)}.sort_by(&:short_name)
end
-
+
def versions
key = params[:resource]
sids = get_params_as_array(:sids)
-
+
unless key.blank?
resource = Project.by_key(params[:resource])
-
+
# we look for the events that are versions and that are not linked to snapshots already displayed on the page
@versions = resource.events.select { |event| !event.snapshot_id.nil? && event.category==EventCategory::KEY_VERSION && !sids.include?(event.snapshot_id.to_s) }
-
+
# check if the latest snapshot if suggested or not (and if not, suggest it as "LATEST" => this is used for views or developers which do not have events)
latest_snapshot_id = resource.last_snapshot.id
current_and_suggested_sids = sids + @versions.map {|e| e.snapshot_id.to_s}
@versions.unshift Event.new(:name => Api::Utils.message('comparison.version.latest'), :snapshot_id => latest_snapshot_id)
end
end
-
+
render :partial => 'versions'
end
-
+
private
-
+
def get_params_as_array(name)
list = params[name]
if list.blank?
});
</script>
</div>
-
+
<div id="resource_div" style="display: inline-block; margin-left: 30px">
<%= resource_select_tag 'new_resource', {
:resource_type_property => 'comparable',
});
</script>
</div>
-
+
</div>
<table class="data">
<thead>
-
+
<tr id="edit-columns-header">
- <th></th>
+ <th></th>
<%
last_index = @snapshots.size-1
@snapshots.each_with_index do |s, index|
</tr>
</table>
</th>
- <% end %>
+ <% end %>
<th></th>
- </tr>
+ </tr>
<tr id="resource-info-header">
<th></th>
<%
</th>
<% end %>
<th></th>
- </tr>
+ </tr>
</thead>
<tbody>
<%= format_measure s.measure(m) -%>
</td>
<% end %>
-
+
<td></td>
</tr>
<% end %>