class Omniboard::Column
The column. Each column represents either:
-
A grouped column, if Column#group_by or Column.group_by are set
-
An ungrouped column, if they aren't
Constants
- ALLOWED_PROJECT_COUNTS
- ALLOWED_PROJECT_DISPLAYS
- INHERITED_PROPERTIES
Attributes
Column
name, used to display
All projects contained by the column
Public Class Methods
Add a column to the global columns register
# File lib/omniboard/column.rb, line 259 def add(c) @columns << c @columns = @columns.sort_by(&:order) end
Clear configuration option. You can always pass :all to clear all configuration options
# File lib/omniboard/column.rb, line 328 def clear_config config case config when :conditions @conditions = nil when :sort @sort = nil when :group_by @group_by = nil when :mark_when @mark_when = nil when :dim_when @dim_when = nil when :icon @icon = nil when :sort_groups @sort_groups = nil when :group_name @group_name = nil when :hide_dimmed @hide_dimmed = false when :display_project_counts @display_project_counts = nil when :all @conditions = nil @sort = nil @group_by = nil @mark_when = nil @dim_when = nil @icon = nil @sort_groups = nil @group_name = nil @hide_dimmed = false @display_project_counts = nil else raise ArgumentError, "Do not know how to clear config: #{config}" end end
Returns the appropriate hue for a given group, if it matches any of the colour groups provided by @colour_groups
# File lib/omniboard/column.rb, line 317 def colour_for_group(group) colour_group = @colour_groups.find{ |cgp| cgp[:block][group] } return colour_group && colour_group[:hue] end
Assign a colour to a group, given it fits a block
# File lib/omniboard/column.rb, line 312 def colour_group(hue, &blck) @colour_groups << {hue: hue, block: blck} end
Config method
# File lib/omniboard/column.rb, line 323 def config &blck self.instance_exec(&blck) end
Intializer. Provide name and block for instance evaluation (optional)
# File lib/omniboard/column.rb, line 59 def initialize(name, &blck) # Set defaults self.name = name self.projects = [] self.order(0) self.width(1) self.columns(1) self.display(:full) self.display_project_counts(nil) self.project_limit(nil) self.filter_button(false) INHERITED_PROPERTIES.each{ |s| self.send(s, :inherit) } instance_exec(&blck) if blck Omniboard::Column.add(self) end
Wipe the global register of columns. Useful when resetting Omniboard
to a default state
# File lib/omniboard/column.rb, line 266 def reset_columns @columns = [] end
Public Instance Methods
Add an array of projects to the column. If conditions
is set, each project will be run through it. Only projects that return true
will be allowed in.
# File lib/omniboard/column.rb, line 87 def add(arr) # Reset cache @grouped_projects = nil # Make sure it's an array arr = [arr] unless arr.is_a?(Array) || arr.is_a?(Rubyfocus::SearchableArray) # Run through individual conditions block arr = arr.select{ |p| self.conditions[p] } if self.conditions # Run through global conditions block arr = arr.select{ |p| self.class.conditions[p] } if self.class.conditions # Wrap in ProjectWrappers arr = arr.map{ |p| p.is_a?(Omniboard::ProjectWrapper) ? p : Omniboard::ProjectWrapper.new(p, column: self) } # Tasks performed upon adding project to column. Add to group, mark & dim appropriately arr.each do |pw| pw.column = self pw.group = self.group_for(pw) pw.marked = self.should_mark(pw) pw.dimmed = self.should_dim(pw) # Icon methods icon_attrs = self.icon_for(pw) if icon_attrs.is_a?(Array) pw.icon, pw.icon_alt = *icon_attrs else pw.icon = icon_attrs end end @projects += arr end
Returns true if column or global group_by supplied
# File lib/omniboard/column.rb, line 149 def can_be_grouped? !!property(:group_by) end
# File lib/omniboard/column.rb, line 224 def count_div total = case property(:display_project_counts) when :all self.projects.count when :active self.projects.select{ |p| !p.dimmed? }.count when :marked self.projects.select{ |p| p.marked? }.count else 0 end css_class = "column-total" css_class << " limit-breached" if project_limit && project_limit < total %|<div class="#{css_class}">#{total}</div>| end
Return the group a project should fall into
# File lib/omniboard/column.rb, line 177 def group_for(project) gby = property(:group_by) if gby Omniboard::Group[gby[project]] else nil end end
Return the group name for a given group
# File lib/omniboard/column.rb, line 187 def group_name_for(group) gname = property(:group_name) gname ? gname[group] : group.to_s end
Return a hash of arrays of sorted projects, grouped using the group_by lambda. Note: Unsorted
# File lib/omniboard/column.rb, line 171 def grouped_projects raise(RuntimeError, "Attempted to return grouped projects from column #{self.name}, but no group_by method defined.") unless can_be_grouped? @grouped_projects ||= self.projects.group_by(&:group) end
Returns a sorted array of groups. Returned as strings
# File lib/omniboard/column.rb, line 154 def groups keys = grouped_projects.keys.map(&:identifier) group_sort_block = property(:sort_groups) if group_sort_block.nil? keys.sort elsif group_sort_block.arity == 1 keys.sort_by(&group_sort_block) elsif group_sort_block.arity == 2 keys.sort(&group_sort_block) else raise ArgumentError, "Omniboard::Column.group_sort has an arity of #{group_sort_block.arity}, must take either 1 or 2 arguments." end end
Return the icon for a given project, based on icon blocks
# File lib/omniboard/column.rb, line 213 def icon_for(project) ic = property(:icon) if ic ic[project] else nil end end
Fetch the appropriate property value. If the value is :inherit, will fetch the appropriate value from Omniboard::Column
# File lib/omniboard/column.rb, line 78 def property(sym) raise(ArgumentError, "Unrecognised property #{sym}: allowed values are #{INHERITED_PROPERTIES.join(", ")}.") unless INHERITED_PROPERTIES.include?(sym) v = self.send(sym) v = Omniboard::Column.send(sym) if v == :inherit v end
Return the dimmed status of a given project, based on mark_when blocks
# File lib/omniboard/column.rb, line 203 def should_dim(project) dim = property(:dim_when) if dim dim[project] else false end end
Return the marked status of a given project, based on mark_when blocks
# File lib/omniboard/column.rb, line 193 def should_mark(project) mark = property(:mark_when) if mark mark[project] else false end end
# File lib/omniboard/column.rb, line 9 def to_s; @name; end