Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initiate_wait_for_task - support :flash => true to flash while waiting #4732

Merged
merged 1 commit into from
Oct 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/controllers/application_controller/wait_for_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ def wait_for_task
end
end

def browser_refresh_task(task_id)
def browser_refresh_task(task_id, should_flash = false)
session[:async][:interval] += 250 if session[:async][:interval] < 5000 # Slowly move up to 5 second retries
render :update do |page|
page << javascript_prologue
ajax_call = remote_function(:url => {:action => 'wait_for_task', :task_id => task_id})
page << "setTimeout(\"#{ajax_call}\", #{session[:async][:interval]});"
page.replace("flash_msg_div", :partial => "layouts/flash_msg") if should_flash
end
end
private :browser_refresh_task
Expand All @@ -38,6 +39,7 @@ def browser_refresh_task(task_id)
# :task_id => id of task to wait for
# :action => 'action_to_call' -- action to be called when the task finishes
# :rx_action => 'method_to_call' -- a method to create a RxJs message
# :flash => true|false -- output queued flash messages *while waiting*
#
def initiate_wait_for_task(options = {})
task_id = options[:task_id]
Expand All @@ -58,7 +60,7 @@ def initiate_wait_for_task(options = {})
session[:async][:params][:rx_action] = options[:rx_action]
end

browser_refresh_task(task_id)
browser_refresh_task(task_id, !!options[:flash])
end
private :initiate_wait_for_task

Expand Down