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

LIVE UPDATES BITCHES

parent c3607e3d
No related branches found
No related tags found
No related merge requests found
class SessionChannel < ApplicationCable::Channel
def subscribed
# stream_from "some_channel"
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
end
end
......@@ -14,7 +14,12 @@ class AssignmentsController < ApplicationController
params[:user_id] ||= params[:assignment][:user_id]
if params[:user_id].nil? or params[:user_id].empty?
flash.now[:alert] = 'Please select a user to assign.'
Turbo::StreamsChannel.broadcast_replace_later_to(
@session,
target: dom_id(@session),
partial: "sessions/session",
locals: { session: @session }
)
respond_to do |format|
format.turbo_stream { render turbo_stream: turbo_stream.replace(helpers.dom_id(@session), partial: "sessions/session", locals: { session: @session }), status: :unprocessable_entity }
format.html { redirect_to conference_session_path(@session.conference, @session), alert: 'Please select a user to assign.' }
......@@ -27,6 +32,12 @@ class AssignmentsController < ApplicationController
@assignment = Assignment.new(user: @user, session: @session)
if @assignment.save
Turbo::StreamsChannel.broadcast_replace_later_to(
@session,
target: helpers.dom_id(@session),
partial: "sessions/session",
locals: { session: @session }
)
flash.now[:success] = 'User assigned successfully.'
respond_to do |format|
format.turbo_stream { render turbo_stream: turbo_stream.replace(helpers.dom_id(@session), partial: "sessions/session", locals: { session: @session }) }
......@@ -46,6 +57,12 @@ class AssignmentsController < ApplicationController
@session = @assignment.session
if @assignment&.destroy
Turbo::StreamsChannel.broadcast_replace_later_to(
@session,
target: helpers.dom_id(@session),
partial: "sessions/session",
locals: { session: @session }
)
respond_to do |format|
format.turbo_stream { render turbo_stream: turbo_stream.replace(helpers.dom_id(@session), partial: "sessions/session", locals: { session: @session }) }
format.html { redirect_to conference_session_path(@session.conference, @session), notice: 'User removed successfully.' }
......
......@@ -15,4 +15,4 @@ document.addEventListener("turbo:load", function() {
flashMessage.parentNode.removeChild(flashMessage);
}, 5000);
});
});
\ No newline at end of file
});import "channels"
// Action Cable provides the framework to deal with WebSockets in Rails.
// You can generate new channels where WebSocket features live using the `bin/rails generate channel` command.
import { createConsumer } from "@rails/actioncable"
export default createConsumer()
// Import all the channels to be used by Action Cable
import "channels/session_channel"
import consumer from "channels/consumer"
consumer.subscriptions.create("SessionChannel", {
connected() {
// Called when the subscription is ready for use on the server
},
disconnected() {
// Called when the subscription has been terminated by the server
},
received(data) {
// Called when there's incoming data on the websocket for this channel
}
});
......@@ -6,13 +6,13 @@ class Session < ApplicationRecord
has_many :session_speakers, dependent: :destroy
has_many :speakers, through: :session_speakers
scope :scheduled, -> { where(status: 'scheduled') }
validates :ref_id, uniqueness: { scope: :conference_id }
after_update :notify_if_changed
after_update_commit -> { broadcast_replace_to "sessions" }
self.implicit_order_column = :starts_at
def to_param
......
<% unassigned_users = @users - session.assignments.collect(&:user) %>
<% unassigned_users = User.all - session.assignments.collect(&:user) %>
<%= turbo_stream_from session %>
<%= turbo_frame_tag dom_id(session) do %>
<div class="session shadow hover:shadow-lg overflow-scroll text-sm w-full !h-full min-h-full hover:!min-h-max <%= session.translators_needed? ? "translators-needed" : "no-translators-needed" %> <%= session.backup_needed? ? "backup-needed" : "no-backup-needed" %> <%= session.has_assignees? ? "has-assignees" : "no-assignees" %>">
<h4>
......
......@@ -5,3 +5,5 @@ pin "@hotwired/stimulus", to: "stimulus.min.js"
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
pin_all_from "app/javascript/controllers", under: "controllers"
pin "@hotwired/turbo-rails", to: "turbo.min.js"
pin "@rails/actioncable", to: "actioncable.esm.js"
pin_all_from "app/javascript/channels", under: "channels"
require "test_helper"
class SessionChannelTest < ActionCable::Channel::TestCase
# test "subscribes" do
# subscribe
# assert subscription.confirmed?
# end
end
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