-
Notifications
You must be signed in to change notification settings - Fork 0
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
Updates oven page automatically when cookie is ready #6
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
document.addEventListener('DOMContentLoaded', () => { | ||
let cookieStatus, eventSource; | ||
|
||
cookieStatus = document.querySelector('.cookie-status'); | ||
eventSource = new EventSource('/ovens/2/progress'); | ||
|
||
eventSource.addEventListener('message', event => { | ||
cookieStatus.innerHTML = event.data; | ||
eventSource.close(); | ||
}); | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
class OvensController < ApplicationController | ||
include ActionController::Live | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This causes RSpec to stop working for some reason I don't fully understand There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See issue #9 for more information |
||
SSE_RETRY_TIME = 5000.freeze | ||
|
||
before_action :authenticate_user! | ||
|
||
def index | ||
|
@@ -16,4 +19,19 @@ def empty | |
end | ||
redirect_to @oven, alert: 'Oven emptied!' | ||
end | ||
|
||
def progress | ||
@oven = Oven.find(params[:id]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security issue here: A User is able to query the Cookie status in other Users Ovens |
||
sse = SSE.new(response.stream) | ||
response.headers['Content-Type'] = 'text/event-stream' | ||
|
||
return sse.close if @oven.cookie.ready? == false | ||
|
||
template = render_to_string(partial: 'cookie.ready', formats: [:html]) | ||
sse.write(template, retry: SSE_RETRY_TIME) | ||
rescue IOError | ||
Rails.Logger.error(IOError) | ||
ensure | ||
sse.close if sse.present? | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
(Your Cookie is Ready) | ||
= button_to "Retrieve Cookie", empty_oven_path, class: 'button tiny' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
resources :ovens do | ||
resource :cookies | ||
member do | ||
get :progress | ||
post :empty | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoded Oven ID