This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from klbtheprogrammer/17.0-1.2
Embedding multiple superset dashboards into Odoo
- Loading branch information
Showing
16 changed files
with
257 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from . import res_config_settings | ||
from . import g2p_superset_dashboard_config |
58 changes: 58 additions & 0 deletions
58
g2p_superset_dashboard/models/g2p_superset_dashboard_config.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}", | ||
# }) |
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
g2p_superset_dashboard/static/src/components/dashboard/g2p_superset_dashboard.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
42 changes: 0 additions & 42 deletions
42
g2p_superset_dashboard/static/src/components/dashboard/superset_dashboard.js
This file was deleted.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
...rset_dashboard/static/src/components/dashboard/superset_dashboard_embedding_templates.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<templates xml:space="preserve" id="G2PSupersetDashboardEmbedded"> | ||
<t t-name="g2p_superset_dashboard.G2PSupersetDashboardEmbedded"> | ||
<!-- Loading State --> | ||
<t t-if="state.isLoading"> | ||
<div | ||
style="display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100vh;" | ||
> | ||
<div class="loading-image-g2p-logo"> | ||
<img | ||
style="max-height: 70px; max-width: 70px;" | ||
src="/g2p_superset_dashboard/static/description/icon.png" | ||
/> | ||
</div> | ||
<span style="font-size: 11px">Loading Superset Dashboard</span> | ||
</div> | ||
</t> | ||
|
||
<!-- No Dashboards Available --> | ||
<t t-elif="!state.isLoading and !state.dashboards.length"> | ||
<div | ||
style="display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100vh;" | ||
> | ||
<div> | ||
<img | ||
style="max-height: 70px; max-width: 70px;" | ||
src="/g2p_superset_dashboard/static/description/icon.png" | ||
/> | ||
</div> | ||
<div style="color: red; font-size: 11px;">No Dashboards Available</div> | ||
</div> | ||
</t> | ||
|
||
<!-- Dashboard Selection and Embedding --> | ||
<t t-else=""> | ||
<div> | ||
<select | ||
t-on-change="onDashboardSelect" | ||
style="font-size: 24px; font-weight: bold; font-family: Roboto;" | ||
> | ||
<t t-foreach="state.dashboards" t-as="dashboard" t-key="dashboard"> | ||
<option | ||
t-att-value="dashboard.url" | ||
t-esc="dashboard.name" | ||
style="font-size: 16px; font-weight: bold; font-family: Roboto;" | ||
/> | ||
</t> | ||
</select> | ||
</div> | ||
<div> | ||
<iframe t-att-src="state.dashboardUrl" style="width:100%; height:100vh;"/> | ||
</div> | ||
</t> | ||
</t> | ||
</templates> |
46 changes: 0 additions & 46 deletions
46
g2p_superset_dashboard/static/src/components/dashboard/superset_dashboard_view.xml
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.