diff options
author | David Gageot <david@gageot.net> | 2012-05-07 09:56:10 +0200 |
---|---|---|
committer | David Gageot <david@gageot.net> | 2012-05-07 15:25:30 +0200 |
commit | eb4ec882eebb4bebea4578888f9e4cdbf3b482f1 (patch) | |
tree | 31c2ea4b2a9932064b3ff9de3304892663313971 | |
parent | 58c44bcceb01f8386df5fdc2f3c26e44f8306dc3 (diff) | |
download | sonarqube-eb4ec882eebb4bebea4578888f9e4cdbf3b482f1.tar.gz sonarqube-eb4ec882eebb4bebea4578888f9e4cdbf3b482f1.zip |
Filter Widget first try
9 files changed, 449 insertions, 359 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 a4746f9dc13..2541173c051 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 @@ -269,6 +269,7 @@ public final class CorePlugin extends SonarPlugin { extensions.add(TreemapWidget.class); extensions.add(GlobalWidget.class); extensions.add(ImageWidget.class); + extensions.add(FilterWidget.class); // dashboards extensions.add(DefaultDashboard.class); diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/FilterWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/FilterWidget.java new file mode 100644 index 00000000000..7feb1410ec7 --- /dev/null +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/FilterWidget.java @@ -0,0 +1,43 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2012 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 + */ +package org.sonar.plugins.core.widgets; + +import org.sonar.api.web.AbstractRubyTemplate; +import org.sonar.api.web.RubyRailsWidget; +import org.sonar.api.web.WidgetCategory; +import org.sonar.api.web.WidgetGlobal; + +@WidgetCategory("Beta") +@WidgetGlobal +public class FilterWidget extends AbstractRubyTemplate implements RubyRailsWidget { + + public String getId() { + return "filter"; + } + + public String getTitle() { + return "Filter"; + } + + @Override + protected String getTemplatePath() { + return "/org/sonar/plugins/core/widgets/filter.html.erb"; + } +} diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/filter.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/filter.html.erb new file mode 100644 index 00000000000..23127eb7fd2 --- /dev/null +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/filter.html.erb @@ -0,0 +1 @@ +<%= render :partial => 'filters/widget' -%>
\ No newline at end of file diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/CorePluginTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/CorePluginTest.java index 75465e752ce..4d58ccd358d 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/CorePluginTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/CorePluginTest.java @@ -19,15 +19,25 @@ */ package org.sonar.plugins.core; -import static org.hamcrest.number.OrderingComparisons.greaterThan; -import static org.junit.Assert.assertThat; import org.junit.Test; +import org.reflections.Reflections; +import org.sonar.api.web.AbstractRubyTemplate; -public class CorePluginTest { +import java.util.Set; + +import static org.fest.assertions.Assertions.assertThat; +public class CorePluginTest { @Test - public void shouldDefineManyExtensions() { - assertThat(new CorePlugin().getExtensions().size(), greaterThan(10)); + public void should_define_many_extensions() { + assertThat(new CorePlugin().getExtensions().size()).isGreaterThan(10); } + @Test + public void should_contain_all_core_widgets() { + Set<Class<? extends AbstractRubyTemplate>> widgets = new Reflections("org.sonar.plugins.core.widgets").getSubTypesOf(AbstractRubyTemplate.class); + + assertThat(widgets).isNotEmpty(); + assertThat(new CorePlugin().getExtensions()).contains(widgets.toArray()); + } } diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties index 33f05a4ee55..efef2bb43b0 100644 --- a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -760,6 +760,9 @@ widget.global.description=Shows Hello Word widget.image.name=Image widget.image.description=Shows an image with a link +widget.filter.name=Filter +widget.filter.description=TODO + #------------------------------------------------------------------------------ # # COMPONENTS diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/filters_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/filters_controller.rb index bb9e2e8a215..d712c13a75a 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/filters_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/filters_controller.rb @@ -34,112 +34,112 @@ class FiltersController < ApplicationController end 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) } + @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) } end def new - @filter=::Filter.new() - @filter.criteria<<Criterion.new_for_qualifiers(['TRK']) + @filter=::Filter.new() + @filter.criteria<<Criterion.new_for_qualifiers(['TRK']) end def create - activate_default_filters_if_needed() - - @filter=::Filter.new() - load_filter_from_params(@filter, params) - - @filter.columns.build(:family => 'name', :order_index => 1, :sort_direction => 'ASC') - @filter.columns.build(:family => 'metric', :kee => 'ncloc', :order_index => 2, :variation => @filter.period?) - @filter.columns.build(:family => 'metric', :kee => 'violations_density', :order_index => 3, :variation => @filter.period?) - @filter.columns.build(:family => 'date', :order_index => 4) - - column_index=0 - @filter.measure_criteria.each do |criterion| - unless @filter.column(criterion.family, criterion.kee) - @filter.columns.build(:family => criterion.family, :kee => criterion.kee, :order_index => 3+column_index, :sort_direction => (column_index==0 ? 'ASC' : nil)) - column_index+=1 - end - end - - 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' - - if params[:preview]=='true' - redirect_to :action => 'edit', :id => @filter.id - else - redirect_to :action => 'index', :id => @filter.id - end - else - render :action => 'new' - end + activate_default_filters_if_needed() + + @filter=::Filter.new() + load_filter_from_params(@filter, params) + + @filter.columns.build(:family => 'name', :order_index => 1, :sort_direction => 'ASC') + @filter.columns.build(:family => 'metric', :kee => 'ncloc', :order_index => 2, :variation => @filter.period?) + @filter.columns.build(:family => 'metric', :kee => 'violations_density', :order_index => 3, :variation => @filter.period?) + @filter.columns.build(:family => 'date', :order_index => 4) + + column_index=0 + @filter.measure_criteria.each do |criterion| + unless @filter.column(criterion.family, criterion.kee) + @filter.columns.build(:family => criterion.family, :kee => criterion.kee, :order_index => 3+column_index, :sort_direction => (column_index==0 ? 'ASC' : nil)) + column_index+=1 + end + end + + 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' + + if params[:preview]=='true' + redirect_to :action => 'edit', :id => @filter.id + else + redirect_to :action => 'index', :id => @filter.id + end + else + render :action => 'new' + end end def edit - @filter=::Filter.find(params[:id]) - access_denied unless @filter.authorized_to_edit?(self) + @filter=::Filter.find(params[:id]) + access_denied unless @filter.authorized_to_edit?(self) - @filter_context=Filters.execute(@filter, self, params) - render :action => 'new' + @filter_context=Filters.execute(@filter, self, params) + render :action => 'new' end def update - @filter=::Filter.find(params[:id]) - access_denied unless @filter.authorized_to_edit?(self) - - load_filter_from_params(@filter, params) - - if @filter.save - flash[:notice]='Filter updated' - if params[:preview]=='true' - redirect_to :action => 'edit', :id => @filter.id - else - redirect_to :action => 'index', :id => @filter.id - end - else - render :action => 'new', :id => @filter.id - end + @filter=::Filter.find(params[:id]) + access_denied unless @filter.authorized_to_edit?(self) + + load_filter_from_params(@filter, params) + + if @filter.save + flash[:notice]='Filter updated' + if params[:preview]=='true' + redirect_to :action => 'edit', :id => @filter.id + else + redirect_to :action => 'index', :id => @filter.id + end + else + render :action => 'new', :id => @filter.id + end end def delete - filter=::Filter.find(:first, :conditions => {:id => params[:id].to_i, :user_id => current_user.id}) - if filter - filter.destroy - flash[:notice]='Filter deleted' - end - redirect_to :action => 'manage' + filter=::Filter.find(:first, :conditions => {:id => params[:id].to_i, :user_id => current_user.id}) + if filter + filter.destroy + flash[:notice]='Filter deleted' + end + redirect_to :action => 'manage' end def activate - 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 } - if existing.nil? - current_user.active_filters.create(:filter => filter, :user => current_user, :order_index => current_user.active_filters.size+1) - end - end - redirect_to :action => 'manage' + 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 } + if existing.nil? + current_user.active_filters.create(:filter => filter, :user => current_user, :order_index => current_user.active_filters.size+1) + end + end + redirect_to :action => 'manage' 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 } - if active_filter - if active_filter.owner? - active_filter.filter.destroy - flash[:notice]='Filter deleted.' - else - active_filter.destroy - flash[:notice]='Filter unfollowed.' - end - end - redirect_to :action => 'manage' + activate_default_filters_if_needed() + 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 + flash[:notice]='Filter deleted.' + else + active_filter.destroy + flash[:notice]='Filter unfollowed.' + end + end + redirect_to :action => 'manage' end @@ -150,52 +150,52 @@ class FiltersController < ApplicationController #--------------------------------------------------------------------- def up - activate_default_filters_if_needed() - - actives=current_user.active_filters - active_index=-1 - active=nil - actives.each_index do |index| - if actives[index].id==params[:id].to_i - active_index=index - active=actives[index] - end - end - - if active && active_index>0 - actives[active_index]=actives[active_index-1] - actives[active_index-1]=active - - actives.each_index do |index| - actives[index].order_index=index+1 - actives[index].save - end - end - redirect_to :action => 'manage' + activate_default_filters_if_needed() + + actives=current_user.active_filters + active_index=-1 + active=nil + actives.each_index do |index| + if actives[index].id==params[:id].to_i + active_index=index + active=actives[index] + end + end + + if active && active_index>0 + actives[active_index]=actives[active_index-1] + actives[active_index-1]=active + + actives.each_index do |index| + actives[index].order_index=index+1 + actives[index].save + end + end + redirect_to :action => 'manage' end def down - activate_default_filters_if_needed() - actives=current_user.active_filters - filter_index=-1 - filter=nil - actives.each_index do |index| - if actives[index].id==params[:id].to_i - filter_index=index - filter=actives[index] - end - end - - if filter && filter_index<actives.size-1 - actives[filter_index]=actives[filter_index+1] - actives[filter_index+1]=filter - - actives.each_index do |index| - actives[index].order_index=index+1 - actives[index].save - end - end - redirect_to :action => 'manage' + activate_default_filters_if_needed() + actives=current_user.active_filters + filter_index=-1 + filter=nil + actives.each_index do |index| + if actives[index].id==params[:id].to_i + filter_index=index + filter=actives[index] + end + end + + if filter && filter_index<actives.size-1 + actives[filter_index]=actives[filter_index+1] + actives[filter_index+1]=filter + + actives.each_index do |index| + actives[index].order_index=index+1 + actives[index].save + end + end + redirect_to :action => 'manage' end @@ -205,86 +205,86 @@ class FiltersController < ApplicationController # #--------------------------------------------------------------------- def delete_column - column=FilterColumn.find(params[:id]) - filter=column.filter - - access_denied unless filter.authorized_to_edit?(self) - - if column.deletable? - column.destroy - redirect_to :action => 'edit', :id => filter.id - else - flash[:error]='Unknown column' - redirect_to :action => 'manage' - end + column=FilterColumn.find(params[:id]) + filter=column.filter + + access_denied unless filter.authorized_to_edit?(self) + + if column.deletable? + column.destroy + redirect_to :action => 'edit', :id => filter.id + else + flash[:error]='Unknown column' + redirect_to :action => 'manage' + end end def add_column - filter=::Filter.find(params[:id]) - access_denied unless filter.authorized_to_edit?(self) - filter.clean_columns_order() # clean the columns which are badly ordered (see SONAR-1902) - - fields=params[:column].split(',') - family=fields[0] - if family=='metric' - filter.columns.create(:family => fields[0], :kee => Metric.by_id(fields[1]).name, :order_index => filter.columns.size + 1, :variation => params[:column_type]=='variation') - elsif family.present? - filter.columns.create(:family => family, :order_index => filter.columns.size + 1) - end - redirect_to :action => 'edit', :id => filter.id + filter=::Filter.find(params[:id]) + access_denied unless filter.authorized_to_edit?(self) + filter.clean_columns_order() # clean the columns which are badly ordered (see SONAR-1902) + + fields=params[:column].split(',') + family=fields[0] + if family=='metric' + filter.columns.create(:family => fields[0], :kee => Metric.by_id(fields[1]).name, :order_index => filter.columns.size + 1, :variation => params[:column_type]=='variation') + elsif family.present? + filter.columns.create(:family => family, :order_index => filter.columns.size + 1) + end + redirect_to :action => 'edit', :id => filter.id end def left_column - column=FilterColumn.find(params[:id]) - filter=column.filter - - access_denied unless filter.authorized_to_edit?(self) - - filter.clean_columns_order() # clean the columns which are badly ordered (see SONAR-1902) - target_column=filter.column_by_id(params[:id].to_i) - if target_column.order_index>1 - target_column.order_index-=1 - target_column.save - old_left_col=filter.columns[target_column.order_index-1] - old_left_col.order_index+=1 - old_left_col.save - end - redirect_to :action => 'edit', :id => filter.id + column=FilterColumn.find(params[:id]) + filter=column.filter + + access_denied unless filter.authorized_to_edit?(self) + + filter.clean_columns_order() # clean the columns which are badly ordered (see SONAR-1902) + target_column=filter.column_by_id(params[:id].to_i) + if target_column.order_index>1 + target_column.order_index-=1 + target_column.save + old_left_col=filter.columns[target_column.order_index-1] + old_left_col.order_index+=1 + old_left_col.save + end + redirect_to :action => 'edit', :id => filter.id end def right_column - column=FilterColumn.find(params[:id]) - filter=column.filter - - access_denied unless filter.authorized_to_edit?(self) - - filter.clean_columns_order() # clean the columns which are badly ordered (see SONAR-1902) - target_column=filter.column_by_id(params[:id].to_i) - if target_column.order_index>=1 && target_column.order_index<filter.columns.size - target_column.order_index+=1 - target_column.save - old_right_col=filter.columns[target_column.order_index-1] - old_right_col.order_index-=1 - old_right_col.save - end - redirect_to :action => 'edit', :id => filter.id + column=FilterColumn.find(params[:id]) + filter=column.filter + + access_denied unless filter.authorized_to_edit?(self) + + filter.clean_columns_order() # clean the columns which are badly ordered (see SONAR-1902) + target_column=filter.column_by_id(params[:id].to_i) + if target_column.order_index>=1 && target_column.order_index<filter.columns.size + target_column.order_index+=1 + target_column.save + old_right_col=filter.columns[target_column.order_index-1] + old_right_col.order_index-=1 + old_right_col.save + end + redirect_to :action => 'edit', :id => filter.id end def set_sorted_column - column=FilterColumn.find(params[:id]) - filter=column.filter - - access_denied unless filter.authorized_to_edit?(self) - - filter.columns.each do |col| - if col==column - col.sort_direction=params[:sort] - else - col.sort_direction=nil - end - col.save! - end - redirect_to :action => 'edit', :id => filter.id + column=FilterColumn.find(params[:id]) + filter=column.filter + + access_denied unless filter.authorized_to_edit?(self) + + filter.columns.each do |col| + if col==column + col.sort_direction=params[:sort] + else + col.sort_direction=nil + end + col.save! + end + redirect_to :action => 'edit', :id => filter.id end @@ -294,36 +294,36 @@ class FiltersController < ApplicationController # #--------------------------------------------------------------------- def set_view - filter=::Filter.find(params[:id]) - access_denied unless filter.authorized_to_edit?(self) + filter=::Filter.find(params[:id]) + access_denied unless filter.authorized_to_edit?(self) - filter.default_view=params[:view] - filter.save - redirect_to :action => :edit, :id => filter.id + filter.default_view=params[:view] + filter.save + redirect_to :action => :edit, :id => filter.id end def set_columns - filter=::Filter.find(params[:id]) - access_denied unless filter.authorized_to_edit?(self) - - filter.columns.clear - params[:columns].each do |colstring| - column=::FilterColumn.create_from_string(colstring) - filter.columns<<column if column - end - filter.save - redirect_to :action => :edit, :id => filter.id + filter=::Filter.find(params[:id]) + access_denied unless filter.authorized_to_edit?(self) + + filter.columns.clear + params[:columns].each do |colstring| + column=::FilterColumn.create_from_string(colstring) + filter.columns<<column if column + end + filter.save + redirect_to :action => :edit, :id => filter.id end def set_page_size - filter=::Filter.find(params[:id]) - access_denied unless filter.authorized_to_edit?(self) - - size=[::Filter::MAX_PAGE_SIZE, params[:size].to_i].min - size=[::Filter::MIN_PAGE_SIZE, size].max - filter.page_size=size - filter.save - redirect_to :action => :edit, :id => filter.id + filter=::Filter.find(params[:id]) + access_denied unless filter.authorized_to_edit?(self) + + size=[::Filter::MAX_PAGE_SIZE, params[:size].to_i].min + size=[::Filter::MIN_PAGE_SIZE, size].max + filter.page_size=size + filter.save + redirect_to :action => :edit, :id => filter.id end #--------------------------------------------------------------------- @@ -332,26 +332,26 @@ class FiltersController < ApplicationController # #--------------------------------------------------------------------- def search_path - if params[:search].present? - if params[:search].size<3 - flash[:warning]='Please type at least 3 characters' - redirect_to :action => :search_path - - 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') - @snapshots=select_authorized(:user, @snapshots) - @snapshots.sort! do |s1, s2| - if s1.qualifier==s2.qualifier - s1.project.long_name<=>s2.project.long_name - else - Resourceable::QUALIFIERS.index(s1.qualifier)<=>Resourceable::QUALIFIERS.index(s2.qualifier) - end - end - end - end - params[:layout]='false' + if params[:search].present? + if params[:search].size<3 + flash[:warning]='Please type at least 3 characters' + redirect_to :action => :search_path + + 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') + @snapshots=select_authorized(:user, @snapshots) + @snapshots.sort! do |s1, s2| + if s1.qualifier==s2.qualifier + s1.project.long_name<=>s2.project.long_name + else + Resourceable::QUALIFIERS.index(s1.qualifier)<=>Resourceable::QUALIFIERS.index(s2.qualifier) + end + end + end + end + params[:layout]='false' end @@ -361,30 +361,30 @@ class FiltersController < ApplicationController # #--------------------------------------------------------------------- def treemap - @filter=::Filter.find(params[:id]) - access_denied unless @filter.authorized_to_execute?(self) + @filter=::Filter.find(params[:id]) + access_denied unless @filter.authorized_to_execute?(self) - @size_metric=Metric.by_key(params[:size_metric]) - @color_metric=Metric.by_key(params[:color_metric]) + @size_metric=Metric.by_key(params[:size_metric]) + @color_metric=Metric.by_key(params[:color_metric]) - params[:metric_ids]=[@size_metric, @color_metric] + params[:metric_ids]=[@size_metric, @color_metric] - @filter.sorted_column=FilterColumn.new('family' => 'metric', :kee => @size_metric.key, :sort_direction => (@size_metric.direction>=0 ? 'ASC' : 'DESC')) + @filter.sorted_column=FilterColumn.new('family' => 'metric', :kee => @size_metric.key, :sort_direction => (@size_metric.direction>=0 ? 'ASC' : 'DESC')) - @filter_context=Filters.execute(@filter, self, params) + @filter_context=Filters.execute(@filter, self, params) - @width=(params[:width]||'800').to_i - @height=(params[:height]||'500').to_i + @width=(params[:width]||'800').to_i + @height=(params[:height]||'500').to_i - @treemap = Sonar::Treemap.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 - }) + @treemap = Sonar::Treemap.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 + }) - #@treemap=Sonar::Treemap.new(@filter_context.measures_by_snapshot, @width, @height, @size_metric, @color_metric, treemap_options) - render :action => "treemap", :layout => false + #@treemap=Sonar::Treemap.new(@filter_context.measures_by_snapshot, @width, @height, @size_metric, @color_metric, treemap_options) + render :action => "treemap", :layout => false end @@ -398,74 +398,74 @@ class FiltersController < ApplicationController private def load_filter_from_params(filter, params) - 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.user_id=current_user.id - filter.period_index=params[:period_index].to_i - filter.criteria=[] - filter.criteria<<Criterion.new_for_qualifiers(params['qualifiers']) - filter.criteria<<Criterion.new(:family => 'date', :operator => params['date_operator'], :value => params['date_value']) if params['date_operator'].present? - filter.criteria<<Criterion.new(:family => 'key', :operator => '=', :text_value => params['key_regexp']) if params['key_regexp'].present? - filter.criteria<<Criterion.new(:family => 'name', :operator => '=', :text_value => params['name_regexp']) if params['name_regexp'].present? - filter.criteria<<Criterion.new(:family => 'language', :operator => '=', :text_value => params['languages'].join(',')) if params['languages'] - - if params[:criteria]['0']['metric_id'].present? - filter.criteria<<Criterion.new_for_metric(params[:criteria]['0']) - end - if params[:criteria]['1']['metric_id'].present? - filter.criteria<<Criterion.new_for_metric(params[:criteria]['1']) - end - if params[:criteria]['2']['metric_id'].present? - filter.criteria<<Criterion.new_for_metric(params[:criteria]['2']) - 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.user_id=current_user.id + filter.period_index=params[:period_index].to_i + filter.criteria=[] + filter.criteria<<Criterion.new_for_qualifiers(params['qualifiers']) + filter.criteria<<Criterion.new(:family => 'date', :operator => params['date_operator'], :value => params['date_value']) if params['date_operator'].present? + filter.criteria<<Criterion.new(:family => 'key', :operator => '=', :text_value => params['key_regexp']) if params['key_regexp'].present? + filter.criteria<<Criterion.new(:family => 'name', :operator => '=', :text_value => params['name_regexp']) if params['name_regexp'].present? + filter.criteria<<Criterion.new(:family => 'language', :operator => '=', :text_value => params['languages'].join(',')) if params['languages'] + + if params[:criteria]['0']['metric_id'].present? + filter.criteria<<Criterion.new_for_metric(params[:criteria]['0']) + end + if params[:criteria]['1']['metric_id'].present? + filter.criteria<<Criterion.new_for_metric(params[:criteria]['1']) + end + if params[:criteria]['2']['metric_id'].present? + filter.criteria<<Criterion.new_for_metric(params[:criteria]['2']) + end end def load_active_filters - @actives=nil - if logged_in? - @actives=current_user.active_filters - @actives=::ActiveFilter.default_active_filters if (@actives.nil? || @actives.empty?) - else - @actives=::ActiveFilter.for_anonymous - end + @actives=nil + if logged_in? + @actives=current_user.active_filters + @actives=::ActiveFilter.default_active_filters if (@actives.nil? || @actives.empty?) + else + @actives=::ActiveFilter.for_anonymous + end end def activate_default_filters_if_needed - if current_user.active_filters.empty? - ActiveFilter.default_active_filters.each do |default_active| - current_user.active_filters.create(:filter => default_active.filter, :user => current_user, :order_index => default_active.order_index) - end - @actives=current_user.active_filters - end + if current_user.active_filters.empty? + ActiveFilter.default_active_filters.each do |default_active| + current_user.active_filters.create(:filter => default_active.filter, :user => current_user, :order_index => default_active.order_index) + end + @actives=current_user.active_filters + end end def load_masterproject() - @masterproject=Snapshot.find(:first, :include => 'project', :conditions => ['projects.kee=? and islast=?', 'MASTER_PROJECT', true]) - @masterproject=nil if @masterproject && !(has_role?(:user, @masterproject)) + @masterproject=Snapshot.find(:first, :include => 'project', :conditions => ['projects.kee=? and islast=?', 'MASTER_PROJECT', true]) + @masterproject=nil if @masterproject && !(has_role?(:user, @masterproject)) end def load_active_filter() - @active=nil - if 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 } - end - - if @active.nil? && !@actives.empty? - @active=@actives.first - end - - @filter=nil - @period_index=params[:period].to_i - if @active - @filter=@active.filter - unless @filter.ajax_loading? - @filter_context=Filters.execute(@filter, self, params) - load_masterproject() if @filter.projects_homepage? - end - end + @active=nil + if 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 } + end + + if @active.nil? && !@actives.empty? + @active=@actives.first + end + + @filter=nil + @period_index=params[:period].to_i + if @active + @filter=@active.filter + unless @filter.ajax_loading? + @filter_context=Filters.execute(@filter, self, params) + load_masterproject() if @filter.projects_homepage? + end + end end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/filters_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/filters_helper.rb index d932ec1131b..f4c41a94f24 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/filters_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/filters_helper.rb @@ -20,59 +20,59 @@ module FiltersHelper def column_title(column, filter) - if column.sortable? - html=link_to h(column.display_name), url_for(:overwrite_params => {:asc => (!(column.ascending?)).to_s, :sort => column.id}) - else - html=h(column.display_name) - end - if column.variation - html="<img src='#{ApplicationController.root_context}/images/trend-up.png'></img> #{html}" - end + if column.sortable? + html=link_to h(column.display_name), url_for(:overwrite_params => {:asc => (!(column.ascending?)).to_s, :sort => column.id}) + else + html=h(column.display_name) + end + if column.variation + html="<img src='#{ApplicationController.root_context}/images/trend-up.png'></img> #{html}" + end - if filter.sorted_column==column - html << (column.ascending? ? image_tag("asc12.png") : image_tag("desc12.png")) - end - html + if filter.sorted_column==column + html << (column.ascending? ? image_tag("asc12.png") : image_tag("desc12.png")) + end + html end def column_align(column) - (column.on_name? || column.on_key?) ? 'left' : 'right' + (column.on_name? || column.on_key?) ? 'left' : 'right' end def treemap_metrics(filter) - metrics=filter.measure_columns.map{|col| col.metric} - size_metric=(metrics.size>=1 ? metrics[0] : Metric.by_key('ncloc')) - color_metric=nil - if metrics.size>=2 - color_metric=metrics[1] - end - if color_metric.nil? || !color_metric.treemap_color? - color_metric=Metric.by_key('violations_density') - end - [size_metric, color_metric] + metrics=filter.measure_columns.map{|col| col.metric} + size_metric=(metrics.size>=1 ? metrics[0] : Metric.by_key('ncloc')) + color_metric=nil + if metrics.size>=2 + color_metric=metrics[1] + end + if color_metric.nil? || !color_metric.treemap_color? + color_metric=Metric.by_key('violations_density') + end + [size_metric, color_metric] end def period_names - p1=Property.value('sonar.timemachine.period1', nil, 'previous_analysis') - p2=Property.value('sonar.timemachine.period2', nil, '5') - p3=Property.value('sonar.timemachine.period3', nil, '30') - [period_name(p1), period_name(p2), period_name(p3)] + p1=Property.value('sonar.timemachine.period1', nil, 'previous_analysis') + p2=Property.value('sonar.timemachine.period2', nil, '5') + p3=Property.value('sonar.timemachine.period3', nil, '30') + [period_name(p1), period_name(p2), period_name(p3)] end private def period_name(property) - if property=='previous_analysis' - message('delta_since_previous_analysis') - elsif property =~ /^[\d]+(\.[\d]+){0,1}$/ - # is integer - message('delta_over_x_days', :params => property) - elsif property =~ /\d{4}-\d{2}-\d{2}/ - message('delta_since', :params => property) - elsif !property.blank? - message('delta_since_version', :params => property) - else - nil - end + if property=='previous_analysis' + message('delta_since_previous_analysis') + elsif property =~ /^[\d]+(\.[\d]+){0,1}$/ + # is integer + message('delta_over_x_days', :params => property) + elsif property =~ /\d{4}-\d{2}-\d{2}/ + message('delta_since', :params => property) + elsif !property.blank? + message('delta_since_version', :params => property) + else + nil + end end -end
\ No newline at end of file +end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_list.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_list.html.erb index bdd465d4e95..1d97fcfedb3 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_list.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_list.html.erb @@ -1,3 +1,25 @@ +<% + def column_align(column) + (column.on_name? || column.on_key?) ? 'left' : 'right' + end + + def column_title(column, filter) + if column.sortable? + html=link_to h(column.display_name), url_for(:overwrite_params => {:asc => (!(column.ascending?)).to_s, :sort => column.id}) + else + html=h(column.display_name) + end + if column.variation + html="<img src='#{ApplicationController.root_context}/images/trend-up.png'></img> #{html}" + end + + if filter.sorted_column==column + html << (column.ascending? ? image_tag("asc12.png") : image_tag("desc12.png")) + end + html + end +%> + <% filter=@filter_context.filter %> <div> <% unless edit_mode %> @@ -42,7 +64,7 @@ <td colspan="<%= filter.columns.size + 1 -%>"> <span id="results_count"><%= pluralize(@filter_context.size, message('result').downcase) %></span> - <% + <% if @filter_context.page_count>1 max_pages = @filter_context.page_count current_page = @filter_context.page_id @@ -57,7 +79,7 @@ end_page = max_pages else start_page = current_page-10 - end_page = current_page+9 + end_page = current_page+9 end end %> @@ -155,4 +177,4 @@ <% if @filter_context.security_exclusions? %> <p class="notes"><%= message('results_not_display_due_to_security') -%></p> <% end %> -</div>
\ No newline at end of file +</div> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_widget.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_widget.html.erb new file mode 100644 index 00000000000..62cd8c0d34c --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_widget.html.erb @@ -0,0 +1,10 @@ +<% + def period_names + ['A','B','C','D'] + end + + @filter=::Filter.find(1) + @filter_context=Filters.execute(@filter, self, params) +%> + +<%= render :partial => "filters/#{@filter.default_view}", :locals => {:edit_mode => false, :period_names => period_names()} %> |