Skip to content

Commit

Permalink
[MIG] web_environment_ribbon: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rven committed Nov 14, 2023
1 parent 85534cc commit 926f9b9
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 73 deletions.
6 changes: 3 additions & 3 deletions web_environment_ribbon/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

{
"name": "Web Environment Ribbon",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"category": "Web",
"author": "Francesco OpenCode Apruzzese, "
"Tecnativa, "
Expand All @@ -20,8 +20,8 @@
"auto_install": False,
"installable": True,
"assets": {
"web.assets_common": [
"web_environment_ribbon/static/**/*",
"web.assets_backend": [
"web_environment_ribbon/static/src/components/environment_ribbon/*",
],
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,3 @@
.test-ribbon b {
font-size: 20px;
}

header:hover ~ .test-ribbon,
nav:hover ~ .test-ribbon {
/* Ease out ribbon when user is using the navigation in Odoo */
opacity: 0;
transition: 0.2s ease;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/** @odoo-module **/

import {Component, xml} from "@odoo/owl";
import {useBus, useService} from "@web/core/utils/hooks";
import {registry} from "@web/core/registry";

export class WebEnvironmentRibbon extends Component {
setup() {
this.orm = useService("orm");
useBus(this.env.bus, "WEB_CLIENT_READY", this.showRibbon.bind(this));
}

// Code from: http://jsfiddle.net/WK_of_Angmar/xgA5C/
validStrColour(strToTest) {
if (strToTest === "") {
return false;
}
if (strToTest === "inherit") {
return true;
}
if (strToTest === "transparent") {
return true;
}
const image = document.createElement("img");
image.style.color = "rgb(0, 0, 0)";
image.style.color = strToTest;
if (image.style.color !== "rgb(0, 0, 0)") {
return true;
}
image.style.color = "rgb(255, 255, 255)";
image.style.color = strToTest;
return image.style.color !== "rgb(255, 255, 255)";
}

showRibbon() {
const ribbon = $(".test-ribbon");
const self = this;
ribbon.hide();
// Get ribbon data from backend
self.orm
.call("web.environment.ribbon.backend", "get_environment_ribbon")
.then(function (ribbon_data) {
// Ribbon name
if (ribbon_data.name && ribbon_data.name !== "False") {
ribbon.show();
ribbon.html(ribbon_data.name);
}
// Ribbon color
if (ribbon_data.color && self.validStrColour(ribbon_data.color)) {
ribbon.css("color", ribbon_data.color);
}
// Ribbon background color
if (
ribbon_data.background_color &&
self.validStrColour(ribbon_data.background_color)
) {
ribbon.css("background-color", ribbon_data.background_color);
}
});
}
/**
* @private
* @param {InputEvent} ev
*/
onMouseOver(ev) {
ev.target.style.display = "none";
}
onMouseDown(ev) {
ev.target.style.display = "none";
}

}

WebEnvironmentRibbon.props = {};
WebEnvironmentRibbon.template = xml`<div class="test-ribbon hidden" />`;

registry.category("main_components").add("WebEnvironmentRibbon", {
Component: WebEnvironmentRibbon,
});
62 changes: 0 additions & 62 deletions web_environment_ribbon/static/src/js/ribbon.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class TestEnvironmentRibbonData(common.TransactionCase):
@classmethod
def setUpClass(cls):
super(TestEnvironmentRibbonData, cls).setUpClass()
super().setUpClass()
cls.env["ir.config_parameter"].set_param("ribbon.name", "Test Ribbon {db_name}")
cls.env["ir.config_parameter"].set_param("ribbon.color", "#000000")
cls.env["ir.config_parameter"].set_param("ribbon.background.color", "#FFFFFF")
Expand Down

0 comments on commit 926f9b9

Please sign in to comment.