forked from External/greenlight
		
	add room functionality
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -1,13 +1,13 @@
 | 
			
		||||
<div class="room-section pb-1">
 | 
			
		||||
  <div class="container">
 | 
			
		||||
    <div class="row pt-8">
 | 
			
		||||
    <div class="row pt-9">
 | 
			
		||||
      <div class="col-lg-9 col-sm-12">
 | 
			
		||||
        <h1 id="user-text" class="display-3 text-left text-primary mb-3"><%= @room.name %>
 | 
			
		||||
          <% if current_user.main_room == @room %>
 | 
			
		||||
            <i class="fas fa-home align-top" style="font-size: 22px;"></i>
 | 
			
		||||
          <% end %>
 | 
			
		||||
        </h1>
 | 
			
		||||
        <h4 class="text-left text-primary mb-6">0 Sessions | 0 Recordings</h4>
 | 
			
		||||
        <h4 class="text-left text-primary mb-6"><%= @room.sessions %> Sessions | <%= @recordings.length %> Recordings</h4>
 | 
			
		||||
        <label class="form-label text-primary">Invite Participants</label>
 | 
			
		||||
        <form class="form-inline">
 | 
			
		||||
          <div class="input-icon" style="width: 45%;">
 | 
			
		||||
@@ -43,7 +43,7 @@
 | 
			
		||||
  </div>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<%= render "shared/sessions", recordings: @room.recordings %>
 | 
			
		||||
<%= render "shared/sessions", recordings: @recordings %>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
var invite_url;
 | 
			
		||||
 
 | 
			
		||||
@@ -26,53 +26,8 @@
 | 
			
		||||
                </td>
 | 
			
		||||
              </tr>
 | 
			
		||||
            <% else %>
 | 
			
		||||
              <% 3.times do %>
 | 
			
		||||
                <tr>
 | 
			
		||||
                  <td>
 | 
			
		||||
                    <div>Example Meeting</div>
 | 
			
		||||
                    <div class="small text-muted">
 | 
			
		||||
                      June 21, 2017 <i>(about 3 hours ago)</i>
 | 
			
		||||
                    </div>
 | 
			
		||||
                  </td>
 | 
			
		||||
                  <td>
 | 
			
		||||
                    <img class="thumbnail px-2" src="http://test-install.blindsidenetworks.com/presentation/b622495d927cd99e9898b0601c2b18a5424a0627-1527259102285/presentation/d2d9a672040fbde2a47a10bf6c37b6a4b5ae187f-1527259102298/thumbnails/thumb-1.png">
 | 
			
		||||
                    <img class="thumbnail px-2" src="http://test-install.blindsidenetworks.com/presentation/b622495d927cd99e9898b0601c2b18a5424a0627-1527259102285/presentation/d2d9a672040fbde2a47a10bf6c37b6a4b5ae187f-1527259102298/thumbnails/thumb-1.png">
 | 
			
		||||
                    <img class="thumbnail px-2" src="http://test-install.blindsidenetworks.com/presentation/b622495d927cd99e9898b0601c2b18a5424a0627-1527259102285/presentation/d2d9a672040fbde2a47a10bf6c37b6a4b5ae187f-1527259102298/thumbnails/thumb-1.png">
 | 
			
		||||
                  </td>
 | 
			
		||||
                  <td class="text-left">
 | 
			
		||||
                    <div class="small text-muted text-uppercase">
 | 
			
		||||
                      Length
 | 
			
		||||
                    </div>
 | 
			
		||||
                    1 hr
 | 
			
		||||
                  </td>
 | 
			
		||||
                  <td class="text-left">
 | 
			
		||||
                    <div class="small text-muted text-uppercase">
 | 
			
		||||
                      Users
 | 
			
		||||
                    </div>
 | 
			
		||||
                    4
 | 
			
		||||
                  </td>
 | 
			
		||||
                  <td class="text-left">
 | 
			
		||||
                    <div class="small text-muted text-uppercase">
 | 
			
		||||
                      Visibility
 | 
			
		||||
                    </div>
 | 
			
		||||
                    Unlisted
 | 
			
		||||
                  </td>
 | 
			
		||||
                  <td>
 | 
			
		||||
                    <a href="#" class="btn btn-secondary">Presentation</a>
 | 
			
		||||
                    <a href="#" class="btn btn-secondary">Podcast</a>
 | 
			
		||||
                  </td>
 | 
			
		||||
                  <td class="text-center">
 | 
			
		||||
                    <div class="item-action dropdown">
 | 
			
		||||
                      <a href="javascript:void(0)" data-toggle="dropdown" class="icon"><i class="fe fe-more-vertical"></i></a>
 | 
			
		||||
                      <div class="dropdown-menu dropdown-menu-right">
 | 
			
		||||
                        <a href="javascript:void(0)" class="dropdown-item"><i class="dropdown-icon far fa-eye"></i> Change Visibility</a>
 | 
			
		||||
                        <a href="javascript:void(0)" class="dropdown-item"><i class="dropdown-icon far fa-envelope"></i> Email Recording</a>
 | 
			
		||||
                        <div class="dropdown-divider"></div>
 | 
			
		||||
                        <a href="javascript:void(0)" class="dropdown-item"><i class="dropdown-icon far fa-trash-alt"></i> Delete</a>
 | 
			
		||||
                      </div>
 | 
			
		||||
                    </div>
 | 
			
		||||
                  </td>
 | 
			
		||||
                </tr>
 | 
			
		||||
              <% recordings.each do |recording| %>
 | 
			
		||||
                <%= render "shared/components/recording_row", recording: recording %>
 | 
			
		||||
              <% end %>
 | 
			
		||||
            <% end %>
 | 
			
		||||
            </tbody>
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										52
									
								
								app/views/shared/components/_recording_row.html.erb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								app/views/shared/components/_recording_row.html.erb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,52 @@
 | 
			
		||||
<tr>
 | 
			
		||||
  <td>
 | 
			
		||||
    <div><%= recording[:name] %></div>
 | 
			
		||||
    <div class="small text-muted">
 | 
			
		||||
      Recorded on <%= recording_date(recording[:startTime]) %>
 | 
			
		||||
    </div>
 | 
			
		||||
  </td>
 | 
			
		||||
  <td>
 | 
			
		||||
    <% p = recording[:playbacks].find do |p| p[:type] == "presentation" end %>
 | 
			
		||||
    <% if p %>
 | 
			
		||||
      <% p[:preview][:images][:image].each do |img| %>
 | 
			
		||||
        <%= image_tag(img[:content], class: "thumbnail px-2") %>
 | 
			
		||||
      <% end %>
 | 
			
		||||
    <% end %>
 | 
			
		||||
  </td>
 | 
			
		||||
  <td class="text-left">
 | 
			
		||||
    <div class="small text-muted text-uppercase">
 | 
			
		||||
      Length
 | 
			
		||||
    </div>
 | 
			
		||||
    <%= recording_length(recording[:startTime], recording[:endTime]) %>
 | 
			
		||||
  </td>
 | 
			
		||||
  <td class="text-left">
 | 
			
		||||
    <div class="small text-muted text-uppercase">
 | 
			
		||||
      Users
 | 
			
		||||
    </div>
 | 
			
		||||
    <%= recording[:participants] %>
 | 
			
		||||
  </td>
 | 
			
		||||
  <td class="text-left">
 | 
			
		||||
    <div class="small text-muted text-uppercase">
 | 
			
		||||
      Visibility
 | 
			
		||||
    </div>
 | 
			
		||||
    <%= recording[:state].capitalize %>
 | 
			
		||||
  </td>
 | 
			
		||||
  <td>
 | 
			
		||||
    <% recording[:playbacks].each do |p| %>
 | 
			
		||||
      <%= link_to p[:type].capitalize, p[:url], class: "btn btn-secondary", target: "_blank" %>
 | 
			
		||||
    <% end %>
 | 
			
		||||
  </td>
 | 
			
		||||
  <td class="text-center">
 | 
			
		||||
    <div class="item-action dropdown">
 | 
			
		||||
      <a href="javascript:void(0)" data-toggle="dropdown" class="icon"><i class="fe fe-more-vertical"></i></a>
 | 
			
		||||
      <div class="dropdown-menu dropdown-menu-right">
 | 
			
		||||
        <a href="javascript:void(0)" class="dropdown-item"><i class="dropdown-icon far fa-eye"></i> Change Visibility</a>
 | 
			
		||||
        <a href="javascript:void(0)" class="dropdown-item"><i class="dropdown-icon far fa-envelope"></i> Email Recording</a>
 | 
			
		||||
        <div class="dropdown-divider"></div>
 | 
			
		||||
        <%= button_to delete_recording_path(@room, record_id: recording[:recordID]), method: :delete, class: "dropdown-item" do %>
 | 
			
		||||
          <i class="dropdown-icon far fa-trash-alt"></i> Delete
 | 
			
		||||
        <% end %>
 | 
			
		||||
      </div>
 | 
			
		||||
    </div>
 | 
			
		||||
  </td>
 | 
			
		||||
</tr>
 | 
			
		||||
@@ -14,21 +14,21 @@
 | 
			
		||||
        <td>
 | 
			
		||||
          <div><%= room.name %></div>
 | 
			
		||||
          <div class="small text-muted">
 | 
			
		||||
            <i>Last Session on <%= room.created_at.strftime("%B #{room.created_at.day.ordinalize}, %Y.") %></i>
 | 
			
		||||
            <i>Last Session on <%= recording_date(room.created_at) %></i>
 | 
			
		||||
          </div>
 | 
			
		||||
        </td>
 | 
			
		||||
        <td class="text-right">
 | 
			
		||||
          <div class="item-action dropdown">
 | 
			
		||||
            <a href="javascript:void(0)" data-toggle="dropdown" class="icon"><i class="fe fe-more-vertical"></i></a>
 | 
			
		||||
            <div class="dropdown-menu dropdown-menu-right">
 | 
			
		||||
              <%= button_to root_path, class: "dropdown-item" do %>
 | 
			
		||||
                <i class="dropdown-icon fas fa-home"></i> Make Home Room
 | 
			
		||||
              <% end %>
 | 
			
		||||
              <% if room != current_user.main_room %>
 | 
			
		||||
                <%= button_to room, method: :delete, data: { confirm: 'Are you sure?' }, class: "dropdown-item" do %>
 | 
			
		||||
                  <i class="dropdown-icon far fa-trash-alt"></i> Delete
 | 
			
		||||
                <%= button_to make_home_path(room), class: "dropdown-item" do %>
 | 
			
		||||
                  <i class="dropdown-icon fas fa-home"></i> Make Home Room
 | 
			
		||||
                <% end %>
 | 
			
		||||
              <% end %>
 | 
			
		||||
              <%= button_to room, method: :delete, data: { confirm: 'Are you sure?' }, class: "dropdown-item" do %>
 | 
			
		||||
                <i class="dropdown-icon far fa-trash-alt"></i> Delete
 | 
			
		||||
              <% end %>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
        </td>
 | 
			
		||||
 
 | 
			
		||||
@@ -10,6 +10,13 @@ Rails.application.routes.draw do
 | 
			
		||||
    match '/wait', to: 'rooms#wait', as: :wait_room, via: [:get, :post]
 | 
			
		||||
    get '/logout', to: 'rooms#logout', as: :logout_room
 | 
			
		||||
    get '/sessions', to: 'rooms#sessions', as: :sessions
 | 
			
		||||
    post '/home', to: 'rooms#home', as: :make_home
 | 
			
		||||
    
 | 
			
		||||
    # Mange recordings.
 | 
			
		||||
    scope '/:record_id' do
 | 
			
		||||
      post '/', to: 'rooms#update_recording', as: :update_recording
 | 
			
		||||
      delete '/', to: 'rooms#delete_recording', as: :delete_recording
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  # Signup route.
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,7 @@ class CreateRooms < ActiveRecord::Migration[5.0]
 | 
			
		||||
      t.string :uid, index: true
 | 
			
		||||
      t.string :bbb_id, index: true
 | 
			
		||||
      t.string :icon, index: true
 | 
			
		||||
      t.integer :sessions, index: true
 | 
			
		||||
      t.integer :sessions, index: true, default: 0
 | 
			
		||||
 | 
			
		||||
      t.timestamps
 | 
			
		||||
    end
 | 
			
		||||
 
 | 
			
		||||
@@ -18,11 +18,13 @@ ActiveRecord::Schema.define(version: 20180504131705) do
 | 
			
		||||
    t.string   "uid"
 | 
			
		||||
    t.string   "bbb_id"
 | 
			
		||||
    t.string   "icon"
 | 
			
		||||
    t.datetime "created_at", null: false
 | 
			
		||||
    t.datetime "updated_at", null: false
 | 
			
		||||
    t.integer  "sessions",   default: 0
 | 
			
		||||
    t.datetime "created_at",             null: false
 | 
			
		||||
    t.datetime "updated_at",             null: false
 | 
			
		||||
    t.index ["bbb_id"], name: "index_rooms_on_bbb_id"
 | 
			
		||||
    t.index ["icon"], name: "index_rooms_on_icon"
 | 
			
		||||
    t.index ["name"], name: "index_rooms_on_name"
 | 
			
		||||
    t.index ["sessions"], name: "index_rooms_on_sessions"
 | 
			
		||||
    t.index ["uid"], name: "index_rooms_on_uid"
 | 
			
		||||
    t.index ["user_id"], name: "index_rooms_on_user_id"
 | 
			
		||||
  end
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user