mint_reporter 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +34 -0
  3. data/app/controllers/admin/reports_controller.rb +3 -0
  4. data/app/models/report.rb +86 -0
  5. data/app/views/admin/reports/_form.html.erb +40 -0
  6. data/app/views/admin/reports/edit.html.erb +14 -0
  7. data/app/views/admin/reports/index.html.erb +96 -0
  8. data/app/views/admin/reports/new.html.erb +13 -0
  9. data/app/views/admin/reports/show.html.erb +51 -0
  10. data/app/workers/csv_generation_worker.rb +8 -0
  11. data/config/initializers/mime_types.rb +1 -0
  12. data/config/routes.rb +5 -0
  13. data/db/migrate/20140703143528_create_reports.rb +16 -0
  14. data/lib/generators/mint_report/USAGE +8 -0
  15. data/lib/generators/mint_report/mint_report_generator.rb +7 -0
  16. data/lib/generators/mint_report/templates/mint_report.rb +9 -0
  17. data/lib/mint_reporter.rb +17 -0
  18. data/lib/mint_reporter/engine.rb +4 -0
  19. data/lib/mint_reporter/version.rb +3 -0
  20. data/lib/tasks/mint_reporter_tasks.rake +4 -0
  21. data/test/dummy/README.rdoc +28 -0
  22. data/test/dummy/Rakefile +6 -0
  23. data/test/dummy/app/assets/javascripts/admin.js +31 -0
  24. data/test/dummy/app/assets/javascripts/application.js +13 -0
  25. data/test/dummy/app/assets/stylesheets/admin.scss +11 -0
  26. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  27. data/test/dummy/app/controllers/admin/admin_controller.rb +3 -0
  28. data/test/dummy/app/controllers/application_controller.rb +7 -0
  29. data/test/dummy/app/helpers/application_helper.rb +8 -0
  30. data/test/dummy/app/models/user.rb +2 -0
  31. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  32. data/test/dummy/bin/bundle +3 -0
  33. data/test/dummy/bin/rails +4 -0
  34. data/test/dummy/bin/rake +4 -0
  35. data/test/dummy/config.ru +4 -0
  36. data/test/dummy/config/application.rb +23 -0
  37. data/test/dummy/config/boot.rb +7 -0
  38. data/test/dummy/config/database.yml +25 -0
  39. data/test/dummy/config/environment.rb +6 -0
  40. data/test/dummy/config/environments/development.rb +29 -0
  41. data/test/dummy/config/environments/production.rb +80 -0
  42. data/test/dummy/config/environments/test.rb +36 -0
  43. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  44. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  45. data/test/dummy/config/initializers/inflections.rb +16 -0
  46. data/test/dummy/config/initializers/mime_types.rb +5 -0
  47. data/test/dummy/config/initializers/secret_token.rb +12 -0
  48. data/test/dummy/config/initializers/session_store.rb +3 -0
  49. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  50. data/test/dummy/config/locales/en.yml +23 -0
  51. data/test/dummy/config/routes.rb +59 -0
  52. data/test/dummy/db/development.sqlite3 +0 -0
  53. data/test/dummy/db/migrate/20140716113109_create_users.rb +9 -0
  54. data/test/dummy/db/migrate/20140723162342_create_reports.mint_reporter_engine.rb +17 -0
  55. data/test/dummy/db/production.sqlite3 +0 -0
  56. data/test/dummy/db/schema.rb +35 -0
  57. data/test/dummy/db/test.sqlite3 +0 -0
  58. data/test/dummy/log/development.log +293 -0
  59. data/test/dummy/log/test.log +17259 -0
  60. data/test/dummy/public/404.html +58 -0
  61. data/test/dummy/public/422.html +58 -0
  62. data/test/dummy/public/500.html +57 -0
  63. data/test/dummy/public/favicon.ico +0 -0
  64. data/test/dummy/public/uploads/test/basic_reports/000/000/001/original.csv +3 -0
  65. data/test/dummy/test/factories/foos.rb +6 -0
  66. data/test/dummy/tmp/cache/assets/test/sass/051af4935d2ac60904721027c383dd9ffc9f7871/_admin-base.scssc +0 -0
  67. data/test/dummy/tmp/cache/assets/test/sass/7f5568ada10d673b8a1d203ce8b8c1dba7fbaf83/admin.scssc +0 -0
  68. data/test/dummy/tmp/cache/assets/test/sprockets/1935933f8fbe88236ef893016c1836bc +0 -0
  69. data/test/dummy/tmp/cache/assets/test/sprockets/27184889e78dc5a556f3c7567afbef63 +0 -0
  70. data/test/dummy/tmp/cache/assets/test/sprockets/37c7a190e68a7e26cf450e38ec190534 +0 -0
  71. data/test/dummy/tmp/cache/assets/test/sprockets/468917569b5c6af93b42fda1a68e426c +0 -0
  72. data/test/dummy/tmp/cache/assets/test/sprockets/638d4b299480bfa854367ae027ff66d0 +0 -0
  73. data/test/dummy/tmp/cache/assets/test/sprockets/6609ee9da4eaea9b8d8137fbcfce6fdd +0 -0
  74. data/test/dummy/tmp/cache/assets/test/sprockets/9d087e6fe6cf75adc1ebe34710cb71bc +0 -0
  75. data/test/dummy/tmp/cache/assets/test/sprockets/ac64f2f5da10d3fe34beec68afda56d4 +0 -0
  76. data/test/dummy/tmp/cache/assets/test/sprockets/b53da076920d68305d6582c3af250465 +0 -0
  77. data/test/dummy/tmp/cache/assets/test/sprockets/d875d477ab20a2e08531d775a5fea6f2 +0 -0
  78. data/test/dummy/tmp/cache/assets/test/sprockets/e017dd8f0cd2f98c7864918d2ba783b3 +0 -0
  79. data/test/dummy/tmp/cache/assets/test/sprockets/f8160f91b680b2f94df78cefd5abc06e +0 -0
  80. data/test/factories/reports.rb +8 -0
  81. data/test/factories/users.rb +5 -0
  82. data/test/fixtures/reports.yml +15 -0
  83. data/test/functional/reports_controller_test.rb +34 -0
  84. data/test/generators/mint_report_generator_test.rb +14 -0
  85. data/test/integration/configuration_test.rb +29 -0
  86. data/test/integration/create_report_test.rb +20 -0
  87. data/test/integration/mint_report_generator.rb +10 -0
  88. data/test/mint_reporter_test.rb +7 -0
  89. data/test/test_helper.rb +45 -0
  90. data/test/tmp/app/models/reports/foo_report.rb +9 -0
  91. data/test/unit/report_test.rb +69 -0
  92. metadata +330 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3a1afefaf2a8bdf1dfaa1bf1d367ba5aa182a7cf
4
+ data.tar.gz: 9fdabc7a849df057a33ec1071311fedecaf5f29a
5
+ SHA512:
6
+ metadata.gz: 77d9eed2712f0ec4d023cd08493c2109d0e4535a1c605ccf61c5da6c1be3cb01536627bece77ea859bc30fb7d3f5f0da036c5211bac257eeba63934f4a582bec
7
+ data.tar.gz: 86e9447ad4065e4181dbc59e7486b271bb72df0a0d70effe409e597588ca2329b632deac2bb049719afd8dd09f72e4c6cdf46f40c9763b23cd5514635bd95dc6
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 = 'MintReporter'
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,3 @@
1
+ class Admin::ReportsController < Admin::AdminController
2
+ # This class generated by mint_admin_tab generator
3
+ end
@@ -0,0 +1,86 @@
1
+ class Report < ActiveRecord::Base
2
+ include AASM
3
+
4
+ # CSV Attachment
5
+ validates_inclusion_of :type, :in => MintReporter.config.reports
6
+ has_attached_file(:csv, MintReporter.config.paperclip_storage_options)
7
+ do_not_validate_attachment_file_type :csv
8
+ after_commit :generate_csv, :on => :create
9
+
10
+ ### AASM States ###
11
+ aasm :column => 'state' do
12
+ initial_state :pending
13
+
14
+ state :pending
15
+ state :generating_csv
16
+ state :csv_generated
17
+ state :csv_ready
18
+ state :csv_failed
19
+
20
+ event :generating_csv do
21
+ transitions :from => [
22
+ :pending,
23
+ :generating_csv,
24
+ :csv_failed
25
+ ], :to => :generating_csv
26
+ end
27
+ event :csv_generated do
28
+ transitions :from => [:generating_csv, :csv_generated, :csv_failed],
29
+ :to => :csv_generated
30
+ end
31
+ event :csv_ready do
32
+ transitions :from => [:csv_generated, :csv_ready], :to => :csv_ready
33
+ end
34
+ event :csv_failure do
35
+ transitions :from => [:generating_csv, :csv_ready, :csv_failed],
36
+ :to => :csv_failed
37
+ end
38
+ end
39
+
40
+ def generate_csv
41
+ CSVGenerationWorker.perform_async(id)
42
+ end
43
+
44
+ def generate_csv!
45
+ generating_csv!
46
+ file = Tempfile.new(["report-#{id}", '.csv'])
47
+ begin
48
+ CSV.open(file, "wb") do |csv|
49
+ csv << csv_column_names
50
+
51
+ scoped_records.each do |record|
52
+ csv << csv_row(record)
53
+ end
54
+ end
55
+ self.csv = file
56
+ save
57
+ file.close
58
+ csv_generated!
59
+ rescue Exception => e
60
+ csv_failure!
61
+ raise e
62
+ end
63
+ end
64
+
65
+ def csv_column_names
66
+ raise MintReporter::Undefined,
67
+ "Subclasses of Report must implement csv_column_names"
68
+ end
69
+
70
+ def csv_row(record)
71
+ raise MintReporter::Undefined,
72
+ "Subclasses of Report must implement csv_row"
73
+ end
74
+
75
+ def records
76
+ raise MintReporter::Undefined,
77
+ "Subclasses of Report must implement records"
78
+ end
79
+
80
+ private
81
+
82
+ def scoped_records
83
+ records.where(:created_at => from_date..to_date).
84
+ order(:created_at => :desc)
85
+ end
86
+ end
@@ -0,0 +1,40 @@
1
+ <% if @report.errors.any? %>
2
+ <div>
3
+ <h2>
4
+ <%= pluralize(@report.errors.count, "error") %>
5
+ prohibited this report from being saved:
6
+ </h2>
7
+
8
+ <ul>
9
+ <% @report.errors.full_messages.each do |msg| %>
10
+ <li><%= msg %></li>
11
+ <% end %>
12
+ </ul>
13
+ </div>
14
+ <% end %>
15
+
16
+ <%= form_for [:admin, @report], :as => :report,
17
+ :html => {:class => 'report'} do |f| %>
18
+ <fieldset>
19
+ <ol>
20
+ <li>
21
+ <%= f.label :type %>
22
+ <%= f.select :type, MintReporter.config.reports %>
23
+ </li>
24
+ <li>
25
+ <%= f.label :from_date %>
26
+ <%= f.datetime_select :from_date %>
27
+ </li>
28
+ <li>
29
+ <%= f.label :to_date %>
30
+ <%= f.datetime_select :to_date %>
31
+ </li>
32
+ </ol>
33
+ </fieldset>
34
+ <div class="submit">
35
+ <%= f.submit 'Save' %>
36
+ <span class="alt">or <%=
37
+ link_to 'cancel', admin_cancel_path(@report)
38
+ %></span>
39
+ </div>
40
+ <% end %>
@@ -0,0 +1,14 @@
1
+ <% content_for :body_class, 'admin-reports edit' %>
2
+ <% content_for :body_id, 'admin-reports-edit' %>
3
+ <% content_for :page_title, 'Reports - Edit' %>
4
+
5
+ <% content_for :page_header do %>
6
+ <h2>
7
+ <%= link_to 'Reports',
8
+ admin_reports_path %>
9
+ &gt; <%=h @report.id %>
10
+ &gt; edit
11
+ </h2>
12
+ <% end %>
13
+
14
+ <%= render 'form' %>
@@ -0,0 +1,96 @@
1
+ <% content_for :body_class, 'admin-reports index' %>
2
+ <% content_for :body_id, 'admin-reports-index' %>
3
+ <% content_for :page_title, 'Reports' %>
4
+
5
+ <% content_for :page_header do %>
6
+ <h2><%= yield :page_title %></h2>
7
+ <ul class="actions">
8
+ <li>
9
+ <%= link_to "Create a new report",
10
+ new_admin_report_path, :class => 'new' %>
11
+ </li>
12
+ </ul>
13
+ <% end %>
14
+
15
+ <% if @reports.any? %>
16
+ <div class="table-section">
17
+ <table cellspacing="0" class="stripe">
18
+ <thead>
19
+ <tr>
20
+ <th>Id</th>
21
+ <th>Type</th>
22
+ <th>From Date</th>
23
+ <th>To Date</th>
24
+ <th>State</th>
25
+ <th>Report</th>
26
+ <th>Created at</th>
27
+ <th>Controls</th>
28
+ </tr>
29
+ </thead>
30
+
31
+ <tbody>
32
+ <% @reports.each do |report| %>
33
+ <tr>
34
+ <td>
35
+ <%= report.id %>
36
+ </td>
37
+ <td>
38
+ <%= report.type %>
39
+ </td>
40
+ <td>
41
+ <span title="<%= time_ago_in_words(report.from_date).html_safe %> ago"><%= admin_time_string(report.from_date).html_safe %></span> </td>
42
+ </td>
43
+ <td>
44
+ <span title="<%= time_ago_in_words(report.to_date).html_safe %> ago"><%= admin_time_string(report.to_date).html_safe %></span> </td>
45
+ </td>
46
+ <td>
47
+ <%= report.state %>
48
+ </td>
49
+ <td>
50
+ <% if report.csv.present? %>
51
+ <%= link_to("download", report.csv.url) %>
52
+ <% else %>
53
+ N/A
54
+ <% end %>
55
+ </td>
56
+ <td>
57
+ <% if report.created_at %>
58
+ <span title="<%= time_ago_in_words(report.created_at).html_safe %> ago"><%= admin_time_string(report.created_at).html_safe %></span>
59
+ <% else %>
60
+ -
61
+ <% end %>
62
+ </td>
63
+ <td class="controls">
64
+ <ul>
65
+ <li>
66
+ <%= link_to 'details',
67
+ admin_report_path(report) %>
68
+ </li>
69
+ <li>
70
+ <%= link_to 'edit',
71
+ edit_admin_report_path(report) %>
72
+ </li>
73
+ <li>
74
+ <%= form_button_to 'delete',
75
+ admin_report_path(report),
76
+ :class => 'text',
77
+ :method => :delete,
78
+ :data => {
79
+ :confirm => 'Are you sure you want to delete this?'
80
+ } %>
81
+ </li>
82
+ </ul>
83
+ </td>
84
+ </tr>
85
+ <% end %>
86
+ </tbody>
87
+ </table>
88
+ </div>
89
+
90
+ <%= will_paginate @reports %>
91
+
92
+ <% else %>
93
+ <div class="empty">
94
+ There are no reports available.
95
+ </div>
96
+ <% end %>
@@ -0,0 +1,13 @@
1
+ <% content_for :body_class, 'admin-reports new' %>
2
+ <% content_for :body_id, 'admin-reports-new' %>
3
+ <% content_for :page_title, 'Reports - New' %>
4
+
5
+ <% content_for :page_header do %>
6
+ <h2>
7
+ <%= link_to 'Reports',
8
+ admin_reports_path %>
9
+ &gt; new
10
+ </h2>
11
+ <% end %>
12
+
13
+ <%= render 'form' %>
@@ -0,0 +1,51 @@
1
+
2
+ <% content_for :body_class, 'admin-reports show' %>
3
+ <% content_for :body_id, 'admin-reports-show' %>
4
+ <% content_for :page_title, 'Reports' %>
5
+
6
+ <% content_for :page_header do %>
7
+ <h2>
8
+ <%= link_to yield(:page_title), admin_reports_path %> &gt;
9
+ <%=h @report.id %>
10
+ </h2>
11
+ <ul class="actions">
12
+ <li>
13
+ <%= link_to 'edit',
14
+ edit_admin_report_path(@report) %>
15
+ </li>
16
+ <li>
17
+ <%= form_button_to 'delete',
18
+ admin_report_path(@report),
19
+ :method => :delete,
20
+ :data => {
21
+ :confirm => 'Are you sure you want to delete this permanently?'
22
+ } %>
23
+ </li>
24
+ </ul>
25
+ <% end %>
26
+
27
+ <div id="admin-content">
28
+ <dl>
29
+ <dt>state</dt>
30
+ <dd><%= @report.state %></dd>
31
+ <dt>report</dt>
32
+ <% if @report.csv.present? %>
33
+ <dd><%= link_to('download', @report.csv.url) %>
34
+ <% else %>
35
+ <dd>N/A</dd>
36
+ <% end %>
37
+ <dt>from_date</dt>
38
+ <dd><%= @report.from_date %></dd>
39
+ <dt>to_date</dt>
40
+ <dd><%= @report.to_date %></dd>
41
+ </dl>
42
+
43
+ <dl class="supplemental">
44
+ <dt>id</dt>
45
+ <dd><%=h @report.id %></dd>
46
+ <dt>created_at</dt>
47
+ <dd><%=h @report.created_at %></dd>
48
+ <dt>updated_at</dt>
49
+ <dd><%=h @report.updated_at %></dd>
50
+ </dl>
51
+ </div><!-- #admin-content -->
@@ -0,0 +1,8 @@
1
+ class CSVGenerationWorker
2
+ include Sidekiq::Worker
3
+ sidekiq_options :retry => false
4
+
5
+ def perform(report_id)
6
+ Report.find(report_id).generate_csv!
7
+ end
8
+ end
@@ -0,0 +1 @@
1
+ Mime::Type.register "application/xls", :xls
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ Rails.application.routes.draw do
2
+ namespace :admin do
3
+ resources :reports
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ class CreateReports < ActiveRecord::Migration
2
+ def change
3
+ create_table :reports do |t|
4
+ t.string :type
5
+ t.datetime :from_date
6
+ t.datetime :to_date
7
+ t.string :csv_file_name
8
+ t.string :csv_content_type
9
+ t.integer :csv_file_size
10
+ t.datetime :csv_updated_at
11
+ t.string :state
12
+
13
+ t.timestamps
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generate a standard Mint report
3
+
4
+ Example:
5
+ rails generate mint_report MyReport
6
+
7
+ This will create:
8
+ app/models/reports/my_report.rb
@@ -0,0 +1,7 @@
1
+ class MintReportGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ def copy_mint_report_file
5
+ template "mint_report.rb", "app/models/reports/#{file_name}.rb"
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ class <%= class_name %> < Report
2
+ def csv_column_names
3
+ super
4
+ end
5
+
6
+ def csv_row(record)
7
+ super
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ require "mint_reporter/engine"
2
+
3
+ require "aasm"
4
+ require "csv"
5
+ require "mint_admin"
6
+ require "paperclip"
7
+ require "sidekiq"
8
+
9
+ module MintReporter
10
+ def self.config(&block)
11
+ @@config ||= MintReporter::Engine::Configuration.new
12
+ yield @@config if block
13
+ @@config
14
+ end
15
+
16
+ class Undefined < StandardError ; end
17
+ end