]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2414 first version of cloud refactoring
authorsimonbrandhof <simon.brandhof@gmail.com>
Tue, 7 Jun 2011 23:42:35 +0000 (01:42 +0200)
committersimonbrandhof <simon.brandhof@gmail.com>
Tue, 7 Jun 2011 23:42:35 +0000 (01:42 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/cloud_controller.rb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/helpers/cloud_helper.rb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/models/measure_color.rb
sonar-server/src/main/webapp/WEB-INF/app/views/cloud/index.html.erb [new file with mode: 0644]

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 (file)
index 0000000..87bacc7
--- /dev/null
@@ -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 (file)
index 0000000..8d21be8
--- /dev/null
@@ -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
index 390dc6bb581d16118d1f27b40f85fe20af1edb78..79b86cfebdb3322f3d94958016a1ec5e5fceaa6d 100644 (file)
@@ -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 (file)
index 0000000..ca30e0a
--- /dev/null
@@ -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