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

Serve Dashboard assets as discrete paths instead of inlining #262

Merged
merged 1 commit into from
May 24, 2021
Merged
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
7 changes: 7 additions & 0 deletions engine/app/assets/vendor/bootstrap/bootstrap.bundle.min.js

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions engine/app/controllers/good_job/assets_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module GoodJob
class AssetsController < ActionController::Base # rubocop:disable Rails/ApplicationController
skip_before_action :verify_authenticity_token

before_action do
expires_in 1.year, public: true
end

def bootstrap_css
render file: GoodJob::Engine.root.join("app", "assets", "vendor", "bootstrap", "bootstrap.min.css")
end

def bootstrap_js
render file: GoodJob::Engine.root.join("app", "assets", "vendor", "bootstrap", "bootstrap.bundle.min.js")
end

def chartist_css
render file: GoodJob::Engine.root.join("app", "assets", "vendor", "chartist", "chartist.css")
end

def chartist_js
render file: GoodJob::Engine.root.join("app", "assets", "vendor", "chartist", "chartist.js")
end

def style_css
render file: GoodJob::Engine.root.join("app", "assets", "style.css")
end
end
end
13 changes: 5 additions & 8 deletions engine/app/views/layouts/good_job/base.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

<style>
<%== render file: GoodJob::Engine.root.join("app", "assets", "vendor", "bootstrap", "bootstrap.min.css") %>
<%== render file: GoodJob::Engine.root.join("app", "assets", "vendor", "chartist", "chartist.css") %>
<%== render file: GoodJob::Engine.root.join("app", "assets", "style.css") %>
</style>
<%= stylesheet_link_tag bootstrap_css_path(v: GoodJob::VERSION) %>
<%= stylesheet_link_tag chartist_css_path(v: GoodJob::VERSION) %>
<%= stylesheet_link_tag style_css_path(v: GoodJob::VERSION) %>

<script>
<%== render file: GoodJob::Engine.root.join("app", "assets", "vendor", "chartist", "chartist.js") %>
</script>
<%= javascript_include_tag bootstrap_js_path(v: GoodJob::VERSION) %>
<%= javascript_include_tag chartist_js_path(v: GoodJob::VERSION) %>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
Expand Down
8 changes: 8 additions & 0 deletions engine/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
GoodJob::Engine.routes.draw do
root to: 'dashboards#index'
resources :active_jobs, only: :show

scope controller: :assets do
get :bootstrap_css
get :bootstrap_js
get :chartist_css
get :chartist_js
get :style_css
end
end
16 changes: 9 additions & 7 deletions spec/test_app/db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
datetime = 7.days.ago
time_series = (1.minute..90.minutes).to_a
start_date = 7.days.ago
time_increments = (1.minute..90.minutes).to_a
job_classes = ['ExampleJob', 'OtherJob']
queue_names = ["default", "mice", "elephants"]

ActiveRecord::Base.transaction do
loop do
active_job_id = SecureRandom.uuid
job_class = ['ExampleJob', 'OtherJob'].sample
queue_name = ["default", "mice", "elephants"].sample
enqueued_at = datetime
job_class = job_classes.sample
queue_name = queue_names.sample
enqueued_at = start_date

serialized_params = {
job_id: active_job_id,
Expand Down Expand Up @@ -34,7 +36,7 @@
error: nil
)

datetime += time_series.sample
break if datetime > Time.current
start_date += time_increments.sample
break if start_date > Time.current
end
end