-
-
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.
Separate sessions from windows from events; add a more usable demo
- Loading branch information
1 parent
4dab5d4
commit e7b974e
Showing
18 changed files
with
174 additions
and
39 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,8 +1,18 @@ | ||
module SpectatorSport | ||
class DashboardsController < ApplicationController | ||
def index | ||
page_id = Event.last&.page_id | ||
@events = Event.where(page_id: page_id).order(:created_at) | ||
@session_windows = SessionWindow.order(:created_at).limit(50).reverse_order | ||
end | ||
|
||
def show | ||
@session_window = SessionWindow.find(params[:id]) | ||
end | ||
|
||
def destroy | ||
@session_window = SessionWindow.find(params[:id]) | ||
@session_window.events.delete_all | ||
@session_window.delete | ||
redirect_to action: :index | ||
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
module SpectatorSport | ||
class Event < ApplicationRecord | ||
belongs_to :session | ||
belongs_to :session_window | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module SpectatorSport | ||
class Session < ApplicationRecord | ||
has_many :session_windows | ||
has_many :events | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module SpectatorSport | ||
class SessionWindow < ApplicationRecord | ||
belongs_to :session | ||
has_many :events | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
<%= render "spectator_sport/shared/rrweb_player" %> | ||
<h1>Spectator Sport</h1> | ||
<% if @session_windows.to_a.any? %> | ||
<ul> | ||
|
||
<script type="module"> | ||
new rrwebPlayer({ | ||
target: document.body, // customizable root element | ||
props: { | ||
events: <%== @events.map(&:event_data).to_json %>, | ||
}, | ||
}); | ||
</script> | ||
<% @session_windows.each do |session_window| %> | ||
<li> | ||
<%= link_to "Session (##{session_window.session_id}) Window (##{session_window.id})", spectator_sport.dashboard_path(session_window.id) %> | ||
<%= button_to "X", { action: :destroy, id: session_window.id }, method: :delete, form: { style: "display: inline-block" } %> | ||
</li> | ||
<% end %> | ||
</ul> | ||
<% else %> | ||
<em>No recordings found.</em> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<%= render "spectator_sport/shared/rrweb_player" %> | ||
|
||
<script type="module"> | ||
new rrwebPlayer({ | ||
target: document.body, // customizable root element | ||
props: { | ||
events: <%== @session_window.events.order(:created_at).map(&:event_data).to_json %>, | ||
}, | ||
}); | ||
</script> |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
SpectatorSport::Engine.routes.draw do | ||
root to: "dashboards#index" | ||
resource :events, only: [:create] | ||
resource :events, only: [ :create ] | ||
resources :dashboards, only: [ :show, :destroy ] | ||
end |
19 changes: 17 additions & 2 deletions
19
db/migrate/20240923140845_create_spectator_sport_events.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 |
---|---|---|
@@ -1,11 +1,26 @@ | ||
class CreateSpectatorSportEvents < ActiveRecord::Migration[7.2] | ||
def change | ||
create_table :spectator_sport_sessions do |t| | ||
t.timestamps | ||
t.string :secure_id, null: false | ||
|
||
t.index [ :secure_id, :created_at ] | ||
end | ||
|
||
create_table :spectator_sport_session_windows do |t| | ||
t.timestamps | ||
t.references :session, null: false | ||
t.string :secure_id, null: false | ||
end | ||
|
||
create_table :spectator_sport_events do |t| | ||
t.timestamps | ||
t.string :page_id, null: false | ||
t.references :session, null: false | ||
t.references :session_window, null: true | ||
t.json :event_data, null: false # TODO: jsonb for postgres ??? | ||
|
||
t.index [:page_id, :created_at] | ||
t.index [ :session_id, :created_at ] | ||
t.index [ :session_window_id, :created_at ] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,22 @@ | ||
class ExamplesController < ApplicationController | ||
def index | ||
end | ||
|
||
def new | ||
@resource = FakeModel.new | ||
end | ||
|
||
def create | ||
resource_params = params.require(:resource).permit(:name, :message) | ||
@resource = FakeModel.new(resource_params) | ||
end | ||
|
||
class FakeModel | ||
include ActiveModel::Model | ||
attr_accessor :name, :message | ||
|
||
def self.model_name | ||
ActiveModel::Name.new(self, nil, "Resource") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<%= @resource.name %> | ||
<%= @resource.message %> |
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 |
---|---|---|
@@ -1 +1,4 @@ | ||
This is an example page. | ||
<p>This is an example page to demonstrate <strong>Spectator Sport</strong></p> | ||
<p>You are being recorded</p> | ||
|
||
<%= link_to "Pretend you are doing stuff", { action: :new } %> |
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,12 @@ | ||
<%= form_with model: @resource, url: { action: :create }, action: :post do |f| %> | ||
<%= f.label :name %> | ||
<%= f.text_field :name %> | ||
|
||
<br><br> | ||
<%= f.label :message %> | ||
<%= f.text_area :message %> | ||
|
||
<br><br> | ||
|
||
<%= f.submit "Submit" %> | ||
<% 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
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