-
Notifications
You must be signed in to change notification settings - Fork 4
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
[SPIKE] Replace Poxa with Action Cable #3105
Draft
sammo1235
wants to merge
5
commits into
main
Choose a base branch
from
replace-poxa-with-action-cable-spike
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d8f44c1
WIP collaborator channels, stop editing unless editor, and switching …
sammo1235 d63f78a
implement per tab lock controls
sammo1235 f039f37
remove unused file
sammo1235 e9edc65
add general room functionality
sammo1235 f045e12
cleanup
sammo1235 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#= require action_cable | ||
#= require_self | ||
#= require_tree . | ||
|
||
@App = {} | ||
App.cable = ActionCable.createConsumer() |
160 changes: 45 additions & 115 deletions
160
app/assets/javascripts/frontend/application_collaborators/access_manager.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,133 +1,63 @@ | ||
window.ApplicationCollaboratorsAccessManager = | ||
|
||
register_member: (member) -> | ||
member_info = ApplicationCollaboratorsAccessManager.get_member_info(member) | ||
|
||
if member.id is String(window.pusher_current_channel.members.me.id) | ||
CollaboratorsLog.log("[ME IS MEMBER] ------------------------- " + member_info) | ||
else | ||
CollaboratorsLog.log("[ANOTHER MEMBER] ------------------------- " + member_info) | ||
|
||
set_access_mode: () -> | ||
editor = ApplicationCollaboratorsAccessManager.current_editor() | ||
CollaboratorsLog.log("[SET ACCESS MODE] ------------ CURRENT EDITOR IS -------- " + editor.id) | ||
editor_id = ApplicationCollaboratorsAccessManager.current_editor_id() | ||
# CollaboratorsLog.log("[SET ACCESS MODE] ------------ CURRENT EDITOR IS -------- " + editor_id) | ||
previous_editor_id = window.pusher_last_editor_id | ||
console.log("previous editor was: " + previous_editor_id) | ||
ApplicationCollaboratorsAccessManager.track_current_editor(editor_id) | ||
|
||
ApplicationCollaboratorsAccessManager.track_current_editor(editor) | ||
|
||
if ApplicationCollaboratorsAccessManager.does_im_current_editor() | ||
if ApplicationCollaboratorsAccessManager.i_am_current_editor() | ||
CollaboratorsLog.log("[EDITOR MODE] ----------------------") | ||
|
||
else | ||
CollaboratorsLog.log("[READ ONLY MODE] ----------------------") | ||
|
||
ApplicationCollaboratorsFormLocker.lock_current_form_section() | ||
ApplicationCollaboratorsEditorBar.render_collaborators_bar() | ||
ApplicationCollaboratorsEditorBar.hide_collaborators_bar() | ||
|
||
login_to_the_room: (current_step) -> | ||
# Unsubscribe client from current section room | ||
room = window.pusher_current_channel.name; | ||
window.pusher.unsubscribe(window.pusher_current_channel.name); | ||
if previous_editor_id != undefined && previous_editor_id != ApplicationCollaboratorsAccessManager.current_editor_id() | ||
CollaboratorsLog.log("[NOW IM EDITOR] ---- REFRESHING PAGE") | ||
|
||
# Clean up last editor id as we switched to another section | ||
window.pusher_last_editor_id = null; | ||
ApplicationCollaboratorsEditorBar.show_loading_bar() | ||
|
||
# And hide collaborators info bar | ||
ApplicationCollaboratorsEditorBar.hide_collaborators_bar() | ||
# Redirect user to same page in order to get the new changes | ||
redirect_url = $(".js-step-link.step-current a").attr('href') | ||
redirect_url += "&form_refresh=true" | ||
|
||
CollaboratorsLog.log("[TAB SWITCH] ------------- Log out from (" + room + ") to " + current_step + " --------------------") | ||
# | ||
# In case it was an attempt to submit and validation errors are present | ||
# then we are passing validate_on_form_load option | ||
# in order to show validation errors to user after redirection | ||
# | ||
if window.location.href.search("validate_on_form_load") > 0 | ||
redirect_url += "&validate_on_form_load=true" | ||
|
||
# Set new pusher section | ||
window.pusher_section = current_step; | ||
|
||
# Set new login timestamp for user | ||
timestamp = new Date().getTime(); | ||
|
||
# Init new room based on selected section | ||
ApplicationCollaboratorsConnectionManager.init_pusher(timestamp) | ||
ApplicationCollaboratorsConnectionManager.init_room() | ||
|
||
my_position_in_members_queue: () -> | ||
i = 0 | ||
my_index = 0 | ||
|
||
members = window.pusher_current_channel.members | ||
me = members.me | ||
|
||
members.each (member) -> | ||
if member.id is String(me.id) | ||
my_index = i | ||
|
||
i += 1 | ||
window.location.href = redirect_url | ||
else | ||
CollaboratorsLog.log("[READ ONLY MODE] ----------------------") | ||
|
||
my_index | ||
ApplicationCollaboratorsFormLocker.lock_current_form_section() | ||
ApplicationCollaboratorsEditorBar.render_collaborators_bar() | ||
|
||
does_im_current_editor: () -> | ||
ApplicationCollaboratorsAccessManager.my_position_in_members_queue() == 0 | ||
i_am_current_editor: () -> | ||
ApplicationCollaboratorsAccessManager.current_editor_id() == window.user_id && | ||
window.tab_ident == ApplicationCollaboratorsAccessManager.current_editor().tab_ident | ||
|
||
im_in_viewer_mode: () -> | ||
!ApplicationCollaboratorsAccessManager.does_im_current_editor() | ||
|
||
normalized_members_array: () -> | ||
list = [] | ||
|
||
members = window.pusher_current_channel.members | ||
members.each (member) -> | ||
list.push(member) | ||
|
||
return list | ||
!ApplicationCollaboratorsAccessManager.i_am_current_editor() | ||
|
||
get_member_info: (m) -> | ||
return ("ID: " + m.id + ", NAME: " + m.info.name + ", JOINED AT: " + m.info.joined_at) | ||
current_editor_id: () -> | ||
editor_id = window.current_channel_members.split("/").find((el) => el.includes("EDITOR")).split(":")[0] | ||
|
||
return editor_id | ||
|
||
current_editor: () -> | ||
editor = ApplicationCollaboratorsAccessManager.normalized_members_array()[0] | ||
member_info = ApplicationCollaboratorsAccessManager.get_member_info(editor) | ||
|
||
CollaboratorsLog.log("[CURRENT EDITOR] ------------- " + member_info + " --------------------") | ||
|
||
return editor | ||
|
||
try_mark_as_editor: () -> | ||
editor = ApplicationCollaboratorsAccessManager.current_editor() | ||
|
||
if ApplicationCollaboratorsAccessManager.can_be_marked_as_editor(editor) | ||
CollaboratorsLog.log("[NOW IM EDITOR] ----------------------") | ||
|
||
ApplicationCollaboratorsEditorBar.show_loading_bar() | ||
|
||
# Redirect user to same page in order to login him | ||
redirect_url = $(".js-step-link.step-current a").attr('href') | ||
redirect_url += "&form_refresh=true" | ||
|
||
# | ||
# In case if was attempt to submit and validation errors are present | ||
# then we are passing validate_on_form_load option | ||
# in order to show validation errors to user after redirection | ||
# | ||
if window.location.href.search("validate_on_form_load") > 0 | ||
redirect_url += "&validate_on_form_load=true" | ||
|
||
window.location.href = redirect_url | ||
else | ||
# | ||
# If I'm not next in queue to be marked as editor | ||
# or I'm already editor | ||
# | ||
# Then do not need to refresh page | ||
# | ||
|
||
if window.pusher_last_editor_id == editor.id | ||
CollaboratorsLog.log("[ACCESS CALC] ---------------------- I'M ALREADY EDITOR OF CURRENT TAB!") | ||
else | ||
CollaboratorsLog.log("[ACCESS CALC] ---------------------- NOPE - I STILL HAVE TO WAIT!") | ||
|
||
track_current_editor: (editor) -> | ||
window.pusher_last_editor_id = editor.id | ||
|
||
can_be_marked_as_editor: (editor) -> | ||
# | ||
# If I'm next in queue to join room as editor | ||
# and I'm not previous editor | ||
# | ||
ApplicationCollaboratorsAccessManager.does_im_current_editor() && | ||
window.pusher_last_editor_id != editor.id | ||
editor = window.current_channel_members.split("/").find((el) => el.includes("EDITOR")).split(":") | ||
editor_info = { | ||
id: editor[0], | ||
tab_ident: editor[1], | ||
email: editor[2], | ||
name: editor[3] | ||
} | ||
|
||
editor_info | ||
|
||
track_current_editor: (editor_id) -> | ||
window.pusher_last_editor_id = editor_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module ApplicationCable | ||
class Channel < ActionCable::Channel::Base | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module ApplicationCable | ||
class Connection < ActionCable::Connection::Base | ||
end | ||
end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
[TODO] remove once testing is complete - this output will muddy the waters