diff --git a/g2p_superset_dashboard/README.md b/g2p_superset_dashboard/README.md index 2889fea..e9ed40a 100644 --- a/g2p_superset_dashboard/README.md +++ b/g2p_superset_dashboard/README.md @@ -1,6 +1,5 @@ -# Superset Dashboard +# Superset Dashboard -This module integrates the Superset dashboard into Odoo, allowing users to view and interact with Superset -visualizations directly from the Odoo interface. +This module integrates the Superset dashboard into Odoo, allowing users to view and interact with Superset visualizations directly from the Odoo interface. Refer to https://docs.openg2p.org. diff --git a/g2p_superset_dashboard/__manifest__.py b/g2p_superset_dashboard/__manifest__.py index 6659072..3761188 100644 --- a/g2p_superset_dashboard/__manifest__.py +++ b/g2p_superset_dashboard/__manifest__.py @@ -7,9 +7,15 @@ "author": "OpenG2P", "website": "https://openg2p.org", "license": "Other OSI approved licence", - "depends": ["base"], + "depends": ["base", "web"], "external_dependencies": {}, - "data": ["views/res_config_settings.xml", "views/superset_dashboard.xml"], + "data": [ + "views/superset_dashboard_config_views.xml", + "views/superset_dashboard_embedding_views.xml", + ], + "demo": [], + "installable": True, + "application": True, "assets": { "web.assets_backend": [ "g2p_superset_dashboard/static/src/components/**/*.js", diff --git a/g2p_superset_dashboard/i18n/g2p_superset_dashboard.pot b/g2p_superset_dashboard/i18n/g2p_superset_dashboard.pot index 6ccfda7..01b3dee 100644 --- a/g2p_superset_dashboard/i18n/g2p_superset_dashboard.pot +++ b/g2p_superset_dashboard/i18n/g2p_superset_dashboard.pot @@ -63,4 +63,4 @@ msgstr "" #. module: g2p_superset_dashboard #: model_terms:ir.ui.view,arch_db:g2p_superset_dashboard.superset_dashboard_res_config_settings_view_form msgid "e.g. http://localhost:8088" -msgstr "" +msgstr "" \ No newline at end of file diff --git a/g2p_superset_dashboard/models/__init__.py b/g2p_superset_dashboard/models/__init__.py index 0deb68c..52d4501 100644 --- a/g2p_superset_dashboard/models/__init__.py +++ b/g2p_superset_dashboard/models/__init__.py @@ -1 +1 @@ -from . import res_config_settings +from . import g2p_superset_dashboard_config diff --git a/g2p_superset_dashboard/models/g2p_superset_dashboard_config.py b/g2p_superset_dashboard/models/g2p_superset_dashboard_config.py new file mode 100644 index 0000000..fbf16dd --- /dev/null +++ b/g2p_superset_dashboard/models/g2p_superset_dashboard_config.py @@ -0,0 +1,58 @@ +import logging + +from odoo import api, fields, models + +_logger = logging.getLogger(__name__) + + +class SupersetDashboardConfig(models.Model): + _name = "g2p.superset.dashboard.config" + _description = "Superset Dashboard Configuration" + + name = fields.Char(string="Dashboard Name", required=True) + url = fields.Char(string="Dashboard URL", required=True) + access_user_ids = fields.Many2many( + "res.users", + string="Access Rights", + ) + + @api.model_create_multi + def create(self, vals_list): + records = super().create(vals_list) + self.create_menus() + return records + + def write(self, vals): + res = super().write(vals) + self.create_menus() + return res + + def unlink(self): + res = super().unlink() + self.create_menus() + return res + + @api.model + def create_menus(self): + existing_menus = self.env["ir.ui.menu"].search( + [("parent_id", "=", self.env.ref("g2p_superset_dashboard.menu_superset_dashboard_embedded").id)] + ) + existing_menus.unlink() + + user = self.env.user + dashboards = self.search([("access_user_ids", "in", user.id)]) + # dashboards = self.search([]) + for dashboard in dashboards: + self.env["ir.actions.client"].create( + { + "name": dashboard.name, + "tag": "g2p.superset_dashboard_embedded", + "context": {"url": dashboard.url}, + } + ) + + # menu_item = self.env['ir.ui.menu'].create({ + # 'name': dashboard.name, + # 'parent_id': self.env.ref('g2p_superset_dashboard.menu_superset_dashboard_embedded').id, + # 'action': f"ir.actions.client,{action.id}", + # }) diff --git a/g2p_superset_dashboard/models/res_config_settings.py b/g2p_superset_dashboard/models/res_config_settings.py deleted file mode 100644 index fc163b4..0000000 --- a/g2p_superset_dashboard/models/res_config_settings.py +++ /dev/null @@ -1,35 +0,0 @@ -import re - -from odoo import api, fields, models -from odoo.exceptions import ValidationError - - -class ResConfigSettings(models.TransientModel): - _inherit = "res.config.settings" - - superset_url = fields.Char( - string="Superset URL", - config_parameter="g2p_superset_dashboard.superset_url", - ) - - def check_url(self, url): - url_pattern = re.compile( - r"^(?:http[s]?://)?(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+$", - re.IGNORECASE, - ) - if not url_pattern.match(url): - error_msg = "Invalid URL format. Please use a valid URL." - raise ValidationError(error_msg) - - @api.model_create_multi - def create(self, vals_list): - for vals in vals_list: - superset_url_value = vals.get("superset_url") - if superset_url_value: - self.check_url(superset_url_value) - self.env["ir.config_parameter"].sudo().set_param( - "g2p_superset_dashboard.superset_url", superset_url_value - ) - - result = super().create(vals_list) - return result diff --git a/g2p_superset_dashboard/static/description/dashboard_icon.png b/g2p_superset_dashboard/static/description/dashboard_icon.png new file mode 100644 index 0000000..93b1131 Binary files /dev/null and b/g2p_superset_dashboard/static/description/dashboard_icon.png differ diff --git a/g2p_superset_dashboard/static/src/components/dashboard/g2p_superset_dashboard.css b/g2p_superset_dashboard/static/src/components/dashboard/g2p_superset_dashboard.css index 1ea4a3e..d8bcec2 100644 --- a/g2p_superset_dashboard/static/src/components/dashboard/g2p_superset_dashboard.css +++ b/g2p_superset_dashboard/static/src/components/dashboard/g2p_superset_dashboard.css @@ -15,17 +15,3 @@ height: auto; animation: zoomInOut 3s infinite; } - -.fade-in-g2p { - animation: fadeInAnimation 0.5s ease-in-out forwards; - opacity: 0; -} - -@keyframes fadeInAnimation { - 0% { - opacity: 0; - } - 100% { - opacity: 1; - } -} diff --git a/g2p_superset_dashboard/static/src/components/dashboard/g2p_superset_dashboard.js b/g2p_superset_dashboard/static/src/components/dashboard/g2p_superset_dashboard.js new file mode 100644 index 0000000..abc2282 --- /dev/null +++ b/g2p_superset_dashboard/static/src/components/dashboard/g2p_superset_dashboard.js @@ -0,0 +1,36 @@ +/** @odoo-module */ +import {registry} from "@web/core/registry"; +import {Component, useState} from "@odoo/owl"; + +export class G2PSupersetDashboardEmbedded extends Component { + setup() { + this.state = useState({ + isLoading: true, + dashboards: [], + dashboardUrl: "", + }); + + const orm = this.env.services.orm; + this.loadDashboards(orm); + } + + async loadDashboards(orm) { + // Fetch dashboard configurations + const dashboardData = await orm.searchRead("g2p.superset.dashboard.config", [], ["name", "url"]); + this.state.dashboards = dashboardData; + + if (dashboardData.length > 0) { + this.state.dashboardUrl = dashboardData[0].url; + } + + this.state.isLoading = false; + } + + onDashboardSelect(event) { + const selectedUrl = event.target.value; + this.state.dashboardUrl = selectedUrl; + } +} + +G2PSupersetDashboardEmbedded.template = "g2p_superset_dashboard.G2PSupersetDashboardEmbedded"; +registry.category("actions").add("g2p.superset_dashboard_embedded", G2PSupersetDashboardEmbedded); diff --git a/g2p_superset_dashboard/static/src/components/dashboard/superset_dashboard.js b/g2p_superset_dashboard/static/src/components/dashboard/superset_dashboard.js deleted file mode 100644 index 57b0281..0000000 --- a/g2p_superset_dashboard/static/src/components/dashboard/superset_dashboard.js +++ /dev/null @@ -1,42 +0,0 @@ -/** @odoo-module */ -import {Component, useState, useSubEnv} from "@odoo/owl"; -import {getDefaultConfig} from "@web/views/view"; -import {registry} from "@web/core/registry"; - -export class G2PSupersetDashboard extends Component { - async setup() { - this.state = useState({ - isLoading: true, - cookieService: null, - }); - - useSubEnv({ - config: { - ...getDefaultConfig(), - ...this.env.config, - }, - }); - - const orm = this.env.services.orm; - this.getSupersetUrl(orm); - } - - async getSupersetUrl(orm) { - const data = await orm.searchRead( - "ir.config_parameter", - [["key", "=", "g2p_superset_dashboard.superset_url"]], - ["value"] - ); - - if (data && data.length > 0 && data[0].value) { - this.superSetUrl = data[0].value; - } else { - this.superSetUrl = false; - } - - this.state.isLoading = false; - } -} - -G2PSupersetDashboard.template = "g2p_superset_dashboard.G2PSupersetDashboard"; -registry.category("actions").add("g2p.superset_dashboard", G2PSupersetDashboard); diff --git a/g2p_superset_dashboard/static/src/components/dashboard/superset_dashboard_embedding_templates.xml b/g2p_superset_dashboard/static/src/components/dashboard/superset_dashboard_embedding_templates.xml new file mode 100644 index 0000000..41d43b2 --- /dev/null +++ b/g2p_superset_dashboard/static/src/components/dashboard/superset_dashboard_embedding_templates.xml @@ -0,0 +1,55 @@ + + + + + +
+ + Loading Superset Dashboard +
+
+ + + +
+
+ +
+
No Dashboards Available
+
+
+ + + +
+ +
+
+