Skip to content

Commit

Permalink
Add show/hide buttons to panels
Browse files Browse the repository at this point in the history
  • Loading branch information
arturboronat authored and barnettwilliam committed Dec 11, 2023
1 parent 3e73b18 commit 26fcee0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
13 changes: 11 additions & 2 deletions platform/src/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,17 @@ class Button {
this.action = "runAction( '" + parentPanel + "', '" + buttonConfigObject.id +"' )";

} else if (buttonConfigObject["internal"] != undefined) {
this.action = buttonConfigObject.internal;


if ((buttonConfigObject.targetPanel) && (buttonConfigObject.internal === "show" || buttonConfigObject.internal === "hide")) {
if (buttonConfigObject.internal === "hide") {
this.action = "hidePanelById( '" + buttonConfigObject.targetPanel + "Panel' )";
} else {
this.action = "showPanelById( '" + buttonConfigObject.targetPanel + "Panel' )";
}
} else {
this.action = buttonConfigObject.internal;
}

} else {
console.log( "Button '" + buttonConfigObject.id + "' with uknown key.");
}
Expand Down
21 changes: 20 additions & 1 deletion platform/src/Playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ function createPanelForDefinitionId(panel){
// No activity defined buttons
newPanel.addButtons( Button.createButtons( panelDefinition.buttons, panel.id));

} else if (panel.buttons != null && panelDefinition.buttons != null) {
} else if (panel.buttons != null && panelDefinition.buttons == null) {
// The activity has defined the buttons
let resolvedButtonConfigs = panel.buttons.map(btn =>{
let resolvedButton;
Expand Down Expand Up @@ -914,6 +914,23 @@ function runAction(source, sourceButton) {
longNotification("Executing program");
}



function hidePanelById(elementId) {
const panelElement = document.getElementById(elementId);
if (panelElement) {
$("#" + panelElement.parentElement.id).hide();
}
}

function showPanelById(elementId) {
const panelElement = document.getElementById(elementId);
if (panelElement) {
$("#" + panelElement.parentElement.id).show();
}
}


function notification(title, message, cls="light"){
const crossIcon = "<div class=\"default-icon-cross\" style=\"float:right\"></div>"
Metro.notify.create(crossIcon + "<b>" + title + "</b>" + "<br>" + message + "<br>", null, {keepOpen: true, cls: cls, width: 300});
Expand Down Expand Up @@ -1065,6 +1082,8 @@ async function checkEditorReady(statusUrl, editorInstanceUrl, editorPanelId, edi
window.fit = fit;
window.updateGutterVisibility = updateGutterVisibility;
window.runAction = runAction;
window.hidePanelById = hidePanelById;
window.showPanelById = showPanelById;
window.panels = panels;
window.savePanelContents = savePanelContents;
window.backend = backend;
Expand Down

0 comments on commit 26fcee0

Please sign in to comment.