diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb index 3dd031f1..8d3c5b24 100644 --- a/app/controllers/rooms_controller.rb +++ b/app/controllers/rooms_controller.rb @@ -48,6 +48,9 @@ class RoomsController < ApplicationController # redirect_to wait_room_path(@room) #end end + + # NOTE: TEST TO MAKE SURE THIS DOESN'T FIRE WHEN THEY ARE NOT OWNER AND REDIRECTED. + @recordings = @room.recordings end # POST /r/:room_uid @@ -62,7 +65,17 @@ class RoomsController < ApplicationController # DELETE /r/:room_uid def destroy - @room.destroy unless @room == current_user.main_room + # Only delete a room if there is another to fallback too. + if current_user.rooms.length > 1 + + # Assign a new random main_room if it's the main room. + if @room == current_user.main_room + current_user.main_room = (current_user.rooms - [@room]).sample + current_user.save + end + + @room.destroy + end redirect_to current_user.main_room end @@ -73,6 +86,9 @@ class RoomsController < ApplicationController opts = default_meeting_options opts[:user_is_moderator] = true + @room.sessions += 1 + @room.save + redirect_to @room.join_path(current_user, opts) end @@ -104,6 +120,43 @@ class RoomsController < ApplicationController end + # POST /r/:room_uid/home + def home + current_user.main_room = @room + current_user.save + + redirect_to @room + end + + # DELETE /r/:room_uid/:record_id + def delete_recording + @room.delete_recording(params[:record_id]) + + redirect_to current_user.main_room + end + + # Helper for converting BigBlueButton dates into the desired format. + def recording_date(date) + date.strftime("%B #{date.day.ordinalize}, %Y.") + end + helper_method :recording_date + + # Helper for converting BigBlueButton dates into a nice length string. + def recording_length(start_time, end_time) + len = ((end_time - start_time) * 24 * 60).to_i + + if len > 60 + "#{len / 60} hrs" + else + if len == 0 + "< 1 min" + else + "#{len} min" + end + end + end + helper_method :recording_length + private def room_params diff --git a/app/models/room.rb b/app/models/room.rb index 90adb05c..e4c8c6c8 100644 --- a/app/models/room.rb +++ b/app/models/room.rb @@ -94,9 +94,37 @@ class Room < ApplicationRecord # Fetches all recordings for a meeting. def recordings res = bbb.get_recordings(meetingID: bbb_id) + + # Format playbacks in a more pleasant way. + res[:recordings].each do |r| + next if r.key?(:error) + r[:playbacks] = if !r[:playback] || !r[:playback][:format] + [] + elsif r[:playback][:format].is_a?(Array) + r[:playback][:format] + else + [r[:playback][:format]] + end + + r.delete(:playback) + end + res[:recordings] end + # Deletes a recording from a room. + def delete_recording(record_id) + res = bbb.delete_recordings(record_id) + + if res[:returncode] + # Handle successful deletion. + + else + # Handle unsuccessful deletion. + + end + end + private def bbb_endpoint diff --git a/app/views/rooms/show.html.erb b/app/views/rooms/show.html.erb index b9182808..4c45e455 100644 --- a/app/views/rooms/show.html.erb +++ b/app/views/rooms/show.html.erb @@ -1,13 +1,13 @@
-
+

<%= @room.name %> <% if current_user.main_room == @room %> <% end %>

-

0 Sessions | 0 Recordings

+

<%= @room.sessions %> Sessions | <%= @recordings.length %> Recordings

@@ -43,7 +43,7 @@
-<%= render "shared/sessions", recordings: @room.recordings %> +<%= render "shared/sessions", recordings: @recordings %>