Skip to content

Commit

Permalink
Merge pull request #184 from lalithkota/17.0-develop
Browse files Browse the repository at this point in the history
Superset dashboard module copied latest for odoo-commons
  • Loading branch information
lalithkota committed Sep 6, 2024
2 parents a2e5a5f + 55ec5f8 commit 47aea4b
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 49 deletions.
8 changes: 8 additions & 0 deletions g2p_superset_dashboard/i18n/g2p_superset_dashboard.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
140 changes: 94 additions & 46 deletions g2p_superset_dashboard/models/g2p_superset_dashboard_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from odoo import api, fields, models
from odoo import fields, models

_logger = logging.getLogger(__name__)

Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@
src="/g2p_superset_dashboard/static/description/icon.png"
/>
</div>
<div style="color: red; font-size: 11px;">No Dashboards Available</div>
<div>
<p
style="color: red; font-size: 18px; font-weight: bold; font-family: Roboto; text-align: center; text-align-last: center;"
>No Dashboards Available</p>
<p
style="color: black; font-size: 14px; font-family:Roboto;"
>Try contacting Admin to configure new dashboards or give you access rights.</p>
</div>
</div>
</t>

Expand All @@ -36,9 +43,9 @@
<div>
<select
t-on-change="onDashboardSelect"
style="font-size: 24px; font-weight: bold; font-family: Roboto;"
style="font-size: 24px; font-weight: bold; font-family: Roboto; text-align: center; text-align-last: center;"
>
<t t-foreach="state.dashboards" t-as="dashboard" t-key="dashboard">
<t t-foreach="state.dashboards" t-as="dashboard" t-key="dashboard.id">
<option
t-att-value="dashboard.url"
t-esc="dashboard.name"
Expand Down

0 comments on commit 47aea4b

Please sign in to comment.