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

broadcast?

parent eaba8b1c
No related branches found
No related tags found
No related merge requests found
class ConferenceChannel < ApplicationCable::Channel
def subscribed
# conference = Conference.find(params[:id])
# stream_for conference
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
end
end
......@@ -14,26 +14,23 @@ 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.' }
end
return
end
@session = Session.find_by(ref_id: params[:session_ref_id])
@conference = Conference.find_by(slug: params[:conference_slug])
@user = User.find(params[:user_id])
@assignment = Assignment.new(user: @user, session: @session)
if @assignment.save
Turbo::StreamsChannel.broadcast_replace_later_to(
@session,
Rails.logger.debug("Saved assignment #{@assignment.inspect}")
@session = Session.find_by(ref_id: params[:session_ref_id])
Turbo::StreamsChannel.broadcast_replace_to(
@session.conference,
target: helpers.dom_id(@session),
partial: "sessions/session",
locals: { session: @session }
......@@ -57,8 +54,10 @@ class AssignmentsController < ApplicationController
@session = @assignment.session
if @assignment&.destroy
@session = @assignment.session
Rails.logger.debug("destroyed assignment")
Turbo::StreamsChannel.broadcast_replace_later_to(
@session,
@session.conference,
target: helpers.dom_id(@session),
partial: "sessions/session",
locals: { session: @session }
......
import consumer from "channels/consumer"
consumer.subscriptions.create("ConferenceChannel", {
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
console.log("received data on ConferenceChannel: ", data)
}
});
// Import all the channels to be used by Action Cable
import "channels/session_channel"
import "channels/conference_channel"
......@@ -11,5 +11,6 @@ consumer.subscriptions.create("SessionChannel", {
received(data) {
// Called when there's incoming data on the websocket for this channel
console.log("received data on SessionChannel: ", data)
}
});
......@@ -9,6 +9,14 @@ class Assignment < ApplicationRecord
after_create_commit :notify_assignment_created
after_destroy_commit :notify_assignment_destroyed
after_create_commit -> {
Rails.logger.debug('Created assignment, broadcasting')
broadcast_replace_to "sessions",
target: session,
partial: "sessions/session",
locals: { session: session }
}
private
def no_overlapping_assignments
......
......@@ -7,12 +7,18 @@ class Session < ApplicationRecord
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" }
after_update_commit -> {
Rails.logger.debug("session update commit")
broadcast_replace_to "sessions",
target: helpers.dom_id(@session),
partial: "sessions/session",
locals: { session: @session }
}
self.implicit_order_column = :starts_at
def to_param
......@@ -38,11 +44,11 @@ class Session < ApplicationRecord
def backup_needed?
return false
is_interpreted && assignments.length < 4
# is_interpreted && assignments.length < 4
end
def has_assignees?
assignments.length > 0
def assignees?
assignments.length.positive?
end
private
......
......@@ -7,6 +7,7 @@ current_time = Time.zone.now.in_time_zone(@conference.time_zone)
# current_time = Time.parse(@conference.days.first.strftime("%Y-%m-%d 11:00"))
#current_time = @sessions_by_date[@conference.days.first].first.starts_at.advance(minutes: 5)
%>
<%= turbo_frame_tag dom_id(@conference) do %>
<div>
<h1 class="text-2xl font-bold my-2"><%= @conference.name %></h1>
<p class="text-xs mb-6">
......@@ -133,4 +134,5 @@ current_time = Time.zone.now.in_time_zone(@conference.time_zone)
</div>
</div>
<% end %>
</div>
\ No newline at end of file
</div>
<% end %>
<% 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" %>">
<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.assignees? ? "has-assignees" : "no-assignees" %>">
<h4>
<small class="text-2xs uppercase font-light bg-black/10 rounded-sm p-1 mr-1 lang-<%= session.language %>"><%= session.language %></small>
<%= link_to session.title, session.url, target: "_top" %>
......
require "test_helper"
class ConferenceChannelTest < 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