compendium 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +39 -33
- data/app/classes/compendium/presenters/metric.rb +15 -2
- data/app/views/compendium/reports/_metric.haml +5 -0
- data/lib/compendium/metric.rb +4 -0
- data/lib/compendium/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YWEzYjAwNDlhYjlhZGQ1ODY0NTBmNThhY2ZjOTU4ZTMzMWMzM2Y0OA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YWZlOGE4NmE3NjQ5ZDM1ODZmMzlhOTJiZjhmYWZjYTU0NTNiN2FiMw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjQyMDM2NTE0OGYxMzZhZGUxNzQ5MDkzNGJlMDJmMzcxZjgyNTFjNzAzNDkw
|
10
|
+
ZmVkNWVlNTcxYzkwZTFhOGE1ODdjYmE2NzdlMjNmOGM2Y2I3MjAwZTNlYWI1
|
11
|
+
NzAwNmVlZTY2OTYwMzI5MDcwMTcxYzg3MmY5Y2Q3ZjI2NTRhNzM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YmYzYmRjZDkyN2Q5ZWU2ZDlhODBiMmJkMjgxNzY3NWE0ZmM4YTFjZDE4NGNj
|
14
|
+
MDY2NTk2YzkwYjIyMmZiMTA1MGYxOWRmOTI2N2NmZjE0MDVlNmYyYTdiNzZh
|
15
|
+
NTIyMjQ3NzNmZDRiYTE3YjI4NTg2NmM5NzJiNWFkODkxM2I1MWI=
|
data/README.md
CHANGED
@@ -8,42 +8,46 @@ Compendium is a reporting framework for Rails which makes it easy to create and
|
|
8
8
|
|
9
9
|
A Compendium report is a subclass of `Compendium::Report`. Reports can be defined using the simple DSL:
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
11
|
+
```ruby
|
12
|
+
class MyReport < Compendium::Report
|
13
|
+
# Options define which parameters your report will accept when being set up.
|
14
|
+
# An option is defined with a name, a type, and some settings (ie. default value, choices for radio buttons and
|
15
|
+
# dropdowns, etc.)
|
16
|
+
option :starting_on, :date, default: -> { Date.today - 1.month }
|
17
|
+
option :ending_on, :date, default: -> { Date.today }
|
18
|
+
option :currency, :radio, choices: [:USD, :CAD, :GBP]
|
19
|
+
|
20
|
+
# By default, queries are converted to SQL and executed instead of returning AR models
|
21
|
+
# The query definition block gets the report's current parameters
|
22
|
+
# totals: true means that the last row returned should be interpretted as a row of totals
|
23
|
+
query :deliveries, totals: true do |params|
|
24
|
+
Items.where(delivered: true, purchased_at: (params[:starting_on]..params[:ending_on]))
|
25
|
+
end
|
26
|
+
|
27
|
+
# Define a query which collects data by using AR directly
|
28
|
+
query :on_hand_inventory, collect: :active_record do |params|
|
29
|
+
Items.where(in_stock: true)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Define a query that works on another query's result set
|
33
|
+
# Note: chart and data are aliases for query
|
34
|
+
chart :deliveries_over_time, through: :deliveries do |results|
|
35
|
+
results.group_by(&:purchased_at)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Queries can also be used to drive metrics
|
39
|
+
metric :shipping_time, -> results { results.last['shipping_time'] }, through: :deliveries
|
40
|
+
end
|
41
|
+
```
|
40
42
|
|
41
43
|
Reports can then also be simply instantiated (which is done automatically if using the supplied
|
42
44
|
`Compendium::ReportsController`):
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
-
|
46
|
+
```ruby
|
47
|
+
report = MyReport.new(starting_on: '2013-06-01')
|
48
|
+
report.run(self) # The parameter is the context to run the report in; usually this should be
|
49
|
+
# a controller context so that methods like current_user can be used
|
50
|
+
```
|
47
51
|
|
48
52
|
Compendium also comes with a variety of different presenters, for rendering the setup page, and displaying charts
|
49
53
|
(`report.render_chart`), tables (`report.render_table`) and metrics for your report. Charting is delegated through a
|
@@ -60,7 +64,9 @@ method (*NOTE:* you have to pass `local_assigns` into it if you want locals to b
|
|
60
64
|
Routes are not automatically added to your application. In order to do so, you can use the `mount_compendium` helper
|
61
65
|
within your `config/routes.rb` file
|
62
66
|
|
63
|
-
|
67
|
+
```ruby
|
68
|
+
mount_compendium at: '/report', controller: 'reports' # controller defaults to compendium/reports
|
69
|
+
```
|
64
70
|
|
65
71
|
### Interaction with other gems
|
66
72
|
* If [accessible_tooltip](https://github.com/dvandersluis/accessible_tooltip) is present, option notes will be rendered
|
@@ -2,10 +2,19 @@ module Compendium::Presenters
|
|
2
2
|
class Metric < Base
|
3
3
|
presents :metric
|
4
4
|
|
5
|
-
delegate :name, :query, :ran?, to: :metric
|
5
|
+
delegate :name, :query, :description, :ran?, to: :metric
|
6
|
+
|
7
|
+
def initialize(template, object, options = {})
|
8
|
+
super(template, object)
|
9
|
+
@options = options
|
10
|
+
end
|
6
11
|
|
7
12
|
def label
|
8
|
-
t("#{query}.#{name}")
|
13
|
+
@options[:label] || t("#{query}.#{name}")
|
14
|
+
end
|
15
|
+
|
16
|
+
def description
|
17
|
+
@options[:description]
|
9
18
|
end
|
10
19
|
|
11
20
|
def result(number_format = '%0.1f', display_nil_as = :na)
|
@@ -15,5 +24,9 @@ module Compendium::Presenters
|
|
15
24
|
t(display_nil_as)
|
16
25
|
end
|
17
26
|
end
|
27
|
+
|
28
|
+
def render
|
29
|
+
@template.render 'compendium/reports/metric', metric: self
|
30
|
+
end
|
18
31
|
end
|
19
32
|
end
|
data/lib/compendium/metric.rb
CHANGED
data/lib/compendium/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: compendium
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Vandersluis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
type: :runtime
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- app/classes/compendium/presenters/table.rb
|
120
120
|
- app/controllers/compendium/reports_controller.rb
|
121
121
|
- app/helpers/compendium/reports_helper.rb
|
122
|
+
- app/views/compendium/reports/_metric.haml
|
122
123
|
- app/views/compendium/reports/run.haml
|
123
124
|
- app/views/compendium/reports/setup.haml
|
124
125
|
- compendium.gemspec
|