helper :metrics, :components
- verify :method => :post, :only => :update_default_treemap_metrics
-
- before_filter :admin_required, :only => :update_default_treemap_metrics
-
- TREEMAP_SIZE = 280
SECTION = Navigation::SECTION_RESOURCE
- TREEMAP_DEFAULT_SIZE_METRIC = 'ncloc'
- TREEMAP_SIZE_METRIC_PROPERTY = 'sonar.core.treemap.sizemetric'
- TREEMAP_DEFAULT_COLOR_METRIC = 'violations_density'
- TREEMAP_COLOR_METRIC_PROPERTY = 'sonar.core.treemap.colormetric'
def index
init_resource_for_user_role
measures = component_measures(@snapshots, metrics)
@measures_by_snapshot = measures_by_snapshot(@snapshots, measures)
- if @components_configuration.treemap_enabled? && @snapshots.size>1
- @treemap = Sonar::Treemap.new(1, default_treemap_size_metric, TREEMAP_SIZE, {
- :color_metric => default_treemap_color_metric,
- :root_snapshot => @snapshot
- })
- end
- end
-
- def update_default_treemap_metrics
- Property.set(TREEMAP_SIZE_METRIC_PROPERTY, params[:size_metric])
- Property.set(TREEMAP_COLOR_METRIC_PROPERTY, params[:color_metric])
- redirect_to :action => 'index', :id => params[:rid], :configuring => true
end
protected
end
end
- def default_treemap_color_metric
- metric=Metric.by_key(Property.value(TREEMAP_COLOR_METRIC_PROPERTY))
- if metric.nil?
- metric = Metric.by_key(TREEMAP_DEFAULT_COLOR_METRIC)
- end
- metric
- end
- def default_treemap_size_metric
- metric=Metric.by_key(Property.value(TREEMAP_SIZE_METRIC_PROPERTY))
- if metric.nil?
- metric = Metric.by_key(TREEMAP_DEFAULT_SIZE_METRIC)
- end
- metric
- end
end
\ No newline at end of file
COLUMNS_SELECTED_KEY = 'sonar.core.projectsdashboard.columns'
COLUMNS_DEFAULT_SORT_KEY = 'sonar.core.projectsdashboard.defaultSortedColumn'
- TREEMAP_ENABLED_KEY = 'sonar.core.projectsdashboard.showTreemap'
def initialize
@sorted_column_id=Property.value(COLUMNS_DEFAULT_SORT_KEY) || Sonar::ColumnsView::TYPE_PROJECT
- @enabled_treemap=(Property.value(TREEMAP_ENABLED_KEY) || 'true')=='true'
@text_columns=Property.value(COLUMNS_SELECTED_KEY) || default_text_columns
end
Property.set(COLUMNS_DEFAULT_SORT_KEY, column_id)
end
- def treemap_enabled?
- @enabled_treemap
- end
-
- def toggle_treemap_enabled
- Property.set(TREEMAP_ENABLED_KEY, !treemap_enabled?)
- end
-
@@available_columns = nil
</form>
</td>
</tr>
- <tr>
- <td colspan="2">
- <%= link_to( message('enable_treemap'),
- {:controller => "columns", :action => "toggle_treemap", :rid => @resource.id}, {:class => 'action'} ) if (!components_configuration.treemap_enabled?) %>
- <%= link_to( message('disable_treemap'),
- {:controller => "columns", :action => "toggle_treemap", :rid => @resource.id}, {:class => 'action'} ) if components_configuration.treemap_enabled? %>
- <%= image_tag("treemap_icon.png") %>
- </td>
- </tr>
</table>
</div>
<% end %>
+++ /dev/null
-<form method="post" id="form_set_default" name="setDefaultForm" action="<%= ApplicationController.root_context -%>/components/update_default_treemap_metrics"
- onsubmit="">
- <input type="hidden" name="rid" value="<%= rid -%>"/>
- <input type="hidden" name="size_metric" />
- <input type="hidden" name="color_metric" />
-</form>
-<script>
- function submitDefaultForm() {
- document.setDefaultForm.size_metric.value=$F('select_size_metric');
- document.setDefaultForm.color_metric.value=$F('select_color_metric');
- document.setDefaultForm.submit();
- }
-</script>
\ No newline at end of file
+++ /dev/null
-<div id="treemap_set_default">
- <%= render :partial => 'components/treemap_set_default',
- :locals => {:controller => 'components', :size_metric => @treemap.size_metric.key, :color_metric => @treemap.color_metric.key, :rid => @resource.id } %>
-</div>
-<table class="spaced">
-<tr>
- <td valign="bottom">
- <span class="comments"><%= message('size') -%></span>
- <br/>
- <%= select_tag 'size_metric', options_grouped_by_domain(Sonar::Treemap.size_metrics, @treemap.size_metric.key),
- :id => 'select_size_metric', :class => 'small',:onchange => "return treemapById(1).changeSizeMetric(this.value);" %>
- </td>
- </tr>
- <tr>
- <td>
- <span class="comments"><%= message('color') -%></span>
- <span id="tm-gradient-1" class="comments little">
- <%= render :partial => 'treemap/gradient', :locals => {:metric => @treemap.color_metric} %>
- </span>
- <%= image_tag('loading.gif', {:id => "tm-loading-1", :style => 'display: none;'}) %>
- <br/>
- <%= select_tag 'color_metric', options_grouped_by_domain(Sonar::Treemap.color_metrics, @treemap.color_metric.key),
- :id => 'select_color_metric', :class => 'small', :onchange => "return treemapById(1).changeColorMetric(this.value);" %>
- </td>
- </tr>
-
- <% if configuring? && has_role?(:admin) %>
- <tr >
- <td class="admin"><%= button_to message('set_as_default'), "#", :id => 'set_default_treemap', :onclick => "submitDefaultForm();return false;" %></td>
- </tr>
- <% end %>
-</table>
<script>TableKit.Sortable.init('components');</script>
<p> </p>
</td>
- <% if @treemap %>
- <td width="10px"> </td>
- <td width="280px" valign="top">
- <script>
- new Treemap(1, '<%= @treemap.size_metric ? @treemap.size_metric.key : '' -%>', '<%= @treemap.color_metric ? @treemap.color_metric.key : '' -%>', 100.0).init('resource',
- <%= @resource.id -%>);
- </script>
-
- <div id="tm-1" class="treemap" style="height:<%= @treemap.height %>px">
- <%= @treemap.generate_html() %>
- </div>
- <%= render :partial => 'components/treemap_settings', :locals => {:action => 'treemap'} %>
- </td>
- <% end %>
</tr>
</table>
<% end %>