clark_kent 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +34 -0
  5. data/app/assets/javascripts/clark_kent/application.js +13 -0
  6. data/app/assets/javascripts/clark_kent/reports.js +10 -0
  7. data/app/assets/stylesheets/_reports.scss +67 -0
  8. data/app/assets/stylesheets/_reports_print.scss +44 -0
  9. data/app/assets/stylesheets/clark_kent/application.css +15 -0
  10. data/app/assets/stylesheets/clark_kent/reports.css +4 -0
  11. data/app/assets/stylesheets/scaffold.css +56 -0
  12. data/app/controllers/clark_kent/application_controller.rb +2 -0
  13. data/app/controllers/clark_kent/report_columns_controller.rb +47 -0
  14. data/app/controllers/clark_kent/report_emails_controller.rb +47 -0
  15. data/app/controllers/clark_kent/report_filters_controller.rb +51 -0
  16. data/app/controllers/clark_kent/reports_controller.rb +79 -0
  17. data/app/controllers/clark_kent/user_report_emails_controller.rb +53 -0
  18. data/app/helpers/clark_kent/application_helper.rb +70 -0
  19. data/app/mailers/clark_kent/report_mailer.rb +15 -0
  20. data/app/models/clark_kent/report.rb +272 -0
  21. data/app/models/clark_kent/report_column.rb +24 -0
  22. data/app/models/clark_kent/report_date_filter.rb +81 -0
  23. data/app/models/clark_kent/report_email.rb +105 -0
  24. data/app/models/clark_kent/report_filter.rb +26 -0
  25. data/app/models/clark_kent/report_filter_option.rb +18 -0
  26. data/app/models/clark_kent/report_number_filter.rb +20 -0
  27. data/app/models/clark_kent/report_object_filter.rb +27 -0
  28. data/app/models/clark_kent/report_result.rb +55 -0
  29. data/app/models/clark_kent/report_string_filter.rb +5 -0
  30. data/app/models/clark_kent/reportable.rb +148 -0
  31. data/app/models/clark_kent/sharing_scope.rb +34 -0
  32. data/app/models/clark_kent/sharing_scope_kind.rb +73 -0
  33. data/app/models/clark_kent/user_report_email.rb +19 -0
  34. data/app/validators/clark_kent/user_email_validator.rb +7 -0
  35. data/app/views/clark_kent/report_columns/_form.html.erb +50 -0
  36. data/app/views/clark_kent/report_columns/_index.html.erb +16 -0
  37. data/app/views/clark_kent/report_columns/_show.html.erb +20 -0
  38. data/app/views/clark_kent/report_columns/_show_wrapper.html.erb +3 -0
  39. data/app/views/clark_kent/report_emails/_edit.html.erb +12 -0
  40. data/app/views/clark_kent/report_emails/_form.html.erb +34 -0
  41. data/app/views/clark_kent/report_emails/_index.html.erb +16 -0
  42. data/app/views/clark_kent/report_emails/_show.html.erb +17 -0
  43. data/app/views/clark_kent/report_emails/_show_wrapper.html.erb +3 -0
  44. data/app/views/clark_kent/report_filters/_date_filter_edit.html.erb +9 -0
  45. data/app/views/clark_kent/report_filters/_date_filter_show.html.erb +1 -0
  46. data/app/views/clark_kent/report_filters/_form.html.erb +58 -0
  47. data/app/views/clark_kent/report_filters/_index.html.erb +16 -0
  48. data/app/views/clark_kent/report_filters/_number_filter_edit.html.erb +2 -0
  49. data/app/views/clark_kent/report_filters/_number_filter_show.html.erb +1 -0
  50. data/app/views/clark_kent/report_filters/_object_filter_edit.html.erb +1 -0
  51. data/app/views/clark_kent/report_filters/_object_filter_show.html.erb +1 -0
  52. data/app/views/clark_kent/report_filters/_show.html.erb +14 -0
  53. data/app/views/clark_kent/report_filters/_show_wrapper.html.erb +3 -0
  54. data/app/views/clark_kent/report_filters/_string_filter_edit.html.erb +0 -0
  55. data/app/views/clark_kent/report_filters/_string_filter_show.html.erb +1 -0
  56. data/app/views/clark_kent/report_mailer/report_run.html.erb +2 -0
  57. data/app/views/clark_kent/reports/_date_filter.html.erb +23 -0
  58. data/app/views/clark_kent/reports/_download_link.html.erb +14 -0
  59. data/app/views/clark_kent/reports/_edit.html.erb +47 -0
  60. data/app/views/clark_kent/reports/_form.html.erb +33 -0
  61. data/app/views/clark_kent/reports/_number_filter.html.erb +21 -0
  62. data/app/views/clark_kent/reports/_object_filter.html.erb +15 -0
  63. data/app/views/clark_kent/reports/_print_report.html.erb +30 -0
  64. data/app/views/clark_kent/reports/_show.html.erb +21 -0
  65. data/app/views/clark_kent/reports/_string_filter.html.erb +9 -0
  66. data/app/views/clark_kent/reports/edit.html.erb +21 -0
  67. data/app/views/clark_kent/reports/index.html.erb +22 -0
  68. data/app/views/clark_kent/reports/new.html.erb +9 -0
  69. data/app/views/clark_kent/reports/show.html.erb +43 -0
  70. data/app/views/clark_kent/user_report_emails/_form.html.erb +40 -0
  71. data/app/views/clark_kent/user_report_emails/_index.html.erb +16 -0
  72. data/app/views/clark_kent/user_report_emails/_show.html.erb +11 -0
  73. data/app/views/clark_kent/user_report_emails/_show_wrapper.html.erb +3 -0
  74. data/config/routes.rb +13 -0
  75. data/db/migrate/20150304233739_create_clark_kent_reports.rb +12 -0
  76. data/lib/clark_kent/engine.rb +5 -0
  77. data/lib/clark_kent/version.rb +3 -0
  78. data/lib/clark_kent.rb +20 -0
  79. data/lib/tasks/clark_kent_tasks.rake +4 -0
  80. data/test/clark_kent_test.rb +7 -0
  81. data/test/controllers/clark_kent/reports_controller_test.rb +51 -0
  82. data/test/dummy/README.rdoc +28 -0
  83. data/test/dummy/Rakefile +6 -0
  84. data/test/dummy/app/assets/javascripts/application.js +13 -0
  85. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  86. data/test/dummy/app/controllers/application_controller.rb +5 -0
  87. data/test/dummy/app/helpers/application_helper.rb +2 -0
  88. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  89. data/test/dummy/bin/bundle +3 -0
  90. data/test/dummy/bin/rails +4 -0
  91. data/test/dummy/bin/rake +4 -0
  92. data/test/dummy/config/application.rb +23 -0
  93. data/test/dummy/config/boot.rb +5 -0
  94. data/test/dummy/config/database.yml +25 -0
  95. data/test/dummy/config/environment.rb +5 -0
  96. data/test/dummy/config/environments/development.rb +37 -0
  97. data/test/dummy/config/environments/production.rb +78 -0
  98. data/test/dummy/config/environments/test.rb +39 -0
  99. data/test/dummy/config/initializers/assets.rb +8 -0
  100. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  101. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  102. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  103. data/test/dummy/config/initializers/inflections.rb +16 -0
  104. data/test/dummy/config/initializers/mime_types.rb +4 -0
  105. data/test/dummy/config/initializers/session_store.rb +3 -0
  106. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  107. data/test/dummy/config/locales/en.yml +23 -0
  108. data/test/dummy/config/routes.rb +4 -0
  109. data/test/dummy/config/secrets.yml +22 -0
  110. data/test/dummy/config.ru +4 -0
  111. data/test/dummy/db/development.sqlite3 +0 -0
  112. data/test/dummy/db/schema.rb +25 -0
  113. data/test/dummy/log/development.log +35 -0
  114. data/test/dummy/public/404.html +67 -0
  115. data/test/dummy/public/422.html +67 -0
  116. data/test/dummy/public/500.html +66 -0
  117. data/test/dummy/public/favicon.ico +0 -0
  118. data/test/dummy/tmp/cache/assets/development/sprockets/0a5b3da98f8307d16bc302a1f7206591 +0 -0
  119. data/test/dummy/tmp/cache/assets/development/sprockets/0a9995208f1340e4b34008cbd5b73c64 +0 -0
  120. data/test/dummy/tmp/cache/assets/development/sprockets/0ec37c0a58c1be93659732a3efc73581 +0 -0
  121. data/test/dummy/tmp/cache/assets/development/sprockets/0fd54fd98cd2fa0085b77e6743046927 +0 -0
  122. data/test/dummy/tmp/cache/assets/development/sprockets/5d3db72d44bc30497bd84a40d2002e12 +0 -0
  123. data/test/dummy/tmp/cache/assets/development/sprockets/60fb63be4cad769d9adc90c4c5501c67 +0 -0
  124. data/test/dummy/tmp/cache/assets/development/sprockets/8aa37926d964a9eb59cf9b940e4fe2f4 +0 -0
  125. data/test/dummy/tmp/cache/assets/development/sprockets/8dd3bd27ebbaecaf6c7ee8ed81be5bde +0 -0
  126. data/test/dummy/tmp/cache/assets/development/sprockets/92058832b745b88c29a75bf2aad7245d +0 -0
  127. data/test/dummy/tmp/cache/assets/development/sprockets/ba6c7581456ee0f828ace58e4856a9f4 +0 -0
  128. data/test/dummy/tmp/cache/assets/development/sprockets/ebe8eac74b8e6016fd44b19e6e708e61 +0 -0
  129. data/test/dummy/tmp/cache/assets/development/sprockets/f23dd414c3bac1b6833d2aa9e62fbedd +0 -0
  130. data/test/fixtures/clark_kent/reports.yml +13 -0
  131. data/test/helpers/clark_kent/reports_helper_test.rb +6 -0
  132. data/test/integration/navigation_test.rb +10 -0
  133. data/test/models/clark_kent/report_test.rb +9 -0
  134. data/test/test_helper.rb +17 -0
  135. metadata +260 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8fe6d8c933913c257f1f21e5ce42da4c2c114667
4
+ data.tar.gz: 1d2effb237dd48be6f01b9168e2c7495c2324a1c
5
+ SHA512:
6
+ metadata.gz: c60fe71c8afc1e1c76d32fcc65a492c795da50c4173b50c53f0a0d26a5aa5e886b04673b8890085ecd6f2634befcfbdad8a804bcd07c784a7fb49848cf8615dc
7
+ data.tar.gz: 86a4a99c241b2598da17c8f884a87b4f94c5ef14f62dca88b399fd65acf434655fb4391da63388ffebcedf911df53b4f633c1cc0cc9ba2557e9099153b9e9cce
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 YOURNAME
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.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = ClarkKent
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'ClarkKent'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,10 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
3
+ $(document).ready(function(){
4
+ $(document).on('change','[data-report-filter]',function(){
5
+ tmp_obj = $('[data-reports-link]').data('form-data');
6
+ if(!tmp_obj){ tmp_obj = {}}
7
+ tmp_obj[$(this).attr('name')] = $(this).val();
8
+ $('[data-reports-link]').data('form-data',tmp_obj)
9
+ })
10
+ })
@@ -0,0 +1,67 @@
1
+ table.report {
2
+ border-collapse:collapse;
3
+ }
4
+ table.report, table.report th, table.report td {
5
+ border: 1px solid $light-grey;
6
+ }
7
+ table.report th, table.report td {
8
+ padding: 3px 6px;
9
+ }
10
+ table.report .left{
11
+ text-align: left;
12
+ }
13
+
14
+ .tape-view {
15
+ td {
16
+ padding: 0;
17
+ margin: 0;
18
+ }
19
+ .report-name-column {
20
+ padding: 12px;
21
+ }
22
+ }
23
+
24
+ .tape-view-intersect-top {
25
+ width: 49px !important;
26
+ height:31px !important;
27
+ margin-bottom: 6px;
28
+ }
29
+
30
+ .tape-view-intersect-bottom {
31
+ width: 49px !important;
32
+ height:31px !important;
33
+ margin-left: 6px;
34
+ margin-top: 6px;
35
+ }
36
+
37
+ .tape-view-available-box,
38
+ .tape-view-reserved-box,
39
+ .tape-view-owner-box,
40
+ .tape-view-maintenance-box,
41
+ .tape-view-owner-guest-box {
42
+ width: 55px;
43
+ height: 34px;
44
+ }
45
+
46
+ .tape-view-reserved-box {
47
+ background: #b0cf59;
48
+ }
49
+
50
+ .tape-view-owner-box {
51
+ background: #73b5e2;
52
+ }
53
+
54
+ .tape-view-owner-guest-box {
55
+ background: #F3A626;
56
+ }
57
+
58
+ .tape-view-maintenance-box {
59
+ background: #e48e8e;
60
+ }
61
+ .report-name-column {
62
+ min-width: 175px;
63
+ }
64
+
65
+ .amount_mismatch {
66
+ color: red !important;
67
+ }
@@ -0,0 +1,44 @@
1
+ @media print {
2
+ header {
3
+ display:none
4
+ }
5
+
6
+ form {
7
+ display:none
8
+ }
9
+
10
+ body, .container {
11
+ width: 100%;
12
+ margin: 0;
13
+ padding: 0;
14
+ }
15
+
16
+ a[href]:after { display:none; }
17
+
18
+ title {
19
+ display: none
20
+ }
21
+
22
+ @page {
23
+ size: landscape;
24
+ margin-left:1cm;
25
+ margin-right:1cm;
26
+ margin-bottom:1cm;
27
+ }
28
+
29
+ .ih-row {
30
+ overflow: visible;
31
+ }
32
+
33
+ #download_link {
34
+ display: none;
35
+ }
36
+
37
+ nav {
38
+ display: none;
39
+ }
40
+
41
+ #report_index {
42
+ display: none;
43
+ }
44
+ }
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,2 @@
1
+ class ClarkKent::ApplicationController < ClarkKent.base_controller
2
+ end
@@ -0,0 +1,47 @@
1
+ class ClarkKent::ReportColumnsController < ClarkKent::ApplicationController
2
+ before_filter :prepare_report_column
3
+ before_filter :prepare_report
4
+
5
+ def new
6
+ @report_column = ClarkKent::ReportColumn.new(report_id: @report.id)
7
+ render partial: 'form', locals: {report_column: @report_column}
8
+ end
9
+
10
+ def create
11
+ @report_column = ClarkKent::ReportColumn.new(params[:report_column])
12
+ @report_column.save
13
+ render partial: 'show_wrapper', locals: {report_column: @report_column}
14
+ end
15
+
16
+ def show
17
+ render partial: 'show', locals: {report_column: @report_column}
18
+ end
19
+
20
+ def edit
21
+ render partial: 'form', locals: {report_column: @report_column}
22
+ end
23
+
24
+ def update
25
+ @report_column.update_attributes(params[:report_column])
26
+ @ajax_flash = {notice: "Your changes were saved."}
27
+ render partial: 'show', locals: {report_column: @report_column}
28
+ end
29
+
30
+ def destroy
31
+ @report_column.destroy
32
+ render nothing: true
33
+ end
34
+
35
+ protected
36
+ def prepare_report_column
37
+ @report_column = ClarkKent::ReportColumn.find(params[:id]) if params[:id]
38
+ end
39
+
40
+ def prepare_report
41
+ report_id = params[:report_id]
42
+ report_id ||= params[:report_column][:report_id] if params[:report_column]
43
+ @report = ClarkKent::Report.find(report_id) if report_id
44
+ @report ||= @report_column.report if @report_column
45
+ end
46
+
47
+ end
@@ -0,0 +1,47 @@
1
+ class ClarkKent::ReportEmailsController < ClarkKent::ApplicationController
2
+ before_filter :prepare_report_email
3
+ before_filter :prepare_report
4
+
5
+ def new
6
+ @report_email = ClarkKent::ReportEmail.new(report_id: @report.id)
7
+ render partial: 'form', locals: {report_email: @report_email}
8
+ end
9
+
10
+ def create
11
+ @report_email = ClarkKent::ReportEmail.new(params[:report_email])
12
+ @report_email.save
13
+ render partial: 'edit', locals: {report_email: @report_email}
14
+ end
15
+
16
+ def show
17
+ render partial: 'show', locals: {report_email: @report_email}
18
+ end
19
+
20
+ def edit
21
+ render partial: 'edit', locals: {report_email: @report_email}
22
+ end
23
+
24
+ def update
25
+ @report_email.update_attributes(params[:report_email])
26
+ @ajax_flash = {notice: "Your changes were saved."}
27
+ render partial: 'show', locals: {report_email: @report_email}
28
+ end
29
+
30
+ def destroy
31
+ @report_email.destroy
32
+ render nothing: true
33
+ end
34
+
35
+ protected
36
+ def prepare_report_email
37
+ @report_email = ClarkKent::ReportEmail.find(params[:id]) if params[:id]
38
+ end
39
+
40
+ def prepare_report
41
+ report_id = params[:report_id]
42
+ report_id ||= params[:report_email][:report_id] if params[:report_email]
43
+ @report = ClarkKent::Report.find(report_id) if report_id
44
+ @report ||= @report_email.report if @report_email
45
+ end
46
+
47
+ end
@@ -0,0 +1,51 @@
1
+ class ClarkKent::ReportFiltersController < ClarkKent::ApplicationController
2
+ before_filter :prepare_report_filter
3
+ before_filter :prepare_report, :prepare_role, :prepare_filters
4
+
5
+ def new
6
+ @report_filter = ClarkKent::ReportFilter.new(filterable_id: @filterable.id, filterable_type: @filterable.class.name)
7
+ render partial: 'form', locals: {report_filter: @report_filter}
8
+ end
9
+
10
+ def create
11
+ report_filter_class = @filterable.get_filter_class(params[:report_filter])
12
+ @report_filter = report_filter_class.new(params[:report_filter])
13
+ @report_filter.save
14
+ render partial: 'show_wrapper', locals: {report_filter: @report_filter}
15
+ end
16
+
17
+ def show
18
+ render partial: 'show', locals: {report_filter: @report_filter}
19
+ end
20
+
21
+ def edit
22
+ render partial: 'form', locals: {report_filter: @report_filter}
23
+ end
24
+
25
+ def update
26
+ @report_filter.update_attributes(params[@report_filter.class.name.underscore])
27
+ @ajax_flash = {notice: "Your changes were saved."}
28
+ render partial: 'show', locals: {report_filter: @report_filter}
29
+ end
30
+
31
+ def destroy
32
+ @report_filter.destroy
33
+ render nothing: true
34
+ end
35
+
36
+ protected
37
+ def prepare_report_filter
38
+ @report_filter = ClarkKent::ReportFilter.find(params[:id]) if params[:id]
39
+ end
40
+
41
+ def prepare_report
42
+ @filterable_id = params[:filterable_id]
43
+ @filterable_type = params[:filterable_type]
44
+ @filterable_id ||= params[:report_filter][:filterable_id] if params[:report_filter]
45
+ @filterable_type ||= params[:report_filter][:filterable_type] if params[:report_filter]
46
+ @filterable_class = @filterable_type.constantize if @filterable_type
47
+ @filterable = @filterable_class.find(@filterable_id) if @filterable_id and @filterable_class
48
+ @filterable ||= @report_filter.filterable if @report_filter
49
+ end
50
+
51
+ end
@@ -0,0 +1,79 @@
1
+ class ClarkKent::ReportsController < ClarkKent::ApplicationController
2
+ require 'csv'
3
+ respond_to :html, :csv
4
+ before_filter :prepare_filters
5
+
6
+ def set_manage_tab
7
+ @manage_tab = 'reports'
8
+ end
9
+
10
+ def index
11
+ end
12
+
13
+ def new
14
+ @report = ClarkKent::Report.new
15
+ end
16
+
17
+ def create
18
+ @report = ClarkKent::Report.new(params[:report])
19
+ @report.save
20
+ render action: :edit
21
+ end
22
+
23
+ def show
24
+ @report = ClarkKent::Report.where(id: params[:id]).includes(:report_columns).first
25
+ if request.xhr?
26
+ render partial: 'show'
27
+ else
28
+ prepare_params
29
+ if params[:run_report].present?
30
+ @these_params[:page] = params[:page]
31
+ @these_params[:per] = @report.resource_class.default_per_page
32
+ query = @report.get_query(@these_params)
33
+ @rows = query.page(params[:page])
34
+ @rows.push @report.summary_row(@rows) if @report.summary_row?
35
+ end
36
+ end
37
+ end
38
+
39
+ def download_link
40
+ @report = ClarkKent::Report.where(id: params[:id]).first
41
+ prepare_params
42
+ @report_result_name = "report-#{@report.id}-#{Time.now.to_formatted_s(:number)}"
43
+ @these_params[:report_result_name] = @report_result_name
44
+ ConeyIsland.submit(ClarkKent::Report,
45
+ :send_report_to_s3,
46
+ args: [@report.id, @these_params],
47
+ timeout: 300,
48
+ work_queue: 'boardwalk')
49
+ render partial: 'download_link'
50
+ end
51
+
52
+ def edit
53
+ @report = ClarkKent::Report.find(params[:id])
54
+ if request.xhr?
55
+ render_ajax
56
+ end
57
+ end
58
+
59
+ def update
60
+ @report = ClarkKent::Report.find(params[:id])
61
+ @report.update_attributes(params[:report])
62
+ render partial: 'show'
63
+ end
64
+
65
+ def clone
66
+ report = ClarkKent::Report.find(params[:id])
67
+ report.deep_clone
68
+ redirect_to reports_url
69
+ end
70
+
71
+ def destroy
72
+ @report = ClarkKent::Report.find(params[:id])
73
+ @report.destroy
74
+ redirect_to reports_url
75
+ end
76
+
77
+ protected
78
+
79
+ end
@@ -0,0 +1,53 @@
1
+ class ClarkKent::UserReportEmailsController < ClarkKent::ApplicationController
2
+ before_filter :prepare_user_report_email
3
+ before_filter :prepare_report_email
4
+
5
+ def new
6
+ @user_report_email = ClarkKent::UserReportEmail.new(report_email_id: @report_email.id)
7
+ render partial: 'form', locals: {user_report_email: @user_report_email}
8
+ end
9
+
10
+ def create
11
+ @user_report_email = ClarkKent::UserReportEmail.new(params[:user_report_email])
12
+ if @user_report_email.save
13
+ render partial: 'show_wrapper', locals: {user_report_email: @user_report_email}
14
+ else
15
+ render partial: 'form', locals: {user_report_email: @user_report_email}, status: 409
16
+ end
17
+ end
18
+
19
+ def show
20
+ render partial: 'show', locals: {user_report_email: @user_report_email}
21
+ end
22
+
23
+ def edit
24
+ render partial: 'form', locals: {user_report_email: @user_report_email}
25
+ end
26
+
27
+ def update
28
+ @user_report_email.update_attributes(params[:user_report_email])
29
+ @ajax_flash = {notice: "Your changes were saved."}
30
+ render partial: 'show', locals: {user_report_email: @user_report_email}
31
+ end
32
+
33
+ def destroy
34
+ @user_report_email.destroy
35
+ render nothing: true
36
+ end
37
+
38
+ def prepare_user_report_email
39
+ @user_report_email = ClarkKent::UserReportEmail.find(params[:id]) if params[:id]
40
+ end
41
+
42
+ def prepare_report_email
43
+ report_email_id = params[:report_email_id]
44
+ report_email_id ||= params[:user_report_email][:report_email_id] if params[:user_report_email]
45
+ @report_email = ClarkKent::ReportEmail.find(report_email_id) if report_email_id
46
+ @report_email ||= @user_report_email.report_email if @user_report_email
47
+ end
48
+
49
+ protected
50
+ def authorize_user!
51
+ authorize! :manage, :reports
52
+ end
53
+ end
@@ -0,0 +1,70 @@
1
+ module ClarkKent
2
+ module ApplicationHelper
3
+
4
+ def select_value_method(filter_param,example_option)
5
+ if respond_to? "#{filter_param}_value_method"
6
+ send "#{filter_param}_value_method"
7
+ elsif example_option.respond_to? :id
8
+ :id
9
+ else
10
+ :to_s
11
+ end
12
+ end
13
+
14
+ def select_text_method(filter_param,example_option)
15
+ if respond_to? "#{filter_param}_text_method"
16
+ send "#{filter_param}_text_method"
17
+ elsif example_option.respond_to? :name
18
+ :name
19
+ else
20
+ :to_s
21
+ end
22
+ end
23
+
24
+ def unit_id_value_method
25
+ :id
26
+ end
27
+
28
+ def unit_id_text_method
29
+ :full_name
30
+ end
31
+
32
+ def is_decimal?(value)
33
+ (value =~ /\d/) && (value =~ /\./) && !(value =~ /[a-zA-Z]/)
34
+ end
35
+
36
+ def display_for_value(value, column_name=nil)
37
+ return link_to(value, edit_manage_reservation_path(value)) if column_name == 'reservation_id'
38
+ return value.join(', ') if value.is_a? Array
39
+ return value.to_formatted_s(:datepicker) if value.is_a? Date
40
+ return number_to_currency(value) if value.is_a? Float or value.is_a? BigDecimal or is_decimal?(value)
41
+ return '&#10003;'.html_safe if 't' == value or true == value
42
+ return '' if 'f' == value or false == value
43
+ return value
44
+ end
45
+
46
+ def get_temp_order_direction(params)
47
+ return 'asc' unless params[:order].present?
48
+ current_order_column, current_order_direction = params[:order].split('-')
49
+ {"asc" => "desc", "desc" => "asc", nil => "asc", '' => 'asc'}[current_order_direction]
50
+ end
51
+
52
+ def get_selected_order_direction(params, column)
53
+ return nil unless params[:order].present?
54
+ current_order_column, current_order_direction = params[:order].split('-')
55
+ return nil unless column.column_name == current_order_column
56
+ {"asc" => '&darr;'.html_safe, "desc" => '&uarr;'.html_safe}[current_order_direction]
57
+ end
58
+
59
+ def print_button(rows, from_modal=false)
60
+ if rows
61
+ onclick_str = "window.print()"
62
+ onclick_str.prepend("$('#print_report_modal').modal('hide');") if from_modal
63
+ link_to 'Print',
64
+ 'javascript:void(0)',
65
+ class: 'btn',
66
+ onclick: raw(onclick_str)
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,15 @@
1
+ module ClarkKent
2
+ class ReportMailer < ActionMailer::Base
3
+ default from: 'reservations@invitedhome.com'
4
+
5
+ def report_run(report_id, user_id, report_download_url)
6
+ @report = Report.find(report_id)
7
+ @user = User.find(user_id)
8
+ @recipient_email = @user.email
9
+ @report_download_url = report_download_url
10
+ @subject = "Your report #{@report.name} is ready"
11
+ mail(to: @recipient_email, subject: @subject)
12
+ end
13
+
14
+ end
15
+ end