Skip to content

Commit

Permalink
Merge pull request #1880 from cvisionai/dev/fix-applet-init
Browse files Browse the repository at this point in the history
Wait for custom element definition before using applet
  • Loading branch information
jrtcppv authored Nov 21, 2024
2 parents 7cd55e4 + 6784a21 commit 2071b43
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 27 deletions.
3 changes: 2 additions & 1 deletion api/main/kube.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ def start_algorithm(
# Add in workflow parameters.
existing_params = manifest["spec"].get("arguments", {}).get("parameters", [])
manifest["spec"]["arguments"] = {
"parameters": existing_params + [
"parameters": existing_params
+ [
{
"name": "name",
"value": self.alg.name,
Expand Down
62 changes: 36 additions & 26 deletions ui/src/js/annotation/tools-applet-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,37 +93,47 @@ export class ToolsAppletPanel extends TatorElement {
initApplet() {
// if (this._appletData == null) { return; }

this._appletElement =
const appletElement =
this._appletView.contentWindow.document.getElementById("toolsApplet");
if (this._appletElement == null) {
if (appletElement == null) {
return;
}

this._appletElement.addEventListener(
"closeApplet",
this.togglePanel.bind(this)
);

// Listen for html registration, and page event with svg as detail
this._appletElement.addEventListener("icon-ready", (evt) => {
if (this._appletTrigger !== null && evt.detail.icon !== null) {
this._appletTrigger.setIcon(evt.detail.icon);
} else {
console.warn(
"Event icon ready heard, but not enough data to set icon."
const appletTagName = appletElement.tagName.toLowerCase();
this._appletView.contentWindow.customElements
.whenDefined(appletTagName)
.then(() => {
this._appletElement =
this._appletView.contentWindow.document.getElementById("toolsApplet");
if (this._appletElement == null) {
return;
}

this._appletElement.addEventListener(
"closeApplet",
this.togglePanel.bind(this)
);
}
});

// RUN THIS LAST! listeners need to be in place above first
this._appletElement.init({
canvas: this._canvas,
canvasElement: this._canvasElement,
data: this._page._data,
});

//
this.dispatchEvent(new Event("appletReady"));
// Listen for html registration, and page event with svg as detail
this._appletElement.addEventListener("icon-ready", (evt) => {
if (this._appletTrigger !== null && evt.detail.icon !== null) {
this._appletTrigger.setIcon(evt.detail.icon);
} else {
console.warn(
"Event icon ready heard, but not enough data to set icon."
);
}
});

// RUN THIS LAST! listeners need to be in place above first
this._appletElement.init({
canvas: this._canvas,
canvasElement: this._canvasElement,
data: this._page._data,
});

//
this.dispatchEvent(new Event("appletReady"));
});
}
}

Expand Down

0 comments on commit 2071b43

Please sign in to comment.