aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-06-08 01:42:35 +0200
committersimonbrandhof <simon.brandhof@gmail.com>2011-06-08 01:42:35 +0200
commit05a19df955ab8084bfcb156bf063fdfa80f52a16 (patch)
tree3c4634b782b93eba71d6d53b014e5db0d3f89573 /sonar-server/src
parent266f3fceb9a159a3adb6fbf5a8c667e0bb766894 (diff)
downloadsonarqube-05a19df955ab8084bfcb156bf063fdfa80f52a16.tar.gz
sonarqube-05a19df955ab8084bfcb156bf063fdfa80f52a16.zip
SONAR-2414 first version of cloud refactoring
Diffstat (limited to 'sonar-server/src')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/cloud_controller.rb72
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/helpers/cloud_helper.rb33
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/measure_color.rb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/cloud/index.html.erb15
4 files changed, 121 insertions, 1 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/cloud_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/cloud_controller.rb
new file mode 100644
index 00000000000..87bacc79aef
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/cloud_controller.rb
@@ -0,0 +1,72 @@
+#
+# Sonar, open source software quality management tool.
+# Copyright (C) 2008-2011 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# Sonar 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.
+#
+# Sonar 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 Sonar; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+#
+class CloudController < ApplicationController
+
+ SECTION=Navigation::SECTION_RESOURCE
+
+ def index
+ resource_key = params[:id]
+ @project = resource_key ? Project.by_key(resource_key) : nil
+ if @project.nil?
+ return render :text => "Resource [#{project_key}] not found", :status => 404
+ end
+ @snapshot=@project.last_snapshot
+
+ # metrics
+ size_metric=Metric.by_key('ncloc')
+ color_metric=Metric.by_key('violations_density')
+
+ snapshot_conditions='snapshots.islast=:islast AND snapshots.scope=:scope AND snapshots.qualifier!=:test_qualifier AND
+ (snapshots.id=:sid OR (snapshots.root_snapshot_id=:root_sid AND snapshots.path LIKE :path))'
+ snapshot_values={
+ :islast => true,
+ :scope => 'FIL',
+ :test_qualifier => 'UTS',
+ :sid => @snapshot.id,
+ :root_sid => (@snapshot.root_snapshot_id || @snapshot.id),
+ :path => "#{@snapshot.path}#{@snapshot.id}.%"
+ }
+
+ @snapshots=Snapshot.find(:all, :conditions => [snapshot_conditions, snapshot_values], :include => 'project', :order => 'projects.name')
+
+ @size_measures=ProjectMeasure.find(:all,
+ :select => 'project_measures.id,project_measures.value,project_measures.metric_id,project_measures.snapshot_id,project_measures.rule_id,project_measures.rule_priority,project_measures.text_value,project_measures.characteristic_id,project_measures.alert_status',
+ :joins => :snapshot,
+ :conditions => [snapshot_conditions + " AND project_measures.metric_id=#{size_metric.id}", snapshot_values],
+ :order => 'project_measures.value')
+
+ @color_measures=ProjectMeasure.find(:all,
+ :select => 'project_measures.id,project_measures.value,project_measures.metric_id,project_measures.snapshot_id,project_measures.rule_id,project_measures.rule_priority,project_measures.text_value,project_measures.characteristic_id,project_measures.alert_status',
+ :joins => :snapshot,
+ :conditions => [snapshot_conditions + " AND project_measures.metric_id=#{color_metric.id}", snapshot_values],
+ :order => 'project_measures.value')
+
+ @size_measure_by_sid={}, @color_measure_by_sid={}
+ @size_measures.each do |m|
+ @size_measure_by_sid[m.snapshot_id]=m
+ end
+ @color_measures.each do |m|
+ @color_measure_by_sid[m.snapshot_id]=m
+ end
+ @min_size_value=(@size_measures.empty? ? 0.0 : @size_measures.first.value)
+ @max_size_value=(@size_measures.empty? ? 0.0 : @size_measures.last.value)
+ end
+
+end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/cloud_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/cloud_helper.rb
new file mode 100644
index 00000000000..8d21be8cbbd
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/cloud_helper.rb
@@ -0,0 +1,33 @@
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2008-2011 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# Sonar 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.
+#
+# Sonar 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 Sonar; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+#
+module CloudHelper
+ MIN_SIZE_PERCENT=60.0
+ MAX_SIZE_PERCENT=240.0
+
+ def font_size(value)
+ divisor=@max_size_value - @min_size_value
+ size=MIN_SIZE_PERCENT
+ if divisor!=0.0
+ multiplier=(MAX_SIZE_PERCENT - MIN_SIZE_PERCENT)/divisor
+ size=MIN_SIZE_PERCENT + ((@max_size_value - (@max_size_value-(value - @min_size_value)))*multiplier)
+ end
+ size.to_i
+ end
+end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/measure_color.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/measure_color.rb
index 390dc6bb581..79b86cfebdb 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/measure_color.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/measure_color.rb
@@ -44,7 +44,7 @@ class MeasureColor
percent = value_to_percent(value, min_value, max_value)
end
else
- if !measure.alert_status.blank? && (options[:check_alert_status]||true)
+ if (options[:check_alert_status]||true) && !measure.alert_status.blank?
case(measure.alert_status)
when Metric::TYPE_LEVEL_OK : percent=100.0
when Metric::TYPE_LEVEL_ERROR : percent=0.0
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/cloud/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/cloud/index.html.erb
new file mode 100644
index 00000000000..ca30e0aaa12
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/cloud/index.html.erb
@@ -0,0 +1,15 @@
+<style>
+#cloud a {
+ text-decoration: none;
+}
+</style>
+<div id="cloud">
+<% @snapshots.each do |s|
+ size_measure=@size_measure_by_sid[s.id]
+ if size_measure && size_measure.value
+ color_measure=@color_measure_by_sid[s.id]
+%>
+ <a href=""><span style="font-size: <%= font_size(size_measure.value) -%>%;color: <%= MeasureColor.color(color_measure, :check_alert_status => false).html -%>"><%= s.resource.name %></span></a>
+<% end
+ end %>
+</div> \ No newline at end of file