-
Notifications
You must be signed in to change notification settings - Fork 15
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
task/DSAPP-46, task/WP-611: Tools & Apps Workspace Changes; Notifications Enhancements #1442
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
fac5908
support .log preview
rstijerina 844126f
change "Account Profile" to "Manage Account
rstijerina 80aac67
add workspace links to account dropdown
rstijerina f4fcc80
change /rw/workspace to /workspace; backwards compatible
rstijerina f230a24
add "Job Status" label to notification bell
rstijerina 793b6d0
enable docker ngrok
rstijerina c7690c9
remove notifications link; adjust dropdown header
rstijerina f8cfe8a
formatting
rstijerina c833469
sync job notification states
rstijerina 08c526f
Merge branch 'main' into task/DSAPP-46--tools-apps-changes
rstijerina 78956c1
update m1 docker-compose; linting
rstijerina cc8411f
adjust toast UI to look like secondary button
rstijerina 940be99
unify ngrok webhook settings, and move to conf/env_files/ngrok.env
rstijerina 450045c
Revert "unify ngrok webhook settings, and move to conf/env_files/ngro…
rstijerina d4d7cdc
Revert "enable docker ngrok"
rstijerina 9e7ec12
Merge branch 'main' into task/DSAPP-46--tools-apps-changes
rstijerina 3fba6c7
Merge branch 'main' into task/DSAPP-46--tools-apps-changes
rstijerina 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
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
10 changes: 10 additions & 0 deletions
10
client/modules/workspace/src/Toast/Notifications.module.css
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,3 +1,13 @@ | ||
.root { | ||
cursor: pointer; | ||
background: #f4f4f4; | ||
border: 1px solid #222222; | ||
&:hover { | ||
border-color: #5695c4; | ||
background: #aac7ff; | ||
} | ||
} | ||
|
||
.toast-is-error { | ||
color: #eb6e6e; | ||
} |
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
4 changes: 2 additions & 2 deletions
4
designsafe/apps/accounts/templates/designsafe/apps/accounts/profile.html
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 |
---|---|---|
@@ -1,52 +1,47 @@ | ||
"""Signal receivers for notifications""" | ||
|
||
import logging | ||
import json | ||
from django.db.models.signals import post_save | ||
from django.dispatch import receiver | ||
from asgiref.sync import async_to_sync | ||
from channels.layers import get_channel_layer | ||
from django.db.models.signals import post_save | ||
from designsafe.apps.api.notifications.models import Notification, Broadcast | ||
import logging | ||
import json | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
WEBSOCKETS_FACILITY = 'websockets' | ||
WEBSOCKETS_FACILITY = "websockets" | ||
|
||
|
||
@receiver(post_save, sender=Notification, dispatch_uid="notification_msg") | ||
def send_notification_ws(instance, created, **kwargs): | ||
"""Send a websocket message to the user when a new notification is created.""" | ||
|
||
@receiver(post_save, sender=Notification, dispatch_uid='notification_msg') | ||
def send_notification_ws(sender, instance, created, **kwargs): | ||
#Only send WS message if it's a new notification not if we're updating. | ||
logger.debug('receiver received something.') | ||
if not created: | ||
return | ||
try: | ||
channel_layer = get_channel_layer() | ||
instance_dict = json.dumps(instance.to_dict()) | ||
logger.debug(instance_dict) | ||
|
||
async_to_sync(channel_layer.group_send)(f"ds_{instance.user}", {"type": "ds.notification", "message": instance_dict}) | ||
channel_layer = get_channel_layer() | ||
instance_dict = json.dumps(instance.to_dict()) | ||
|
||
async_to_sync(channel_layer.group_send)( | ||
f"ds_{instance.user}", {"type": "ds.notification", "message": instance_dict} | ||
) | ||
|
||
# logger.debug('WS socket msg sent: {}'.format(instance_dict)) | ||
except Exception as e: | ||
# logger.debug('Exception sending websocket message', | ||
# exc_info=True, | ||
# extra = instance.to_dict()) | ||
logger.debug('Exception sending websocket message', | ||
exc_info=True) | ||
return | ||
|
||
@receiver(post_save, sender=Broadcast, dispatch_uid='broadcast_msg') | ||
def send_broadcast_ws(sender, instance, created, **kwargs): | ||
|
||
@receiver(post_save, sender=Broadcast, dispatch_uid="broadcast_msg") | ||
def send_broadcast_ws(instance, created, **kwargs): | ||
"""Send a websocket message to all users when a new broadcast is created.""" | ||
|
||
if not created: | ||
return | ||
try: | ||
event_type, user, body = decompose_message(instance) | ||
#rp = RedisPublisher(facility = WEBSOCKETS_FACILITY,broadcast=True) | ||
channel_layer = get_channel_layer() | ||
instance_dict = json.dumps(instance.to_dict()) | ||
|
||
async_to_sync(channel_layer.group_send)("ds_broadcast", {"type": "ds.notification", "message": instance_dict}) | ||
logger.debug('WS socket msg sent: {}'.format(instance_dict)) | ||
except Exception as e: | ||
logger.debug('Exception sending websocket message', | ||
exc_info=True, | ||
extra = instance.to_dict()) | ||
|
||
channel_layer = get_channel_layer() | ||
instance_dict = json.dumps(instance.to_dict()) | ||
|
||
async_to_sync(channel_layer.group_send)( | ||
"ds_broadcast", {"type": "ds.notification", "message": instance_dict} | ||
) | ||
|
||
return |
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,28 +1,37 @@ | ||
import json | ||
"""Websocket consumers""" | ||
|
||
from channels.generic.websocket import WebsocketConsumer, AsyncWebsocketConsumer | ||
import json | ||
from channels.generic.websocket import AsyncWebsocketConsumer | ||
from channels.layers import get_channel_layer | ||
|
||
|
||
class DesignsafeWebsocketConsumer(AsyncWebsocketConsumer): | ||
"""Websocket consumer for DesignSafe notifications""" | ||
|
||
async def connect(self): | ||
self.user_channel = f"ds_{self.scope['user']}" | ||
self.broadcast_channel = "ds_broadcast" | ||
await self.channel_layer.group_add( | ||
self.user_channel, self.channel_name | ||
f"ds_{self.scope['user']}", self.channel_name | ||
) | ||
await self.accept() | ||
|
||
async def disconnect(self, close_code): | ||
await self.channel_layer.group_discard( | ||
self.user_channel, self.channel_name | ||
) | ||
async def disconnect(self, code): | ||
await self.channel_layer.group_discard( | ||
self.broadcast_channel, self.channel_name | ||
f"ds_{self.scope['user']}", self.channel_name | ||
) | ||
await self.channel_layer.group_discard("ds_broadcast", self.channel_name) | ||
|
||
async def receive(self, text_data): | ||
pass | ||
async def receive(self, text_data=None, bytes_data=None): | ||
if text_data == "markAllNotificationsAsRead": | ||
channel_layer = get_channel_layer() | ||
await channel_layer.group_send( | ||
f"ds_{self.scope['user']}", | ||
{ | ||
"type": "ds_notification", | ||
"message": json.dumps({"event_type": "markAllNotificationsAsRead"}), | ||
}, | ||
) | ||
|
||
async def ds_notification(self, event): | ||
"""Send notification to user""" | ||
message = event["message"] | ||
await self.send(text_data=message) |
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
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.
If a user sends this signal then refreshes the page, do the "unread" notifications come back? I don't see anything that persists read/unread state to the db.
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.
Yes the mark read state is persisted already via the requests, so these websocket messages only need to communicate that to each other.