reporta-modules 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24231287130d42d72c0e84992b2bea414f81289b
4
- data.tar.gz: 6d19674561f3ae544758cb1f11ddbb096429f471
3
+ metadata.gz: 5a0b0b3335348ee5b77bc4aff01fd8c8b7d79b8e
4
+ data.tar.gz: 51f3bb93e2b15078a4a2e6241422217c7f0a3806
5
5
  SHA512:
6
- metadata.gz: 25052bfc227fda62f69bb12aba5b783b9a74681153c4c2922b8c013c866a67f11a598d356f39e2411887356797a700465cbd1cbd821538ea6f7fe159c1ca0bec
7
- data.tar.gz: 74616e062c0781180563f51f2fa82c4bd75a6df85e15afb5e16e3c9108bb8f1e48224444173191e397700acc53c68f4d0823309c6187b2ea8abf3b3dc7e6a1ff
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 Reporta to your Gemfile
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 in your project
15
+ Generate default view templates /
16
16
  `$ rails generate reporta:views`
17
17
 
18
- Turn any plain Ruby class into a Reporta class by including `Reporta::Reportable`
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
- ## Basic Example
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 = ProjectsReport.new(params[:reporta_form])
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` module added some DSL for your covenience to create your report's [__view model/object__](http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/).
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
- Report are normally generated based on some filter or a certain criteria.
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 force a field to be set. Defaults to `false`.
99
- * `collection` - setting a collection will force the filter to render as a select input.
100
- * `include_blank` - only has an affect if a collection is set. defaults to `true`.
101
- * `as` - set the type of field to render. Available values are `:boolean`, `:string`, `:check_boxes`, `:radio`, `:date`. Defaults to `:string`.
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 of display
102
+ * `label` - set the label for the filter.
104
103
 
105
- #### Columns
104
+ #### Defining Columns
106
105
 
107
- When is comes to displaying the report you will generally want to display a subset of data from the rows, custom calculations or maybe some associated data. Here's a quick example of defining a variety of columns.
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 :formatted_date, title: 'Created at'
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 formatted_date(project)
123
- project.created_at.strftime("%b %d, %Y")
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 for the colum. Defaults to the column name
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` - these classes will be applied to the column to allow for custom styling or Javascript hooks.
133
- * `helper` - format your column
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
- ### Required Methods
138
+ #### Defining Required Methods
136
139
 
137
- As a very minimum you need to define the `rows` method which will return the rows that are displayed in the report.
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
- #### Default View Templates
157
+ #### Generating View Templates
151
158
 
152
- In order to render the results of your report there are a variety of different ways to access and display the data. If you have any filters defined you will probably want to display a form for the user to enter parameters into.
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
- The `filters_for` helper generates a basic form based on the filters you have defined.
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
- To display the results of the report you can simply use the `table_for` helper method.
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
@@ -59,6 +59,7 @@ module Reporta
59
59
  filters.each do |name, filter|
60
60
  value = values[name].present? ? values[name] : filter.default
61
61
  value = convert_boolean(values[name]) if filter.boolean?
62
+ @params[name] = value
62
63
 
63
64
  self.send "#{name}=", value
64
65
  end
@@ -1,3 +1,3 @@
1
1
  module Reporta
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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.1
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-04 00:00:00.000000000 Z
15
+ date: 2014-09-05 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rails