Module: Sequel::Plugins::BureauAdapter::ClassMethods

Includes:
Bureau::Adapter::ClassMethods
Defined in:
lib/sequel_bureau_adapter.rb

Instance Attribute Summary collapse

Attributes included from Bureau::Adapter::ClassMethods

#bureau_config

Instance Method Summary collapse

Methods included from Bureau::Adapter::ClassMethods

#command_plus, #command_reload, #command_search, #human_name, #list_title, #list_view_header, #many_to_many_picker

Instance Attribute Details

#list_optionsObject

Returns the value of attribute list_options.



78
79
80
# File 'lib/sequel_bureau_adapter.rb', line 78

def list_options
  @list_options
end

Instance Method Details

#foreign_key_name(plural) ⇒ Object



107
108
109
# File 'lib/sequel_bureau_adapter.rb', line 107

def foreign_key_name plural 
  "#{underscore(demodulize(name))}_id#{'s' if plural}" 
end

#human_plural_nameObject



111
# File 'lib/sequel_bureau_adapter.rb', line 111

def human_plural_name; self.table_name.to_s.tr('_', ' ').gsub(/(['\w]+)/) {|s| "#{s.capitalize}"}; end

#list_view(r) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/sequel_bureau_adapter.rb', line 80

def list_view(r)
  @list_options={:request=>r, :destination=>r.fullpath, :path=>r.script_name }
  # symbolize keys of filter
  unless r['filter'].nil?
    @list_options[:filter] = {}
    r['filter'].each do |key,value|
      @list_options[:filter][key.to_sym] = value
    end
  end
  @list_options.store(:search, r['q'].scan(/\w+/).map {|w| "%#{w}%"}) unless r['q'].to_s==''
  @list_options.store(:sortable,sortable_on_that_page?)
  o = @list_options

  out = list_view_header
  out << scene_selector unless bureau_config[:scene_selector_class].nil?
  out << many_to_many_picker unless bureau_config[:minilist_class].nil?
  out << "<ul class='nut-tree #{'sortable' if o[:sortable]} #{bureau_config[:nut_tree_class]}' id='#{self.name}' rel='#{o[:path]}/#{self.name}'>"
  
  ds = self
  ds = ds.filter(o[:filter]) unless o[:filter].nil?
  ds = ds.grep(text_columns, o[:search], {:all_patterns=>true, :case_insensitive=>true}) unless (o[:search].nil? || o[:search].empty?)
  ds.all {|e| out << e.to_nutshell }
  
  out << "</ul>"
  out
end

#minilist_viewObject



119
120
121
122
123
124
125
126
# File 'lib/sequel_bureau_adapter.rb', line 119

def minilist_view
  o = "<ul class='minilist'>\n"
  self.all do |m|
    thumb = m.respond_to?(:to_bureau_thumb) ? m.to_bureau_thumb('stash_thumb.gif') : m.placeholder_thumb('stash_thumb.gif')
    o << "<li title='#{m.to_label}' id='mini-#{m.id}'>#{thumb}<div>#{m.to_label}</div></li>\n"
  end
  o << "</ul>\n"
end

#scene_selectorObject



128
129
130
# File 'lib/sequel_bureau_adapter.rb', line 128

def scene_selector
  "Not yet implemented for Sequel. See Mongo implementation. And do not forget to implement instance.scene_selector_coordinates."
end

#sortable_on_that_page?Boolean

Returns:

  • (Boolean)


114
115
116
117
# File 'lib/sequel_bureau_adapter.rb', line 114

def sortable_on_that_page?
  o = @list_options
  o[:search].nil? && respond_to?(:position_field) && (o[:filter]||{}).keys==[bureau_config[:position_scope]].compact 
end

#text_columnsObject



112
# File 'lib/sequel_bureau_adapter.rb', line 112

def text_columns; crushyform_schema.inject([]){|a,(k,v)| a<<k if [:text,:string,:autocomplete,:permalink,:select].include?(v[:type]);a}; end