forked from External/greenlight
		
	reduce can_upload post requests
This commit is contained in:
		@@ -38,16 +38,6 @@ class @Recordings
 | 
			
		||||
 | 
			
		||||
  constructor: ->
 | 
			
		||||
    recordingsObject = this
 | 
			
		||||
    canUpload = {}
 | 
			
		||||
 | 
			
		||||
    # Determine which recordings can be uploaded to Youtube.
 | 
			
		||||
    $.ajax({
 | 
			
		||||
      method: 'GET',
 | 
			
		||||
      async: false,
 | 
			
		||||
      url: recordingsObject.getRecordingsURL() + '/can_upload'
 | 
			
		||||
    }).success((res_data) ->
 | 
			
		||||
      canUpload = res_data
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    # configure the datatable for recordings
 | 
			
		||||
    this.table = $('#recordings').dataTable({
 | 
			
		||||
@@ -144,13 +134,6 @@ class @Recordings
 | 
			
		||||
              trigger.removeClass(classes.join(' '))
 | 
			
		||||
              trigger.addClass(cls)
 | 
			
		||||
 | 
			
		||||
              upload_btn = recordingActions.find('.cloud-upload')
 | 
			
		||||
 | 
			
		||||
              if canUpload[row.id]
 | 
			
		||||
                upload_btn.attr('data-popover-body', '.mail_youtube_popover')
 | 
			
		||||
              else
 | 
			
		||||
                upload_btn.attr('data-popover-body', '.mail_popover')
 | 
			
		||||
 | 
			
		||||
              return recordingActions.html()
 | 
			
		||||
            return data
 | 
			
		||||
        }
 | 
			
		||||
@@ -266,6 +249,7 @@ class @Recordings
 | 
			
		||||
    table_api = this.table.api()
 | 
			
		||||
    recordingsObject = this
 | 
			
		||||
    selectedUpload = null
 | 
			
		||||
    canUpload = false
 | 
			
		||||
 | 
			
		||||
    @getTable().on 'click', '.recording-update', (event) ->
 | 
			
		||||
      btn = $(this)
 | 
			
		||||
@@ -331,12 +315,14 @@ class @Recordings
 | 
			
		||||
          check = selectedUpload.find('.green-check')
 | 
			
		||||
          spinner = selectedUpload.find('.load-spinner')
 | 
			
		||||
          
 | 
			
		||||
          showAlert(I18n.successful_upload, 4000);
 | 
			
		||||
 | 
			
		||||
          spinner.hide()
 | 
			
		||||
          check.show()
 | 
			
		||||
          setTimeout ( ->
 | 
			
		||||
            cloud.show()
 | 
			
		||||
            check.hide()
 | 
			
		||||
          ), 4000
 | 
			
		||||
          ), 2500
 | 
			
		||||
      })
 | 
			
		||||
 | 
			
		||||
      selectedUpload.find('.cloud-blue').hide()
 | 
			
		||||
@@ -364,8 +350,28 @@ class @Recordings
 | 
			
		||||
      $('#video-title').attr('value', row.name)
 | 
			
		||||
 | 
			
		||||
    @getTable().on 'click', '.cloud-upload', (event) ->
 | 
			
		||||
      btn = $(this)
 | 
			
		||||
      row = table_api.row($(this).closest('tr')).data()
 | 
			
		||||
      id = row.id
 | 
			
		||||
 | 
			
		||||
      selectedUpload = $(this)
 | 
			
		||||
 | 
			
		||||
      # Determine if the recording can be uploaded to Youtube.
 | 
			
		||||
      $.ajax({
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        data: {'rec_id': id}
 | 
			
		||||
        url: recordingsObject.getRecordingsURL() + '/can_upload'
 | 
			
		||||
      }).success((res_data) ->
 | 
			
		||||
        canUpload = res_data['uploadable']
 | 
			
		||||
      )
 | 
			
		||||
 | 
			
		||||
      if canUpload
 | 
			
		||||
        $(this).attr('data-popover-body', '.mail_youtube_popover')
 | 
			
		||||
      else
 | 
			
		||||
        $(this).attr('data-popover-body', '.mail_popover')
 | 
			
		||||
 | 
			
		||||
      $(this).popover('show')
 | 
			
		||||
 | 
			
		||||
    @getTable().on 'draw.dt', (event) ->
 | 
			
		||||
      $('time[data-time-ago]').timeago();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -186,18 +186,13 @@ class BbbController < ApplicationController
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  # GET /rooms/:room_id/recordings/can_upload
 | 
			
		||||
  # POST /rooms/:room_id/recordings/can_upload
 | 
			
		||||
  def can_upload
 | 
			
		||||
    upload_data = {}
 | 
			
		||||
    bbb_get_recordings[:recordings].each{ |recording_data|
 | 
			
		||||
      next if recording_data[:recordID] == ""
 | 
			
		||||
    # The recording is uploadable if it contains webcam data and they are logged in thorugh Google.
 | 
			
		||||
      uploadable = Faraday.head(get_webcams_url(recording_data[:recordID])).status == 200 &&
 | 
			
		||||
    uploadable = Faraday.head(get_webcams_url(params[:rec_id])).status == 200 &&
 | 
			
		||||
                 Rails.application.config.omniauth_google &&
 | 
			
		||||
                 current_user.provider == 'google'
 | 
			
		||||
      upload_data[recording_data[:recordID]] = uploadable
 | 
			
		||||
    }
 | 
			
		||||
    render json: upload_data
 | 
			
		||||
    render json: {:uploadable => uploadable}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def get_webcams_url(recording_id)
 | 
			
		||||
 
 | 
			
		||||
@@ -67,6 +67,7 @@ en-US:
 | 
			
		||||
    recording_unlisted: Recording was unlisted
 | 
			
		||||
    recording_unpublished: Recording was unpublished
 | 
			
		||||
    share: Share
 | 
			
		||||
    successful_upload: Recording successfully uploaded to Youtube!
 | 
			
		||||
    unpublish_recording: Hide recording
 | 
			
		||||
    unlisted: Unlisted
 | 
			
		||||
    unpublished: No one
 | 
			
		||||
 
 | 
			
		||||
@@ -38,7 +38,7 @@ Rails.application.routes.draw do
 | 
			
		||||
    scope '/:room_id', :constraints => {:room_id => disallow_slash} do
 | 
			
		||||
      # recording routes for updating, deleting and viewing recordings
 | 
			
		||||
      get '/(:id)/recordings', to: 'bbb#recordings', defaults: {id: nil, format: 'json'}, :constraints => {:id => disallow_slash}
 | 
			
		||||
      get '/(:id)/recordings/can_upload', to: 'bbb#can_upload', defaults: {id: nil, format: 'json'}, :constraints => {:id => disallow_slash}
 | 
			
		||||
      post '/(:id)/recordings/can_upload', to: 'bbb#can_upload', defaults: {id: nil, format: 'json'}, :constraints => {:id => disallow_slash}
 | 
			
		||||
      post '/(:id)/recordings/:record_id', to: 'bbb#youtube_publish', defaults: {id: nil, format: 'json'}, :constraints => {:id => disallow_slash}
 | 
			
		||||
      patch '/(:id)/recordings/:record_id', to: 'bbb#update_recordings', defaults: {id: nil, format: 'json'}, :constraints => {:id => disallow_slash}
 | 
			
		||||
      delete '/(:id)/recordings/:record_id', to: 'bbb#delete_recordings', defaults: {id: nil, format: 'json'}, :constraints => {:id => disallow_slash}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user