Skip to content

Commit

Permalink
[chore] Show description with md support
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhanus3133 committed May 23, 2024
1 parent 2be7037 commit 581cc90
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion openwisp_notifications/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Meta(NotificationSerializer.Meta):
fields = [
'id',
'message',
'description',
'get_description',
'unread',
'target_url',
'email_subject',
Expand Down
4 changes: 4 additions & 0 deletions openwisp_notifications/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ def target_url(self):
def message(self):
return self.get_message()

@cached_property
def get_description(self):
return mark_safe(markdown(self.description))

@property
def email_message(self):
return self.get_message(email_message=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ function notificationWidget($) {
</div>
<div class="ow-notification-date">${datetime}</div>
</div>
${elem.description ? elem.message.replace(/<a [^>]*>([^<]*)<\/a>/g, '$1') : convertMessageWithRelativeURL(elem.message)}
${elem.get_description ? elem.message.replace(/<a [^>]*>([^<]*)<\/a>/g, '$1') : convertMessageWithRelativeURL(elem.message)}
</div>
</div>`;
}
Expand Down Expand Up @@ -326,7 +326,7 @@ function notificationWidget($) {
}

var notification = fetchedPages.flat().find((notification) => notification.id == elem.get(0).id.replace('ow-', ''));
if (notification.description) {
if (notification.get_description) {
const datetime = dateTimeStampToDateTimeLocaleString(new Date(notification.timestamp));
document.querySelector('.ow-dialog-notification-level-wrapper').innerHTML = `
<div class="ow-notification-level-wrapper">
Expand All @@ -336,7 +336,7 @@ function notificationWidget($) {
<div class="ow-notification-date">${datetime}</div>
`;
document.querySelector('.ow-message-title').innerHTML = convertMessageWithRelativeURL(notification.message);
document.querySelector('.ow-message-description').innerHTML = notification.description;
document.querySelector('.ow-message-description').innerHTML = notification.get_description;
$('.ow-dialog-overlay').removeClass('ow-hide');
if (notification.target_url) {
var target_url = new URL(notification.target_url, window.location.href);
Expand Down

0 comments on commit 581cc90

Please sign in to comment.