From b24e990ed5f20d3d402c5db592dc503301859162 Mon Sep 17 00:00:00 2001 From: EyuaelB Date: Thu, 29 Aug 2024 12:17:03 +0300 Subject: [PATCH] Superset Dashboard - initial commit Iframe integration with root menu --- g2p_superset_dashboard/__init__.py | 1 + g2p_superset_dashboard/__manifest__.py | 11 ++- g2p_superset_dashboard/models/__init__.py | 1 + .../models/res_config_settings.py | 35 +++++++++ .../dashboard/g2p_superset_dashboard.css | 31 ++++++++ .../dashboard/superset_dashboard.js | 74 +++++++++++++++++++ .../dashboard/superset_dashboard_view.xml | 46 ++++++++++++ .../views/res_config_settings.xml | 30 ++++++++ .../views/superset_dashboard.xml | 15 ++++ 9 files changed, 242 insertions(+), 2 deletions(-) create mode 100644 g2p_superset_dashboard/models/res_config_settings.py create mode 100644 g2p_superset_dashboard/static/src/components/dashboard/g2p_superset_dashboard.css create mode 100644 g2p_superset_dashboard/static/src/components/dashboard/superset_dashboard.js create mode 100644 g2p_superset_dashboard/static/src/components/dashboard/superset_dashboard_view.xml create mode 100644 g2p_superset_dashboard/views/res_config_settings.xml create mode 100644 g2p_superset_dashboard/views/superset_dashboard.xml diff --git a/g2p_superset_dashboard/__init__.py b/g2p_superset_dashboard/__init__.py index e69de29..0650744 100644 --- a/g2p_superset_dashboard/__init__.py +++ b/g2p_superset_dashboard/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/g2p_superset_dashboard/__manifest__.py b/g2p_superset_dashboard/__manifest__.py index 57e9954..6659072 100644 --- a/g2p_superset_dashboard/__manifest__.py +++ b/g2p_superset_dashboard/__manifest__.py @@ -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", + ], + }, } diff --git a/g2p_superset_dashboard/models/__init__.py b/g2p_superset_dashboard/models/__init__.py index e69de29..0deb68c 100644 --- a/g2p_superset_dashboard/models/__init__.py +++ b/g2p_superset_dashboard/models/__init__.py @@ -0,0 +1 @@ +from . import res_config_settings diff --git a/g2p_superset_dashboard/models/res_config_settings.py b/g2p_superset_dashboard/models/res_config_settings.py new file mode 100644 index 0000000..fc163b4 --- /dev/null +++ b/g2p_superset_dashboard/models/res_config_settings.py @@ -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 diff --git a/g2p_superset_dashboard/static/src/components/dashboard/g2p_superset_dashboard.css b/g2p_superset_dashboard/static/src/components/dashboard/g2p_superset_dashboard.css new file mode 100644 index 0000000..1ea4a3e --- /dev/null +++ b/g2p_superset_dashboard/static/src/components/dashboard/g2p_superset_dashboard.css @@ -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; + } +} diff --git a/g2p_superset_dashboard/static/src/components/dashboard/superset_dashboard.js b/g2p_superset_dashboard/static/src/components/dashboard/superset_dashboard.js new file mode 100644 index 0000000..6946184 --- /dev/null +++ b/g2p_superset_dashboard/static/src/components/dashboard/superset_dashboard.js @@ -0,0 +1,74 @@ +/** @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.getSupersertUrl(orm); + } + + async getSupersertUrl(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; + } + + async attemptLogin() { + try { + console.log(`this is the url ${this.superSetUrl}/api/v1/security/login`); + + const response = await fetch(`${this.superSetUrl}/api/v1/security/login`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + password: "tr17", + provider: "db", + refresh: true, + username: "tr17", + }), + credentials: "include", + }); + + if (!response.ok) { + throw new Error(`Login failed with status ${response.status}`); + } + + console.log(`The login API request is successful here is status ${response.status}`); + + const data = await response.json(); + return {success: data.success}; + } catch (error) { + console.error("Error during login:", error); + return {success: false}; + } + } +} + +G2PSupersetDashboard.template = "g2p_superset_dashboard.G2PSupersetDashboard"; +registry.category("actions").add("g2p.superset_dashboard", G2PSupersetDashboard); diff --git a/g2p_superset_dashboard/static/src/components/dashboard/superset_dashboard_view.xml b/g2p_superset_dashboard/static/src/components/dashboard/superset_dashboard_view.xml new file mode 100644 index 0000000..bb84ca6 --- /dev/null +++ b/g2p_superset_dashboard/static/src/components/dashboard/superset_dashboard_view.xml @@ -0,0 +1,46 @@ + + + + + + +
+ + + + + Loading Superset Dashboard +
+ +
+ + +
+
+ +
+ +
Superset Dashboard URL not set
+ +
+
+ + +