From 7dbc751f1e65bf1e318655fe5ce79527851bb7a7 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Thu, 10 May 2012 15:17:13 +0200 Subject: SONAR-3465 My filters configuration --- .../main/resources/org/sonar/l10n/core.properties | 3 +- .../app/controllers/admin_filters_controller.rb | 100 ---- .../WEB-INF/app/controllers/filters_controller.rb | 586 +++++++++------------ .../WEB-INF/app/views/admin_filters/index.html.erb | 72 --- .../webapp/WEB-INF/app/views/filters/_menu.erb | 15 + .../WEB-INF/app/views/filters/_tabs.html.erb | 21 - .../WEB-INF/app/views/filters/index.html.erb | 5 +- .../WEB-INF/app/views/filters/manage.html.erb | 105 ++-- .../webapp/WEB-INF/app/views/filters/new.html.erb | 321 +++++------ .../WEB-INF/app/views/layouts/_layout.html.erb | 2 +- 10 files changed, 463 insertions(+), 767 deletions(-) delete mode 100644 sonar-server/src/main/webapp/WEB-INF/app/controllers/admin_filters_controller.rb delete mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/admin_filters/index.html.erb create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/filters/_menu.erb delete mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/filters/_tabs.html.erb 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 97cba6c2cd5..de40f14bc95 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 @@ -357,6 +357,7 @@ session.flash_notice.logged_out=You have been logged out. # #------------------------------------------------------------------------------ +filters.new=New filter filters.size=Size filters.color=Color filters.add_filter=Add filter @@ -380,8 +381,6 @@ filters.treemap_not_supported_for_period_selection=Treemap does not support yet filters.my_filters=My filters filters.no_filters=No filters filters.do_you_want_to_stop_following=Do you want to stop following this filter ? -filters.shared_filters=Shared filters -filters.shared_filters_description=These filters are shared by administrators and can be followed without copying them. filters.criteria=Criteria filters.display_form.title=Display filters.display_form.as=Display as diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/admin_filters_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/admin_filters_controller.rb deleted file mode 100644 index 621a4b9e29f..00000000000 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/admin_filters_controller.rb +++ /dev/null @@ -1,100 +0,0 @@ -# -# Sonar, entreprise quality control 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 -# -class AdminFiltersController < ApplicationController - include FiltersHelper - - SECTION=Navigation::SECTION_CONFIGURATION - - verify :method => :post, :only => [:up, :down, :remove, :add], :redirect_to => {:action => :index} - before_filter :admin_required - before_filter :load_active_filters - - def index - @shared_filters=::Filter.find(:all, :conditions => {:shared => true}).sort{|a,b| a.name.downcase<=>b.name.downcase} - ids=@actives.map{|af| af.filter_id} - @shared_filters.reject!{|f| ids.include?(f.id) } - end - - def up - 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 => 'index' - end - - def down - 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 => 'index' - end - - def add - filter=::Filter.find(:first, :conditions => ['shared=? and id=?', true, params[:id].to_i]) - if filter - ActiveFilter.create(:filter => filter, :user => nil, :order_index => @actives.size+1) - flash[:notice]='Default filter added.' - end - redirect_to :action => 'index' - end - - def remove - active=@actives.to_a.find{|af| af.id==params[:id].to_i} - if active - active.destroy - flash[:notice]='Filter removed from default filters.' - end - redirect_to :action => 'index' - end - - private - - def load_active_filters - @actives=ActiveFilter.default_active_filters - end -end 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 d712c13a75a..2b9649f1ad8 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 @@ -22,269 +22,183 @@ class FiltersController < ApplicationController helper MetricsHelper helper FiltersHelper + #SECTION=Navigation::SECTION_CONFIGURATION 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'] def index + load_active_filters() load_active_filter() 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) } + @filters = ::Filter.find(:all, :conditions => ['user_id=? or user_id is null', current_user.id]) end def new - @filter=::Filter.new() - @filter.criteria< '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 => 'manage', :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 => 'manage', :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' - 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' - end - - - #--------------------------------------------------------------------- - # - # TABS - # - #--------------------------------------------------------------------- - - 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' - 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 'manage' - end - - #--------------------------------------------------------------------- # # COLUMNS # #--------------------------------------------------------------------- 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 '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 '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 +208,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< :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< :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 +246,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 +275,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 +312,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< 'date', :operator => params['date_operator'], :value => params['date_value']) if params['date_operator'].present? - filter.criteria< 'key', :operator => '=', :text_value => params['key_regexp']) if params['key_regexp'].present? - filter.criteria< 'name', :operator => '=', :text_value => params['name_regexp']) if params['name_regexp'].present? - filter.criteria< 'language', :operator => '=', :text_value => params['languages'].join(',')) if params['languages'] - - if params[:criteria]['0']['metric_id'].present? - filter.criteria< 'date', :operator => params['date_operator'], :value => params['date_value']) if params['date_operator'].present? + filter.criteria< 'key', :operator => '=', :text_value => params['key_regexp']) if params['key_regexp'].present? + filter.criteria< 'name', :operator => '=', :text_value => params['name_regexp']) if params['name_regexp'].present? + filter.criteria< 'language', :operator => '=', :text_value => params['languages'].join(',')) if params['languages'] + + if params[:criteria]['0']['metric_id'].present? + filter.criteria< 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_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 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/views/admin_filters/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/admin_filters/index.html.erb deleted file mode 100644 index 06254b1f73a..00000000000 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/admin_filters/index.html.erb +++ /dev/null @@ -1,72 +0,0 @@ -
-

<%= message('filters.default') -%>

-

<%= message('filters.default.description') -%>

- - - - - - - - - - - - <% if @actives.empty? %> - - - - <% else %> - <% @actives.each_with_index do |active, index| %> - - - - - - - <% end %> - <% end %> - -
<%= message('name') -%><%= message('author') -%><%= message('order') -%><%= message('operations') -%>
No results.
<%= active.name %> - <%= h(active.author_name) %> - - <% if index>0 %> - <%= link_to image_tag('blue-up.png'), {:action => :up, :id => active.id}, :method => :post, :id => "up-#{u active.name}" %> - <% else %> - <%= image_tag('transparent_16.gif') %> - <% end %> - <% if index<@actives.size-1 %> - <%= link_to image_tag('blue-down.png'), {:action => :down, :id => active.id}, :method => :post, :id => "down-#{u active.name}" %> - <% end %> - - <%= link_to 'Remove', {:action => 'remove', :id => active.id}, {:confirm => 'Are you sure to remove it from default filters ?', :method => :post, :id => "remove-#{u active.name}", :class => 'link-action'} %> -
- -

<%= message('filters.shared') -%>

-

<%= message('filters.shared.description') -%>

- - - - - - - - - - - <% if @shared_filters.nil? || @shared_filters.empty? %> - - - - <% else %> - <% @shared_filters.each do |filter| %> - - - - - - <% end %> - <% end %> - -
<%= message('name') -%><%= message('author') -%><%= message('operations') -%>
No results.
<%= h(filter.name) -%><%= h(filter.user.name) if filter.user -%><%= link_to 'Add to defaults', {:action => 'add', :id => filter.id}, {:method => :post, :id => "add-#{u filter.name}", :class => 'link-action'} %>
-
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_menu.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_menu.erb new file mode 100644 index 00000000000..63d0f4adccc --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_menu.erb @@ -0,0 +1,15 @@ +<% if logged_in? %> +
+ +
+<% end %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_tabs.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_tabs.html.erb deleted file mode 100644 index 09fd2a9013d..00000000000 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_tabs.html.erb +++ /dev/null @@ -1,21 +0,0 @@ -<% if logged_in? %> -
- -
-<% end %> - -<% if selected_tab && @actives && !@actives.empty? %> - -<% end %> \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/filters/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/filters/index.html.erb index 4790275a8c5..137ece702db 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/filters/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/filters/index.html.erb @@ -1,4 +1 @@ -<%= render :partial => 'filters/tabs', :locals => {:selected_tab=> (@active && @active.filter ? @active.filter.id : nil) } %> -
- <%= render :partial => "filters/#{@filter.default_view}", :locals => {:edit_mode => false} if @filter %> -
+<%= render :partial => "#{@filter.default_view}", :locals => {:edit_mode => false} if @filter %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/filters/manage.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/filters/manage.html.erb index 8d7486cb191..9e191947586 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/filters/manage.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/filters/manage.html.erb @@ -1,80 +1,39 @@ -<%= render :partial => 'filters/tabs', :locals => {:selected_tab => nil} %> +<%= render :partial => 'menu' %> -

<%= message('filters.my_filters') -%>

-
- - - - - - - - - - - - <% if @actives.nil? || @actives.empty? %> - +
+

<%= message('filters.my_filters') -%>

- <% - else - @actives.each_with_index do |active,index| %> -
- - - - - - - <% end - end - %> - -
<%= message('name') -%><%= message('author') -%><%= message('shared') -%><%= message('order') -%><%= message('operations') -%>
<%= message('filters.no_filters') -%>
<%= active.name %> - <%= h(active.author_name) %> - - <%= boolean_icon(active.filter.shared, {:display_false => false}) -%> - - <% if index>0 %> - <%= link_to image_tag('blue-up.png'), {:action => :up, :id => active.id}, :method => :post, :id => "up-#{u active.name}" %> - <% else %> - <%= image_tag('transparent_16.gif') %> - <% end %> - <% if index<@actives.size-1 %> - <%= link_to image_tag('blue-down.png'), {:action => :down, :id => active.id}, :method => :post, :id => "down-#{u active.name}" %> - <% end %> - - <% if active.filter.authorized_to_edit?(self) %> - <%= link_to message('edit'), {:action => 'edit', :id => active.filter_id}, :id => "edit-#{u active.name}" %> | - <%= link_to message('delete'), {:action => 'deactivate', :id => active.filter_id}, :method => :post, :confirm => message('filters.do_you_want_to_delete'), :id => "delete-#{u active.name}" %> - <% else %> - <%= link_to message('unfollow'), {:action => 'deactivate', :id => active.filter_id}, :method => :post, :confirm => message('filters.do_you_want_to_stop_following'), :id => "unfollow-#{u active.name}" %> - <% end %> -
- -


-

<%= message('filters.shared_filters') -%>

-

<%= message('filters.shared_filters_description') -%>

-
- - +
+ - - + + - - - <% if @shared_filters.nil? || @shared_filters.empty? %> - - <% else %> - <% @shared_filters.each do |filter| %> - - - - + + + <% if @filters.empty? %> + + + <% else %> + <% @filters.each do |filter| %> + + + + + + <% end %> <% end %> - <% end %> - -
<%= message('name') -%><%= message('author') -%><%= message('operations') -%><%= message('shared') -%><%= message('operations') -%>
<%= message('no_results') -%>.
<%= h(filter.name) -%><%= h(filter.user.name) if filter.user -%><%= link_to 'Follow', {:action => 'activate', :id => filter.id}, :method => :post, :id => "add-#{u filter.name}" %>
<%= message('filters.no_filters') -%>
+ <%= filter.name -%> + + <%= boolean_icon(filter.shared, {:display_false => false}) -%> + + <% if filter.authorized_to_edit?(self) %> + <%= link_to message('edit'), {:action => :edit, :id => filter.id}, :id => "edit-#{u filter.name}", :class => 'link-action' %> | + <%= link_to message('delete'), {:action => :delete, :id => filter.id}, :method => :post, :confirm => message('filters.do_you_want_to_delete'), :id => "delete-#{u filter.name}", :class => 'link-action' %> + <% end %> +
\ No newline at end of file + + + diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/filters/new.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/filters/new.html.erb index a8ec9cb8a0c..208c3b92317 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/filters/new.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/filters/new.html.erb @@ -1,206 +1,211 @@ -<%= render :partial => 'filters/tabs', :locals => {:selected_tab=> (@filter.id ? @filter.id : 'new')} %> - - -
+<%= render :partial => 'menu' %> + +

<%= message('filters.new') -%>

+
- + <%= error_messages_for 'filter', :header_message => nil, :class => 'formError', :message => nil %> - - - - - - - + + + + + + - - - - - - - - - - - - - - <% unless @filter.advanced_search? %> + <% for desc in controller.java_facade.getResourceTypesForFilter() + qualifier = desc.getQualifier() %> + id="q-<%= qualifier -%>"/> + + + <% end %> + + + + + + + + + + + + + + + <% unless @filter.advanced_search? %> - + - <% end %> + <% end %> - - - - - - - + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - + - - -
<%= message('name') -%>: - + <% if is_admin? %> - - - > + + + /> <% end %>
<%= message('path') -%>: - <%= @filter.resource ? @filter.resource.path_name : params[:path_name] -%> - - <%= message('search_verb') -%> - <%= message('reset_verb') -%> -
<%= message('filters.search_for') -%>: - <% qualifiers=(@filter.criterion('qualifier') ? @filter.criterion('qualifier').text_values : []) %> +
<%= message('path') -%>: + <%= @filter.resource ? @filter.resource.path_name : params[:path_name] -%> + + <%= message('search_verb') -%> + <%= message('reset_verb') -%> +
<%= message('filters.search_for') -%>: + <% qualifiers=(@filter.criterion('qualifier') ? @filter.criterion('qualifier').text_values : []) %> - id="q-TRK"> - + id="q-TRK"/> + + - id="q-BRC"> - + id="q-BRC"/> + + - id="q-DIR"> - + id="q-DIR"/> + + - id="q-FIL"> - + id="q-FIL"/> + + - id="q-UTS"> - + id="q-UTS"/> + + - <% for desc in controller.java_facade.getResourceTypesForFilter() - qualifier = desc.getQualifier() %> - id="q-<%= qualifier -%>"> - - - <% end %> -
<%= message('filters.criteria') -%>: - <%= render :partial => 'filters/criterion', :locals => {:id => '0', :criterion => (@filter.measure_criteria.size>0 ? @filter.measure_criteria[0] : nil)} %> -
<%= message('and').downcase -%>: - <%= render :partial => 'filters/criterion', :locals => {:id => '1', :criterion => (@filter.measure_criteria.size>1 ? @filter.measure_criteria[1] : nil) } %> -
<%= message('and').downcase -%>: - <%= render :partial => 'filters/criterion', :locals => {:id => '2', :criterion => (@filter.measure_criteria.size>2 ? @filter.measure_criteria[2] : nil) } %> -
<%= message('filters.criteria') -%>: + <%= render :partial => 'filters/criterion', :locals => {:id => '0', :criterion => (@filter.measure_criteria.size>0 ? @filter.measure_criteria[0] : nil)} %> +
<%= message('and').downcase -%>: + <%= render :partial => 'filters/criterion', :locals => {:id => '1', :criterion => (@filter.measure_criteria.size>1 ? @filter.measure_criteria[1] : nil)} %> +
<%= message('and').downcase -%>: + <%= render :partial => 'filters/criterion', :locals => {:id => '2', :criterion => (@filter.measure_criteria.size>2 ? @filter.measure_criteria[2] : nil)} %> +
<%= message('filters.default_period') -%>: - -
<%= message('language') -%>: - <% languages=(@filter.criterion('language') ? @filter.criterion('language').text_values : []) %> - <% controller.java_facade.getLanguages().each do |language| %> - id="lang-<%= language.getKey() -%>"> +
<%= message('filters.default_period') -%>: +
<%= image_tag 'star.png' %> - > -
- <% key_regexp_criterion=@filter.criterion('key') %> - - <%= message('filters.use_star_to_match') -%> -
- <% name_regexp_criterion=@filter.criterion('name') %> - - <%= message('filters.use_star_to_match') -%> -
- <% date_criterion = @filter.criterion('date') %> - - <%= message('days').downcase -%> -
<%= message('language') -%>: + <% languages=(@filter.criterion('language') ? @filter.criterion('language').text_values : []) %> + <% controller.java_facade.getLanguages().each do |language| %> + id="lang-<%= language.getKey() -%>"> + + <% end %> + <%= message('filters.when_no_language_no_filter_apply') -%> +
<%= image_tag 'star.png' %> + + /> +
+ <% key_regexp_criterion=@filter.criterion('key') %> + + <%= message('filters.use_star_to_match') -%> +
+ <% name_regexp_criterion=@filter.criterion('name') %> + + <%= message('filters.use_star_to_match') -%> +
+ <% date_criterion = @filter.criterion('date') %> + + <%= message('days').downcase -%> +
- - - +
+ + + + + <% if @filter.id + confirmation_message = message('filters.do_you_want_to_delete') + %> + - <% if @filter.id - confirmation_message = message('filters.do_you_want_to_delete') - %> - - - <%= message('cancel') -%> - <% else %> - <%= message('cancel') -%> - <% end %> -
-
+ <%= message('cancel') -%> + <% else %> + <%= message('cancel') -%> + <% end %> + + + + +
-
<% if @filter_context %>

<%= message('filters.display_form.title') -%>

+
- <%= render :partial => "filters/customize_#{@filter.default_view}" %> + <%= render :partial => "customize_#{@filter.default_view}" %>
<%= message('filters.display_form.as') -%>:
- id="view-list" onClick="$('view-loading').show();submit();"> + id="view-list" onClick="$('view-loading').show();submit();"/> + - id="view-treemap" onClick="$('view-loading').show();submit();"> + id="view-treemap" onClick="$('view-loading').show();submit();"/> + - <%= image_tag 'loading.gif', :id => 'view-loading', :style=>'display: none' %> + <%= image_tag 'loading.gif', :id => 'view-loading', :style => 'display: none' %>

- <%= render :partial => "filters/#{@filter.default_view}", :locals => {:edit_mode => true} %> + <%= render :partial => "#{@filter.default_view}", :locals => {:edit_mode => true} %> <% end %> -
\ No newline at end of file + + diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb index bd130391597..8a4a2cb790a 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb @@ -126,7 +126,7 @@
  • <%= message('manual_rules.page') -%>
  • - <%= message('default_filters.page') -%>
  • + <%= message('default_filters.page') -%>
  • <%= message('default_dashboards.page') -%>
  • <% controller.java_facade.getPages(Navigation::SECTION_CONFIGURATION, nil, nil, nil, nil).each do |page| -- cgit v1.2.3