-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add frontend for dashboard (bootstrap, turbo); make table of recordin…
…gs; touch session window (#20)
- Loading branch information
1 parent
7325bcb
commit aaa778e
Showing
22 changed files
with
2,901 additions
and
66 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
app/controllers/spectator_sport/dashboard/frontends_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# frozen_string_literal: true | ||
|
||
module SpectatorSport | ||
module Dashboard | ||
class FrontendsController < ActionController::Base # rubocop:disable Rails/ApplicationController | ||
protect_from_forgery with: :exception | ||
skip_after_action :verify_same_origin_request, raise: false | ||
|
||
def self.asset_path(path) | ||
Engine.root.join("app/frontend/spectator_sport/dashboard", path) | ||
end | ||
|
||
STATIC_ASSETS = { | ||
css: { | ||
bootstrap: asset_path("vendor/bootstrap/bootstrap.min.css"), | ||
"rrweb-player": asset_path("vendor/rrweb-player/rrweb-player.min.css"), | ||
style: asset_path("style.css") | ||
}, | ||
js: { | ||
bootstrap: asset_path("vendor/bootstrap/bootstrap.bundle.min.js"), | ||
es_module_shims: asset_path("vendor/es_module_shims.js") | ||
}, | ||
svg: { | ||
icons: asset_path("icons.svg") | ||
} | ||
}.freeze | ||
|
||
MODULE_OVERRIDES = { | ||
application: asset_path("application.js"), | ||
"rrweb-player": asset_path("vendor/rrweb-player/rrweb-player.min.js"), | ||
stimulus: asset_path("vendor/stimulus.js"), | ||
turbo: asset_path("vendor/turbo.js") | ||
}.freeze | ||
|
||
def self.js_modules | ||
@_js_modules ||= asset_path("modules").children.select(&:file?).each_with_object({}) do |file, modules| | ||
key = File.basename(file.basename.to_s, ".js").to_sym | ||
modules[key] = file | ||
end.merge(MODULE_OVERRIDES) | ||
end | ||
|
||
before_action do | ||
expires_in 1.year, public: true | ||
end | ||
|
||
def static | ||
file_path = STATIC_ASSETS.dig(params[:format]&.to_sym, params[:id]&.to_sym) || raise(ActionController::RoutingError, "Not Found") | ||
send_file file_path, disposition: "inline" | ||
end | ||
|
||
def module | ||
raise(ActionController::RoutingError, "Not Found") if params[:format] != "js" | ||
|
||
file_path = self.class.js_modules[params[:id]&.to_sym] || raise(ActionController::RoutingError, "Not Found") | ||
send_file file_path, disposition: "inline" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/*jshint esversion: 6, strict: false */ | ||
|
||
import "turbo"; | ||
import { Application } from "stimulus"; | ||
import ThemeController from "theme_controller"; | ||
window.Stimulus = Application.start(); | ||
Stimulus.register("theme", ThemeController); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions
44
app/frontend/spectator_sport/dashboard/modules/theme_controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// hello_controller.js | ||
import { Controller } from "stimulus" | ||
export default class extends Controller { | ||
static targets = [ "dropdown", "button" ] | ||
|
||
connect() { | ||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => { | ||
const theme = localStorage.getItem('spectator_sport-theme'); | ||
if (!["light", "dark"].includes(theme)) { | ||
this.setTheme(this.autoTheme()); | ||
} | ||
}); | ||
|
||
this.setTheme(this.getStoredTheme() || 'light'); | ||
} | ||
|
||
change(event) { | ||
const theme = event.params.value; | ||
localStorage.setItem('spectator_sport-theme', theme); | ||
this.setTheme(theme); | ||
} | ||
|
||
setTheme(theme) { | ||
document.documentElement.setAttribute('data-bs-theme', theme === 'auto' ? this.autoTheme() : theme); | ||
|
||
this.buttonTargets.forEach((button) => { | ||
button.classList.remove('active'); | ||
if (button.dataset.themeValueParam === theme) { | ||
button.classList.add('active'); | ||
} | ||
}); | ||
|
||
const svg = this.buttonTargets.filter(b => b.matches(".active"))[0]?.querySelector('svg'); | ||
this.dropdownTarget.querySelector('svg').outerHTML = svg.outerHTML; | ||
} | ||
|
||
getStoredTheme() { | ||
return localStorage.getItem('spectator_sport-theme'); | ||
} | ||
|
||
autoTheme() { | ||
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
.tooltip { | ||
position: absolute; | ||
z-index: 1; | ||
padding: 5px; | ||
background: rgba(0, 0, 0, 0.3); | ||
opacity: 1; | ||
border-radius: 3px; | ||
text-align: center; | ||
pointer-events: none; | ||
color: white; | ||
transition: opacity .1s ease-out; | ||
} | ||
|
||
.tooltip.tooltip-hidden { | ||
opacity: 0; | ||
} | ||
|
||
.ct-label.ct-horizontal { | ||
white-space: nowrap; | ||
} | ||
|
||
.chart-wrapper { | ||
position: relative; | ||
height: 200px; | ||
} | ||
|
||
.legend-item-color-box { | ||
display: inline-block; | ||
flex-shrink: 0; | ||
height: 20px; | ||
width: 20px; | ||
border-style: solid; | ||
margin-right: 3px; | ||
} | ||
|
||
#chart-legend-container { | ||
height: 200px; | ||
} | ||
|
||
/* Break out of a container */ | ||
.break-out { | ||
width:100vw; | ||
position:relative; | ||
left:calc(-1 * (100vw - 100%)/2); | ||
} | ||
|
||
.toast-container { | ||
z-index: 1; | ||
} | ||
|
||
.btn-outline-secondary { | ||
border-color: #ced4da; /* $gray-400 */ | ||
} | ||
|
||
.min-w-auto { | ||
min-width: auto; | ||
} | ||
|
||
.w-fit-content { | ||
width: fit-content | ||
} | ||
|
||
.svg-icon { | ||
height: 1rem; | ||
width: 1rem; | ||
} |
6 changes: 6 additions & 0 deletions
6
app/frontend/spectator_sport/dashboard/vendor/bootstrap/bootstrap.bundle.min.js
Large diffs are not rendered by default.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
app/frontend/spectator_sport/dashboard/vendor/bootstrap/bootstrap.min.css
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
app/frontend/spectator_sport/dashboard/vendor/es_module_shims.js
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
app/frontend/spectator_sport/dashboard/vendor/rrweb-player/rrweb-player.min.css
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
app/frontend/spectator_sport/dashboard/vendor/rrweb-player/rrweb-player.min.js
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.