diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2014-07-04 17:06:25 +0600 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2014-07-04 17:06:34 +0600 |
commit | bc7dddf031537bc5a658573c63f7bc9d73e633cb (patch) | |
tree | 8345e212e201be908d0fd635103e42e0f72566ae /plugins | |
parent | 0b07455499c27bd5d18acf8c5e59ab93ead4d11c (diff) | |
download | sonarqube-bc7dddf031537bc5a658573c63f7bc9d73e633cb.tar.gz sonarqube-bc7dddf031537bc5a658573c63f7bc9d73e633cb.zip |
SONAR-5207 Treemap as a metric widget skeleton
Diffstat (limited to 'plugins')
7 files changed, 113 insertions, 93 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java index 22e37e6bf34..484ff746d68 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java @@ -216,7 +216,7 @@ public final class CorePlugin extends SonarPlugin { HotspotMetricWidget.class, TreemapWidget.class, MeasureFilterListWidget.class, - MeasureFilterTreemapWidget.class, + MeasureFilterAsTreemapWidget.class, WelcomeWidget.class, DocumentationCommentsWidget.class, DuplicationsWidget.class, diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/GlobalDefaultDashboard.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/GlobalDefaultDashboard.java index f7933cfbbf4..5e204b18537 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/GlobalDefaultDashboard.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/GlobalDefaultDashboard.java @@ -27,8 +27,8 @@ import org.sonar.core.measure.db.MeasureFilterDto; import org.sonar.plugins.core.measurefilters.MyFavouritesFilter; import org.sonar.plugins.core.measurefilters.ProjectFilter; import org.sonar.plugins.core.widgets.WelcomeWidget; +import org.sonar.plugins.core.widgets.measures.MeasureFilterAsTreemapWidget; import org.sonar.plugins.core.widgets.measures.MeasureFilterListWidget; -import org.sonar.plugins.core.widgets.measures.MeasureFilterTreemapWidget; /** * Projects global dashboard for Sonar @@ -75,10 +75,10 @@ public final class GlobalDefaultDashboard extends DashboardTemplate { .setProperty(MeasureFilterListWidget.PAGE_SIZE_PROPERTY, "20"); dashboard - .addWidget(MeasureFilterTreemapWidget.ID, 2) + .addWidget(MeasureFilterAsTreemapWidget.ID, 2) .setProperty(MeasureFilterListWidget.FILTER_PROPERTY, filter.getId().toString()) - .setProperty(MeasureFilterTreemapWidget.SIZE_METRIC_PROPERTY, "ncloc") - .setProperty(MeasureFilterTreemapWidget.COLOR_METRIC_PROPERTY, "coverage"); + .setProperty(MeasureFilterAsTreemapWidget.SIZE_METRIC_PROPERTY, "ncloc") + .setProperty(MeasureFilterAsTreemapWidget.COLOR_METRIC_PROPERTY, "coverage"); } } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TreemapWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TreemapWidget.java index 6ce87b3be75..c941ef8ca36 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TreemapWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TreemapWidget.java @@ -33,6 +33,6 @@ import org.sonar.api.web.WidgetPropertyType; public class TreemapWidget extends CoreWidget { public TreemapWidget() { // do not use the id "treemap" to avoid conflict with the same CSS class - super("treemap-widget", "Treemap of Components", "/org/sonar/plugins/core/widgets/treemap.html.erb"); + super("treemap-widget", "Treemap of Components", "/Users/Stas/Projects/sonar/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/treemap.html.erb"); } } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/measures/MeasureFilterAsTreemapWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/measures/MeasureFilterAsTreemapWidget.java new file mode 100644 index 00000000000..ae959dd25ce --- /dev/null +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/measures/MeasureFilterAsTreemapWidget.java @@ -0,0 +1,55 @@ +/* + * 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. + */ +package org.sonar.plugins.core.widgets.measures; + +import org.sonar.api.web.*; +import org.sonar.plugins.core.widgets.CoreWidget; +import org.sonar.plugins.core.widgets.WidgetConstants; + +import static org.sonar.api.web.WidgetScope.GLOBAL; + +@WidgetCategory({"Filters"}) +@WidgetScope(GLOBAL) +@WidgetProperties({ + @WidgetProperty(key = MeasureFilterAsTreemapWidget.FILTER_PROPERTY, type = WidgetPropertyType.FILTER, + optional = false), + @WidgetProperty(key = MeasureFilterAsTreemapWidget.CHART_TITLE_PROPERTY, type = WidgetPropertyType.STRING), + @WidgetProperty(key = MeasureFilterAsTreemapWidget.SIZE_METRIC_PROPERTY, type = WidgetPropertyType.METRIC, + optional = true, options = { WidgetConstants.FILTER_OUT_NEW_METRICS }), + @WidgetProperty(key = MeasureFilterAsTreemapWidget.COLOR_METRIC_PROPERTY, type = WidgetPropertyType.METRIC, + optional = true, options = { WidgetConstants.FILTER_OUT_NEW_METRICS, "type:PERCENT,RATING,LEVEL" }), + @WidgetProperty(key = MeasureFilterAsTreemapWidget.HEIGHT_PERCENTS_PROPERTY, type = WidgetPropertyType.INTEGER, + optional = true, defaultValue = "55", description = "Height in percents of width"), + @WidgetProperty(key = MeasureFilterAsTreemapWidget.MAX_ITEMS_PROPERTY, type = WidgetPropertyType.INTEGER, + defaultValue = "100") +}) +public class MeasureFilterAsTreemapWidget extends CoreWidget { + public static final String FILTER_PROPERTY = "filter"; + public static final String SIZE_METRIC_PROPERTY = "sizeMetric"; + public static final String COLOR_METRIC_PROPERTY = "colorMetric"; + public static final String HEIGHT_PERCENTS_PROPERTY = "heightInPercents"; + public static final String CHART_TITLE_PROPERTY = "chartTitle"; + public static final String MAX_ITEMS_PROPERTY = "maxItems"; + public static final String ID = "measure_filter_treemap"; + + public MeasureFilterAsTreemapWidget() { + super(ID, "Measure Filter as Treemap", "/Users/Stas/Projects/sonar/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/measure_filter_treemap.html.erb"); + } +} diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/measures/MeasureFilterTreemapWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/measures/MeasureFilterTreemapWidget.java deleted file mode 100644 index 29bc578b684..00000000000 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/measures/MeasureFilterTreemapWidget.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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. - */ -package org.sonar.plugins.core.widgets.measures; - -import org.sonar.api.web.*; -import org.sonar.plugins.core.widgets.CoreWidget; -import org.sonar.plugins.core.widgets.WidgetConstants; - -import static org.sonar.api.web.WidgetScope.GLOBAL; - -@WidgetCategory({"Filters"}) -@WidgetScope(GLOBAL) -@WidgetProperties({ - @WidgetProperty(key = MeasureFilterTreemapWidget.FILTER_PROPERTY, type = WidgetPropertyType.FILTER, optional = false), - @WidgetProperty(key = MeasureFilterTreemapWidget.SIZE_METRIC_PROPERTY, type = WidgetPropertyType.METRIC, optional = true, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}), - @WidgetProperty(key = MeasureFilterTreemapWidget.COLOR_METRIC_PROPERTY, type = WidgetPropertyType.METRIC, optional = true, - options = {WidgetConstants.FILTER_OUT_NEW_METRICS,"type:PERCENT,RATING,LEVEL"}), - @WidgetProperty(key = MeasureFilterTreemapWidget.HEIGHT_PERCENTS_PROPERTY, type = WidgetPropertyType.INTEGER, optional = true, defaultValue = "55", - description = "Height in percents of width"), - @WidgetProperty(key = MeasureFilterListWidget.DISPLAY_FILTER_DESCRIPTION, type = WidgetPropertyType.BOOLEAN, defaultValue = "false") -}) -public class MeasureFilterTreemapWidget extends CoreWidget { - public static final String FILTER_PROPERTY = "filter"; - public static final String SIZE_METRIC_PROPERTY = "sizeMetric"; - public static final String COLOR_METRIC_PROPERTY = "colorMetric"; - public static final String HEIGHT_PERCENTS_PROPERTY = "heightInPercents"; - public static final String DISPLAY_FILTER_DESCRIPTION = "displayFilterDescription"; - public static final String ID = "measure_filter_treemap"; - - public MeasureFilterTreemapWidget() { - super(ID, "Measure Filter as Treemap", "/org/sonar/plugins/core/widgets/measure_filter_treemap.html.erb"); - } -} diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/measure_filter_treemap.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/measure_filter_treemap.html.erb index 8d1021f5ade..67d2bd13cfb 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/measure_filter_treemap.html.erb +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/measure_filter_treemap.html.erb @@ -1,41 +1,56 @@ <% - filter_id = widget_properties['filter'] - size_metric = widget_properties['sizeMetric'] - color_metric = widget_properties['colorMetric'] - filter = MeasureFilter.find_by_id(filter_id.to_i) if filter_id - if filter - url_options = {:controller => 'measures', :action => 'filter', :id => filter.id} - filter.load_criteria_from_data - filter.set_criteria_value(:display, 'treemap') - if size_metric - filter.set_criteria_value(:tmSize, size_metric.key) - url_options[:tmSize]=size_metric.key - end - if color_metric - filter.set_criteria_value(:tmColor, color_metric.key) - url_options[:tmColor]=color_metric.key - end - filter.set_criteria_value(:tmHeight, widget_properties['heightInPercents']) + containerId = 'treemap-widget' + widget.id.to_s + chartTitle = widget_properties['chartTitle'] + filterId = widget_properties['filter'].to_i + maxItems = widget_properties['maxItems'].to_i - - if !filter.require_authentication? || logged_in? - filter.execute(self, :user => current_user) - - @widget_title = link_to h(filter.name), url_options + filter = MeasureFilter.find_by_id(filterId.to_i) + @widget_title = link_to h(filter.name), {:controller => 'measures', :action => 'filter', :id => filter.id, :display => 'list'} %> - <% if widget_properties['displayFilterDescription'] && !filter.description.blank? %> - <div style="padding-bottom: 5px"> - <span class="note"><%= h filter.description -%></span> - </div> +<div class="treemap-widget" id="<%= containerId %>"> + <!--[if lte IE 8 ]> <h3><%= message('widget.unsupported_browser_warning') -%></h3> <![endif]--> + + <!--[if (gte IE 9)|!(IE)]><!--> + <% if chartTitle %> + <h3 style="margin-bottom: 5px;"><%= h(chartTitle) -%></h3> <% end %> + <!--<![endif]--> +</div> - <%= render :partial => 'measures/display_treemap', :locals => {:edit_mode => false, :widget_id => widget.id, :filter => filter} %> -<% - end - else -%> - <p><i class="icon-alert-warn"></i> <%= message 'measure_filter.widget.unknown_filter_warning' -%></p> -<% - end -%> +<!--[if (gte IE 9)|!(IE)]><!--> +<script> + (function () { + var metrics = [ + '<%= widget_properties['colorMetric'].name -%>', + '<%= widget_properties['sizeMetric'].name -%>' + ], + query = [ + 'filter=<%= filterId -%>', + 'metrics=' + metrics.join(','), + 'fields=name,longName,qualifier', + 'pageSize=<%= maxItems -%>', + 'page=1', + 'sort=metric:' + metrics[1], + 'asc=false' + ].join('&'), + widget = new SonarWidgets.Widget(); + + widget + .type('Treemap') + .source(baseUrl + '/measures/search_filter?' + query) + .metricsPriority(metrics) + .options({ + heightInPercents: '<%= widget_properties['heightInPercents'] -%>', + maxItemsReachedMessage: '<%= message("widget.measure_filter_histogram.max_items_reached", :params => [maxItems]) -%>', + baseUrl: baseUrl + '/dashboard/index/', + noData: '<%= message('no_data') -%>' + }) + .render('#<%= containerId -%>'); + + autoResize(500, function() { + widget.update('#<%= containerId -%>'); + }); + })(); +</script> +<!--<![endif]--> diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/GlobalDefaultDashboardTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/GlobalDefaultDashboardTest.java index 49770b62dd7..b5f79bb88de 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/GlobalDefaultDashboardTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/GlobalDefaultDashboardTest.java @@ -29,8 +29,8 @@ import org.sonar.plugins.core.CorePlugin; import org.sonar.plugins.core.measurefilters.MyFavouritesFilter; import org.sonar.plugins.core.measurefilters.ProjectFilter; import org.sonar.plugins.core.widgets.WelcomeWidget; +import org.sonar.plugins.core.widgets.measures.MeasureFilterAsTreemapWidget; import org.sonar.plugins.core.widgets.measures.MeasureFilterListWidget; -import org.sonar.plugins.core.widgets.measures.MeasureFilterTreemapWidget; import java.util.List; @@ -77,7 +77,7 @@ public class GlobalDefaultDashboardTest { assertThat(secondColumn).hasSize(2); assertThat(secondColumn.get(0).getId()).isEqualTo(MeasureFilterListWidget.ID); assertThat(secondColumn.get(0).getProperty("filter")).isEqualTo("101"); - assertThat(secondColumn.get(1).getId()).isEqualTo(MeasureFilterTreemapWidget.ID); + assertThat(secondColumn.get(1).getId()).isEqualTo(MeasureFilterAsTreemapWidget.ID); assertThat(secondColumn.get(1).getProperty("filter")).isEqualTo("101"); } |