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 #11 from EyuaelB/17.0-1.2
Browse files Browse the repository at this point in the history
Superset Dashboard - initial commit, IFrame integration with root menu
  • Loading branch information
shibu-narayanan committed Sep 2, 2024
2 parents 13b8082 + 22a7b84 commit 442fc29
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 2 deletions.
1 change: 1 addition & 0 deletions g2p_superset_dashboard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
11 changes: 9 additions & 2 deletions g2p_superset_dashboard/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
"license": "Other OSI approved licence",
"depends": ["base"],
"external_dependencies": {},
"data": [],
"assets": {},
"data": ["views/res_config_settings.xml", "views/superset_dashboard.xml"],
"assets": {
"web.assets_backend": [
"g2p_superset_dashboard/static/src/components/**/*.js",
"g2p_superset_dashboard/static/src/components/**/*.xml",
"g2p_superset_dashboard/static/src/components/**/*.css",
"g2p_superset_dashboard/static/src/components/**/*.scss",
],
},
}
1 change: 1 addition & 0 deletions g2p_superset_dashboard/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import res_config_settings
35 changes: 35 additions & 0 deletions g2p_superset_dashboard/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@keyframes zoomInOut {
0% {
transform: scale(1);
}
50% {
transform: scale(1.1); /* Zoom in */
}
100% {
transform: scale(1); /* Zoom out */
}
}

.loading-image-g2p-logo {
width: auto;
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,42 @@
/** @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);
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="g2p_superset_dashboard.G2PSupersetDashboard" class="fade-in">

<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>

<t t-elif="!state.isLoading and !superSetUrl">
<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;">Superset Dashboard URL not set</div>

</div>
</t>

<t t-else="!state.isLoading and superSetUrl">
<iframe t-att-src="superSetUrl" style="width:100%; height:100%;" />
</t>

</t>

</templates>
30 changes: 30 additions & 0 deletions g2p_superset_dashboard/views/res_config_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="superset_dashboard_res_config_settings_view_form" model="ir.ui.view">
<field name="name">res.config.settings.view.form.inherit.superset.dashboard</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="base.res_config_settings_view_form" />
<field name="priority" eval="2000" />
<field name="arch" type="xml">
<xpath expr="//form" position="inside">
<app
string="G2P Superset Dashboard Settings"
name="g2p_superset_dashboard_settings"
logo="/g2p_superset_dashboard/static/description/icon.png"
>
<block title="G2P Superset Dashboard Settings">
<setting
string="Superset Instance URL"
help="Enter the URL for your Superset instance to configure the dashboard. URL must start with 'http://' or 'https://'"
>

<field name="superset_url" placeholder="e.g. http://localhost:8088" />

</setting>

</block>
</app>
</xpath>
</field>
</record>
</odoo>
15 changes: 15 additions & 0 deletions g2p_superset_dashboard/views/superset_dashboard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="action_g2p_superset_dashboard" model="ir.actions.client">
<field name="name">Dashboard</field>
<field name="tag">g2p.superset_dashboard</field>
</record>

<menuitem
name="Dashboard"
id="menu_g2p_superset_dashboard"
sequence="1"
action="action_g2p_superset_dashboard"
web_icon="g2p_superset_dashboard,static/description/icon.png"
/>
</odoo>

0 comments on commit 442fc29

Please sign in to comment.