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 #11 from EyuaelB/17.0-1.2
Superset Dashboard - initial commit, IFrame integration with root menu
- Loading branch information
Showing
9 changed files
with
210 additions
and
2 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import res_config_settings |
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,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 |
31 changes: 31 additions & 0 deletions
31
g2p_superset_dashboard/static/src/components/dashboard/g2p_superset_dashboard.css
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,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; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
g2p_superset_dashboard/static/src/components/dashboard/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,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); |
46 changes: 46 additions & 0 deletions
46
g2p_superset_dashboard/static/src/components/dashboard/superset_dashboard_view.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,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> |
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,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> |
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,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> |