Skip to content

Commit

Permalink
Review response: Mixin moved to presenter
Browse files Browse the repository at this point in the history
  • Loading branch information
romanblanco committed Mar 20, 2017
1 parent 896b77b commit 226652f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 31 deletions.
29 changes: 0 additions & 29 deletions app/controllers/mixins/custom_buttons.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,6 @@
module Mixins::CustomButtons
extend ActiveSupport::Concern

def get_tree_aset_kids_for_nil_id(object, count_only)
count_only ? get_custom_buttons(object).count : get_custom_buttons(object).sort_by { |a| a.name.downcase }
end

def buttons_ordered?(object)
!!(object[:set_data] && object[:set_data][:button_order])
end

def x_get_tree_aset_kids(object, count_only)
if object.id.nil?
get_tree_aset_kids_for_nil_id(object, count_only)
elsif count_only
object.members.count
else
button_order = buttons_ordered?(object) ? object[:set_data][:button_order] : nil
Array(button_order).each_with_object([]) do |bidx, arr|
object.members.each { |b| arr.push(b) if bidx == b.id && !arr.include?(b) }
end
end
end

def get_custom_buttons(object)
# FIXME: don't we have a method for the splits?
# FIXME: cannot we ask for the null parent using Arel?
CustomButton.buttons_for(object.name.split('|').last.split('-').last).select do |uri|
uri.parent.nil?
end
end

def custom_toolbar?
return nil unless self.class.instance_eval { @custom_buttons }

Expand Down
31 changes: 31 additions & 0 deletions app/presenters/custom_buttons_mixin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module CustomButtonsMixin
extend ActiveSupport::Concern
def get_tree_aset_kids_for_nil_id(object, count_only)
count_only ? get_custom_buttons(object).count : get_custom_buttons(object).sort_by { |a| a.name.downcase }
end

def buttons_ordered?(object)
!!(object[:set_data] && object[:set_data][:button_order])
end

def get_custom_buttons(object)
# FIXME: don't we have a method for the splits?
# FIXME: cannot we ask for the null parent using Arel?
CustomButton.buttons_for(object.name.split('|').last.split('-').last).select do |uri|
uri.parent.nil?
end
end

def x_get_tree_aset_kids(object, count_only)
if object.id.nil?
get_tree_aset_kids_for_nil_id(object, count_only)
elsif count_only
object.members.count
else
button_order = buttons_ordered?(object) ? object[:set_data][:button_order] : nil
Array(button_order).each_with_object([]) do |bidx, arr|
object.members.each { |b| arr.push(b) if bidx == b.id && !arr.include?(b) }
end
end
end
end
2 changes: 1 addition & 1 deletion app/presenters/tree_builder_buttons.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class TreeBuilderButtons < TreeBuilderAeCustomization
include Mixins::CustomButtons
include CustomButtonsMixin
has_kids_for CustomButtonSet, [:x_get_tree_aset_kids]

private
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/tree_builder_catalogs_class.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class TreeBuilderCatalogsClass < TreeBuilder
include Mixins::CustomButtons
include CustomButtonsMixin
has_kids_for CustomButtonSet, [:x_get_tree_aset_kids]

private
Expand Down

0 comments on commit 226652f

Please sign in to comment.