Métodos comunes para los contenidos que tienen asignado un área a través del tag del área .
# File app/models/tools/with_area_tag.rb, line 31 def self.included(base) base.after_save :sync_comments_area_tags base.before_save :save_tag_list_and_area_tag_list end
Si hay más de un área que corresponde al documento, usamos el órden de las áreas y cogemos el primero.
# File app/models/tools/with_area_tag.rb, line 44 def area self.areas.first end
# File app/models/tools/with_area_tag.rb, line 48 def area_id=(aid) # guardamos el valor nuevo por si sale un error al guardar los datos y hay que volver al formulario if aid.present? @area_id = aid.to_i # borrar el área anterior if self.area.present? current_area_tag = self.area.area_tag self.taggings = self.taggings.map {|t| t unless t.tag_id.eql?(current_area_tag.id)}.compact end # añadir el área nuevo. Puede estar en blanco if Area.exists?(aid) new_area_tag = Area.find(aid).area_tag self.taggings.build(:tag_id => new_area_tag.id) end @area_id end end
def #area_tags=(atags)
logger.info "------------ #{atags}" @area_tags = atags
end
# File app/models/tools/with_area_tag.rb, line 89 def area_ids areas.collect(&:id) end
# File app/models/tools/with_area_tag.rb, line 77 def area_name self.area.present? ? self.area.name : '' end
El área de un documento se coge de los tags de áreas que este tiene. Se ordenan de acuerdo con el orden oficial de las áreas
# File app/models/tools/with_area_tag.rb, line 38 def areas Tagging.find(:all, :conditions => {:taggable_type => 'Area', :tag_id => self.tag_ids}).map {|t| t.taggable}.sort {|a,b| a.position <=> b.position} end
# File app/models/tools/with_area_tag.rb, line 117 def save_tag_list_and_area_tag_list if @area_tags || @tag_list_without_areas tags = [] tags << @area_tags if @area_tags tags << @tag_list_without_areas.split(',') if @tag_list_without_areas self.tag_list = TagList.from(tags).uniq.join(',') end end