diff --git a/client/templates/includes/boundaryConditionsEditor.pug b/client/templates/includes/boundaryConditionsEditor.pug index 61dc60bbc7..fea9fc7d4b 100644 --- a/client/templates/includes/boundaryConditionsEditor.pug +++ b/client/templates/includes/boundaryConditionsEditor.pug @@ -76,7 +76,13 @@ div#boundary-conditions.card td(data-hook="new-bc-target") tr th(scope="row") Value - td(data-hook="new-bc-value" data-target="value") + td + div(data-hook="new-bc-velocity-value") + div(data-hook="new-bc-value-x" data-target="value") + div(data-hook="new-bc-value-y" data-target="value") + div(data-hook="new-bc-value-z" data-target="value") + div(data-hook="new-bc-other-value" style="display: none") + div(data-hook="new-bc-value" data-target="value") tr th(scope="row") Concentration td @@ -84,7 +90,7 @@ div#boundary-conditions.card div.col-sm-6 - div + div(style="display: flex;") span.inline.mr-3(for="new-bc-type") Type: div.inline(id="new-bc-type" data-hook="new-bc-type" data-target="type_id") diff --git a/client/views/boundary-conditions-editor.js b/client/views/boundary-conditions-editor.js index 60a27794cd..bfc9607a00 100644 --- a/client/views/boundary-conditions-editor.js +++ b/client/views/boundary-conditions-editor.js @@ -38,6 +38,9 @@ module.exports = View.extend({ 'change [data-hook=new-bc-deterministic]' : 'handleSetDeterministic', 'change [data-hook=new-bc-type]' : 'handleSetValue', 'change [data-hook=new-bc-value]' : 'handleSetValue', + 'change [data-hook=new-bc-value-x]' : 'handleSetValue', + 'change [data-hook=new-bc-value-y]' : 'handleSetValue', + 'change [data-hook=new-bc-value-z]' : 'handleSetValue', 'change [data-hook=new-bc-x-min]' : 'handleSetValue', 'change [data-hook=new-bc-x-max]' : 'handleSetValue', 'change [data-hook=new-bc-y-min]' : 'handleSetValue', @@ -77,7 +80,12 @@ module.exports = View.extend({ handleAddBCClick: function (e) { let endpoint = path.join(app.getApiPath(), "model/new-bc") let self = this; - app.postXHR(endpoint, this.newBC, { + if(this.newBC.property === "v") { + this.newBC.value = this.newBCVector + } + let data = {model_path: this.collection.parent.directory, + kwargs: this.newBC} + app.postXHR(endpoint, data, { success: function (err, response, body) { self.collection.addNewBoundaryCondition(self.newBCName, body.expression); self.setDefaultBC(); @@ -92,12 +100,22 @@ module.exports = View.extend({ let properties = ["v", "nu", "rho"]; let target = e.target.value; if(properties.includes(target)) { + if(target === "v") { + $(this.queryByHook("new-bc-other-value")).css("display", "none"); + $(this.queryByHook("new-bc-velocity-value")).css("display", "block"); + }else { + $(this.queryByHook("new-bc-velocity-value")).css("display", "none"); + $(this.queryByHook("new-bc-other-value")).css("display", "block"); + } this.newBC.property = target; this.newBC.species = null; $(this.queryByHook("new-bc-deterministic")).prop("disabled", true); }else{ + let species = this.collection.parent.species.filter(function (specie) { + return specie.compID === Number(target) + })[0].name; this.newBC.property = null; - this.newBC.species = target; + this.newBC.species = species; $(this.queryByHook("new-bc-deterministic")).prop("disabled", false); } }, @@ -108,11 +126,18 @@ module.exports = View.extend({ this.newBCName = value; }else{ if(key.endsWith("min") || key.endsWith("max") || key === "type_id"){ - value = this.validateNewBCCondition(key, value); - }else if(key === "value" && value === "") { - value = null; + this.newBC[key] = this.validateNewBCCondition(key, value); + }else if(key === "value") { + if(e.delegateTarget.dataset.hook.endsWith("x")) { + this.newBCVector[0] = value === "" ? 0 : value + }else if(e.delegateTarget.dataset.hook.endsWith("y")) { + this.newBCVector[1] = value === "" ? 0 : value + }else if(e.delegateTarget.dataset.hook.endsWith("z")) { + this.newBCVector[2] = value === "" ? 0 : value + }else{ + this.newBC[key] = value === "" ? null : value + } } - this.newBC[key] = value; } this.toggleAddNewBCButton(); }, @@ -169,10 +194,13 @@ module.exports = View.extend({ this.newBCName = ""; this.newBC = {"species": null, "property": "v", "value": null, "deterministic": true, "type_id": null, "xmin": null, "ymin": null, "zmin": null, "xmax": null, "ymax": null, "zmax": null}; + this.newBCVector = [0, 0, 0] this.setConditions = []; }, toggleAddNewBCButton: function () { - let disabled = this.newBCName === "" || this.newBC.value === null || !this.setConditions.length; + let invalidName = this.newBCName === "" + let invalidValue = this.newBC.property === "v" ? this.newBCVector === [0, 0, 0] : this.newBC.value === null + let disabled = invalidName || invalidValue || !this.setConditions.length; $(this.queryByHook("add-new-bc")).prop("disabled", disabled); }, update: function (e) {}, @@ -229,7 +257,45 @@ module.exports = View.extend({ name: 'value', tests: tests.valueTests, valueType: 'number', - value: this.newBC.value + }); + } + }, + newBCValueX: { + hook: "new-bc-value-x", + prepareView: function (el) { + return new InputView({ + parent: this, + required: false, + name: 'value-x', + tests: tests.valueTests, + valueType: 'number', + label: "X: " + }); + } + }, + newBCValueY: { + hook: "new-bc-value-y", + prepareView: function (el) { + return new InputView({ + parent: this, + required: false, + name: 'value-y', + tests: tests.valueTests, + valueType: 'number', + label: "Y: " + }); + } + }, + newBCValueZ: { + hook: "new-bc-value-z", + prepareView: function (el) { + return new InputView({ + parent: this, + required: false, + name: 'value-z', + tests: tests.valueTests, + valueType: 'number', + label: "Z: " }); } }, diff --git a/stochss/handlers/models.py b/stochss/handlers/models.py index 545c69c0b4..04c210ad94 100644 --- a/stochss/handlers/models.py +++ b/stochss/handlers/models.py @@ -423,11 +423,14 @@ async def post(self): ---------- ''' self.set_header('Content-Type', 'application/json') - kwargs = json.loads(self.request.body.decode()) + data = json.loads(self.request.body.decode()) + path = data['model_path'] + kwargs = data['kwargs'] log.debug("Args passed to the boundary condition constructor: %s", kwargs) try: log.info("Creating the new boundary condition") - resp = StochSSSpatialModel.create_boundary_condition(kwargs) + model = StochSSSpatialModel(path=path) + resp = model.create_boundary_condition(kwargs) log.info("Successfully created the new boundary condition") log.debug("Response Message: %s", resp) self.write(resp) diff --git a/stochss/handlers/util/stochss_spatial_model.py b/stochss/handlers/util/stochss_spatial_model.py index 16369c1067..60a9191783 100644 --- a/stochss/handlers/util/stochss_spatial_model.py +++ b/stochss/handlers/util/stochss_spatial_model.py @@ -389,8 +389,7 @@ def convert_to_spatialpy(self): return s_model - @classmethod - def create_boundary_condition(cls, kwargs): + def create_boundary_condition(self, kwargs): ''' Create a new boundary condition using spatialpy.BoundaryCondition @@ -399,7 +398,8 @@ def create_boundary_condition(cls, kwargs): kwargs : dict Arguments passed to the spatialpy.BoundaryCondition constructor ''' - new_bc = BoundaryCondition(**kwargs) + model = self.convert_to_spatialpy() + new_bc = BoundaryCondition(model=model, **kwargs) expression = new_bc.expression() return {"expression": expression}