Skip to content
Snippets Groups Projects
Commit 06591d00 authored by Teal's avatar Teal
Browse files

Add turbo/hotwire, fix routing

parent 8a8785ae
No related branches found
No related tags found
No related merge requests found
Showing
with 174 additions and 3 deletions
...@@ -61,3 +61,7 @@ gem "solid_queue" ...@@ -61,3 +61,7 @@ gem "solid_queue"
gem "httparty" gem "httparty"
gem "tailwindcss-rails", "~> 2.6" gem "tailwindcss-rails", "~> 2.6"
gem "hotwire-rails", "~> 0.1.3"
gem "importmap-rails", "~> 2.0"
...@@ -108,11 +108,19 @@ GEM ...@@ -108,11 +108,19 @@ GEM
raabro (~> 1.4) raabro (~> 1.4)
globalid (1.2.1) globalid (1.2.1)
activesupport (>= 6.1) activesupport (>= 6.1)
hotwire-rails (0.1.3)
rails (>= 6.0.0)
stimulus-rails
turbo-rails
httparty (0.21.0) httparty (0.21.0)
mini_mime (>= 1.0.0) mini_mime (>= 1.0.0)
multi_xml (>= 0.5.2) multi_xml (>= 0.5.2)
i18n (1.14.4) i18n (1.14.4)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
importmap-rails (2.0.1)
actionpack (>= 6.0.0)
activesupport (>= 6.0.0)
railties (>= 6.0.0)
io-console (0.7.2) io-console (0.7.2)
irb (1.12.0) irb (1.12.0)
rdoc rdoc
...@@ -229,6 +237,8 @@ GEM ...@@ -229,6 +237,8 @@ GEM
sqlite3 (1.7.3-aarch64-linux) sqlite3 (1.7.3-aarch64-linux)
sqlite3 (1.7.3-arm64-darwin) sqlite3 (1.7.3-arm64-darwin)
sqlite3 (1.7.3-x86_64-linux) sqlite3 (1.7.3-x86_64-linux)
stimulus-rails (1.3.3)
railties (>= 6.0.0)
stringio (3.1.0) stringio (3.1.0)
strscan (3.1.0) strscan (3.1.0)
tailwindcss-rails (2.6.0-aarch64-linux) tailwindcss-rails (2.6.0-aarch64-linux)
...@@ -239,6 +249,10 @@ GEM ...@@ -239,6 +249,10 @@ GEM
railties (>= 7.0.0) railties (>= 7.0.0)
thor (1.3.1) thor (1.3.1)
timeout (0.4.1) timeout (0.4.1)
turbo-rails (2.0.5)
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
railties (>= 6.0.0)
tzinfo (2.0.6) tzinfo (2.0.6)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
web-console (4.2.1) web-console (4.2.1)
...@@ -264,7 +278,9 @@ DEPENDENCIES ...@@ -264,7 +278,9 @@ DEPENDENCIES
bootsnap bootsnap
capybara capybara
debug debug
hotwire-rails (~> 0.1.3)
httparty httparty
importmap-rails (~> 2.0)
jbuilder jbuilder
puma (>= 5.0) puma (>= 5.0)
rails (~> 7.1.2) rails (~> 7.1.2)
......
//= link_tree ../images //= link_tree ../images
//= link_directory ../stylesheets .css //= link_directory ../stylesheets .css
//= link_tree ../builds //= link_tree ../builds
//= link_tree ../../javascript .js
//= link_tree ../../../vendor/javascript .js
class AssignmentsController < ApplicationController
def index
@assignments = Assignment.all
if params[:user_id]
@assignments = @assignments.where(user_id: params[:user_id])
end
end
end
...@@ -7,5 +7,6 @@ class ConferencesController < ApplicationController ...@@ -7,5 +7,6 @@ class ConferencesController < ApplicationController
@conference = Conference.find_by(slug: params[:slug]) @conference = Conference.find_by(slug: params[:slug])
@sessions = @conference.sessions.where.not(starts_at: nil).includes(:stage).order(:starts_at) @sessions = @conference.sessions.where.not(starts_at: nil).includes(:stage).order(:starts_at)
@sessions_by_date = @sessions.group_by{ |x| x.starts_at.to_date } @sessions_by_date = @sessions.group_by{ |x| x.starts_at.to_date }
@users = User.all
end end
end end
...@@ -16,4 +16,44 @@ class SessionsController < ApplicationController ...@@ -16,4 +16,44 @@ class SessionsController < ApplicationController
# Further filtering options can be added here # Further filtering options can be added here
end end
def show
@conference = Conference.find_by(slug: params[:slug])
@session = Session.includes(:stage).find_by(ref_id: params[:ref_id])
@users = User.all
end
def assign_user
@session = Session.find_by(ref_id: params[:ref_id])
@conference = Conference.find_by(slug: params[:slug])
@user = User.find(params[:user_id])
@assignment = @session.assignments.new(session: @session, user: @user)
@users = User.all
if @assignment.save
flash.now[:success] = 'User assigned successfully.'
respond_to do |format|
# format.turbo_stream
format.html { redirect_to conference_session_path(@session.conference, @session), success: 'User assigned successfully.' }
end
else
flash.now[:alert] = 'Failed to assign user.'
respond_to do |format|
# format.turbo_stream { render :show, status: :unprocessable_entity }
format.html { render :show, status: :unprocessable_entity, alert: 'Failed to assign user.' }
end
end
end
def unassign_user
@session = Session.find_by(ref_id: params[:ref_id])
@user = User.find(params[:user_id])
@assignment = Assignment.find_by(session: @session, user: @user)
if @assignment&.destroy
redirect_to conference_session_path(@session.conference, @session), notice: 'User removed successfully.'
else
redirect_to conference_session_path(@session.conference, @session), alert: 'Failed to remove user.'
end
end
end end
module AssignmentsHelper
end
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
import "controllers"
import "@hotwired/turbo-rails"
import { Application } from "@hotwired/stimulus"
const application = Application.start()
// Configure Stimulus development experience
application.debug = false
window.Stimulus = application
export { application }
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
connect() {
this.element.textContent = "Hello World!"
}
}
// Import and register all your controllers from the importmap under controllers/*
import { application } from "controllers/application"
// Eager load all controllers defined in the import map under controllers/**/*_controller
import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
eagerLoadControllersFrom("controllers", application)
// Lazy load controllers as they appear in the DOM (remember not to preload controllers in import map!)
// import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading"
// lazyLoadControllersFrom("controllers", application)
class Assignment < ApplicationRecord class Assignment < ApplicationRecord
belongs_to :user belongs_to :user
belongs_to :session belongs_to :session
validates :user_id, uniqueness: { scope: :session_id, message: "has already been assigned to this session" }
end end
...@@ -6,4 +6,8 @@ class Conference < ApplicationRecord ...@@ -6,4 +6,8 @@ class Conference < ApplicationRecord
def days def days
(starts_at.to_date..ends_at.to_date) (starts_at.to_date..ends_at.to_date)
end end
def to_param
slug
end
end end
...@@ -5,4 +5,8 @@ class Session < ApplicationRecord ...@@ -5,4 +5,8 @@ class Session < ApplicationRecord
has_many :users, through: :assignments has_many :users, through: :assignments
validates :ref_id, uniqueness: { scope: :conference_id } validates :ref_id, uniqueness: { scope: :conference_id }
def to_param
ref_id
end
end end
<div>
<% @assignments.group_by(&:user).each do |user, assignments| %>
<h4><%= user.name %></h4>
<ul>
<% assignments.each do |assignment| %>
<li><%= link_to assignment.session.title, assignment.session %></li>
<% end %>
</ul>
<% end %>
</div>
\ No newline at end of file
<div>
<h1 class="font-bold text-4xl">Assignments#show</h1>
<p>Find me in app/views/assignments/show.html.erb</p>
</div>
...@@ -52,10 +52,15 @@ current_time = @sessions_by_date[@conference.days.first].first.starts_at.advance ...@@ -52,10 +52,15 @@ current_time = @sessions_by_date[@conference.days.first].first.starts_at.advance
<h4><%= stage.name %></h4> <h4><%= stage.name %></h4>
<div class="stage-sessions"> <div class="stage-sessions">
<% sessions.each do |session| %> <% sessions.each do |session| %>
<div class="session" style="position: absolute; top: <%= (session.starts_at - timeline_starts_at) / 3600.0 * pixels_per_hour %>px; height: <%= (session.ends_at - session.starts_at) / 3600.0 * pixels_per_hour%>px;"> <div class="session" style="position: absolute; top: <%= (session.starts_at - timeline_starts_at) / 3600.0 * pixels_per_hour %>px; height: <%= (session.ends_at - session.starts_at) / 3600.0 * pixels_per_hour%>px; overflow: scroll;">
<h4><%= session.title %></h4> <h4><%= link_to session.title, [@conference, session] %></h4>
<p class="session-time"><%= session.starts_at.strftime('%H:%M') %> - <%= session.ends_at.strftime('%H:%M') %></p> <p class="session-time"><%= session.starts_at.strftime('%H:%M') %> - <%= session.ends_at.strftime('%H:%M') %></p>
<div class="session-desc"><%= session.description.html_safe %></div> <%#<div class="session-desc"><%= session.description.html_safe %><%#/div>%>
<%= form_with url: assign_user_session_path(@conference, session), method: :post, local: true do |f| %>
<%= f.label :user_id, "Assign User" %>
<%= f.select :user_id, options_from_collection_for_select(@users, :id, :name) %>
<%= f.submit "Assign" %>
<% end %>
</div> </div>
<% end %> <% end %>
</div> </div>
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
<%= stylesheet_link_tag "tailwind", "inter-font", "data-turbo-track": "reload" %> <%= stylesheet_link_tag "tailwind", "inter-font", "data-turbo-track": "reload" %>
<%= stylesheet_link_tag "application" %> <%= stylesheet_link_tag "application" %>
<%= javascript_importmap_tags %>
</head> </head>
<body> <body>
......
<div>
<h6><%= @session.conference.name %></h6>
<h1><%= @session.title %></h1>
<h2><%= @session.language %> <%= @session.is_interpreted ? "(live interpretation)" : "" %></h2>
<h2><%= @session.starts_at.strftime("%Y-%m-%d") %> <%= @session.starts_at.strftime("%H:%M") %> &ndash; <%= @session.ends_at.strftime("%H:%M") %></h2>
<h2><%= @session.stage.name %>&middot; <%= @session.session_format %> &middot; <%= @session.track %></h2>
<p><%= @session.description.html_safe %></p>
<h3>Assigned Users</h3>
<ul>
<% @session.users.each do |user| %>
<li>
<%= user.name %>
<%= link_to '[Remove]', unassign_user_session_path([@session.conference, @session], user_id: user.id), data: { turbo_method: :delete, confirm: 'Are you sure?' } %>
</li>
<% end %>
</ul>
<%= form_with url: assign_user_session_path([@session.conference, @session]), method: :post, local: true do |f| %>
<%= f.label :user_id, "Assign User" %>
<%= f.select :user_id, options_from_collection_for_select(@users, :id, :name) %>
<%= f.submit "Assign" %>
<div id="flash">
<% flash.each do |key, value| %>
<div class="alert alert-<%= key %>"><%= value %></div>
<% end %>
</div>
<% if @assignment&.errors&.any? %>
<div class="alert alert-danger">
<%= @assignment.errors.full_messages.join(", ") %>
</div>
<% end %>
<% end %>
</div>
\ No newline at end of file
#!/usr/bin/env ruby
require_relative "../config/application"
require "importmap/commands"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment