Skip to content

Commit

Permalink
Merge pull request #192 from leolivier:leolivier/issue189
Browse files Browse the repository at this point in the history
don't show again masked admin messages
  • Loading branch information
leolivier authored Dec 27, 2024
2 parents 4daf4a1 + 26b781b commit 08b4d8a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
22 changes: 22 additions & 0 deletions cm_main/static/cm_main/js/cm_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,28 @@ $(document).ready(function() {
$container = checked.closest('.toggle-container');
$translation = (checked.val() === 'option2') ? 'translateX(100%)' : 'translateX(0)';
$container.css('--toggle-translate', $translation);

// Manage hidden notifications

// Restore hidden notifications
const hiddenMessages = JSON.parse(sessionStorage.getItem('hiddenMessages') || '[]');

hiddenMessages.forEach(id => {
$(`.admin-message[data-id="${id}"]`).hide();
});

// Managing the click on the delete button
$('.admin-message .delete').click(function() {
const $message = $(this).closest('.admin-message');
const messageId = $message.data('id');

$message.hide();

// Save in sessionStorage
const hidden = JSON.parse(sessionStorage.getItem('hiddenMessages') || '[]');
hidden.push(messageId);
sessionStorage.setItem('hiddenMessages', JSON.stringify(hidden));
});
});

// Functions to open and close a modal
Expand Down
2 changes: 1 addition & 1 deletion cm_main/templates/cm_main/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<div class="block">
{%get_flatpages settings.ADMIN_MESSAGE_PAGE_URL_PREFIX as admin_messages%}
{%for admin_message in admin_messages %}
<div class="notification is-info">
<div class="notification is-info admin-message" data-id="{{admin_message.id}}">
<button class="delete"></button>
{%autoescape off%}
{{admin_message.content}}
Expand Down
6 changes: 3 additions & 3 deletions pages/tests/tests_admin_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_admin_message(self):
self.assertIsNotNone(adm_msg)
response = self.client.get(reverse('cm_main:Home'), follow=True)
# self.print_response(response)
self.assertContains(response, f'''<div class="notification is-info">
self.assertContains(response, f'''<div class="notification is-info admin-message" data-id="{adm_msg.id}">
<button class="delete"></button>
{admin_message['content']}
</div>''', html=True)
Expand All @@ -37,10 +37,10 @@ def test_admin_messages(self):
},
]
for admin_message in admin_messages:
create_page(**admin_message)
admin_message['obj'] = create_page(**admin_message)
response = self.client.get(reverse('cm_main:Home'), follow=True)
for admin_message in admin_messages:
self.assertContains(response, f'''<div class="notification is-info">
self.assertContains(response, f'''<div class="notification is-info admin-message" data-id="{admin_message['obj'].id}">
<button class="delete"></button>
{admin_message['content']}
</div>''', html=True)

0 comments on commit 08b4d8a

Please sign in to comment.