reporta-modules 0.0.1

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.
Files changed (81) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +203 -0
  4. data/Rakefile +20 -0
  5. data/lib/generators/reporta/views_generator.rb +24 -0
  6. data/lib/generators/templates/reports/_box.html.erb +48 -0
  7. data/lib/generators/templates/reports/_chartjs_bar.html.erb +31 -0
  8. data/lib/generators/templates/reports/_chartjs_line.html.erb +33 -0
  9. data/lib/generators/templates/reports/_chartjs_pie.html.erb +19 -0
  10. data/lib/generators/templates/reports/_filters.html.erb +100 -0
  11. data/lib/generators/templates/reports/_table.html.erb +49 -0
  12. data/lib/reporta-modules.rb +15 -0
  13. data/lib/reporta/box_helper.rb +17 -0
  14. data/lib/reporta/chartjs_helper.rb +74 -0
  15. data/lib/reporta/models/column.rb +68 -0
  16. data/lib/reporta/models/filter.rb +42 -0
  17. data/lib/reporta/models/form.rb +77 -0
  18. data/lib/reporta/models/reportable.rb +50 -0
  19. data/lib/reporta/railtie.rb +8 -0
  20. data/lib/reporta/version.rb +3 -0
  21. data/lib/reporta/view_helper.rb +38 -0
  22. data/lib/tasks/reporta_tasks.rake +4 -0
  23. data/spec/dummy/README.rdoc +28 -0
  24. data/spec/dummy/Rakefile +6 -0
  25. data/spec/dummy/app/assets/javascripts/application.js +18 -0
  26. data/spec/dummy/app/assets/javascripts/jquery.dataTables.js +12099 -0
  27. data/spec/dummy/app/assets/javascripts/jquery.flot.js +3061 -0
  28. data/spec/dummy/app/assets/javascripts/jquery.flot.time.js +431 -0
  29. data/spec/dummy/app/assets/javascripts/jquery.js +2 -0
  30. data/spec/dummy/app/assets/stylesheets/application.css +14 -0
  31. data/spec/dummy/app/assets/stylesheets/bootstrap.min.css +9 -0
  32. data/spec/dummy/app/assets/stylesheets/style.css +57 -0
  33. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  34. data/spec/dummy/app/controllers/reports_controller.rb +18 -0
  35. data/spec/dummy/app/helpers/application_helper.rb +5 -0
  36. data/spec/dummy/app/models/account.rb +3 -0
  37. data/spec/dummy/app/models/account_chart.rb +41 -0
  38. data/spec/dummy/app/models/account_report.rb +39 -0
  39. data/spec/dummy/app/models/user.rb +8 -0
  40. data/spec/dummy/app/views/layouts/application.html.erb +28 -0
  41. data/spec/dummy/app/views/reports/chart.html.erb +6 -0
  42. data/spec/dummy/app/views/reports/dynamic_table.html.erb +33 -0
  43. data/spec/dummy/app/views/reports/dynamic_table_with_bootstrap.html.erb +37 -0
  44. data/spec/dummy/app/views/reports/overview.html.erb +4 -0
  45. data/spec/dummy/app/views/reports/table.html.erb +12 -0
  46. data/spec/dummy/bin/bundle +3 -0
  47. data/spec/dummy/bin/rails +4 -0
  48. data/spec/dummy/bin/rake +4 -0
  49. data/spec/dummy/config.ru +4 -0
  50. data/spec/dummy/config/application.rb +23 -0
  51. data/spec/dummy/config/boot.rb +5 -0
  52. data/spec/dummy/config/database.yml +25 -0
  53. data/spec/dummy/config/environment.rb +5 -0
  54. data/spec/dummy/config/environments/development.rb +29 -0
  55. data/spec/dummy/config/environments/production.rb +80 -0
  56. data/spec/dummy/config/environments/test.rb +36 -0
  57. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  58. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  59. data/spec/dummy/config/initializers/inflections.rb +16 -0
  60. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  61. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  62. data/spec/dummy/config/initializers/session_store.rb +3 -0
  63. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  64. data/spec/dummy/config/locales/en.yml +23 -0
  65. data/spec/dummy/config/routes.rb +7 -0
  66. data/spec/dummy/db/migrate/20130622041213_create_users.rb +14 -0
  67. data/spec/dummy/db/migrate/20130623054801_create_accounts.rb +9 -0
  68. data/spec/dummy/db/schema.rb +33 -0
  69. data/spec/dummy/db/seeds.rb +20 -0
  70. data/spec/dummy/db/test.sqlite3 +0 -0
  71. data/spec/dummy/log/test.log +1190 -0
  72. data/spec/dummy/public/404.html +58 -0
  73. data/spec/dummy/public/422.html +58 -0
  74. data/spec/dummy/public/500.html +57 -0
  75. data/spec/dummy/public/favicon.ico +0 -0
  76. data/spec/models/column_spec.rb +76 -0
  77. data/spec/models/filter_spec.rb +63 -0
  78. data/spec/models/form_spec.rb +81 -0
  79. data/spec/models/report_spec.rb +51 -0
  80. data/spec/spec_helper.rb +43 -0
  81. metadata +247 -0
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/404.html -->
52
+ <div class="dialog">
53
+ <h1>The page you were looking for doesn't exist.</h1>
54
+ <p>You may have mistyped the address or the page may have moved.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/422.html -->
52
+ <div class="dialog">
53
+ <h1>The change you wanted was rejected.</h1>
54
+ <p>Maybe you tried to change something you didn't have access to.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/500.html -->
52
+ <div class="dialog">
53
+ <h1>We're sorry, but something went wrong.</h1>
54
+ </div>
55
+ <p>If you are the application owner check the logs for more information.</p>
56
+ </body>
57
+ </html>
File without changes
@@ -0,0 +1,76 @@
1
+ # Copyright 2013-2014 University of Technology, Sydney (github.com/uts)
2
+
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'spec_helper'
23
+ require 'date'
24
+
25
+ class ColumReport
26
+ include Reporta::Column
27
+
28
+ column :name
29
+ column :full_name
30
+ column :date, title: 'Completed at'
31
+ column :formatted_date
32
+ column :customer_name, data_chain: 'customer.name'
33
+ column :email_customer, helper: :customer_email_link
34
+
35
+ def formatted_date(project)
36
+ project.created_at.strftime('%b %d, %Y')
37
+ end
38
+ end
39
+
40
+ describe Reporta::Column do
41
+
42
+ it 'initializes columns' do
43
+ expect { ColumReport.column :name }.to_not raise_error
44
+ end
45
+
46
+ context 'with columns defined' do
47
+ subject(:report) { ColumReport.new }
48
+
49
+ it 'defaults to the column name' do
50
+ expect(report.columns[:full_name].title).to eq 'Full name'
51
+ end
52
+
53
+ it 'sets a custom title' do
54
+ expect(report.columns[:date].title).to eq 'Completed at'
55
+ end
56
+
57
+ it 'returns the value using a local method' do
58
+ project = double created_at: Date.new(2013, 01, 15)
59
+ expect(
60
+ report.value_for(project, :formatted_date)
61
+ ).to eq 'Jan 15, 2013'
62
+ end
63
+
64
+ it 'uses a chain of methods of fetch the value' do
65
+ customer = double name: 'World Co.'
66
+ project = double customer: customer
67
+ expect(report.value_for(project, :customer_name))
68
+ .to eq 'World Co.'
69
+ end
70
+
71
+ it 'sets a custom helper' do
72
+ expect(report.columns[:email_customer].helper).to eq :customer_email_link
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,63 @@
1
+ # Copyright 2013-2014 University of Technology, Sydney (github.com/uts)
2
+
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+ require 'spec_helper'
22
+
23
+ class FilteredReport
24
+ include Reporta::Filter
25
+
26
+ filter :start_date, default: '2013-01-01'
27
+ filter :finish_date
28
+ filter :active, as: :boolean
29
+ filter :employee_type, required: true
30
+ filter :age, include_blank: false
31
+ filter :be_blank_true
32
+ filter :valid, collection: %w/true false/
33
+ end
34
+
35
+ describe Reporta::Filter do
36
+ context 'with columns defined' do
37
+ subject(:report) { FilteredReport.new }
38
+
39
+ it 'defaults to correct date' do
40
+ expect(report.filters[:start_date].default).to eq '2013-01-01'
41
+ end
42
+
43
+ it 'accepts boolean column types' do
44
+ expect(report.filters[:active].as).to eq :boolean
45
+ end
46
+
47
+ it 'requires columns to be set' do
48
+ expect(report.filters[:employee_type].required).to eq true
49
+ end
50
+
51
+ it 'allows include_blank to bet set' do
52
+ expect(report.filters[:age].include_blank).to eq false
53
+ end
54
+
55
+ it 'defaults include_blank to true' do
56
+ expect(report.filters[:be_blank_true].include_blank).to eq true
57
+ end
58
+
59
+ it 'allows collections to be set' do
60
+ expect(report.filters[:valid].collection).to eq %w/true false/
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,81 @@
1
+ # Copyright 2013-2014 University of Technology, Sydney (github.com/uts)
2
+
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+ require 'spec_helper'
22
+ require 'ostruct'
23
+
24
+ class FormFilters
25
+ include Reporta::Filter
26
+
27
+ filter :active, as: :boolean
28
+ filter :start_date, default: '2013-01-01', required: true
29
+ filter :name, required: true
30
+ end
31
+
32
+ describe Reporta::Form do
33
+ let(:filters) { FormFilters.new.filters }
34
+
35
+ it 'is initialized with filters and default values' do
36
+ expect { Reporta::Form.new filters, {} }.to_not raise_error
37
+ end
38
+
39
+ it 'stores and retreives values based on the filter name' do
40
+ form = Reporta::Form.new filters
41
+ expect(form.active).to be false
42
+ form.active = true
43
+ expect(form.active).to be true
44
+ end
45
+
46
+ it 'falls back to the filter default value if set' do
47
+ form = Reporta::Form.new filters
48
+ expect(form.start_date).to eq '2013-01-01'
49
+ end
50
+
51
+ it 'adds an error message on validation when a required field is missing' do
52
+ form = Reporta::Form.new filters
53
+ expect(form.valid?).to be false
54
+ expect(form.errors[:name].to_s).to match /required/
55
+ end
56
+
57
+ describe 'filters_applied?' do
58
+ it 'is false when no values are initialized' do
59
+ form = Reporta::Form.new filters
60
+ expect(form.filter_applied?).to be false
61
+ end
62
+
63
+ it 'is true when one or more values are initialized' do
64
+ form = Reporta::Form.new filters, active: true
65
+ expect(form.filter_applied?).to be true
66
+ end
67
+ end
68
+
69
+ context 'with boolean filter' do
70
+ it 'converts boolean "0" to false' do
71
+ form = Reporta::Form.new filters, active: '0'
72
+ expect(form.active).to be false
73
+ end
74
+
75
+ it 'converts boolean "1" to true' do
76
+ form = Reporta::Form.new filters, active: '1'
77
+ expect(form.active).to be true
78
+ end
79
+ end
80
+
81
+ end
@@ -0,0 +1,51 @@
1
+ # Copyright 2013-2014 University of Technology, Sydney (github.com/uts)
2
+
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+ require 'spec_helper'
22
+
23
+ class BaseReport
24
+ include Reporta::Reportable
25
+
26
+ filter :active, as: :boolean
27
+ filter :start_date
28
+ end
29
+
30
+ describe Reporta::Reportable do
31
+ it 'can be initialized' do
32
+ expect { BaseReport.new }.to_not raise_error
33
+ end
34
+
35
+ it 'initializes and validates a new Form' do
36
+ args = { name: 'Joe' }
37
+ filters = double()
38
+ form = double()
39
+
40
+ expect(form).to receive(:valid?)
41
+ expect(Reporta::Form).to receive(:new).with(filters, args).and_return form
42
+ BaseReport.any_instance.stub(:filters).and_return(filters)
43
+
44
+ BaseReport.new args
45
+ end
46
+
47
+ it 'allows a filter value to be set and retrieved' do
48
+ report = BaseReport.new start_date: '2013-01-19'
49
+ expect(report.start_date).to eq '2013-01-19'
50
+ end
51
+ end