include FiltersHelper
helper MetricsHelper
helper FiltersHelper
-
+
SECTION=Navigation::SECTION_HOME
verify :method => :post, :only => [:create, :delete, :up, :down, :activate, :deactivate, :up_column, :down_column, :add_column, :delete_column, :set_sorted_column, :set_view, :set_columns, :set_page_size], :redirect_to => {:action => :index}
before_filter :load_active_filters, :except => ['admin_console', 'treemap', 'set_view', 'set_columns']
before_filter :login_required, :except => ['index', 'treemap']
- before_filter :admin_required, :only => ['admin_console' ]
+ before_filter :admin_required, :only => ['admin_console']
def index
load_active_filter()
def manage
@shared_filters=::Filter.find(:all, :conditions => ['shared=? and (user_id<>? or user_id is null)', true, current_user.id])
- ids=@actives.map{|af| af.filter_id}
- @shared_filters.reject!{|f| ids.include?(f.id) }
+ ids=@actives.map { |af| af.filter_id }
+ @shared_filters.reject! { |f| ids.include?(f.id) }
end
def new
if @filter.valid?
@filter.save
-
+
# activate it by default
current_user.active_filters.create(:filter => @filter, :user_id => current_user.id, :order_index => (current_user.active_filters.size + 1))
flash[:notice]='Filter saved'
activate_default_filters_if_needed()
filter=::Filter.find(params[:id])
if filter && filter.shared
- existing=current_user.active_filters.to_a.find{|a| a.filter_id==filter.id}
+ existing=current_user.active_filters.to_a.find { |a| a.filter_id==filter.id }
if existing.nil?
current_user.active_filters.create(:filter => filter, :user => current_user, :order_index => current_user.active_filters.size+1)
end
def deactivate
activate_default_filters_if_needed()
- active_filter=current_user.active_filters.to_a.find{|a| a.filter_id==params[:id].to_i}
+ active_filter=current_user.active_filters.to_a.find { |a| a.filter_id==params[:id].to_i }
if active_filter
if active_filter.owner?
active_filter.filter.destroy
actives[index].order_index=index+1
actives[index].save
end
- end
+ end
redirect_to :action => 'manage'
end
end
-
-
-
#---------------------------------------------------------------------
#
# COLUMNS
end
-
#---------------------------------------------------------------------
#
# CUSTOMIZE DISPLAY
else
@snapshots=Snapshot.find(:all, :include => [:project, {:root_snapshot => :project}, {:parent_snapshot => :project}],
- :conditions => ['snapshots.status=? AND snapshots.islast=? AND snapshots.scope=? AND projects.scope=? AND UPPER(projects.long_name) LIKE ?', 'P', true, 'PRJ', 'PRJ', "%#{params[:search].upcase}%"],
- :order => 'projects.long_name')
+ :conditions => ['snapshots.status=? AND snapshots.islast=? AND snapshots.scope=? AND projects.scope=? AND UPPER(projects.long_name) LIKE ?', 'P', true, 'PRJ', 'PRJ', "%#{params[:search].upcase}%"],
+ :order => 'projects.long_name')
@snapshots=select_authorized(:user, @snapshots)
- @snapshots.sort! do |s1,s2|
+ @snapshots.sort! do |s1, s2|
if s1.qualifier==s2.qualifier
s1.project.long_name<=>s2.project.long_name
else
end
-
#---------------------------------------------------------------------
#
# TREEMAP
@width=(params[:width]||'800').to_i
@height=(params[:height]||'500').to_i
- treemap_options={:period_index => @filter_context.period_index}
- @treemap=Sonar::Treemap.new(@filter_context.measures_by_snapshot, @width, @height, @size_metric, @color_metric, treemap_options)
+ @treemap = Treemap2.new(@filter.id, @size_metric, @width, @height, {
+ :color_metric => @color_metric,
+ :period_index => @filter_context.period_index,
+ :measures_by_snapshot => @filter_context.measures_by_snapshot,
+ :browsable => false
+ })
+
+
+ #@treemap=Sonar::Treemap.new(@filter_context.measures_by_snapshot, @width, @height, @size_metric, @color_metric, treemap_options)
render :action => "treemap", :layout => false
+
end
filter.name=params[:name]
filter.shared=(params[:shared].present? && is_admin?)
filter.favourites=params[:favourites].present?
- filter.resource_id=(params[:path_id].present? ? Project.by_key(params[:path_id]).id : nil)
+ filter.resource_id=(params[:path_id].present? ? Project.by_key(params[:path_id]).id : nil)
filter.user_id=current_user.id
filter.period_index=params[:period_index].to_i
filter.criteria=[]
@actives=nil
if logged_in?
@actives=current_user.active_filters
- @actives=::ActiveFilter.default_active_filters if(@actives.nil? || @actives.empty?)
+ @actives=::ActiveFilter.default_active_filters if (@actives.nil? || @actives.empty?)
else
@actives=::ActiveFilter.for_anonymous
end
def load_active_filter()
@active=nil
if params[:name]
- @active=@actives.to_a.find{|a| a.name==params[:name]}
+ @active=@actives.to_a.find { |a| a.name==params[:name] }
elsif params[:id]
- @active=@actives.to_a.find{|a| a.filter.id==params[:id].to_i}
+ @active=@actives.to_a.find { |a| a.filter.id==params[:id].to_i }
end
if @active.nil? && !@actives.empty?
render :update do |page|
page.replace_html "tm-#{html_id}", :partial => 'treemap', :object => treemap
page.replace_html "tm-gradient-#{html_id}", :partial => 'gradient', :locals => {:metric => color_metric}
+ page.hide "tm-loading-#{html_id}"
end
end
@color_metric = options[:color_metric]
@root_snapshot = options[:root_snapshot]
- @measures = options[:measures] # pre-computed measures, for example by filters
+ @measures_by_snapshot = options[:measures_by_snapshot] # pre-computed measures, for example by filters
+ @browsable = options[:browsable]
if options[:period_index] && options[:period_index]>0
@period_index = options[:period_index]
end
protected
- def measures
- @measures ||=
+ def measures_by_snapshot
+ @measures_by_snapshot ||=
begin
metric_ids=[@size_metric.id]
metric_ids << @color_metric.id if @color_metric && @color_metric.id!=@size_metric.id
sql_conditions<<" AND snapshots.scope='PRJ' and snapshots.qualifier='TRK'"
end
- ProjectMeasure.find(:all, :include => {:snapshot => :project}, :conditions => [sql_conditions].concat(sql_values))
+ hash = {}
+ ProjectMeasure.find(:all, :include => {:snapshot => :project}, :conditions => [sql_conditions].concat(sql_values)).each do |m|
+ hash[m.snapshot]||={}
+ hash[m.snapshot][m.metric]=m
+ end
+ hash
end
end
def build_tree(node)
- color_measures_by_sid={}
- if @color_metric
- measures.each do |measure|
- color_measures_by_sid[measure.snapshot_id]=measure if measure.metric_id==@color_metric.id
- end
- end
-
- measures.each do |measure|
- if measure.metric_id==@size_metric.id
- color_measure = color_measures_by_sid[measure.snapshot_id]
- resource = measure.snapshot.project
- child = Treemap::Node.new(:id => "#{@id}-#{@id_counter += 1}",
- :size => size_value(measure),
- :label => resource.name(false),
- :title => escape_javascript(resource.name(true)),
- :tooltip => tooltip(resource, measure, color_measure),
- :color => html_color(color_measure),
- :rid => resource.id,
- :browsable => resource.display_dashboard?)
- node.add_child(child)
- end
+ measures_by_snapshot.each_pair do |snapshot, measures|
+ size_measure=measures[size_metric]
+ color_measure=(color_metric ? measures[color_metric] : nil)
+ resource = snapshot.project
+ child = Treemap::Node.new(:id => "#{@id}-#{@id_counter += 1}",
+ :size => size_value(size_measure),
+ :label => resource.name(false),
+ :title => escape_javascript(resource.name(true)),
+ :tooltip => tooltip(resource, size_measure, color_measure),
+ :color => html_color(color_measure),
+ :rid => resource.copy_resource_id || resource.id,
+ :browsable => @browsable && resource.display_dashboard?)
+ node.add_child(child)
end
end
- def tooltip(resource,size_measure, color_measure)
+ def tooltip(resource, size_measure, color_measure)
html=CGI::escapeHTML(resource.name(true))
html += " - #{CGI::escapeHTML(@size_metric.short_name)}: #{CGI::escapeHTML(size_measure.formatted_value)}"
if color_measure
</td>
<td class="sep"> </td>
<td>
- <span class="comments"><%= message('color') -%>: <%= render :partial => 'components/treemap_gradient', :locals => {:color_metric => @color_metric} %></span>
+ <span class="comments"><%= message('color') -%>: <%= render :partial => 'treemap/gradient', :locals => {:metric => @color_metric} %></span>
<br/>
<%= select_tag 'color_metric', options_grouped_by_domain(Sonar::TreemapBuilder.color_metrics, @color_metric.key),
:id => 'color_metric', :class => 'small', :onchange => "load_treemap(this.form.size_metric.value,this.form.color_metric.value, false);return false;" %>
</form>
<br/>
<% end %>
-<div class="treemap" style="height:<%= @treemap.height %>px">
- <%= @treemap.generate_html() %>
+
+<div class="treemap">
+ <%= render :partial => 'treemap/treemap' -%>
</div>
\ No newline at end of file
-<div style="width: <%= treemap.width -%>px; height:<%= treemap.height %>px;">
+<div class="treemap" style="width: <%= treemap.width -%>px; height:<%= treemap.height %>px;">
<%= treemap.generate_html() -%>
</div>
<script>
for (var i = 1; i <= <%= treemap.id_counter -%>; i++) {
addTmEvent(<%= treemap.id -%>, i);
}
- $('tm-loading-<%= treemap.id -%>').hide();
</script>
<span class="comments"><%= message('size') -%></span>
<br/>
<%= select_tag "size", options_grouped_by_domain(Sonar::TreemapBuilder.size_metrics, (size_metric ? size_metric.key : nil), :include_empty => true),
- :id => "tm-size-#{treemap_id}", :class => 'small spacer-right', :onchange => "refreshTm(#{treemap_id}, #{resource_id})" %>
+ :id => "tm-size-#{treemap_id}", :class => 'small spacer-right', :onchange => "refreshTm(#{treemap_id}, null)" %>
</td>
<td valign="top" class="thin nowrap">
<span class="comments"><%= message('color') -%></span>
<span id="tm-gradient-<%= treemap_id -%>" class="note"></span>
<br/>
<%= select_tag 'color', options_grouped_by_domain(Sonar::TreemapBuilder.color_metrics, (color_metric ? color_metric.key : nil), :include_empty => true),
- :id => "tm-color-#{treemap_id}", :class => 'small', :onchange => "refreshTm(#{treemap_id}, #{resource_id})" %>
+ :id => "tm-color-#{treemap_id}", :class => 'small', :onchange => "refreshTm(#{treemap_id}, null)" %>
<%= image_tag 'loading.gif', :id => "tm-loading-#{treemap_id}", :style => 'vertical-align: top;display: none' -%>
</td>
<td></td>
</table>
<input type="hidden" id="tm-h-<%= treemap_id -%>" value="<%= heightInPercents -%>"/>
</div>
-<div id="tm-error-<%= treemap_id -%>" class="error" style="display:none"></div>
-<div id="tm-<%= treemap_id -%>" class="treemap spacer-bottom"></div>
+<div id="tm-<%= treemap_id -%>" class="spacer-bottom"></div>
<div style="margin: 5px 0 0 0" class="notes">
<div style="float: right"><span>Left click to zoom in. Right click to zoom out.</span></div>
var color = $F('tm-color-' + treemap_id);
var width = $('tm-' + treemap_id).getWidth() - 10;
var height = Math.round(width * parseFloat($F('tm-h-' + treemap_id) / 100.0));
+ var rid = (resource_id!=null ? resource_id : context[context.length-1][0]);
context = treemapContexts[treemap_id];
var output = '';
$('tm-loading-' + treemap_id).show();
new Ajax.Request(
- baseUrl + '/treemap/index?id=' + treemap_id + '&width=' + width + '&height=' + height + '&size_metric=' + size + '&color_metric=' + color + '&resource=' + resource_id,
+ baseUrl + '/treemap/index?id=' + treemap_id + '&width=' + width + '&height=' + height + '&size_metric=' + size + '&color_metric=' + color + '&resource=' + rid,
{asynchronous:true, evalScripts:true});
return false;