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