Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
tsonntag committed Mar 5, 2012
1 parent a3d4065 commit b7ae90f
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 28 deletions.
1 change: 0 additions & 1 deletion lib/gitter/base.rb
Expand Up @@ -41,7 +41,6 @@ def initialize *args
@values[name] = value
end
end
puts "IIIIIIIIIIIII #{@values}"
end

def filter_value filter_name
Expand Down
4 changes: 2 additions & 2 deletions lib/gitter/column.rb
Expand Up @@ -36,8 +36,8 @@ def cell model
if block
grid.eval block, model
else
model.send attr
end
model.send(attr)
end
end

def ordered
Expand Down
2 changes: 1 addition & 1 deletion lib/gitter/columns.rb
Expand Up @@ -46,7 +46,7 @@ def header_rows
end

def row_for model
columns.map{|c| c.cell model }.compact
columns.map{|c| c.cell model }
end

def rows driver = self.scope
Expand Down
2 changes: 1 addition & 1 deletion lib/gitter/drivers/active_record_driver.rb
Expand Up @@ -58,7 +58,7 @@ def named_scope name

def distinct_values attr
attribute = attr.to_s.split(/\./).last || attr
scope.select("DISTINCT #{attr}").map(&:"#{attribute}")
scope.select("DISTINCT #{attr}").map(&:"#{attribute}").uniq
end

private
Expand Down
43 changes: 22 additions & 21 deletions lib/gitter/facet.rb
Expand Up @@ -6,8 +6,8 @@ class FacetData
include Utils

attr_reader :facet, :value, :count
delegate :grid, :name, :to => :facet
delegate :h, :to => :grid
delegate :grid, :name, to: :facet
delegate :h, to: :grid

def initialize facet, value, count
@facet, @value, @count = facet, value, count
Expand All @@ -22,25 +22,26 @@ def selected?
end

def link
h = grid.h
p = grid.params.dup
p[name] = value.nil? ? '' : value
p = grid.scoped_params p
p[:page] = 1

value_class = selected? ? 'facet_value_selected' : 'selected'
value_tag = h.content_tag :span, (value.nil? ? '-' : value), class: value_class
value_tag = h.link_to value_tag, url_for(p)

puts "FFFFFFFFFF #{self}, selected=#{selected?}, f=#{facet.selected?}"
if selected? or not facet.selected?
count_tag = h.content_tag :span, "(#{count})", :class => 'facet_count'
count_tag = h.link_to count_tag, url_for(p.merge(:show=>true))
else
count_tag = ''
@link ||= begin
p = grid.params.dup
p.delete name
p[name] = value if value.present?
p = grid.scoped_params p
p[:page] = 1

value_class = selected? ? 'facet_value_selected' : 'selected'
value_tag = h.content_tag :span, (value.nil? ? '-' : value), class: value_class
value_tag = h.link_to value_tag, url_for(p)

if selected? or not facet.selected?
count_tag = h.content_tag :span, "(#{count})", class: 'facet_count'
count_tag = h.link_to count_tag, url_for(p.merge(show: true))
else
count_tag = ''
end

h.content_tag :span, (value_tag + count_tag), {class: 'facet_entry'}, false
end

h.content_tag :span, (value_tag + count_tag), {:class => 'facet_entry'}, false
end

def to_s
Expand All @@ -51,7 +52,7 @@ def to_s

class Facet
attr_reader :filter
delegate :grid, :name, :to => :filter
delegate :grid, :name, to: :filter

def initialize filter
@filter = filter
Expand Down
6 changes: 4 additions & 2 deletions lib/gitter/header.rb
Expand Up @@ -7,8 +7,10 @@ def self.blank

attr_reader :grid, :name, :content, :html_options, :column

def initialize grid, name = nil, content = nil, opts = {}
@grid, @name, @content = grid, name, content
def initialize grid, *args
opts = args.extract_options!
@grid = grid
@name, @content = *args
@column = opts.delete(:column){nil}
@html_options = opts
end
Expand Down
4 changes: 4 additions & 0 deletions lib/gitter/helpers.rb
Expand Up @@ -18,6 +18,10 @@ def mark *keys
{ mark: keys.map{|k|filter_value k}.select{|v|v.present?} }
end

def highlight text, *keys
h.highlight "#{text}", mark(*keys)[:mark]
end

def h
@decorator.h
end
Expand Down

0 comments on commit b7ae90f

Please sign in to comment.