Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TR#400] Add blazer generator #97

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/generators/rolemodel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

## What you get

* [Blazer](./blazer)
* [CSS](./css)
* [Github](./github)
* [Heroku](./heroku)
Expand Down
1 change: 1 addition & 0 deletions lib/generators/rolemodel/all_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def run_all_the_generators
generate 'rolemodel:simple_form'
generate 'rolemodel:soft_destroyable'
generate 'rolemodel:saas:all'
generate 'rolemodel:blazer'
generate 'rolemodel:editors'
generate 'rolemodel:linters:all'
generate 'rolemodel:mailers'
Expand Down
21 changes: 21 additions & 0 deletions lib/generators/rolemodel/blazer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Blazer Generator

Depends on the blazer generator
Depends on [RSpec Generator](../testing/rspec)
Depends on slim
Works best with Optics
* If not using with Optics, update blazer.css to use your own tokens.

## What you get

Installs [blazer](https://github.com/ankane/blazer) with customization for enabling non-admin users to run Dashboard-type reports (SQL queries with variables) at /reports/dashboards. Prevents SQL-injection vulnerability present in base gem which assumes super-admin access only.

### Controllers
* Adds Reports::DashboardController
* Add Reports::QueriesController

### Views
* Reports list and show

### Tests
* Report system test
5 changes: 5 additions & 0 deletions lib/generators/rolemodel/blazer/USAGE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Description:
installs and configures Blazer

Example:
rails generate rolemodel:blazer
69 changes: 69 additions & 0 deletions lib/generators/rolemodel/blazer/blazer_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
require_relative '../../../bundler_helpers'

module Rolemodel
class BlazerGenerator < Rails::Generators::Base
include Rolemodel::BundlerHelpers
source_root File.expand_path('templates', __dir__)

def install_blazer
gem 'sprockets-rails' unless File.readlines('Gemfile').grep(/sprockets/).any?
gem 'blazer'
run_bundle

generate 'blazer:install'
end

def update_migration
filename = Dir.glob('db/migrate/*_install_blazer.rb').first
inject_into_file filename, ', foreign_key: { to_table: :users }', after: 't.references :creator'
end

def add_routes
return if File.readlines('config/routes.rb').grep(/blazer/).any?

# add routes for the report controllers
route_info = " namespace :reports do\n"
route_info += " resources :dashboards, only: %i[index show]\n"
route_info += " resources :queries, only: [] do\n"
route_info += " post :run, on: :collection\n"
route_info += " # post :cancel, on: :collection\n"
route_info += " end\n"
route_info += " end\n"
route route_info

# add routes for the Blazer engine
route_info = " # authenticate :user, ->(u) { Admin::ReportPolicy.new(u, :report).manage? } do\n"
route_info += " mount Blazer::Engine => '/admin/reports', as: :blazer\n"
route_info += " # end\n"
route route_info
end

def add_extensions
copy_file 'config/initializers/blazer.rb'
copy_file 'lib/blazer_extensions/data_source.rb'
end

def add_controllers
directory 'app/controllers/reports'
end

def add_views
directory 'app/views/reports'
end

def add_styles
copy_file 'app/assets/stylesheets/blazer.css'
copy_file 'app/assets/stylesheets/selectize.css'
append_to_file 'app/assets/config/manifest.js', "\n//= link blazer.css"
end

def add_tests
copy_file 'spec/factories/blazer_queries.rb'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be copying blazer_dashboards.rb too?

Suggested change
copy_file 'spec/factories/blazer_queries.rb'
copy_file 'spec/factories/blazer_dashboards.rb'
copy_file 'spec/factories/blazer_queries.rb'

copy_file 'spec/system/reporting_spec.rb'
end

def add_rake_task
copy_file 'lib/tasks/reports.rake'
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
*= require ./selectize
*= require_self
*= require blazer/daterangepicker
*/

/* These styles map Blazer's html structure into our look and feel. */

.results-container { /* Copied from .table__wrapper */
overflow: auto;
}

.text-muted {
color: var(--rm-color-disabled);
}

.chart-container { /* Copied from .card */
position: relative;
border: 1px solid var(--rm-color-contrast-medium);
border-radius: var(--rm-radius);
padding: var(--rm-space-large);
width: 100%;
background: var(--rm-color-white);
margin-bottom: var(--rm-space-medium);
}

.btn-success { /* Copied from .btn--rm-primary */
background: var(--rm-color-primary-minus-four);
color: var(--rm-color-white);
&:hover {
opacity: 0.7;
}
&:visited {
color: var(--rm-color-white);
}
}

.form-inline {
display: flex;
align-items: center;
}

.form-inline label {
margin-bottom: 0;
}

.selectize-control {
margin-right: var(--rm-space-medium);
}

/* date range picker */
body .daterangepicker .drp-buttons .btn {
font-size: var(--rm-text-small);
padding: inherit;
margin-top: var(--rm-space-x-small);
margin-bottom: var(--rm-space-x-small);
}

body .daterangepicker .drp-buttons .btn.cancelBtn {
box-shadow: var(--rm-border-all) var(--rm-border-color);
background: var(--rm-color-white);
color: var(--rm-color-neutral-minus-max);
}

body .daterangepicker .drp-buttons .btn.applyBtn {
background: var(--rm-color-primary-minus-four);
color: var(--rm-color-white);
}

body .daterangepicker td.in-range {
background: var(--rm-color-primary-plus-four);
}

body .daterangepicker td.active, body .daterangepicker td.active:hover {
background: var(--rm-color-primary-minus-four);
color: var(--rm-color-white);
}

body .daterangepicker .ranges li.active {
background: var(--rm-color-primary-minus-four);
color: var(--rm-color-white);
}
Loading