Class: Omniboard::Column
- Inherits:
-
Object
- Object
- Omniboard::Column
- Extended by:
- Property
- Includes:
- Property
- Defined in:
- lib/omniboard/column.rb
Overview
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
Constant Summary collapse
- INHERITED_PROPERTIES =
%i(sort mark_when dim_when icon group_by sort_groups group_name hide_dimmed display_project_counts)
- ALLOWED_PROJECT_COUNTS =
%i(all active marked inherit)
- ALLOWED_PROJECT_DISPLAYS =
%i(full compact)
Class Attribute Summary collapse
-
.columns ⇒ Object
readonly
Returns the value of attribute columns.
Instance Attribute Summary collapse
-
#name ⇒ Object
Column name, used to display.
-
#projects(group = nil) ⇒ Object
Return an array of projects, sorted according to the sort block (or not, if no sort block supplied).
Class Method Summary collapse
-
.add(c) ⇒ Object
Add a column to the global columns register.
-
.clear_config(config) ⇒ Object
Clear configuration option.
-
.colour_for_group(group) ⇒ Object
Returns the appropriate hue for a given group, if it matches any of the colour groups provided by @colour_groups.
-
.colour_group(hue, &blck) ⇒ Object
Assign a colour to a group, given it fits a block.
-
.config(&blck) ⇒ Object
Config method.
-
.reset_columns ⇒ Object
Wipe the global register of columns.
Instance Method Summary collapse
-
#<< ⇒ Object
Add an array of projects to the column.
-
#add(arr) ⇒ Object
Add an array of projects to the column.
-
#can_be_grouped? ⇒ Boolean
Returns true if column or global group_by supplied.
-
#count_div ⇒ Object
————————————— Presentation methods.
-
#group_for(project) ⇒ Object
Return the group a project should fall into.
-
#group_name_for(group) ⇒ Object
Return the group name for a given group.
-
#grouped_projects ⇒ Object
Return a hash of arrays of sorted projects, grouped using the group_by lambda.
-
#groups ⇒ Object
Returns a sorted array of groups.
-
#icon_for(project) ⇒ Object
Return the icon for a given project, based on icon blocks.
-
#initialize(name, &blck) ⇒ Column
constructor
Intializer.
-
#property(sym) ⇒ Object
Fetch the appropriate property value.
-
#should_dim(project) ⇒ Object
Return the dimmed status of a given project, based on mark_when blocks.
-
#should_mark(project) ⇒ Object
Return the marked status of a given project, based on mark_when blocks.
- #to_s ⇒ Object
Methods included from Property
Constructor Details
#initialize(name, &blck) ⇒ Column
Intializer. Provide name and block for instance evaluation (optional)
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# 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.(false) INHERITED_PROPERTIES.each{ |s| self.send(s, :inherit) } instance_exec(&blck) if blck Omniboard::Column.add(self) end |
Class Attribute Details
.columns ⇒ Object (readonly)
Returns the value of attribute columns.
256 257 258 |
# File 'lib/omniboard/column.rb', line 256 def columns @columns end |
Instance Attribute Details
#name ⇒ Object
Column name, used to display
8 9 10 |
# File 'lib/omniboard/column.rb', line 8 def name @name end |
#projects(group = nil) ⇒ Object
Return an array of projects, sorted according to the sort block (or not, if no sort block supplied). If group string is provided, only fetched projects for that group
12 13 14 |
# File 'lib/omniboard/column.rb', line 12 def projects @projects end |
Class Method Details
.add(c) ⇒ Object
Add a column to the global columns register
259 260 261 262 |
# File 'lib/omniboard/column.rb', line 259 def add(c) @columns << c @columns = @columns.sort_by(&:order) end |
.clear_config(config) ⇒ Object
Clear configuration option. You can always pass :all to clear all configuration options
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
# 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 |
.colour_for_group(group) ⇒ Object
Returns the appropriate hue for a given group, if it matches any of the colour groups provided by @colour_groups
317 318 319 320 |
# 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 |
.colour_group(hue, &blck) ⇒ Object
Assign a colour to a group, given it fits a block
312 313 314 |
# File 'lib/omniboard/column.rb', line 312 def colour_group(hue, &blck) @colour_groups << {hue: hue, block: blck} end |
.config(&blck) ⇒ Object
Config method
323 324 325 |
# File 'lib/omniboard/column.rb', line 323 def config &blck self.instance_exec(&blck) end |
.reset_columns ⇒ Object
Wipe the global register of columns. Useful when resetting Omniboard to a default state
266 267 268 |
# File 'lib/omniboard/column.rb', line 266 def reset_columns @columns = [] end |
Instance Method Details
#<< ⇒ Object
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.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/omniboard/column.rb', line 122 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 |
#add(arr) ⇒ Object
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.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# 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 |
#can_be_grouped? ⇒ Boolean
Returns true if column or global group_by supplied
149 150 151 |
# File 'lib/omniboard/column.rb', line 149 def can_be_grouped? !!property(:group_by) end |
#count_div ⇒ Object
Presentation methods
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# 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 |
#group_for(project) ⇒ Object
Return the group a project should fall into
177 178 179 180 181 182 183 184 |
# 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 |
#group_name_for(group) ⇒ Object
Return the group name for a given group
187 188 189 190 |
# File 'lib/omniboard/column.rb', line 187 def group_name_for(group) gname = property(:group_name) gname ? gname[group] : group.to_s end |
#grouped_projects ⇒ Object
Return a hash of arrays of sorted projects, grouped using the group_by lambda. Note: Unsorted
171 172 173 174 |
# 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 |
#groups ⇒ Object
Returns a sorted array of groups. Returned as strings
154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# 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 |
#icon_for(project) ⇒ Object
Return the icon for a given project, based on icon blocks
213 214 215 216 217 218 219 220 |
# File 'lib/omniboard/column.rb', line 213 def icon_for(project) ic = property(:icon) if ic ic[project] else nil end end |
#property(sym) ⇒ Object
Fetch the appropriate property value. If the value is :inherit, will fetch the appropriate value from Omniboard::Column
78 79 80 81 82 83 |
# 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 |
#should_dim(project) ⇒ Object
Return the dimmed status of a given project, based on mark_when blocks
203 204 205 206 207 208 209 210 |
# File 'lib/omniboard/column.rb', line 203 def should_dim(project) dim = property(:dim_when) if dim dim[project] else false end end |
#should_mark(project) ⇒ Object
Return the marked status of a given project, based on mark_when blocks
193 194 195 196 197 198 199 200 |
# File 'lib/omniboard/column.rb', line 193 def should_mark(project) mark = property(:mark_when) if mark mark[project] else false end end |
#to_s ⇒ Object
9 |
# File 'lib/omniboard/column.rb', line 9 def to_s; @name; end |