Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
150 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module Gitter | ||
|
||
class Axis | ||
|
||
attr_reader :grid, :name, :attr | ||
|
||
def initialize grid, name, opts = {} | ||
@grid, @name = grid, name | ||
@attr = opts.delete(:column){name} | ||
only = opts.delete(:only){nil} | ||
case only | ||
when Hash | ||
@only_data, @titles= only.keys, only | ||
else | ||
@only_data, @titles = only, nil | ||
end | ||
@except = opts.delete(:except){[]} | ||
end | ||
|
||
|
||
def data | ||
data = case attr | ||
when Symbol,String | ||
grid.scope.select(attr).uniq.map(&:"#{attr}").sort | ||
else | ||
attr | ||
end | ||
|
||
data = (data & @only_data) if @only_data | ||
data = data - @except | ||
end | ||
|
||
def titles | ||
if @titles | ||
data.map{|d|@titles[d]} | ||
else | ||
data | ||
end | ||
end | ||
|
||
def data_titles | ||
res = {} | ||
data.each{|d| res[d] = @titles ? @titles[d] : d} | ||
res | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
module Gitter | ||
|
||
module Pivot | ||
|
||
def x_axis *args | ||
if args.present? | ||
@x_axis = Axis.new self, *args | ||
else | ||
@x_axis or raise ConfigurationError, 'undefined x_axis' | ||
end | ||
end | ||
|
||
def y_axis *args | ||
if args.present? | ||
@y_axis = Axis.new self, *args | ||
else | ||
@y_axis or raise ConfigurationError, 'undefined y_axis' | ||
end | ||
end | ||
|
||
def cell &cell | ||
if cell | ||
@cell ||= cell | ||
else | ||
@cell or raise ConfigurationError, 'undefined cell' | ||
end | ||
end | ||
|
||
def drill_down *names | ||
if names.present? | ||
@drill_down ||= [names].flatten.map{|name| @filters[name] or raise ConfigurationError, "unknown filter #{name}"} | ||
else | ||
@drill_down ||= @filters | ||
end | ||
end | ||
|
||
def input_tags | ||
[] | ||
end | ||
|
||
def columns | ||
@columns ||= x_axis.titles.map{|x|Column.new self, x} | ||
end | ||
|
||
def header_rows | ||
@header_rows ||= begin | ||
row = [''] + x_axis.titles | ||
row = row.map{|h|Gitter::Header.new self, h} | ||
[row] | ||
end | ||
end | ||
|
||
def rows scope = self.scope | ||
y_axis.data_titles.map do |y,y_title| | ||
row = [] | ||
row << Gitter::Cell.new(y_title) | ||
row += x_axis.data.map do |x| | ||
content = cell.call data_scope, x, y | ||
Gitter::Cell.new content | ||
end | ||
end | ||
end | ||
|
||
private | ||
def data_scope | ||
@data_scope ||= scope.group(x_axis.attr).group(y_axis.attr) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'gitter/driver' | ||
require 'gitter/base' | ||
require 'gitter/pivot' | ||
require 'gitter/breadcrumbs' | ||
require 'gitter/csv' | ||
require 'gitter/i18n' | ||
require 'gitter/helpers' | ||
require 'gitter/model' | ||
|
||
module Gitter | ||
|
||
class PivotGrid | ||
include Gitter::Base | ||
include Gitter::Driver | ||
include Gitter::Pivot | ||
include Gitter::Breadcrumbs | ||
include Gitter::CSV | ||
include Gitter::I18n | ||
include Gitter::Helpers | ||
include Gitter::Model | ||
end | ||
|
||
end |