Index: app/views/issues/_attributes.html.erb =================================================================== --- app/views/issues/_attributes.html.erb Fri May 31 10:36:41 2013 +0200 +++ app/views/issues/_attributes.html.erb Wed Aug 07 15:28:59 2013 +0200 @@ -19,7 +19,7 @@ <% end %> <% if @issue.safe_attribute?('category_id') && @issue.project.issue_categories.any? %> -

<%= f.select :category_id, (@issue.project.issue_categories.collect {|c| [c.name, c.id]}), :include_blank => true, :required => @issue.required_attribute?('category_id') %> +

<%= f.select :category_id, (@issue.project.issue_categories[0].get_categories(@project,nil).collect{ |c| [c.full_name(c,@project,c.name),c.id]}), :include_blank => true, :required => @issue.required_attribute?('category_id') %> <%= link_to(image_tag('add.png', :style => 'vertical-align: middle;'), new_project_issue_category_path(@issue.project), :remote => true, Index: app/models/issue_category.rb ======================================================================== --- app/models/issue_category.rb Fri May 31 10:36:41 2013 +0200 +++ app/models/issue_category.rb Wed Aug 07 15:28:59 2013 +0200 @@ -25,7 +25,7 @@ validates_uniqueness_of :name, :scope => [:project_id] validates_length_of :name, :maximum => 30 - safe_attributes 'name', 'assigned_to_id' + safe_attributes 'name', 'assigned_to_id', 'categoria_padre' scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)} @@ -43,6 +43,45 @@ def <=>(category) name <=> category.name end - + + def all_sons(cat,proj) + mysons = proj.issue_categories.select{ |c| c.categoria_padre == cat.id } + sons = [] + if mysons.length < 1 + return mysons + else + for son in mysons + sons.push(son) + sons.push *all_sons(son,proj) + end + return sons + end + end + + def full_name(cat,proj,fullname) + if cat.categoria_padre.nil? + myfathers = proj.issue_categories.select{ |c| c.id == 0 } + else + myfathers = proj.issue_categories.select{ |c| c.id == cat.categoria_padre } + end + if myfathers.length < 1 + return fullname + else + father = myfathers[0] + fullname = father.name+" / "+fullname + return full_name(father,proj,fullname) + end + end + + def get_categories(proj,idcat) + categories = proj.issue_categories.select{ |c| c.categoria_padre == nil && !c.id.nil? && c.id != idcat } + cats = [] + for c in categories + cats.push(c) + cats.push *all_sons(c,proj) + end + return cats + end + def to_s; name end end Index: app/views/issue_categories/_form.html.erb ======================================================================== --- app/views/issue_categories/_form.html.erb Fri May 31 10:36:41 2013 +0200 +++ app/views/issue_categories/_form.html.erb Wed Aug 07 15:28:59 2013 +0200 @@ -3,4 +3,5 @@

<%= f.text_field :name, :size => 30, :required => true %>

<%= f.select :assigned_to_id, principals_options_for_select(@project.assignable_users, @category.assigned_to), :include_blank => true %>

+

<%= f.select :categoria_padre, options_for_select(@category.name.nil? || @category.name=="" ? @category.get_categories(@project,nil).collect{ |c| [c.full_name(c,@project,c.name),c.id]} : ((@category.get_categories(@project,@category.id).collect{ |c| [c.full_name(c,@project,c.name),c.id] })),@category.categoria_padre) , :include_blank => true %>

Index: app/views/issues/show.html.erb =================================================================== --- app/views/issues/show.html.erb Fri May 31 10:36:41 2013 +0200 +++ app/views/issues/show.html.erb Wed Aug 07 15:28:59 2013 +0200 @@ -40,7 +40,7 @@ rows.left l(:field_assigned_to), avatar(@issue.assigned_to, :size => "14").to_s.html_safe + (@issue.assigned_to ? link_to_user(@issue.assigned_to) : "-"), :class => 'assigned-to' end unless @issue.disabled_core_fields.include?('category_id') - rows.left l(:field_category), h(@issue.category ? @issue.category.name : "-"), :class => 'category' + rows.left l(:field_category), h(@issue.category ? @issue.category.full_name(@issue.category,@project,@issue.category.name) : "-"), :class => 'category' end unless @issue.disabled_core_fields.include?('fixed_version_id') rows.left l(:field_fixed_version), (@issue.fixed_version ? link_to_version(@issue.fixed_version) : "-"), :class => 'fixed-version' Index: app/models/project.rb =================================================================== --- app/models/project.rb Fri May 31 10:36:41 2013 +0200 +++ app/models/project.rb Wed Aug 07 15:28:59 2013 +0200 @@ -45,7 +45,7 @@ has_many :queries, :class_name => 'IssueQuery', :dependent => :delete_all has_many :documents, :dependent => :destroy has_many :news, :dependent => :destroy, :include => :author - has_many :issue_categories, :dependent => :delete_all, :order => "#{IssueCategory.table_name}.name" + has_many :issue_categories, :dependent => :delete_all, :order => "COALESCE(#{IssueCategory.table_name}.categoria_padre, #{IssueCategory.table_name}.id), #{IssueCategory.table_name}.categoria_padre IS NOT NULL, #{IssueCategory.table_name}.id" has_many :boards, :dependent => :destroy, :order => "position ASC" has_one :repository, :conditions => ["is_default = ?", true] has_many :repositories, :dependent => :destroy Index: db/migrate/20130807152159_add_categoria_padre_to_issue_categories.rb ======================================================================== --- db/migrate/20130807152159_add_categoria_padre_to_issue_categories.rb Thu Aug 08 08:41:00 2013 +0000 +++ db/migrate/20130807152159_add_categoria_padre_to_issue_categories.rb Thu Aug 08 08:42:00 2013 +0200 @@ -0,0 +1,11 @@ +class AddCategoriaPadreToIssueCategories < ActiveRecord::Migration + + def self.up + add_column :issue_categories, :categoria_padre, :int, :default => 0 + end + + def self.down + remove_column :issue_categories, :categoria_padre + end + +end \ No newline at end of file Index: app/views/projects/settings/_issue_categories.html.erb =================================================================== --- app/views/projects/settings/_issue_categories.html.erb Thu Aug 08 08:41:00 2013 +0200 +++ app/views/projects/settings/_issue_categories.html.erb Thu Aug 08 08:42:00 2013 +0200 @@ -2,14 +2,16 @@ + -<% for category in @project.issue_categories %> +<% for category in @project.issue_categories[0].get_categories(@project,nil) %> <% unless category.new_record? %> - + +
<%= l(:label_issue_category) %><%= l(:categoria_padre) %> <%= l(:field_assigned_to) %>
<%=h(category.name) %><%=h( ("»"*((category.full_name(category,@project,category.name).split("/").length)-1))+" "+category.name ) %><%=h((@project.issue_categories.detect{ |c| c.id == category.categoria_padre}).name) if category.categoria_padre %> <%=h(category.assigned_to.name) if category.assigned_to %> <% if User.current.allowed_to?(:manage_categories, @project) %> Index: config/locales/es.yml =================================================================== --- config/locales/es.yml Thu Aug 08 08:41:00 2013 +0200 +++ config/locales/es.yml Thu Aug 08 08:42:00 2013 +0200 @@ -1124,3 +1124,6 @@ field_closed_on: Closed setting_default_projects_tracker_ids: Default trackers for new projects label_total_time: Total + categoria_padre: categoría padre + field_categoria_padre: categoría padre + notice_tiene_subcategorias: "Primero debe eliminar las subcategorias" Index: app/controllers/issue_categories_controller.rb =================================================================== --- app/controllers/issue_categories_controller.rb Thu Aug 08 08:41:00 2013 +0200 +++ app/controllers/issue_categories_controller.rb Thu Aug 08 08:42:00 2013 +0200 @@ -51,6 +51,8 @@ def create @category = @project.issue_categories.build @category.safe_attributes = params[:issue_category] + #cat2 = @project.issue_categories.detect{ |c| c.id == @category.categoria_padre } + @category.name = level(@category,"") + @category.name if @category.save respond_to do |format| format.html do @@ -69,6 +70,22 @@ end end end + + def level(cat=nil,lev="") + if cat.categoria_padre.nil? || cat.categoria_padre == "" + return lev + else + #lev = lev+">" + cat2 = @project.issue_categories.detect{ |c| c.id == cat.categoria_padre } + if !cat2.name.nil? && cat2.name != "" + #lev = lev + ">" + #super unless ['try', 'test', 'my_method'].include? + level(cat2,lev) + else + return lev + end + end + end def edit end @@ -91,21 +107,26 @@ end def destroy - @issue_count = @category.issues.size - if @issue_count == 0 || params[:todo] || api_request? - reassign_to = nil - if params[:reassign_to_id] && (params[:todo] == 'reassign' || params[:todo].blank?) - reassign_to = @project.issue_categories.find_by_id(params[:reassign_to_id]) - end - @category.destroy(reassign_to) - respond_to do |format| - format.html { redirect_to_settings_in_projects } - format.api { render_api_ok } - end - return - end - @categories = @project.issue_categories - [@category] - end + if @category.all_sons(@category,@project).length > 0 + flash[:notice] = l(:notice_tiene_subcategorias) + index + else + @issue_count = @category.issues.size + if @issue_count == 0 || params[:todo] || api_request? + reassign_to = nil + if params[:reassign_to_id] && (params[:todo] == 'reassign' || params[:todo].blank?) + reassign_to = @project.issue_categories.find_by_id(params[:reassign_to_id]) + end + @category.destroy(reassign_to) + respond_to do |format| + format.html { redirect_to_settings_in_projects } + format.api { render_api_ok } + end + return + end + @categories = @project.issue_categories - [@category] + end + end private