Index: app/models/query.rb
===================================================================
--- app/models/query.rb	(revision 7557)
+++ app/models/query.rb	(working copy)
@@ -222,7 +222,8 @@
                            "start_date" => { :type => :date, :order => 11 },
                            "due_date" => { :type => :date, :order => 12 },
                            "estimated_hours" => { :type => :float, :order => 13 },
-                           "done_ratio" =>  { :type => :integer, :order => 14 }}
+                           "done_ratio" =>  { :type => :integer, :order => 14 },
+                           "limit_sub_level" => { :type => :list, :order => 16, :values => ["0","1","2"]}}
 
     principals = []
     if project
@@ -632,6 +633,37 @@
     '(' + sql_for_field("assigned_to_id", operator, members_of_roles, Issue.table_name, "assigned_to_id", false) + ')'
   end
 
+  def sql_for_limit_sub_level_field(field, operator, value)
+    sql_for_field = "("
+    v = value.to_s.to_i
+    if v >= 0
+      sql_for_field << "#{Issue.table_name}.parent_id IS NULL "
+    end
+    if v >= 1
+      sql_for_field << "OR #{Issue.table_name}.parent_id IN" 
+      sql_for_field << "( "
+      sql_for_field << "SELECT #{Issue.table_name}.id "
+      sql_for_field << "FROM #{Issue.table_name} "
+      sql_for_field << "WHERE #{Issue.table_name}.parent_id IS NULL"
+      sql_for_field << ")"
+    end
+    if v >= 2
+      sql_for_field << "OR #{Issue.table_name}.parent_id IN" 
+      sql_for_field << "( "
+      sql_for_field << "SELECT #{Issue.table_name}.id "
+      sql_for_field << "FROM #{Issue.table_name} "
+      sql_for_field << "WHERE #{Issue.table_name}.parent_id IN"
+      sql_for_field << "( "
+      sql_for_field << "SELECT #{Issue.table_name}.id "
+      sql_for_field << "FROM #{Issue.table_name} "
+      sql_for_field << "WHERE #{Issue.table_name}.parent_id IS NULL"
+      sql_for_field << ")"
+      sql_for_field << ")"
+    end
+    sql_for_field << ")"
+    sql_for_field
+  end
+  
   private
 
   def sql_for_custom_field(field, operator, value, custom_field_id)
Index: config/locales/en-GB.yml
===================================================================
--- config/locales/en-GB.yml	(revision 7557)
+++ config/locales/en-GB.yml	(working copy)
@@ -311,6 +311,7 @@
   field_text: Text field
   field_visible: Visible
   field_warn_on_leaving_unsaved: "Warn me when leaving a page with unsaved text"
+  field_limit_sub_level: Sub issues limit
   
   setting_app_title: Application title
   setting_app_subtitle: Application subtitle
Index: config/locales/en.yml
===================================================================
--- config/locales/en.yml	(revision 7557)
+++ config/locales/en.yml	(working copy)
@@ -315,6 +315,7 @@
   field_root_directory: Root directory
   field_cvsroot: CVSROOT
   field_cvs_module: Module
+  field_limit_sub_level: Sub issues limit
 
   setting_app_title: Application title
   setting_app_subtitle: Application subtitle
Index: config/locales/fr.yml
===================================================================
--- config/locales/fr.yml	(revision 7557)
+++ config/locales/fr.yml	(working copy)
@@ -315,7 +315,8 @@
   field_issues_visibility: Visibilité des demandes
   field_is_private: Privée
   field_commit_logs_encoding: Encodage des messages de commit
-
+  field_limit_sub_level: Limite de sous tâche
+  
   setting_app_title: Titre de l'application
   setting_app_subtitle: Sous-titre de l'application
   setting_welcome_text: Texte d'accueil
