Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions web_notify/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

==========
Web Notify
==========
Expand All @@ -17,7 +13,7 @@ Web Notify
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
:target: https://odoo-community.org/page/development-status
:alt: Production/Stable
.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github
Expand Down Expand Up @@ -89,6 +85,25 @@ or

self.env.user.notify_default(message='My default message')

You can also add sound to your notifications by using the ``sound``
parameter. The sound parameter expects a string containing the URL path
to the audio file that should be played when the notification is
displayed.

.. code:: python

self.env.user.notify_success(message='My success message', sound='/<YOUR_MODULE>/static/audio/success.mp3')

or

.. code:: python

self.env.user.notify_info(message='My information message', sound='/<YOUR_MODULE>/static/audio/info.mp3')

The sound parameter can be used with any notification type (success,
danger, warning, info, or default). If the sound parameter is not
provided, the notification will be displayed without any sound.

The notifications can bring interactivity with some buttons.

- One allowing to refresh the active view
Expand Down
5 changes: 3 additions & 2 deletions web_notify/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
Send notification messages to user""",
"version": "17.0.1.1.0",
"license": "LGPL-3",
"author": "ACSONE SA/NV," "AdaptiveCity," "Odoo Community Association (OCA)",
"author": "ACSONE SA/NV,AdaptiveCity,Odoo Community Association (OCA)",
"development_status": "Production/Stable",
"website": "https://github.com/OCA/web",
"depends": ["web", "bus", "base", "mail"],
"assets": {
"web.assets_backend": [
"web_notify/static/src/js/services/*.js",
"web_notify/static/src/**/*.js",
"web_notify/static/src/**/*.xml",
]
},
"demo": ["views/res_users_demo.xml"],
Expand Down
27 changes: 22 additions & 5 deletions web_notify/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ def notify_success(
target=None,
action=None,
params=None,
sound=None,
):
title = title or _("Success")
self._notify_channel(SUCCESS, message, title, sticky, target, action, params)
self._notify_channel(
SUCCESS, message, title, sticky, target, action, params, sound
)

def notify_danger(
self,
Expand All @@ -62,9 +65,12 @@ def notify_danger(
target=None,
action=None,
params=None,
sound=None,
):
title = title or _("Danger")
self._notify_channel(DANGER, message, title, sticky, target, action, params)
self._notify_channel(
DANGER, message, title, sticky, target, action, params, sound
)

def notify_warning(
self,
Expand All @@ -74,9 +80,12 @@ def notify_warning(
target=None,
action=None,
params=None,
sound=None,
):
title = title or _("Warning")
self._notify_channel(WARNING, message, title, sticky, target, action, params)
self._notify_channel(
WARNING, message, title, sticky, target, action, params, sound
)

def notify_info(
self,
Expand All @@ -86,9 +95,12 @@ def notify_info(
target=None,
action=None,
params=None,
sound=None,
):
title = title or _("Information")
self._notify_channel(INFO, message, title, sticky, target, action, params)
self._notify_channel(
INFO, message, title, sticky, target, action, params, sound
)

def notify_default(
self,
Expand All @@ -98,9 +110,12 @@ def notify_default(
target=None,
action=None,
params=None,
sound=None,
):
title = title or _("Default")
self._notify_channel(DEFAULT, message, title, sticky, target, action, params)
self._notify_channel(
DEFAULT, message, title, sticky, target, action, params, sound
)

def _notify_channel(
self,
Expand All @@ -111,6 +126,7 @@ def _notify_channel(
target=None,
action=None,
params=None,
sound=None,
):
if not (self.env.user._is_admin() or self.env.su) and any(
user.id != self.env.uid for user in self
Expand All @@ -129,6 +145,7 @@ def _notify_channel(
"sticky": sticky,
"action": action,
"params": dict(params or []),
"sound": sound,
}

notifications = [[partner, "web.notify", [bus_message]] for partner in target]
Expand Down
19 changes: 18 additions & 1 deletion web_notify/readme/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ or
self.env.user.notify_default(message='My default message')
```

You can also add sound to your notifications by using the `sound` parameter.
The sound parameter expects a string containing the URL path to the audio file
that should be played when the notification is displayed.

``` python
self.env.user.notify_success(message='My success message', sound='/<YOUR_MODULE>/static/audio/success.mp3')
```

or

``` python
self.env.user.notify_info(message='My information message', sound='/<YOUR_MODULE>/static/audio/info.mp3')
```

The sound parameter can be used with any notification type (success, danger, warning, info, or
default). If the sound parameter is not provided, the notification will be displayed without any sound.

The notifications can bring interactivity with some buttons.

- One allowing to refresh the active view
Expand Down Expand Up @@ -59,4 +76,4 @@ module in a demo database. Access the users form through Settings -\>
Users & Companies. You'll see a tab called "Test web notify", here
you'll find two buttons that'll allow you test the module.

![](../static/img/test_notifications_demo.png)
![](../static/img/test_notifications_demo.png)
42 changes: 25 additions & 17 deletions web_notify/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>README.rst</title>
<title>Web Notify</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -360,21 +360,16 @@
</style>
</head>
<body>
<div class="document">
<div class="document" id="web-notify">
<h1 class="title">Web Notify</h1>


<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
</a>
<div class="section" id="web-notify">
<h1>Web Notify</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:86311536004dce32521aac8f85d837314ea5ba06eefbee1eef12ace3ed7e2f20
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web/tree/17.0/web_notify"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-17-0/web-17-0-web_notify"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web/tree/17.0/web_notify"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-17-0/web-17-0-web_notify"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Send instant notification messages to the user in live.</p>
<p>This technical module allows you to send instant notification messages
from the server to the user in live. Two kinds of notification are
Expand All @@ -401,12 +396,12 @@ <h1>Web Notify</h1>
</ul>
</div>
<div class="section" id="installation">
<h2><a class="toc-backref" href="#toc-entry-1">Installation</a></h2>
<h1><a class="toc-backref" href="#toc-entry-1">Installation</a></h1>
<p>This module is based on the Instant Messaging Bus. To work properly, the
server must be launched in gevent mode.</p>
</div>
<div class="section" id="usage">
<h2><a class="toc-backref" href="#toc-entry-2">Usage</a></h2>
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<p>To send a notification to the user you just need to call one of the new
methods defined on res.users:</p>
<pre class="code python literal-block">
Expand All @@ -428,6 +423,20 @@ <h2><a class="toc-backref" href="#toc-entry-2">Usage</a></h2>
<pre class="code python literal-block">
<span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">notify_default</span><span class="p">(</span><span class="n">message</span><span class="o">=</span><span class="s1">'My default message'</span><span class="p">)</span>
</pre>
<p>You can also add sound to your notifications by using the <tt class="docutils literal">sound</tt>
parameter. The sound parameter expects a string containing the URL path
to the audio file that should be played when the notification is
displayed.</p>
<pre class="code python literal-block">
<span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">notify_success</span><span class="p">(</span><span class="n">message</span><span class="o">=</span><span class="s1">'My success message'</span><span class="p">,</span> <span class="n">sound</span><span class="o">=</span><span class="s1">'/&lt;YOUR_MODULE&gt;/static/audio/success.mp3'</span><span class="p">)</span>
</pre>
<p>or</p>
<pre class="code python literal-block">
<span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">notify_info</span><span class="p">(</span><span class="n">message</span><span class="o">=</span><span class="s1">'My information message'</span><span class="p">,</span> <span class="n">sound</span><span class="o">=</span><span class="s1">'/&lt;YOUR_MODULE&gt;/static/audio/info.mp3'</span><span class="p">)</span>
</pre>
<p>The sound parameter can be used with any notification type (success,
danger, warning, info, or default). If the sound parameter is not
provided, the notification will be displayed without any sound.</p>
<p>The notifications can bring interactivity with some buttons.</p>
<ul class="simple">
<li>One allowing to refresh the active view</li>
Expand Down Expand Up @@ -456,24 +465,24 @@ <h2><a class="toc-backref" href="#toc-entry-2">Usage</a></h2>
<p><img alt="image2" src="https://raw.githubusercontent.com/OCA/web/17.0/web_notify/static/img/test_notifications_demo.png" /></p>
</div>
<div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h2>
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/web/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_notify%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h2><a class="toc-backref" href="#toc-entry-4">Credits</a></h2>
<h1><a class="toc-backref" href="#toc-entry-4">Credits</a></h1>
<div class="section" id="authors">
<h3><a class="toc-backref" href="#toc-entry-5">Authors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
<ul class="simple">
<li>ACSONE SA/NV</li>
<li>AdaptiveCity</li>
</ul>
</div>
<div class="section" id="contributors">
<h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<ul class="simple">
<li>Laurent Mignon &lt;<a class="reference external" href="mailto:laurent.mignon&#64;acsone.eu">laurent.mignon&#64;acsone.eu</a>&gt;</li>
<li>Serpent Consulting Services Pvt. Ltd.&lt;<a class="reference external" href="mailto:jay.vora&#64;serpentcs.com">jay.vora&#64;serpentcs.com</a>&gt;</li>
Expand All @@ -489,7 +498,7 @@ <h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
</ul>
</div>
<div class="section" id="maintainers">
<h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
Expand All @@ -502,6 +511,5 @@ <h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
</div>
</div>
</div>
</div>
</body>
</html>
78 changes: 78 additions & 0 deletions web_notify/static/src/components/audio_player.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/** @odoo-module alias=web_notify.AudioPlayer **/

import {Component, useState} from "@odoo/owl";

/**
* @typedef AudioPlayerProps
* @property {string} src URL of the audio file to be played
* @property {number} [volume=1.0] Volume level of the audio (from 0.0 to 1.0)
* @property {boolean} [loop=false] Whether the audio should loop
* @property {Function} [onEnded] Callback function to be called when the audio ends
*/

/**
* The AudioPlayer component is responsible for playing audio files with
* specified settings like volume and looping. It also provides the ability
* to trigger actions when the audio playback ends.
*/
export class AudioPlayer extends Component {
setup() {
this.state = useState({isPlaying: false});
this.audioElement = new Audio(this.props.src);

// Set audio properties
this.audioElement.volume = this.props.volume || 1.0;
this.audioElement.loop = this.props.loop || false;

// Start playing the audio
this.audioElement
.play()
.then(() => {
this.state.isPlaying = true;
})
.catch((error) => {
console.error("Audio playback failed:", error);
});

// Listen for the end of the audio playback
this.audioElement.addEventListener("ended", this.onAudioEnded.bind(this));
}

/**
* Stops the audio playback and triggers the onEnded callback if provided.
*/
stopAudio() {
this.audioElement.pause();
this.audioElement.currentTime = 0;
this.state.isPlaying = false;

if (this.props.onEnded) {
this.props.onEnded();
}
}

/**
* Handler for when the audio playback ends.
*/
onAudioEnded() {
if (!this.props.loop) {
this.stopAudio();
}
}

willUnmount() {
// Clean up the audio element and listeners
this.audioElement.removeEventListener("ended", this.onAudioEnded);
this.audioElement.pause();
}
}

AudioPlayer.props = {
src: {type: String},
volume: {type: Number, optional: true},
loop: {type: Boolean, optional: true},
onEnded: {type: Function, optional: true},
close: {type: Function, optional: true},
};

AudioPlayer.template = "web_notify.AudioPlayer";
10 changes: 10 additions & 0 deletions web_notify/static/src/components/audio_player.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Copyright 2024 Cetmix OÜ
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<templates xml:space="preserve">

<t t-name="web_notify.AudioPlayer" owl="1">
<!-- No visual elements needed, audio is controlled programmatically -->
</t>

</templates>
Loading
Loading