Skip to content

Commit

Permalink
[12.0] web_notify: improve popup UI (OCA#1231)
Browse files Browse the repository at this point in the history
* [ADD]: all available bootstrap notifications (success/danger/warning/info/default)
* [IMP] use black color for text for default notification.
* [FIX] reverted require string for `bus.Longpolling` and rename `on_message_received` to `on_message` to prevent collisions.
  • Loading branch information
shepilov-vladislav authored and trisdoan committed Oct 3, 2024
1 parent db48101 commit 42225e6
Show file tree
Hide file tree
Showing 17 changed files with 404 additions and 115 deletions.
36 changes: 29 additions & 7 deletions web_notify/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ Web Notify

Send instant notification messages to the user in live.

This technical module allows you to send instant notification messages from the server to the user in live.
This technical module allows you to send instant notification messages from the server to the user in live.
Two kinds of notification are supported.

* Warning: Displayed in a red flying popup div
* Information: Displayed in a light yellow flying popup div
* Success: Displayed in a `success` theme color flying popup div
* Danger: Displayed in a `danger` theme color flying popup div
* Warning: Displayed in a `warning` theme color flying popup div
* Information: Displayed in a `info` theme color flying popup div
* Default: Displayed in a `default` theme color flying popup div

**Table of contents**

Expand All @@ -50,14 +53,32 @@ Usage
To send a notification to the user you just need to call one of the new methods defined on res.users:

.. code-block:: python
self.env.user.notify_success(message='My success message')
or

.. code-block:: python
self.env.user.notify_danger(message='My danger message')
or

.. code-block:: python
self.env.user.notify_warning(message='My warning message')
or

.. code-block:: python
self.env.user.notify_info(message='My information message')
or
or

.. code-block:: python
self.env.user.notify_warning(message='My marning message')
self.env.user.notify_default(message='My default message')
.. figure:: https://raw.githubusercontent.com/OCA/web/12.0/web_notify/static/description/notifications_screenshot.png
:scale: 80 %
Expand Down Expand Up @@ -95,6 +116,7 @@ Contributors
* Laurent Mignon <[email protected]>
* Serpent Consulting Services Pvt. Ltd.<[email protected]>
* Aitor Bouzas <[email protected]>
* Shepilov Vladislav <[email protected]>

Maintainers
~~~~~~~~~~~
Expand Down
1 change: 1 addition & 0 deletions web_notify/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-docstring
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
2 changes: 1 addition & 1 deletion web_notify/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-docstring
# Copyright 2016 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

Expand All @@ -6,7 +7,6 @@
'summary': """
Send notification messages to user""",
'version': '12.0.1.0.0',
'description': 'Web Notify',
'license': 'AGPL-3',
'author': 'ACSONE SA/NV,'
'AdaptiveCity,'
Expand Down
54 changes: 51 additions & 3 deletions web_notify/i18n/web_notify.pot
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,80 @@ msgstr ""
"Plural-Forms: \n"

#. module: web_notify
#: code:addons/web_notify/models/res_users.py:23
#: code:addons/web_notify/models/res_users.py:44
#, python-format
msgid "Danger"
msgstr ""

#. module: web_notify
#: code:addons/web_notify/models/res_users.py:60
#, python-format
msgid "Default"
msgstr ""

#. module: web_notify
#: code:addons/web_notify/models/res_users.py:54
#, python-format
msgid "Information"
msgstr ""

#. module: web_notify
#: model:ir.model.fields,field_description:web_notify.field_res_users__notify_danger_channel_name
msgid "Notify Danger Channel Name"
msgstr ""

#. module: web_notify
#: model:ir.model.fields,field_description:web_notify.field_res_users__notify_default_channel_name
msgid "Notify Default Channel Name"
msgstr ""

#. module: web_notify
#: model:ir.model.fields,field_description:web_notify.field_res_users__notify_info_channel_name
msgid "Notify Info Channel Name"
msgstr ""

#. module: web_notify
#: model:ir.model.fields,field_description:web_notify.field_res_users__notify_success_channel_name
msgid "Notify Success Channel Name"
msgstr ""

#. module: web_notify
#: model:ir.model.fields,field_description:web_notify.field_res_users__notify_warning_channel_name
msgid "Notify Warning Channel Name"
msgstr ""

#. module: web_notify
#: code:addons/web_notify/models/res_users.py:37
#: code:addons/web_notify/models/res_users.py:75
#, python-format
msgid "Sending a notification to another user is forbidden."
msgstr ""

#. module: web_notify
#: code:addons/web_notify/models/res_users.py:38
#, python-format
msgid "Success"
msgstr ""

#. module: web_notify
#: model_terms:ir.ui.view,arch_db:web_notify.view_users_form_simple_modif_inherit
msgid "Test danger notification"
msgstr ""

#. module: web_notify
#: model_terms:ir.ui.view,arch_db:web_notify.view_users_form_simple_modif_inherit
msgid "Test default notification"
msgstr ""

#. module: web_notify
#: model_terms:ir.ui.view,arch_db:web_notify.view_users_form_simple_modif_inherit
msgid "Test info notification"
msgstr ""

#. module: web_notify
#: model_terms:ir.ui.view,arch_db:web_notify.view_users_form_simple_modif_inherit
msgid "Test success notification"
msgstr ""

#. module: web_notify
#: model_terms:ir.ui.view,arch_db:web_notify.view_users_form_simple_modif_inherit
msgid "Test warning notification"
Expand All @@ -56,7 +104,7 @@ msgid "Users"
msgstr ""

#. module: web_notify
#: code:addons/web_notify/models/res_users.py:29
#: code:addons/web_notify/models/res_users.py:50
#, python-format
msgid "Warning"
msgstr ""
Expand Down
1 change: 1 addition & 0 deletions web_notify/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-docstring
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import res_users
99 changes: 70 additions & 29 deletions web_notify/models/res_users.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,87 @@
# pylint: disable=missing-docstring
# Copyright 2016 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, exceptions, fields, models, _
from odoo import _, api, exceptions, fields, models

DEFAULT_MESSAGE = "Default message"

SUCCESS = "success"
DANGER = "danger"
WARNING = "warning"
INFO = "info"
DEFAULT = "default"


class ResUsers(models.Model):
_inherit = 'res.users'
_inherit = "res.users"

@api.depends('create_date')
@api.depends("create_date")
def _compute_channel_names(self):
for record in self:
res_id = record.id
record.notify_info_channel_name = 'notify_info_%s' % res_id
record.notify_warning_channel_name = 'notify_warning_%s' % res_id
record.notify_success_channel_name = "notify_success_%s" % res_id
record.notify_danger_channel_name = "notify_danger_%s" % res_id
record.notify_warning_channel_name = "notify_warning_%s" % res_id
record.notify_info_channel_name = "notify_info_%s" % res_id
record.notify_default_channel_name = "notify_default_%s" % res_id

notify_success_channel_name = fields.Char(compute="_compute_channel_names")
notify_danger_channel_name = fields.Char(compute="_compute_channel_names")
notify_warning_channel_name = fields.Char(compute="_compute_channel_names")
notify_info_channel_name = fields.Char(compute="_compute_channel_names")
notify_default_channel_name = fields.Char(compute="_compute_channel_names")

def notify_success(
self, message="Default message", title=None, sticky=False
):
title = title or _("Success")
self._notify_channel(SUCCESS, message, title, sticky)

notify_info_channel_name = fields.Char(
compute='_compute_channel_names')
notify_warning_channel_name = fields.Char(
compute='_compute_channel_names')
def notify_danger(
self, message="Default message", title=None, sticky=False
):
title = title or _("Danger")
self._notify_channel(DANGER, message, title, sticky)

def notify_warning(
self, message="Default message", title=None, sticky=False
):
title = title or _("Warning")
self._notify_channel(WARNING, message, title, sticky)

def notify_info(self, message="Default message", title=None, sticky=False):
title = title or _('Information')
self._notify_channel(
'notify_info_channel_name', message, title, sticky)

def notify_warning(self, message="Default message",
title=None, sticky=False):
title = title or _('Warning')
self._notify_channel(
'notify_warning_channel_name', message, title, sticky)

def _notify_channel(self, channel_name_field, message, title, sticky):
if (not self.env.user._is_admin()
and any(user.id != self.env.uid for user in self)):
title = title or _("Information")
self._notify_channel(INFO, message, title, sticky)

def notify_default(
self, message="Default message", title=None, sticky=False
):
title = title or _("Default")
self._notify_channel(DEFAULT, message, title, sticky)

def _notify_channel(
self,
type_message=DEFAULT,
message=DEFAULT_MESSAGE,
title=None,
sticky=False,
):
# pylint: disable=protected-access
if not self.env.user._is_admin() and any(
user.id != self.env.uid for user in self
):
raise exceptions.UserError(
_('Sending a notification to another user is forbidden.')
_("Sending a notification to another user is forbidden.")
)
channel_name_field = "notify_{}_channel_name".format(type_message)
bus_message = {
'message': message,
'title': title,
'sticky': sticky
"type": type_message,
"message": message,
"title": title,
"sticky": sticky,
}
notifications = [(record[channel_name_field], bus_message)
for record in self]
self.env['bus.bus'].sendmany(notifications)
notifications = [
(record[channel_name_field], bus_message) for record in self
]
self.env["bus.bus"].sendmany(notifications)
3 changes: 2 additions & 1 deletion web_notify/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Laurent Mignon <[email protected]>
* Serpent Consulting Services Pvt. Ltd.<[email protected]>
* Aitor Bouzas <[email protected]>
* Aitor Bouzas <[email protected]>
* Shepilov Vladislav <[email protected]>
9 changes: 6 additions & 3 deletions web_notify/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
Send instant notification messages to the user in live.

This technical module allows you to send instant notification messages from the server to the user in live.
This technical module allows you to send instant notification messages from the server to the user in live.
Two kinds of notification are supported.

* Warning: Displayed in a red flying popup div
* Information: Displayed in a light yellow flying popup div
* Success: Displayed in a `success` theme color flying popup div
* Danger: Displayed in a `danger` theme color flying popup div
* Warning: Displayed in a `warning` theme color flying popup div
* Information: Displayed in a `info` theme color flying popup div
* Default: Displayed in a `default` theme color flying popup div
2 changes: 1 addition & 1 deletion web_notify/readme/INSTALL.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
This module is based on the Instant Messaging Bus. To work properly, the server must be launched in gevent mode.
This module is based on the Instant Messaging Bus. To work properly, the server must be launched in gevent mode.
26 changes: 22 additions & 4 deletions web_notify/readme/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,32 @@
To send a notification to the user you just need to call one of the new methods defined on res.users:

.. code-block:: python
self.env.user.notify_success(message='My success message')
or

.. code-block:: python
self.env.user.notify_danger(message='My danger message')
or

.. code-block:: python
self.env.user.notify_warning(message='My warning message')
or

.. code-block:: python
self.env.user.notify_info(message='My information message')
or
or

.. code-block:: python
self.env.user.notify_warning(message='My marning message')
self.env.user.notify_default(message='My default message')
.. figure:: static/description/notifications_screenshot.png
:scale: 80 %
Expand Down
Loading

0 comments on commit 42225e6

Please sign in to comment.