From 9ddfd194befe17df06276ab0ac8cbcf6fe8bcaf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 29 Dec 2021 18:51:25 +0100 Subject: [PATCH] notification: small vue component to toggle read status of a notification --- .../public/module/notification/toggle_read.js | 38 +++++++++++++++++ .../Notification/NotificationReadToggle.vue | 42 +++++++++++++++++++ .../views/Notification/list.html.twig | 13 ++++++ .../views/Notification/show.html.twig | 13 ++++++ .../Resources/views/layout.html.twig | 2 +- .../ChillMainBundle/chill.webpack.config.js | 4 +- 6 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/Resources/public/module/notification/toggle_read.js create mode 100644 src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/Notification/NotificationReadToggle.vue diff --git a/src/Bundle/ChillMainBundle/Resources/public/module/notification/toggle_read.js b/src/Bundle/ChillMainBundle/Resources/public/module/notification/toggle_read.js new file mode 100644 index 000000000..6d1637494 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/public/module/notification/toggle_read.js @@ -0,0 +1,38 @@ +import {createApp} from "vue"; +import NotificationReadToggle from "ChillMainAssets/vuejs/_components/Notification/NotificationReadToggle.vue"; + +const App = { + template: '', + components: { + NotificationReadToggle, + }, + methods: { + onMarkRead() { + this.isRead = true; + }, + onMarkUnread() { + this.isRead = false; + }, + } +} + +window.addEventListener('DOMContentLoaded', function (e) { + document.querySelectorAll('.notification_toggle_read_status') + .forEach(function (app) { + console.log('app', app); + const myApp = Object.assign(App, { + data() { + return { + notificationId: +app.dataset.notificationId, + isRead: 1 === +app.dataset.notificationCurrentIsRead, + } + } + }) + + createApp(myApp).mount(app); + }); +}) diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/Notification/NotificationReadToggle.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/Notification/NotificationReadToggle.vue new file mode 100644 index 000000000..d88c9916c --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/Notification/NotificationReadToggle.vue @@ -0,0 +1,42 @@ + + + + + diff --git a/src/Bundle/ChillMainBundle/Resources/views/Notification/list.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Notification/list.html.twig index 064adcee1..915f42c25 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Notification/list.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Notification/list.html.twig @@ -2,6 +2,16 @@ {% block title 'notification.List'|trans %} +{% block js %} + {{ parent() }} + {{ encore_entry_script_tags('mod_notification_toggle_read_status') }} +{% endblock %} + +{% block css %} + {{ parent() }} + {{ encore_entry_link_tags('mod_notification_toggle_read_status') }} +{% endblock %} + {% block content %}
@@ -66,6 +76,9 @@
    +
  • + +
  • {% if is_granted('CHILL_MAIN_NOTIFICATION_UPDATE', notification) %}
  • diff --git a/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig index 86fafd031..4fa354e67 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig @@ -2,6 +2,16 @@ {% block title 'notification.show notification from %sender%'|trans({ '%sender%': notification.sender|chill_entity_render_string }) %} +{% block js %} + {{ parent() }} + {{ encore_entry_script_tags('mod_notification_toggle_read_status') }} +{% endblock %} + +{% block css %} + {{ parent() }} + {{ encore_entry_link_tags('mod_notification_toggle_read_status') }} +{% endblock %} + {% block content %}
    @@ -77,6 +87,9 @@ {{ 'Cancel'|trans|chill_return_path_label }}
  • +
  • + +
diff --git a/src/Bundle/ChillMainBundle/Resources/views/layout.html.twig b/src/Bundle/ChillMainBundle/Resources/views/layout.html.twig index 07b7970d8..a123ce405 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/layout.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/layout.html.twig @@ -106,6 +106,6 @@ }); - {% block js%}{% endblock %} + {% block js %}{% endblock %} diff --git a/src/Bundle/ChillMainBundle/chill.webpack.config.js b/src/Bundle/ChillMainBundle/chill.webpack.config.js index dfa113206..adc4ba3c8 100644 --- a/src/Bundle/ChillMainBundle/chill.webpack.config.js +++ b/src/Bundle/ChillMainBundle/chill.webpack.config.js @@ -61,10 +61,10 @@ module.exports = function(encore, entries) encore.addEntry('mod_ckeditor5', __dirname + '/Resources/public/module/ckeditor5/index.js'); encore.addEntry('mod_disablebuttons', __dirname + '/Resources/public/module/disable-buttons/index.js'); encore.addEntry('mod_blur', __dirname + '/Resources/public/module/blur/index.js'); - encore.addEntry('mod_input_address', __dirname + '/Resources/public/vuejs/Address/mod_input_address_index.js'); + encore.addEntry('mod_notification_toggle_read_status', __dirname + '/Resources/public/module/notification/toggle_read.js'); + // Vue entrypoints encore.addEntry('vue_address', __dirname + '/Resources/public/vuejs/Address/index.js'); encore.addEntry('vue_onthefly', __dirname + '/Resources/public/vuejs/OnTheFly/index.js'); - };