Skip to content

✨ Frontend: Expose inputs required property #5899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
af3a4f0
patchNode
odeimaiz May 30, 2024
7cf0459
retire exposedNodes
odeimaiz May 30, 2024
6fad4c6
"Input Required" button
odeimaiz May 30, 2024
3c20946
fixes
odeimaiz May 30, 2024
7c64098
minor
odeimaiz May 30, 2024
7c9a8b3
Merge branch 'master' into feature/fe-inputs-required
odeimaiz May 31, 2024
f1c3ba0
toggleInputRequired
odeimaiz May 31, 2024
99a1dc3
working
odeimaiz May 31, 2024
08634ef
minor
odeimaiz May 31, 2024
59cc0ad
minor
odeimaiz May 31, 2024
a015cd3
setRequired on label
odeimaiz May 31, 2024
0f3698b
minor
odeimaiz May 31, 2024
a69692d
evalRequired
odeimaiz May 31, 2024
e0b7b42
minor
odeimaiz May 31, 2024
3dd9f86
minor
odeimaiz May 31, 2024
b8fef19
changeInputsRequired
odeimaiz May 31, 2024
b345340
evalFieldRequired
odeimaiz May 31, 2024
4b12d6b
tooltip text
odeimaiz May 31, 2024
ac96071
minor
odeimaiz May 31, 2024
1fd1f9e
deepCloneObject
odeimaiz May 31, 2024
70fdd14
@elisabettai fixed text
odeimaiz May 31, 2024
1b433c3
tooltip also on field
odeimaiz May 31, 2024
f97df41
minor
odeimaiz May 31, 2024
e402e65
Merge branch 'master' into feature/fe-inputs-required
odeimaiz May 31, 2024
36514f0
Merge branch 'master' into feature/fe-inputs-required
odeimaiz May 31, 2024
5beaf4e
minor
odeimaiz May 31, 2024
fb61021
add "required" text to the description
odeimaiz May 31, 2024
ac4e6f7
Merge branch 'feature/fe-inputs-required' of github.com:odeimaiz/ospa…
odeimaiz May 31, 2024
136a8c9
more unused
odeimaiz Jun 3, 2024
6712969
backwards compatible
odeimaiz Jun 3, 2024
3fd620d
minor
odeimaiz Jun 3, 2024
fbcdc17
Merge branch 'master' into feature/fe-inputs-required
odeimaiz Jun 3, 2024
12764d3
Merge branch 'master' into feature/fe-inputs-required
odeimaiz Jun 3, 2024
b4f61b2
Merge branch 'master' into feature/fe-inputs-required
odeimaiz Jun 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,15 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
},

_reloadCards: function() {
this.__addNewStudyButtons();

const fetching = this._loadingResourcesBtn ? this._loadingResourcesBtn.getFetching() : false;
const visibility = this._loadingResourcesBtn ? this._loadingResourcesBtn.getVisibility() : "excluded";

this._resourcesContainer.setResourcesToList(this._resourcesList);
const cards = this._resourcesContainer.reloadCards("studiesList");
this.__configureCards(cards);

this.__addNewStudyButtons();

const loadMoreBtn = this.__createLoadMoreButton();
loadMoreBtn.set({
fetching,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ qx.Class.define("osparc.data.model.Node", {
this.setOutputs({});

this.__inputNodes = [];
this.__exposedNodes = [];

if (study) {
this.setStudy(study);
Expand Down Expand Up @@ -136,6 +135,12 @@ qx.Class.define("osparc.data.model.Node", {
event: "changeInputs"
},

inputsRequired: {
check: "Array",
init: [],
event: "changeInputsRequired"
},

outputs: {
check: "Object",
nullable: false,
Expand Down Expand Up @@ -228,7 +233,8 @@ qx.Class.define("osparc.data.model.Node", {
"fileUploaded": "qx.event.type.Event",
"showInLogger": "qx.event.type.Data",
"outputListChanged": "qx.event.type.Event",
"changeInputNodes": "qx.event.type.Event"
"changeInputNodes": "qx.event.type.Event",
"changeInputsRequired": "qx.event.type.Event"
},

statics: {
Expand Down Expand Up @@ -331,7 +337,6 @@ qx.Class.define("osparc.data.model.Node", {
members: {
__metaData: null,
__inputNodes: null,
__exposedNodes: null,
__settingsForm: null,
__posX: null,
__posY: null,
Expand Down Expand Up @@ -512,7 +517,8 @@ qx.Class.define("osparc.data.model.Node", {
}
this.setOutputData(nodeData.outputs);
this.addInputNodes(nodeData.inputNodes);
this.addOutputNodes(nodeData.outputNodes);
// backwards compatible
this.setInputsRequired(nodeData.inputsRequired || []);
},

populateStates: function(nodeData) {
Expand Down Expand Up @@ -875,43 +881,17 @@ qx.Class.define("osparc.data.model.Node", {
},
// !---- Input Nodes -----

// ----- Output Nodes -----
getOutputNodes: function() {
return this.__exposedNodes;
},

addOutputNodes: function(outputNodes) {
if (outputNodes) {
outputNodes.forEach(outputNode => {
this.addOutputNode(outputNode);
});
}
},

addOutputNode: function(outputNodeId) {
if (!this.__exposedNodes.includes(outputNodeId)) {
this.__exposedNodes.push(outputNodeId);
this.fireEvent("outputListChanged");
return true;
}
return false;
},

removeOutputNode: function(outputNodeId) {
const index = this.__exposedNodes.indexOf(outputNodeId);
toggleInputRequired: function(portId) {
const inputsRequired = this.getInputsRequired();
const index = inputsRequired.indexOf(portId);
if (index > -1) {
// remove node connection
this.__exposedNodes.splice(index, 1);
this.fireEvent("outputListChanged");
inputsRequired.splice(index, 1);
} else {
inputsRequired.push(portId);
}
return false;
},

isOutputNode: function(outputNodeId) {
const index = this.__exposedNodes.indexOf(outputNodeId);
return (index > -1);
this.setInputsRequired(inputsRequired);
this.fireEvent("changeInputsRequired");
},
// !---- Output Nodes -----

canNodeStart: function() {
return this.isDynamic() && ["idle", "failed"].includes(this.getStatus().getInteractive());
Expand Down Expand Up @@ -1532,6 +1512,7 @@ qx.Class.define("osparc.data.model.Node", {
inputsUnits: this.__getInputUnits(),
inputAccess: this.getInputAccess(),
inputNodes: this.getInputNodes(),
inputsRequired: this.getInputsRequired(),
thumbnail: this.getThumbnail(),
bootOptions: this.getBootOptions()
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,12 +676,11 @@ qx.Class.define("osparc.data.model.Workbench", {
if (node === null) {
continue;
}
this.__addInputOutputNodesAndEdges(node, nodeData.inputNodes, true);
this.__addInputOutputNodesAndEdges(node, nodeData.outputNodes, false);
this.__addInputOutputNodesAndEdges(node, nodeData.inputNodes);
}
},

__addInputOutputNodesAndEdges: function(node, inputOutputNodeIds, isInput) {
__addInputOutputNodesAndEdges: function(node, inputOutputNodeIds) {
if (inputOutputNodeIds) {
inputOutputNodeIds.forEach(inputOutputNodeId => {
const node1 = this.getNode(inputOutputNodeId);
Expand All @@ -690,11 +689,7 @@ qx.Class.define("osparc.data.model.Workbench", {
}
const edge = new osparc.data.model.Edge(null, node1, node);
this.addEdge(edge);
if (isInput) {
node.addInputNode(inputOutputNodeId);
} else {
node.addOutputNode(inputOutputNodeId);
}
node.addInputNode(inputOutputNodeId);
});
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ qx.Class.define("osparc.desktop.StudyEditor", {

study.openStudy()
.then(() => {
this.__lastSavedStudy = study.serialize();
this.__lastSavedStudy = osparc.utils.Utils.deepCloneObject(study.serialize());

this.__workbenchView.setStudy(study);
this.__slideshowView.setStudy(study);
Expand Down Expand Up @@ -761,7 +761,7 @@ qx.Class.define("osparc.desktop.StudyEditor", {
const newObj = this.getStudy().serialize();
return this.getStudy().updateStudy(newObj, run)
.then(() => {
this.__lastSavedStudy = osparc.wrapper.JsonDiffPatch.getInstance().clone(newObj);
this.__lastSavedStudy = osparc.utils.Utils.deepCloneObject(newObj);
})
.catch(error => {
if ("status" in error && error.status === 409) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ qx.Class.define("osparc.form.PortInfoHint", {
const color = qx.theme.manager.Color.getInstance().resolve("failed-red");
text += `<br><br><font color="${color}">${errorMsg}</font>`;
}
this._hint.setText(text);
this.setHintText(text);
this.set({
source: errorMsg ? this.self().ERROR_ICON : osparc.ui.hint.InfoHint.INFO_ICON,
textColor: errorMsg ? "failed-red" : "text"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ qx.Class.define("osparc.form.renderer.PropForm", {
});
});
}

if (optionsMenu.getChildren().length) {
optionsMenu.addSeparator();
}
const inputRequiredButton = this.__getInputRequiredButton(field.key);
optionsMenu.add(inputRequiredButton);
},

__connectToInputNode: function(targetPortId, inputNodeId, outputKey) {
Expand Down Expand Up @@ -342,6 +348,26 @@ qx.Class.define("osparc.form.renderer.PropForm", {
return null;
},

__populateInputNodePortsMenu: function(inputNodeId, targetPortId, menu, menuBtn) {
menuBtn.exclude();
menu.removeAll();

const inputNode = this.getStudy().getWorkbench().getNode(inputNodeId);
if (inputNode) {
for (const outputKey in inputNode.getOutputs()) {
osparc.utils.Ports.arePortsCompatible(inputNode, outputKey, this.getNode(), targetPortId)
.then(compatible => {
if (compatible) {
const paramButton = new qx.ui.menu.Button(inputNode.getOutput(outputKey).label);
paramButton.addListener("execute", () => this.__connectToInputNode(targetPortId, inputNodeId, outputKey), this);
menu.add(paramButton);
menuBtn.show();
}
});
}
}
},

__getSelectFileButton: function(portId) {
const selectFileButton = new qx.ui.menu.Button(this.tr("Select File"));
selectFileButton.addListener("execute", () => this.fireDataEvent("filePickerRequested", {
Expand All @@ -366,26 +392,6 @@ qx.Class.define("osparc.form.renderer.PropForm", {
return existingParamBtn;
},

__populateInputNodePortsMenu: function(inputNodeId, targetPortId, menu, menuBtn) {
menuBtn.exclude();
menu.removeAll();

const inputNode = this.getStudy().getWorkbench().getNode(inputNodeId);
if (inputNode) {
for (const outputKey in inputNode.getOutputs()) {
osparc.utils.Ports.arePortsCompatible(inputNode, outputKey, this.getNode(), targetPortId)
.then(compatible => {
if (compatible) {
const paramButton = new qx.ui.menu.Button(inputNode.getOutput(outputKey).label);
paramButton.addListener("execute", () => this.__connectToInputNode(targetPortId, inputNodeId, outputKey), this);
menu.add(paramButton);
menuBtn.show();
}
});
}
}
},

__populateExistingParamsMenu: function(targetPortId, menu, menuBtn) {
menuBtn.exclude();
menu.removeAll();
Expand All @@ -410,6 +416,26 @@ qx.Class.define("osparc.form.renderer.PropForm", {
});
},

__getInputRequiredButton: function(portId) {
const node = this.getNode();
const inputRequiredBtn = new qx.ui.menu.Button(this.tr("Required Input"));
const evalButton = () => {
if (node.getInputsRequired().includes(portId)) {
inputRequiredBtn.set({
icon: "@FontAwesome5Regular/check-square/12"
});
} else {
inputRequiredBtn.set({
icon: "@FontAwesome5Regular/square/12"
});
}
}
node.addListener("changeInputsRequired", () => evalButton(), this);
inputRequiredBtn.addListener("execute", () => node.toggleInputRequired(portId), this);
evalButton();
return inputRequiredBtn;
},

// overridden
addItems: function(items, names, title, itemOptions, headerOptions) {
this.base(arguments, items, names, title, itemOptions, headerOptions);
Expand All @@ -419,6 +445,7 @@ qx.Class.define("osparc.form.renderer.PropForm", {

for (let i = 0; i < items.length; i++) {
const item = items[i];
const portId = item.key;

const fieldOpts = this.__createLinkUnlinkStack(item);
if (fieldOpts) {
Expand All @@ -428,10 +455,10 @@ qx.Class.define("osparc.form.renderer.PropForm", {
});
}

this.__createDropMechanism(item, item.key);
this.__createDropMechanism(item, portId);

// Notify focus and focus out
const msgDataFn = (nodeId, portId) => this.__arePortsCompatible(nodeId, portId, this.getNode().getNodeId(), item.key);
const msgDataFn = (nodeId, pId) => this.__arePortsCompatible(nodeId, pId, this.getNode().getNodeId(), item.key);

item.addListener("focus", () => {
if (this.getNode()) {
Expand All @@ -447,6 +474,14 @@ qx.Class.define("osparc.form.renderer.PropForm", {
row++;
}

const evalRequired = () => {
for (const portId in this.__ctrlLinkMap) {
this.evalFieldRequired(portId);
}
}
this.getNode().addListener("changeInputsRequired", () => evalRequired());
evalRequired();

// add port button
const addPortButton = this.__addInputPortButton = new qx.ui.form.Button().set({
label: this.tr("Input"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ qx.Class.define("osparc.form.renderer.PropFormBase", {

const label = this._createLabel(names[i], item);
label.set({
rich: false, // override, required for showing the vut off ellipses
rich: false, // override, required for showing the cut off ellipses
toolTipText: names[i]
});
label.setBuddy(item);
Expand Down Expand Up @@ -191,6 +191,38 @@ qx.Class.define("osparc.form.renderer.PropFormBase", {
return filteredData;
},

evalFieldRequired: function(portId) {
const label = this._getLabelFieldChild(portId).child;
const inputsRequired = this.getNode().getInputsRequired();

// add star (*) to the label
const requiredSuffix = " *";
let newLabel = label.getValue();
newLabel = newLabel.replace(requiredSuffix, "");
if (inputsRequired.includes(portId)) {
newLabel += requiredSuffix;
}
label.setValue(newLabel);

// add "required" text to the label's tooltip
const toolTipSuffix = "<br>" + this.tr("Required input: without it, the service will not start/run.");
let newToolTip = label.getToolTipText();
newToolTip = newToolTip.replace(toolTipSuffix, "");
if (inputsRequired.includes(portId)) {
newToolTip += toolTipSuffix;
}
label.setToolTipText(newToolTip);

// add "required" text to the description
const infoButton = this._getInfoFieldChild(portId).child;
let newHintText = infoButton.getHintText();
newHintText = newHintText.replace(toolTipSuffix, "");
if (inputsRequired.includes(portId)) {
newHintText += toolTipSuffix;
}
infoButton.setHintText(newHintText);
},

getChangedXUnits: function() {
const xUnits = {};
const ctrls = this._form.getControls();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ qx.Class.define("osparc.widget.NodeOptions", {
const startStopButton = new osparc.node.StartStopButton();
startStopButton.setNode(node);
this._add(startStopButton);

startStopButton.getChildControl("stop-button").bind("visibility", instructions, "visibility");
}

sections.forEach(section => this._add(section));
Expand Down
Loading