Feature #3718 » 0009-categoria_padre.diff
| app/views/issues/_attributes.html.erb Wed Aug 07 15:28:59 2013 +0200 | ||
|---|---|---|
|
<% end %>
|
||
|
|
||
|
<% if @issue.safe_attribute?('category_id') && @issue.project.issue_categories.any? %>
|
||
|
<p><%= f.select :category_id, (@issue.project.issue_categories.collect {|c| [c.name, c.id]}), :include_blank => true, :required => @issue.required_attribute?('category_id') %>
|
||
|
<p><%= 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,
|
||
| app/models/issue_category.rb Wed Aug 07 15:28:59 2013 +0200 | ||
|---|---|---|
|
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)}
|
||
|
|
||
| ... | ... | |
|
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
|
||
| app/views/issue_categories/_form.html.erb Wed Aug 07 15:28:59 2013 +0200 | ||
|---|---|---|
|
<div class="box tabular">
|
||
|
<p><%= f.text_field :name, :size => 30, :required => true %></p>
|
||
|
<p><%= f.select :assigned_to_id, principals_options_for_select(@project.assignable_users, @category.assigned_to), :include_blank => true %></p>
|
||
|
<p><%= 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 %></p>
|
||
|
</div>
|
||
| app/views/issues/show.html.erb Wed Aug 07 15:28:59 2013 +0200 | ||
|---|---|---|
|
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'
|
||
| app/models/project.rb Wed Aug 07 15:28:59 2013 +0200 | ||
|---|---|---|
|
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
|
||
| db/migrate/20130807152159_add_categoria_padre_to_issue_categories.rb Thu Aug 08 08:42:00 2013 +0200 | ||
|---|---|---|
|
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
|
||
| app/views/projects/settings/_issue_categories.html.erb Thu Aug 08 08:42:00 2013 +0200 | ||
|---|---|---|
|
<table class="list">
|
||
|
<thead><tr>
|
||
|
<th><%= l(:label_issue_category) %></th>
|
||
|
<th><%= l(:categoria_padre) %></th>
|
||
|
<th><%= l(:field_assigned_to) %></th>
|
||
|
<th></th>
|
||
|
</tr></thead>
|
||
|
<tbody>
|
||
|
<% for category in @project.issue_categories %>
|
||
|
<% for category in @project.issue_categories[0].get_categories(@project,nil) %>
|
||
|
<% unless category.new_record? %>
|
||
|
<tr class="<%= cycle 'odd', 'even' %>">
|
||
|
<td><%=h(category.name) %></td>
|
||
|
<td><%=h( ("»"*((category.full_name(category,@project,category.name).split("/").length)-1))+" "+category.name ) %></td>
|
||
|
<td><%=h((@project.issue_categories.detect{ |c| c.id == category.categoria_padre}).name) if category.categoria_padre %></td>
|
||
|
<td><%=h(category.assigned_to.name) if category.assigned_to %></td>
|
||
|
<td class="buttons">
|
||
|
<% if User.current.allowed_to?(:manage_categories, @project) %>
|
||
| config/locales/es.yml Thu Aug 08 08:42:00 2013 +0200 | ||
|---|---|---|
|
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"
|
||
| app/controllers/issue_categories_controller.rb Thu Aug 08 08:42:00 2013 +0200 | ||
|---|---|---|
|
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
|
||
| ... | ... | |
|
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
|
||
| ... | ... | |
|
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
|
||
|
|
||
- « Previous
- 1
- …
- 3
- 4
- 5
- Next »