-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3105 from bitzesty/replace-poxa-with-action-cable…
…-spike Form Collaboration: Replace Poxa with Action Cable
- Loading branch information
Showing
27 changed files
with
400 additions
and
286 deletions.
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
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,6 @@ | ||
#= require actioncable | ||
#= require_self | ||
#= require_tree . | ||
|
||
@App = {} | ||
App.cable = ActionCable.createConsumer() |
146 changes: 33 additions & 113 deletions
146
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,53 @@ | ||
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) | ||
return if !window.current_channel_members | ||
|
||
ApplicationCollaboratorsAccessManager.track_current_editor(editor) | ||
editor_id = ApplicationCollaboratorsAccessManager.current_editor().id | ||
|
||
if ApplicationCollaboratorsAccessManager.does_im_current_editor() | ||
CollaboratorsLog.log("[EDITOR MODE] ----------------------") | ||
CollaboratorsLog.log("[SET ACCESS MODE] ------------ CURRENT EDITOR IS -------- " + editor_id) | ||
previous_editor_id = window.last_editor_id | ||
|
||
else | ||
CollaboratorsLog.log("[READ ONLY MODE] ----------------------") | ||
ApplicationCollaboratorsAccessManager.track_current_editor(editor_id) | ||
|
||
ApplicationCollaboratorsFormLocker.lock_current_form_section() | ||
ApplicationCollaboratorsEditorBar.render_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); | ||
|
||
# Clean up last editor id as we switched to another section | ||
window.pusher_last_editor_id = null; | ||
|
||
# And hide collaborators info bar | ||
ApplicationCollaboratorsEditorBar.hide_collaborators_bar() | ||
|
||
CollaboratorsLog.log("[TAB SWITCH] ------------- Log out from (" + room + ") to " + current_step + " --------------------") | ||
|
||
# Set new pusher section | ||
window.pusher_section = current_step; | ||
if ApplicationCollaboratorsAccessManager.i_am_current_editor() | ||
CollaboratorsLog.log("[EDITOR MODE] ----------------------") | ||
|
||
# Set new login timestamp for user | ||
timestamp = new Date().getTime(); | ||
ApplicationCollaboratorsEditorBar.hide_collaborators_bar() | ||
|
||
# Init new room based on selected section | ||
ApplicationCollaboratorsConnectionManager.init_pusher(timestamp) | ||
ApplicationCollaboratorsConnectionManager.init_room() | ||
if previous_editor_id != undefined && previous_editor_id != ApplicationCollaboratorsAccessManager.current_editor().id | ||
CollaboratorsLog.log("[NOW IM EDITOR] ---- REFRESHING PAGE") | ||
|
||
my_position_in_members_queue: () -> | ||
i = 0 | ||
my_index = 0 | ||
ApplicationCollaboratorsEditorBar.show_loading_bar() | ||
|
||
members = window.pusher_current_channel.members | ||
me = members.me | ||
# 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" | ||
|
||
members.each (member) -> | ||
if member.id is String(me.id) | ||
my_index = i | ||
# | ||
# 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" | ||
|
||
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 | ||
|
||
get_member_info: (m) -> | ||
return ("ID: " + m.id + ", NAME: " + m.info.name + ", JOINED AT: " + m.info.joined_at) | ||
!ApplicationCollaboratorsAccessManager.i_am_current_editor() | ||
|
||
current_editor: () -> | ||
editor = ApplicationCollaboratorsAccessManager.normalized_members_array()[0] | ||
member_info = ApplicationCollaboratorsAccessManager.get_member_info(editor) | ||
|
||
CollaboratorsLog.log("[CURRENT EDITOR] ------------- " + member_info + " --------------------") | ||
window.current_channel_members[0] | ||
|
||
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 | ||
track_current_editor: (editor_id) -> | ||
window.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
Oops, something went wrong.