Skip to content

Commit 290163b

Browse files
committed
enh
1 parent ddc3e74 commit 290163b

File tree

1 file changed

+44
-34
lines changed
  • services/static-webserver/client/source/class/osparc/form/renderer

1 file changed

+44
-34
lines changed

services/static-webserver/client/source/class/osparc/form/renderer/PropForm.js

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -135,58 +135,68 @@ qx.Class.define("osparc.form.renderer.PropForm", {
135135
/*
136136
* <-- Dynamic inputs -->
137137
*/
138-
__getEmptyDataLastPorts: function() {
139-
let emptyDataPorts = [];
140-
const minVisibleInputs = this.getNode().getMinVisibleInputs();
141-
if (minVisibleInputs === null) {
142-
return emptyDataPorts;
143-
}
138+
//
139+
__getHideablePorts: function() {
140+
const hideablePorts = [];
144141
const portIds = this.getPortIds();
145-
// it will always show 1 more, so: -1
146-
for (let i=minVisibleInputs-1; i<portIds.length; i++) {
142+
// if there is no minVisibleInputs defined, make at least 4 visible
143+
const minVisibleInputs = this.getNode().getMinVisibleInputs() || 4;
144+
// start from the last port and check the port types
145+
// if all last ports are the same type, then mark them as hideable
146+
let hideablePortType = null;
147+
for (let i=portIds.length-1; i>=minVisibleInputs; i--) {
147148
const portId = portIds[i];
148149
const ctrl = this._form.getControl(portId);
149-
if (ctrl && ctrl.type.includes("data:") && !("link" in ctrl)) {
150-
emptyDataPorts.push(portId);
150+
if (ctrl && hideablePortType === null) {
151+
hideablePortType = ctrl.type;
152+
}
153+
if (ctrl &&
154+
ctrl.type === hideablePortType &&
155+
// make sure it's not linked
156+
!("link" in ctrl)
157+
) {
158+
hideablePorts.unshift(portId);
151159
} else {
152-
emptyDataPorts = [];
160+
break;
153161
}
154162
}
155-
return emptyDataPorts;
163+
console.log("hideablePorts", hideablePorts);
164+
return hideablePorts;
156165
},
157166

158-
__getVisibleEmptyDataLastPort: function() {
159-
let emptyDataPorts = null;
160-
this.getPortIds().forEach(portId => {
161-
const ctrl = this._form.getControl(portId);
167+
__getVisibleEmptyLastPort: function() {
168+
let emptyPorts = null;
169+
const hideablePorts = this.__getHideablePorts();
170+
for (let i=hideablePorts.length-1; i>=0; i--) {
171+
const portId = hideablePorts[i]
162172
const label = this._getLabelFieldChild(portId).child;
163173
if (
164-
ctrl && ctrl.type.includes("data:") && !("link" in ctrl) &&
165-
label && label.isVisible()
174+
label && label.isVisible() &&
175+
emptyPorts === null
166176
) {
167-
emptyDataPorts = portId;
177+
emptyPorts = portId;
168178
}
169-
});
170-
return emptyDataPorts;
179+
}
180+
return emptyPorts;
171181
},
172182

173183
__addInputPortButtonClicked: function() {
174-
const emptyDataPorts = this.__getEmptyDataLastPorts();
175-
const lastEmptyDataPort = this.__getVisibleEmptyDataLastPort();
176-
if (emptyDataPorts.length>1 && lastEmptyDataPort) {
177-
const idx = emptyDataPorts.indexOf(lastEmptyDataPort);
178-
if (idx+1 < emptyDataPorts.length) {
179-
this.__showPort(emptyDataPorts[idx+1]);
184+
const emptyPorts = this.__getHideablePorts();
185+
const lastEmptyPort = this.__getVisibleEmptyLastPort();
186+
if (emptyPorts.length>1 && lastEmptyPort) {
187+
const idx = emptyPorts.indexOf(lastEmptyPort);
188+
if (idx+1 < emptyPorts.length) {
189+
this.__showPort(emptyPorts[idx+1]);
180190
}
181191
this.__addInputPortButton.setVisibility(this.__checkAddInputPortButtonVisibility());
182192
}
183193
},
184194

185195
__checkAddInputPortButtonVisibility: function() {
186-
const emptyDataPorts = this.__getEmptyDataLastPorts();
187-
const lastEmptyDataPort = this.__getVisibleEmptyDataLastPort();
188-
const idx = emptyDataPorts.indexOf(lastEmptyDataPort);
189-
if (idx < emptyDataPorts.length-1) {
196+
const emptyPorts = this.__getHideablePorts();
197+
const lastEmptyPort = this.__getVisibleEmptyLastPort();
198+
const idx = emptyPorts.indexOf(lastEmptyPort);
199+
if (idx < emptyPorts.length-1) {
190200
return "visible";
191201
}
192202
return "excluded";
@@ -225,9 +235,9 @@ qx.Class.define("osparc.form.renderer.PropForm", {
225235
makeInputsDynamic: function() {
226236
this.getPortIds().forEach(portId => this.__showPort(portId));
227237

228-
const emptyDataPorts = this.__getEmptyDataLastPorts();
229-
for (let i=1; i<emptyDataPorts.length; i++) {
230-
const hidePortId = emptyDataPorts[i];
238+
const emptyPorts = this.__getHideablePorts();
239+
for (let i=1; i<emptyPorts.length; i++) {
240+
const hidePortId = emptyPorts[i];
231241
this.__excludePort(hidePortId);
232242
}
233243

0 commit comments

Comments
 (0)