From 55ec5f848dda28d8abf6119a8376b9a52b05b5a6 Mon Sep 17 00:00:00 2001 From: Lalith Kota Date: Sat, 7 Sep 2024 03:09:33 +0530 Subject: [PATCH] Superset dashboard module copied latest for odoo-commons Signed-off-by: Lalith Kota --- .../i18n/g2p_superset_dashboard.pot | 8 + .../models/g2p_superset_dashboard_config.py | 140 ++++++++++++------ ...superset_dashboard_embedding_templates.xml | 13 +- 3 files changed, 112 insertions(+), 49 deletions(-) diff --git a/g2p_superset_dashboard/i18n/g2p_superset_dashboard.pot b/g2p_superset_dashboard/i18n/g2p_superset_dashboard.pot index d054cd5..f9528c1 100644 --- a/g2p_superset_dashboard/i18n/g2p_superset_dashboard.pot +++ b/g2p_superset_dashboard/i18n/g2p_superset_dashboard.pot @@ -98,3 +98,11 @@ msgstr "" #: model:ir.ui.menu,name:g2p_superset_dashboard.menu_superset_dashboard_embedded msgid "Superset Dashboards" msgstr "" + +#. module: g2p_superset_dashboard +#. odoo-javascript +#: code:addons/g2p_superset_dashboard/static/src/components/dashboard/superset_dashboard_embedding_templates.xml:0 +#, python-format +msgid "" +"Try contacting Admin to configure new dashboards or give you access rights." +msgstr "" diff --git a/g2p_superset_dashboard/models/g2p_superset_dashboard_config.py b/g2p_superset_dashboard/models/g2p_superset_dashboard_config.py index fbf16dd..c39d5e6 100644 --- a/g2p_superset_dashboard/models/g2p_superset_dashboard_config.py +++ b/g2p_superset_dashboard/models/g2p_superset_dashboard_config.py @@ -1,6 +1,6 @@ import logging -from odoo import api, fields, models +from odoo import fields, models _logger = logging.getLogger(__name__) @@ -11,48 +11,96 @@ class SupersetDashboardConfig(models.Model): 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}", - # }) + access_user_ids = fields.Many2many("res.users", string="Access Rights") + + +# *** USE CODE BELOW TO EMBED SUPERSET DASHBOARD IN ODOO MENUITEMS. *** +# THIS MAY SLOW PERFORMANCE OF ODOO SINCE IT WILL BE CREATING MENUITEMS AND ACTIONS FOR EACH DASHBOARDS. + + +# Override create method to regenerate menus when new dashboards are created.s +# @api.model_create_multi +# def create(self, vals_list): +# records = super().create(vals_list) +# self._create_or_update_menus(records) +# return records + +# # Override write method to regenerate menus when dashboards are updated. +# def write(self, vals): +# res = super().write(vals) +# self._create_or_update_menus(self) +# return res + +# # Override unlink method to delete menus related to the dashboards being deleted. +# def unlink(self): +# dashboard_names = self.mapped("name") +# res = super().unlink() +# self._delete_menus(dashboard_names) +# return res + +# # Create or update the menus for the provided dashboards. +# def _create_or_update_menus(self, dashboards): +# try: +# for dashboard in dashboards: +# existing_menu = self.env["ir.ui.menu"].search([ +# ("parent_id", "=", self.env.ref( +# "g2p_superset_dashboard.menu_superset_dashboard_embedded").id), +# ("name", "=", dashboard.name) +# ]) +# existing_menu.unlink() + +# action = self.env["ir.actions.client"].create({ +# "name": dashboard.name, +# "tag": "g2p_superset_dashboard_embedded", +# "context": {"url": dashboard.url}, +# }) + +# 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}", +# }) + +# _logger.info(f"Menu for dashboard '{dashboard.name}' created/updated successfully.") +# except Exception as e: +# _logger.error(f"Error while creating/updating menus: {e}") +# raise + +# # Delete the menus associated with the dashboards being deleted. +# # def _delete_menus(self, dashboard_names): +# # try: +# menus_to_delete = self.env["ir.ui.menu"].search([ +# ("parent_id", "=", self.env.ref( +# "g2p_superset_dashboard.menu_superset_dashboard_embedded").id), +# ("name", "in", dashboard_names) +# ]) +# # if menus_to_delete: +# menus_to_delete.unlink() +# _logger.info(f"Menus for dashboards {dashboard_names} deleted successfully.") +# else: +# _logger.info(f"No menus found for dashboards {dashboard_names} to delete.") +# except Exception as e: +# _logger.error(f"Error while deleting menus: {e}") +# raise + +# # Regenerates all menus for the dashboards. +# # @api.model +# # def create_menus(self): +# # try: +# # # Clear all existing dynamic menus +# existing_menus = self.env["ir.ui.menu"].search([ +# ("parent_id", "=", self.env.ref( +# "g2p_superset_dashboard.menu_superset_dashboard_embedded").id) +# ]) +# # existing_menus.unlink() + +# # Fetch all dashboards +# dashboards = self.search([]) + +# # Create or update menus for all dashboards +# self._create_or_update_menus(dashboards) + +# except Exception as e: +# _logger.error(f"Error while regenerating all menus: {e}") +# raise 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 index 19f83e0..eee6b20 100644 --- 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 @@ -27,7 +27,14 @@ src="/g2p_superset_dashboard/static/description/icon.png" /> -
No Dashboards Available
+
+

No Dashboards Available

+

Try contacting Admin to configure new dashboards or give you access rights.

+
@@ -36,9 +43,9 @@