[IMP] web_notify: migration improvements

- Use ES6 in js files
- Update screenshots
- Clean old lint exceptions
- New icon

TT38350
This commit is contained in:
David
2023-01-05 16:26:33 +01:00
parent dd92d61f30
commit 23269fcbd6
15 changed files with 85 additions and 87 deletions

View File

@@ -0,0 +1,12 @@
/** @odoo-module */
import {Notification} from "@web/core/notifications/notification";
import {patch} from "web.utils";
patch(Notification.props, "webNotifyProps", {
type: {
type: String,
optional: true,
validate: (t) =>
["warning", "danger", "success", "info", "default"].includes(t),
},
});

View File

@@ -1,14 +0,0 @@
odoo.define("web_notify.Notification", function (require) {
"use strict";
const {Notification} = require("@web/core/notifications/notification");
const {patch} = require("web.utils");
patch(Notification.props, "webNotifyProps", {
type: {
type: String,
optional: true,
validate: (t) =>
["warning", "danger", "success", "info", "default"].includes(t),
},
});
});

View File

@@ -0,0 +1,45 @@
/** @odoo-module **/
import {browser} from "@web/core/browser/browser";
import {registry} from "@web/core/registry";
export const webNotificationService = {
dependencies: ["notification"],
start(env, {notification}) {
let webNotifTimeouts = {};
/**
* Displays the web notification on user's screen
*/
function displaywebNotification(notifications) {
Object.values(webNotifTimeouts).forEach((notif) =>
browser.clearTimeout(notif)
);
webNotifTimeouts = {};
notifications.forEach(function (notif) {
browser.setTimeout(function () {
notification.add(notif.message, {
title: notif.title,
type: notif.type,
sticky: notif.sticky,
className: notif.className,
});
});
});
}
env.bus.on("WEB_CLIENT_READY", null, async () => {
const legacyEnv = owl.Component.env;
legacyEnv.services.bus_service.onNotification(this, (notifications) => {
for (const {payload, type} of notifications) {
if (type === "web.notify") {
displaywebNotification(payload);
}
}
});
legacyEnv.services.bus_service.startPolling();
});
},
};
registry.category("services").add("webNotification", webNotificationService);

View File

@@ -1,47 +0,0 @@
odoo.define("web_notify.NotificationService", function (require) {
"use strict";
const {browser} = require("@web/core/browser/browser");
const {registry} = require("@web/core/registry");
const webNotificationService = {
dependencies: ["notification"],
start(env, {notification}) {
let webNotifTimeouts = {};
/**
* Displays the web notification on user's screen
*/
function displaywebNotification(notifications) {
Object.values(webNotifTimeouts).forEach((notif) =>
browser.clearTimeout(notif)
);
webNotifTimeouts = {};
notifications.forEach(function (notif) {
browser.setTimeout(function () {
notification.add(notif.message, {
title: notif.title,
type: notif.type,
sticky: notif.sticky,
className: notif.className,
});
});
});
}
env.bus.on("WEB_CLIENT_READY", null, async () => {
const legacyEnv = owl.Component.env;
legacyEnv.services.bus_service.onNotification(this, (notifications) => {
for (const {payload, type} of notifications) {
if (type === "web.notify") {
displaywebNotification(payload);
}
}
});
legacyEnv.services.bus_service.startPolling();
});
},
};
registry.category("services").add("webNotification", webNotificationService);
});