Skip to content

Commit

Permalink
Merge pull request #151 from mdenet/feature/composite-panel
Browse files Browse the repository at this point in the history
Updated composite panel
  • Loading branch information
barnettwilliam authored Dec 15, 2023
2 parents a547712 + 844db67 commit c859278
Show file tree
Hide file tree
Showing 13 changed files with 273 additions and 269 deletions.
20 changes: 20 additions & 0 deletions platform/public/common/utility.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@

"icon": "problems"

},

{
"id": "composite",

"name": "composite",

"panelclass": "CompositePanel",

"icon": "diagram"
},

{
"id": "output",

"name": "output",

"panelclass": "OutputPanel",

"icon": "console"
}
]
}
Expand Down
6 changes: 1 addition & 5 deletions platform/public/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
}

.editor {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
height: 100%;
width: 100%;
}

.info {
Expand Down
70 changes: 50 additions & 20 deletions platform/src/ActivityManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ActivityManager {
*/
resolvePanelReference(activityId, panelRef){

const foundPanel = this.activities[activityId].panels.find( pnl => pnl.id == panelRef );
const foundPanel = this.findPanel(panelRef,this.activities[activityId].panels);

if ( foundPanel != undefined && typeof foundPanel.id == "string" ){

Expand All @@ -94,6 +94,26 @@ class ActivityManager {
}
}

/**
* Required to search within CompositePanels
*
* @param {*} panelRef
* @param {*} panelList
* @returns
*/
findPanel(panelRef, panelList) {
for(let panel of panelList) {
if (panel.id == panelRef) return panel;
else {
if (panel.childPanels) {
const pnl = this.findPanel(panelRef, panel.childPanels)
if (pnl) return pnl;
}
}
}
return undefined;
}

/**
* Fetches all the activities from activitiesUrl
* and populates the activities array
Expand Down Expand Up @@ -326,6 +346,34 @@ class ActivityManager {
return null;
}



/* resolve panel refs recursively because of CompositePanels */
resolveRef(panelList) {
for ( let apanel of panelList ){

if (apanel.file != null) {
apanel.url = new URL( apanel.file, this.activitiesUrl).href;
let file = this.fetchFile(apanel.file);
apanel.file = file.content;
apanel.sha = file.sha;
};

// Resolve the panel definition reference
if ( typeof apanel.ref == "string" ){
const panelDef = this.accessPanelDef(apanel.ref);

if (panelDef != null){
apanel.ref = panelDef;
}
}

if (apanel.childPanels) {
this.resolveRef(apanel.childPanels);
}
}
}

/**
* Fetches the contents of the activity with the provided ID
*/
Expand All @@ -335,25 +383,7 @@ class ActivityManager {

var activity = this.activities[id];

for ( let apanel of activity.panels ){

if (apanel.file != null) {
apanel.url = new URL( apanel.file, this.activitiesUrl).href;
let file = this.fetchFile(apanel.file);
apanel.file = file.content;
apanel.sha = file.sha;
};

// Resolve the panel definition reference
if ( typeof apanel.ref == "string" ){

const panelDef = this.accessPanelDef(apanel.ref);

if (panelDef != null){
apanel.ref = panelDef;
}
}
}
this.resolveRef(activity.panels);

return activity;
}
Expand Down
9 changes: 7 additions & 2 deletions platform/src/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ class Button {
this.action = "runAction( '" + parentPanel + "', '" + buttonConfigObject.id +"' )";

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


if (buttonConfigObject.targetPanel && buttonConfigObject.internal === "toggle") {
this.action = "togglePanelById( '" + buttonConfigObject.targetPanel + "Panel' )";
} else {
this.action = buttonConfigObject.internal;
}

} else {
console.log( "Button '" + buttonConfigObject.id + "' with uknown key.");
}
Expand Down
93 changes: 93 additions & 0 deletions platform/src/CompositePanel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { Panel } from "./Panel.js";
import { Layout } from "./Layout.js";

class CompositePanel extends Panel {
childPanels = [];
constructor(id = "composite") {
super(id);
}

initialize(editor) {
super.initialize(editor)
this.childPanels.forEach(panel => {
panel.initialize(editor);
panel.parentComposite = this;
});
}

/**
* Check whether there are saveable changes to a child panels contents.
* @override
* @returns true if there are changes that can be saved.
*/
canSave(){
let childrenCanSave = false;

this.childPanels.forEach( (cp) => childrenCanSave = childrenCanSave || cp.canSave() );

return childrenCanSave;
}

/**
* @override
*/
save(fileHandler){
let savePromises = this.childPanels.map( (cp) => {
if (cp.canSave()) {
//save each child panel
return cp.save(fileHandler);
} else {
return null;
}
});
return Promise.all(savePromises);
}

addPanel(panel) {
this.childPanels.push(panel);
panel.parentComposite = this; // Set a reference to the parent CompositePanel
}

removePanel(panel) {
this.childPanels = this.childPanels.filter(p => p !== panel);
}



createElement() {
var root = document.createElement("div");
root.setAttribute("class", "compositePanel");
root.setAttribute("data-role", "panel");
root.setAttribute("id", this.id + "Panel");

root.style.display = "flex";
root.style.flexDirection = "column";
root.style.flex = "1";

var childElementList = []
if (this.childPanels) {
this.childPanels.forEach(childPanel => {
var childElement = childPanel.getElement();
childElementList.push(childElement);
});
}
const splitter = Layout.createHorizontalSplitter(childElementList);
splitter.setAttribute("class", "h-100");

root.appendChild(splitter);

return root;
}

fit() {
const panelElement = document.getElementById(this.id + "Panel");
panelElement.firstChild.style.height = "100%";

this.childPanels.forEach(panel => {
panel.fit();
});
}

}

export { CompositePanel };
8 changes: 6 additions & 2 deletions platform/src/ConsolePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ class ConsolePanel extends Panel {

constructor(id) {
super(id);
}

initialize(editor) {
super.initialize(editor)

this.editor.setReadOnly(true);
this.editor.setValue("", 1);

let buttons = [];
let clearButton = new Button(
{ id:"clear",
Expand Down Expand Up @@ -59,8 +63,8 @@ class ConsolePanel extends Panel {
root.setAttribute("id", this.id + "Panel");

var editor = document.createElement("div");
editor.setAttribute("id", this.id + "Editor");
editor.setAttribute("class", "editor");
editor.setAttribute("id", this.id + "Editor");

root.appendChild(editor);

Expand Down
19 changes: 0 additions & 19 deletions platform/src/MetamodelPanel.js

This file was deleted.

Loading

0 comments on commit c859278

Please sign in to comment.