+++ /dev/null
-#
-# SonarQube, open source software quality management tool.
-# Copyright (C) 2008-2014 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# SonarQube is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 3 of the License, or (at your option) any later version.
-#
-# SonarQube is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-
-class ComparisonController < ApplicationController
-
- SECTION=Navigation::SECTION_HOME
-
- def index
- snapshots = []
- resource_key = params[:resource]
- if resource_key && !resource_key.blank?
- # the request comes from a project: let's select its 5 latest versions
- project = Project.by_key(resource_key)
- return render_not_found('Project not found') unless project
-
- snapshots = project.events.select { |event| event.snapshot && 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_analysis
- unless snapshots.last == last_snapshot
- snapshots.shift
- snapshots.push(last_snapshot)
- end
- else
- # the request comes from the comparison page: let's compare the given snapshots
- suuids = get_params_as_array(:suuids)
- unless suuids.empty?
- selected_snapshots = Snapshot.all(:conditions => ['uuid in (?)', suuids])
- # next loop is required to keep the order that was decided by the user and which comes from the "suuids" parameter
- suuids.each do |uuid|
- selected_snapshots.each do |s|
- snapshots << s if uuid==s.uuid.to_s
- end
- end
- end
- end
- @snapshots = select_authorized(:user, snapshots).map { |snapshot| ComponentSnapshot.new(snapshot, snapshot.resource) }
-
- metrics = get_params_as_array(:metrics)
- if metrics.empty?
- metrics = [
- 'ncloc',
- 'complexity',
- 'comment_lines_density',
- 'duplicated_lines_density',
- 'violations',
- 'coverage'
- ]
- 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
- id = params[:id]
- suuids = get_params_as_array(:suuids)
-
- unless id.blank?
- project = Project.by_key(id)
-
- # we look for the events that are versions and that are not linked to snapshots already displayed on the page
- @versions = project.events.select { |event| event.category==EventCategory::KEY_VERSION && !suuids.include?(event.analysis_uuid.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_uuid = project.last_analysis.uuid
- current_and_suggested_suuids = suuids + @versions.map {|e| e.analysis_uuid.to_s}
- unless current_and_suggested_suuids.include?(latest_snapshot_uuid.to_s)
- @versions.unshift Event.new(:name => Api::Utils.message('comparison.version.latest'), :analysis_uuid => latest_snapshot_uuid)
- end
- end
-
- render :partial => 'versions'
- end
-
-
- private
-
- def get_params_as_array(name)
- list = params[name]
- if list.blank?
- []
- else
- list.split(',')
- end
- end
-
-end
+++ /dev/null
-<% content_for :style do %>
- <style>
- #comparison-page td {
- vertical-align: middle;
- }
-
- #comparison-page .move-actions a {
- visibility: hidden;
- }
-
- #comparison-page .move-actions:hover a {
- visibility: visible;
- }
- </style>
-<% end %>
-<% content_for :script do %>
- <script>
- function submitForm() {
- $j('#compare-form').submit();
- }
-
- function moveLeft(index) {
- suuids = $j('#suuids').val().split(',');
- idToLeft = suuids[index];
- idToRight = suuids[index - 1];
- suuids.splice(index - 1, 2, [idToLeft, idToRight]);
- $j('#suuids').val(suuids.join(','));
- submitForm();
- }
-
- function moveRight(index) {
- suuids = $j('#suuids').val().split(',');
- idToRight = suuids[index];
- idToLeft = suuids[index + 1];
- suuids.splice(index, 2, [idToLeft, idToRight]);
- $j('#suuids').val(suuids.join(','));
- submitForm();
- }
-
- function moveUp(index) {
- metrics = $j('#metrics').val().split(',');
- idToUp = metrics[index];
- idToBottom = metrics[index - 1];
- metrics.splice(index - 1, 2, [idToUp, idToBottom]);
- $j('#metrics').val(metrics.join(','));
- submitForm();
- }
-
- function moveDown(index) {
- metrics = $j('#metrics').val().split(',');
- idToBottom = metrics[index];
- idToUp = metrics[index + 1];
- metrics.splice(index, 2, [idToUp, idToBottom]);
- $j('#metrics').val(metrics.join(','));
- submitForm();
- }
-
- function removeFromList(index, inputField) {
- value = inputField.val().split(',');
- value.splice(index, 1);
- inputField.val(value.join(','));
- submitForm();
- }
- </script>
-<% end %>
-
-
- <div id="comparison-page" class="page">
- <header class="page-header">
- <h1 class="page-title"><%= h message('comparison.page') -%></h1>
- </header>
- <form method="GET" id="compare-form" action="<%= ApplicationController.root_context -%>/comparison/index">
- <input type="hidden" name="suuids" id="suuids" value="<%= @snapshots.map { |s| s.uuid.to_s }.join(',') -%>">
- <input type="hidden" name="metrics" id="metrics" value="<%= @metrics.map { |m| m.key }.join(',') -%>">
-
- <div style="margin-bottom: 4px">
- <div id="metric_div" style="display: inline-block">
- <%= metric_select_tag 'new_metric', @metric_to_choose, {
- :allow_empty => true,
- :select2_options => {'placeholder' => "'" + message('comparison.add_metric') + "'"}
- } -%>
- <script>
- // we don't want this parameter to be submitted, so we set its name to ''
- $j('#new_metric').attr('name', '');
- $j('#new_metric').change(function (event) {
- var metric = event.target.value;
- if (metric != null) {
- var currentMetrics = $j('#metrics').val();
- if (currentMetrics.length > 0) {
- currentMetrics += ',';
- }
- currentMetrics += metric;
- $j('#metrics').val(currentMetrics);
- $j('#compare-form').submit();
- }
- });
- </script>
- </div>
-
- <div id="resource_div" style="display: inline-block; margin-left: 30px">
- <%= resource_select_tag 'new_resource', {
- :resource_type_property => 'comparable',
- :width => '250px',
- :select2_options => {'placeholder' => "'" + message('comparison.add_project') + "'"}
- } -%>
- <script>
- // we don't want this parameter to be submitted, so we set its name to ''
- $j('#new_resource').attr('name', '');
- $j('#new_resource').change(function (event) {
- var id = event.target.value;
- if (id != null) {
- $j('#version_loading').show();
- $j.ajax({
- type:'GET',
- url:'<%= ApplicationController.root_context -%>/comparison/versions?id='
- + id + '&suuids='
- + $j('#suuids').val(),
- success:function (data) {
- $j('#new_version').html(data);
- $j('#new_version').select2({
- width: '250px',
- placeholder:'<%= message('comparison.select_version') -%>'
- });
- $j('#version_loading').hide();
- $j('#version_div').show();
- $j('#version_div').css("display", "inline-block");
- $j('#new_version').select2("focus");
- }
- });
- }
- });
- $j('#new_resource').select2("focus");
- </script>
- </div>
-
- <span id="version_loading" class="loading" style="display: none"></span>
-
- <div id="version_div" style="display: none">
- <select id="new_version">
- </select>
- <script>
- $j('#new_version').change(function (event) {
- var uuid = event.target.value;
- if (uuid != null) {
- var currentSnapshotUuids = $j('#suuids').val();
- if (currentSnapshotUuids.length > 0) {
- currentSnapshotUuids += ',';
- }
- currentSnapshotUuids += uuid;
- $j('#suuids').val(currentSnapshotUuids);
- $j('#compare-form').submit();
- }
- });
- </script>
- </div>
-
- </div>
-
- <table class="data">
- <thead>
-
- <tr id="edit-columns-header">
- <th></th>
- <%
- last_index = @snapshots.size-1
- @snapshots.each_with_index do |s, index|
- %>
- <th class="thin move-actions" style="padding: 5px !important;">
- <table>
- <tr>
- <td style="vertical-align: bottom;">
- <% if index > 0 %>
- <a class="icon-move-left" href="#" onclick="moveLeft(<%= index -%>)" id="left-<%= index -%>"></a>
- <% else %>
- <img src="<%= ApplicationController.root_context -%>/images/transparent_16.gif"/>
- <% end %>
- </td>
- <td style="text-align: center; min-width: 100px">
- <div style="width: 100%; text-align: center;">
- <a class="icon-delete" href="#" onclick="removeFromList(<%= index -%>, $j('#suuids'))" id="del-r-<%= index -%>" title="<%= message('comparison.suppress_column') -%>"></a>
- </div>
- </td>
- <td style="vertical-align: bottom;">
- <% if index < last_index %>
- <a class="icon-move-right" href="#" onclick="moveRight(<%= index -%>)" id="right-<%= index -%>"></a>
- <% else %>
- <img src="<%= ApplicationController.root_context -%>/images/transparent_16.gif"/>
- <% end %>
- </td>
- </tr>
- </table>
- </th>
- <% end %>
- <th></th>
- </tr>
- <tr id="resource-info-header">
- <th></th>
- <%
- last_index = @snapshots.size-1
- @snapshots.each_with_index do |s, index|
- event = s.event(EventCategory::KEY_VERSION)
- %>
- <th style="text-align: center; vertical-align: top; line-height: 1.5;">
- <span class="no-transform">
- <a href="<%= ApplicationController.root_context -%>/dashboard/index/<%= s.component.key -%>"><%= h s.component.name(true) -%></a>
- <br/>
- <span class="note"><b><%= event ? h(event.name) : message('comparison.version.latest') -%></b></span>
- <br/>
- <span class="note"><%= human_short_date s.created_at -%></span>
- </span>
- </th>
- <% end %>
- <th></th>
- </tr>
- </thead>
-
- <tbody>
- <%
- last_index = @metrics.size-1
- @metrics.each_with_index do |m, index|
- %>
- <tr class="<%= cycle 'even', 'odd' -%> move-actions">
- <td class="thin">
- <table>
- <tr>
- <td class="nowrap" style="vertical-align: bottom; width: 100%;"><%= m.short_name -%></td>
- <td class="nowrap" style="padding-left: 10px">
- <% if index > 0 %>
- <a class="icon-move-up" href="#" onclick="moveUp(<%= index -%>)" id="up-<%= index -%>"></a>
- <% end %>
- <% if index < last_index %>
- <a class="icon-move-down" href="#" onclick="moveDown(<%= index -%>)" id="down-<%= index -%>"></a>
- <% end %>
- <a class="icon-delete" href="#" onclick="removeFromList(<%= index -%>, $j('#metrics'))" id="del-m-<%= index -%>" title="<%= message('comparison.suppress_line') -%>"></a>
- </td>
- </tr>
- </table>
- </td>
-
- <% @snapshots.each do |s| %>
- <td style="text-align: center">
- <%= format_measure s.measure(m) -%>
- </td>
- <% end %>
-
- <td></td>
- </tr>
- <% end %>
- </tbody>
- </table>
- </form>
- </div>