diff --git a/app/channels/conference_channel.rb b/app/channels/conference_channel.rb new file mode 100644 index 0000000000000000000000000000000000000000..d967ed89f3fa02900914f8819712f9a8400ba12e --- /dev/null +++ b/app/channels/conference_channel.rb @@ -0,0 +1,10 @@ +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 diff --git a/app/controllers/assignments_controller.rb b/app/controllers/assignments_controller.rb index f7ab1eb03ffcb7a21545af8e555cfbd31a7f3ac2..14ad1bcb7b7461dad8e0648e5fc00e2c039c5e88 100644 --- a/app/controllers/assignments_controller.rb +++ b/app/controllers/assignments_controller.rb @@ -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 } diff --git a/app/javascript/channels/conference_channel.js b/app/javascript/channels/conference_channel.js new file mode 100644 index 0000000000000000000000000000000000000000..560c3f291a5d4ecd5b2d1b8526bec7cb6b6eb02d --- /dev/null +++ b/app/javascript/channels/conference_channel.js @@ -0,0 +1,16 @@ +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) + } +}); diff --git a/app/javascript/channels/index.js b/app/javascript/channels/index.js index 7b67b920150c440dea903703b0f836bbb029e1da..79c2648c3b2fc1fcc0fbe2b07c85ed7e312f5fa0 100644 --- a/app/javascript/channels/index.js +++ b/app/javascript/channels/index.js @@ -1,2 +1,3 @@ // Import all the channels to be used by Action Cable import "channels/session_channel" +import "channels/conference_channel" diff --git a/app/javascript/channels/session_channel.js b/app/javascript/channels/session_channel.js index 70416541775b681b4530cea1f736ac5257c9db52..32b8bd8387d32beac53d656dea69bb47f5435bee 100644 --- a/app/javascript/channels/session_channel.js +++ b/app/javascript/channels/session_channel.js @@ -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) } }); diff --git a/app/models/assignment.rb b/app/models/assignment.rb index 20d75f3035a88522c005abb1cd99a0f2aed2beca..20fabd09597b2916f934e6d9c7f86e004e2273ee 100644 --- a/app/models/assignment.rb +++ b/app/models/assignment.rb @@ -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 diff --git a/app/models/session.rb b/app/models/session.rb index 2c718d8e091b1aadc629584f7c9730d665e937b7..5506da89ccf11f2b194a1c0f54d18fd79210001f 100644 --- a/app/models/session.rb +++ b/app/models/session.rb @@ -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 diff --git a/app/views/conferences/show.html.erb b/app/views/conferences/show.html.erb index 054bb99a5b0c1dac0e99a48dd6c93e14adb5fbec..97ed2bb3fa68b739f6058fba4823dae88ac75a62 100644 --- a/app/views/conferences/show.html.erb +++ b/app/views/conferences/show.html.erb @@ -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 %> diff --git a/app/views/sessions/_session.html.erb b/app/views/sessions/_session.html.erb index 4a49a8a8c3b9a38e4689d0bcc3bcd397bfab4254..80a61d326131fd0578f99630869d58873350231a 100644 --- a/app/views/sessions/_session.html.erb +++ b/app/views/sessions/_session.html.erb @@ -1,7 +1,6 @@ <% 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" %> diff --git a/test/channels/conference_channel_test.rb b/test/channels/conference_channel_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..6500d215278633a5cc3516007a2b14c2f47c398a --- /dev/null +++ b/test/channels/conference_channel_test.rb @@ -0,0 +1,8 @@ +require "test_helper" + +class ConferenceChannelTest < ActionCable::Channel::TestCase + # test "subscribes" do + # subscribe + # assert subscription.confirmed? + # end +end