reporta-modules 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +52 -36
- data/lib/reporta/models/form.rb +1 -0
- data/lib/reporta/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a0b0b3335348ee5b77bc4aff01fd8c8b7d79b8e
|
4
|
+
data.tar.gz: 51f3bb93e2b15078a4a2e6241422217c7f0a3806
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 328bd9641ffd9e1c6e0a13a0b1b70b7375abb2276b9b5b0254fc9f0ba7d745ff418760c4323131db8d9f11e8cbc3edc992a9eedd1afc170fb8d259067f471f75
|
7
|
+
data.tar.gz: 42a43a4bd06d947328c143ff949b8fa19c9fa4855acf33d090ff3008a289ddfb73d8094d84452e8fb4ddf9da08d1fcba91a89823d608a529e85962bec91526c4
|
data/README.md
CHANGED
@@ -2,20 +2,20 @@
|
|
2
2
|
|
3
3
|
__reporta-modules__ is a Rails gem packed with modules and helpers to help you build your reports.
|
4
4
|
|
5
|
-
It is also a fork from the original [__reporta__](github.com/uts/reporta) Rails engine gem.
|
5
|
+
It is also a [fork](https://github.com/uts/reporta/issues/2) from the original [__reporta__](github.com/uts/reporta) Rails engine gem.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
Add
|
9
|
+
Add __reporta-modules__ to your Gemfile
|
10
10
|
|
11
11
|
```ruby
|
12
12
|
gem 'reporta-modules'
|
13
13
|
```
|
14
14
|
|
15
|
-
Generate default view templates
|
15
|
+
Generate default view templates /
|
16
16
|
`$ rails generate reporta:views`
|
17
17
|
|
18
|
-
|
18
|
+
Include `Reporta::Reportable` in your view model.
|
19
19
|
|
20
20
|
```ruby
|
21
21
|
class YourReport
|
@@ -23,7 +23,7 @@ class YourReport
|
|
23
23
|
end
|
24
24
|
```
|
25
25
|
|
26
|
-
##
|
26
|
+
## Example
|
27
27
|
|
28
28
|
### View Model
|
29
29
|
|
@@ -48,12 +48,12 @@ end
|
|
48
48
|
```ruby
|
49
49
|
class ProjectReportsController < ApplicationController
|
50
50
|
def show
|
51
|
-
@report =
|
51
|
+
@report = ProjectReport.new(params[:reporta_form])
|
52
52
|
end
|
53
53
|
end
|
54
54
|
```
|
55
55
|
|
56
|
-
### View
|
56
|
+
### View Helpers
|
57
57
|
|
58
58
|
```erb
|
59
59
|
<%= filters_for @report %>
|
@@ -64,13 +64,13 @@ end
|
|
64
64
|
|
65
65
|
## Reporta Modules
|
66
66
|
|
67
|
-
### Reporta::Reportable
|
67
|
+
### Reporta::Reportable - DSL for report's view model
|
68
68
|
|
69
|
-
`Reporta::Reportable`
|
69
|
+
`Reporta::Reportable` added DSL for your convenience to create your report's [__view model/object__](http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/).
|
70
70
|
|
71
|
-
#### Filters
|
71
|
+
#### Defining Filters
|
72
72
|
|
73
|
-
|
73
|
+
Reports are normally generated based on filters or input from users. Define those filters with `filter filter_name [options]`.
|
74
74
|
For example:
|
75
75
|
|
76
76
|
```ruby
|
@@ -82,7 +82,6 @@ class ProjectReport
|
|
82
82
|
filter :status, collection: Status.all, include_blank: false
|
83
83
|
filter :exclude_deleted, as: :boolean, default: false
|
84
84
|
|
85
|
-
# required method
|
86
85
|
def rows
|
87
86
|
# use filters above to manipulate the results
|
88
87
|
projects = Project.where(created_at: start_date..finish_date)
|
@@ -95,23 +94,27 @@ end
|
|
95
94
|
|
96
95
|
**Filter Options**
|
97
96
|
|
98
|
-
* `required` - set to `true` to
|
99
|
-
* `collection` -
|
100
|
-
* `include_blank` -
|
101
|
-
* `as` -
|
97
|
+
* `required` - set to `true` to specify it as required, defaults to `false`.
|
98
|
+
* `collection` - specify a collection to render a select input, will be used in `options_for_select(collection)`
|
99
|
+
* `include_blank` - specify whether to include blank in the select input, defaults to `true`.
|
100
|
+
* `as` - specify the type of field. e.g. `:boolean`, `:string`, `:check_boxes`, `:radio`, `:date`, defaults to `:string`.
|
102
101
|
* `default` - set the default value for the filter.
|
103
|
-
* `label` - set the label
|
102
|
+
* `label` - set the label for the filter.
|
104
103
|
|
105
|
-
#### Columns
|
104
|
+
#### Defining Columns
|
106
105
|
|
107
|
-
|
106
|
+
Tables will be generated in your report, defining columns with DSL allows the flexibility of changes on what will be display. Define those columns with `column column_name [options]`.
|
107
|
+
For example:
|
108
108
|
|
109
109
|
```ruby
|
110
110
|
class ProjectReport
|
111
111
|
include Reporta::Reportable
|
112
|
-
|
112
|
+
|
113
|
+
def indexed; @index||=0; @index += 1; end
|
114
|
+
|
115
|
+
column :indexed, title: 'No.:'
|
113
116
|
column :name
|
114
|
-
column :
|
117
|
+
column :created_at, helper: :readable_date, title: 'Created at'
|
115
118
|
column :manager, data_chain: 'manager.full_name'
|
116
119
|
column :cost, class_names: 'sum currency'
|
117
120
|
|
@@ -119,45 +122,50 @@ class ProjectReport
|
|
119
122
|
Projects.all
|
120
123
|
end
|
121
124
|
|
122
|
-
def
|
123
|
-
|
125
|
+
def readable_date(value)
|
126
|
+
value.strftime("%b %d, %Y")
|
124
127
|
end
|
125
128
|
end
|
126
129
|
```
|
127
130
|
|
128
131
|
**Column Options**
|
129
132
|
|
130
|
-
* `title` - set a custom title
|
133
|
+
* `title` - set a custom title, defaults to the `column.humanize`
|
131
134
|
* `data_chain` - provide a chain of methods to call in order to fetch the data.
|
132
|
-
* `class_names` -
|
133
|
-
* `helper` -
|
135
|
+
* `class_names` - specify html class attribute for column, useful for custom styling or Javascript hooks.
|
136
|
+
* `helper` - specify view helper for the column
|
134
137
|
|
135
|
-
|
138
|
+
#### Defining Required Methods
|
136
139
|
|
137
|
-
|
140
|
+
Define the `rows` method to represent data rows to be used for display.
|
141
|
+
__Note: For the return array of records, each record should comform(respond_to) to the specified columns__.
|
142
|
+
For example:
|
138
143
|
|
139
144
|
```ruby
|
140
145
|
class ProjectReport
|
141
146
|
include Reporta::Reportable
|
142
147
|
|
148
|
+
column :full_name
|
149
|
+
|
143
150
|
def rows
|
144
|
-
Project.all
|
151
|
+
Project.select('concat(first_name, last_name) as full_name').all
|
145
152
|
end
|
146
153
|
end
|
147
154
|
```
|
148
155
|
|
149
156
|
|
150
|
-
####
|
157
|
+
#### Generating View Templates
|
151
158
|
|
152
|
-
|
159
|
+
View templates are available after running `rails generate reporta:views`, it will generate views in `app/views/reporta` folder for you to customize. These templates are required for the view helpers:
|
153
160
|
|
154
|
-
|
161
|
+
##### filters_for
|
162
|
+
The `filters_for` helper generates a html form based on the `filter`s you have defined.
|
155
163
|
|
156
164
|
```erb
|
157
165
|
<%= filters_for @report %>
|
158
166
|
```
|
159
|
-
If we look at how `filters_for` is created you can see the underlying data structures used to render the form.
|
160
167
|
|
168
|
+
Template: `app/views/reporta/report/_filters.html.erb`
|
161
169
|
```erb
|
162
170
|
<%= form_for @report.form do |f| %>
|
163
171
|
<% @report.filters.each do |filter| %>
|
@@ -167,13 +175,14 @@ If we look at how `filters_for` is created you can see the underlying data struc
|
|
167
175
|
<%= f.submit %>
|
168
176
|
<% end %>
|
169
177
|
```
|
170
|
-
|
178
|
+
##### table_for
|
179
|
+
The `table_for` helper generates a html table based on the `column`s you have defined.
|
171
180
|
|
172
181
|
```erb
|
173
182
|
<%= table_for @report %>
|
174
183
|
```
|
175
|
-
Or for more detailed control you can build the table yourself.
|
176
184
|
|
185
|
+
Template:
|
177
186
|
```erb
|
178
187
|
<table>
|
179
188
|
<thead>
|
@@ -199,5 +208,12 @@ Or for more detailed control you can build the table yourself.
|
|
199
208
|
</table>
|
200
209
|
```
|
201
210
|
|
211
|
+
#### Other useful instance methods
|
212
|
+
|
213
|
+
After `Reporta::Reportable` is included, useful instance methods are also added as below:
|
214
|
+
|
215
|
+
* `filters` - returns hash of filters definition. e.g. `filters[:name]`
|
216
|
+
* `params` - return hash of filters' values received from request. e.g. `params[:name]`
|
217
|
+
|
202
218
|
## License
|
203
|
-
see MIT-LICENSE
|
219
|
+
see MIT-LICENSE
|
data/lib/reporta/models/form.rb
CHANGED
data/lib/reporta/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reporta-modules
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Harvey
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2014-09-
|
15
|
+
date: 2014-09-05 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: rails
|