Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #12 from klbtheprogrammer/17.0-1.2
Browse files Browse the repository at this point in the history
Embedding multiple superset dashboards into Odoo
  • Loading branch information
shibu-narayanan authored Sep 3, 2024
2 parents 5f61807 + f82a82e commit 617a37b
Show file tree
Hide file tree
Showing 16 changed files with 257 additions and 189 deletions.
5 changes: 2 additions & 3 deletions g2p_superset_dashboard/README.md
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.
10 changes: 8 additions & 2 deletions g2p_superset_dashboard/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion g2p_superset_dashboard/i18n/g2p_superset_dashboard.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
2 changes: 1 addition & 1 deletion g2p_superset_dashboard/models/__init__.py
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 g2p_superset_dashboard/models/g2p_superset_dashboard_config.py
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}",
# })
35 changes: 0 additions & 35 deletions g2p_superset_dashboard/models/res_config_settings.py

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
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);

This file was deleted.

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>

This file was deleted.

30 changes: 0 additions & 30 deletions g2p_superset_dashboard/views/res_config_settings.xml

This file was deleted.

15 changes: 0 additions & 15 deletions g2p_superset_dashboard/views/superset_dashboard.xml

This file was deleted.

Loading

0 comments on commit 617a37b

Please sign in to comment.