From 3b74c9a8d27d0c8a12bd24f6b2f07393b317c2a5 Mon Sep 17 00:00:00 2001 From: imedina Date: Tue, 3 Dec 2024 02:20:32 +0000 Subject: [PATCH] core: add initial jupyter-notebook component --- src/core/clients/opencga/opencga-client.js | 30 ++--- src/sites/iva/conf/config.js | 14 +-- src/sites/iva/iva-app.js | 8 ++ .../commons/analysis/jupyter-notebook.js | 106 ++++++++++++++++++ .../commons/layout/layout-primary-bar.js | 69 ++++++++++-- .../commons/layout/layout-sidebar.js | 11 +- 6 files changed, 204 insertions(+), 34 deletions(-) create mode 100644 src/webcomponents/commons/analysis/jupyter-notebook.js diff --git a/src/core/clients/opencga/opencga-client.js b/src/core/clients/opencga/opencga-client.js index 58d788702..f4b3ecfed 100644 --- a/src/core/clients/opencga/opencga-client.js +++ b/src/core/clients/opencga/opencga-client.js @@ -511,21 +511,21 @@ export class OpenCGAClient { // Fetch the Workflows for each Study console.log("Fetching Workflows"); - const workflowPromises = []; - for (const study of studies) { - const promise = this.workflows() - .search({ - study: study, - limit: 1000, - }); - workflowPromises.push(promise); - } - const workflowResponses = await Promise.all(workflowPromises); - for (let i = 0, t = 0; i < session.projects.length; i++) { - for (let x = 0; x < session.projects[i].studies.length; x++, t++) { - session.projects[i].studies[x].workflows = workflowResponses[t].getResults(); - } - } + // const workflowPromises = []; + // for (const study of studies) { + // const promise = this.workflows() + // .search({ + // study: study, + // limit: 1000, + // }); + // workflowPromises.push(promise); + // } + // const workflowResponses = await Promise.all(workflowPromises); + // for (let i = 0, t = 0; i < session.projects.length; i++) { + // for (let x = 0; x < session.projects[i].studies.length; x++, t++) { + // session.projects[i].studies[x].workflows = workflowResponses[t].getResults(); + // } + // } } resolve(session); } catch (e) { diff --git a/src/sites/iva/conf/config.js b/src/sites/iva/conf/config.js index 5a6ed8565..872927882 100644 --- a/src/sites/iva/conf/config.js +++ b/src/sites/iva/conf/config.js @@ -26,7 +26,7 @@ const hosts = [ }, { id: "reference", - url: "https://test.app.zettagenomics.com/TASK-6445/opencga" + url: "https://test.app.zettagenomics.com/TASK-6757a/opencga" }, ]; @@ -521,16 +521,16 @@ const SUITE = { about: { dropdown: true, links: [ - {id: "code", name: "Source code", url: "https://github.com/opencb/iva", icon: "fa fa-code"}, - {id: "documentation", name: "Documentation", url: "http://docs.opencb.org/display/iva", icon: "fa fa-book"}, - {id: "tutorial", name: "Tutorial", url: "http://docs.opencb.org/display/iva/Tutorials", icon: "fa fa-question-circle"}, - {id: "releases", name: "Releases", url: "https://github.com/opencb/iva/releases", icon: "fa fa-archive"}, + // {id: "code", name: "Source code", url: "https://github.com/opencb/iva", icon: "fa fa-code"}, + // {id: "documentation", name: "Documentation", url: "http://docs.opencb.org/display/iva", icon: "fa fa-book"}, + // {id: "tutorial", name: "Tutorial", url: "http://docs.opencb.org/display/iva/Tutorials", icon: "fa fa-question-circle"}, + // {id: "releases", name: "Releases", url: "https://github.com/opencb/iva/releases", icon: "fa fa-archive"}, {id: "about", name: "About", url: "#about", icon: "fa fa-info-circle"}, {id: "terms", name: "Terms", url: "#terms", icon: "fa fa-file-alt"}, {id: "contact", name: "Contact", url: "#contact", icon: "fa fa-envelope"}, {id: "faq", name: "FAQ", url: "#faq", icon: "fa fa-question"}, - {id: "rest-api", name: "OpenCGA REST API", icon: "fas fa-book-open"}, - {id: "getting-started", name: "Getting Started", tab: false, url: "#getting-started", icon: "fa fa-book"} + // {id: "rest-api", name: "OpenCGA REST API", icon: "fas fa-book-open"}, + // {id: "getting-started", name: "Getting Started", tab: false, url: "#getting-started", icon: "fa fa-book"} ] }, fileExplorer: { diff --git a/src/sites/iva/iva-app.js b/src/sites/iva/iva-app.js index e0e56109c..6bdb21132 100644 --- a/src/sites/iva/iva-app.js +++ b/src/sites/iva/iva-app.js @@ -74,6 +74,7 @@ import "../../webcomponents/user/user-profile.js"; import "../../webcomponents/api/rest-api.js"; import "../../webcomponents/note/note-browser.js"; import "../../webcomponents/commons/analysis/analysis-tools.js"; +import "../../webcomponents/commons/analysis/jupyter-notebook.js"; import "../../webcomponents/commons/layouts/custom-footer.js"; import "../../webcomponents/commons/layouts/custom-navbar.js"; @@ -1606,6 +1607,13 @@ class IvaApp extends LitElement { `; break; + case "jupyter-notebook": + content = html` + + + `; + break; default: // TODO: check for extensions // ExtensionsManager.getTools().map(tool => html` diff --git a/src/webcomponents/commons/analysis/jupyter-notebook.js b/src/webcomponents/commons/analysis/jupyter-notebook.js new file mode 100644 index 000000000..a0f6b813e --- /dev/null +++ b/src/webcomponents/commons/analysis/jupyter-notebook.js @@ -0,0 +1,106 @@ +/* + * Copyright 2015-2016 OpenCB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {LitElement, html} from "lit"; +import UtilsNew from "../../../core/utils-new.js"; +import {guardPage} from "../html-utils.js"; +import "../../text-icon.js"; +import "./opencga-analysis-tool-form.js"; + +export default class JupyterNotebook extends LitElement { + + constructor() { + super(); + + this._init(); + } + + createRenderRoot() { + return this; + } + + static get properties() { + return { + opencgaSession: { + type: Object + }, + config: { + type: Object + } + }; + } + + _init() { + this._prefix = UtilsNew.randomString(8); + } + + connectedCallback() { + super.connectedCallback(); + } + + update(changedProperties) { + if (changedProperties.has("config")) { + this._config = { + ...this.config + }; + // this.requestUpdate(); + } + super.update(changedProperties); + } + + onAnalysisRun(e) { + // Execute function provided in the configuration + /* if (this.analysisClass.execute) { + this.analysisClass.execute(this.opencgaSession, e.detail.data, e.detail.params); + } else { + console.error(`No execute() function provided for analysis: ${this._config.id}`) + }*/ + + // TODO NOTE onAnalysisRun at the moment just forwards the `analysisRun` event fired in opencga-analysis-tool-form + this.dispatchEvent(new CustomEvent("execute", { + detail: e.detail + })); + } + + render() { + // Check Project exists + if (!this.opencgaSession.study) { + return guardPage("No OpenCGA study available to run an analysis. Please login to continue."); + } + + const userId = this.opencgaSession.user.id; + const organizationId = this.opencgaSession.organization.id; + const serverUrl = this.opencgaSession.server.host.replace("/opencga", ""); + const jupyterLoginUrl = serverUrl + "/jupyter/hub/login"; + const token = this.opencgaSession.token; + debugger + return html` +
+ +
+ +
+ + +
+ `; + } + +} + +customElements.define("jupyter-notebook", JupyterNotebook); diff --git a/src/webcomponents/commons/layout/layout-primary-bar.js b/src/webcomponents/commons/layout/layout-primary-bar.js index 0fd75851d..6f7367c38 100644 --- a/src/webcomponents/commons/layout/layout-primary-bar.js +++ b/src/webcomponents/commons/layout/layout-primary-bar.js @@ -1,3 +1,4 @@ + import {html, LitElement, nothing} from "lit"; import UtilsNew from "../../../core/utils-new.js"; import LitUtils from "../utils/lit-utils.js"; @@ -30,6 +31,16 @@ export default class LayoutPrimaryBar extends LitElement { }; } + onSearch(e) { + const value = document.querySelector("#PrimaryBarInputSearch")?.value; + if (value?.length > 3) { + // if (value.include(":")) { + // + // } + } + debugger + } + onStudySelect(e, study) { LitUtils.dispatchCustomEvent(this, "studySelect", "", {event: e, study: study}, null); } @@ -74,7 +85,6 @@ export default class LayoutPrimaryBar extends LitElement { `)} - ${this.renderSeparator()} `; } return nothing; @@ -85,14 +95,57 @@ export default class LayoutPrimaryBar extends LitElement {