Skip to content

Commit

Permalink
Merge pull request #1418 from StochSS/domain-types-update
Browse files Browse the repository at this point in the history
Domain types update
  • Loading branch information
BryanRumsey authored Dec 7, 2022
2 parents 7155399 + b20ae39 commit e829c4e
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 159 deletions.
14 changes: 14 additions & 0 deletions client/domain-view/domain-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ module.exports = View.extend({
this.renderTypesQuickview();
}else{
this.updateParticleViews();
this.model.on('update-type-deps', this.updateTypeDeps, this);
this.model.on('update-geometry-deps', this.updateGeometryDeps, this);
this.model.on('update-lattice-deps', this.updateLatticeDeps, this);
this.model.on('update-transformation-deps', this.updateTransformationDeps, this);
Expand Down Expand Up @@ -562,6 +563,19 @@ module.exports = View.extend({
});
this.model.transformations.trigger('update-inuse', {deps: deps});
},
updateTypeDeps: function () {
let deps = [];
let typeNames = this.model.types.map((type) => {
return type.name;
});
this.model.actions.forEach((action) => {
let type = this.model.types.get(action.typeID, 'typeID').name;
if(typeNames.includes(type) && !deps.includes(type)) {
deps.push(type);
}
});
this.model.types.trigger('update-inuse', {deps: deps});
},
updateParticleViews: function () {
this.renderNewParticleView();
this.renderEditParticleView();
Expand Down
20 changes: 3 additions & 17 deletions client/domain-view/templates/editType.pug
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,17 @@ div.mx-1

input(type="checkbox" data-hook="select" data-toggle="collapse" data-target="#collapse-type-details" + this.model.typeID)

div.col-sm-3
div.col-sm-5

div(data-hook="type-name" data-target=this.model.typeID)

div.col-sm-3
div.col-sm-4

div=this.model.numParticles

div.col-sm-3

button.btn.btn-outline-secondary.box-shadow(data-type=this.model.typeID data-hook='unassign-all') Un-Assign Particles

div.col-sm-2

button.btn.btn-outline-secondary.box-shadow.dropdown-toggle(
id="delete-domain-type",
data-toggle="dropdown",
aria-haspopup="true",
aria-expanded="false",
type="button"
) Delete <span class="caret"></span>

ul.dropdown-menu(aria-labelledby="delete-domain-type")
li.dropdown-item(data-hook="delete-type" data-type=this.model.typeID) Type
li.dropdown-item(data-hook="delete-all" data-type=this.model.typeID) Type and Particles
button.btn.btn-outline-secondary.box-shadow(data-hook="remove") X

div-mx-1.pl-2(data-hook="type-details")

Expand Down
8 changes: 6 additions & 2 deletions client/domain-view/templates/typesView.pug
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,18 @@ div#domain-types-editor.card

h6.inline <b>Edit</b>

div.col-sm-3
div.col-sm-5

h6.inline <b>Name</b>

div.col-sm-8
div.col-sm-4

h6.inline <b>Number of Particles</b>

div.col-sm-2

h6.inline <b>Remove</b>

div.my-3(data-hook="edit-domain-types-list")

button.btn.btn-outline-primary.box-shadow(data-hook="add-domain-type") Add Type
Expand Down
3 changes: 3 additions & 0 deletions client/domain-view/views/action-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,21 @@ module.exports = View.extend({
this.model.geometry = e.target.value;
this.model.collection.parent.trigger('update-geometry-deps');
this.model.collection.parent.trigger('update-transformation-deps');
this.updateViewer();
},
selectLattice: function (e) {
this.model.lattice = e.target.value;
this.model.collection.parent.trigger('update-lattice-deps');
this.model.collection.parent.trigger('update-transformation-deps');
this.updateViewer();
},
setParticleFixed: function (e) {
this.model.fixed = !this.model.fixed;
this.updateViewer();
},
setParticleType: function (e) {
this.model.typeID = Number(e.target.value);
this.model.collection.parent.trigger('update-type-deps');
this.updateViewer();
},
setPoint: function (e) {
Expand Down
10 changes: 10 additions & 0 deletions client/domain-view/views/actions-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ module.exports = View.extend({
this.collection.on('update-geometry-options', this.updateGeometryOptions, this);
this.collection.on('update-lattice-options', this.updateLatticeOptions, this);
this.collection.on('update-transformation-options', this.updateTransformationOptions, this);
this.collection.on('update-type-options', this.updateTypeOptions, this);
}
this.renderViewActionsView();
},
Expand Down Expand Up @@ -122,5 +123,14 @@ module.exports = View.extend({
view.renderGeometrySelectView();
view.renderLatticeSelectView();
});
},
updateTypeOptions: function ({currName=null, newName=null}={}) {
if(currName === null && newName === null) { return; }
this.editActionsView.views.forEach((view) => {
if(view.model.typeID === currName) {
view.model.typeID = newName;
}
view.renderTypeSelectView();
});
}
});
49 changes: 21 additions & 28 deletions client/domain-view/views/type-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,19 @@ module.exports = View.extend({
el.checked = value;
},
hook: 'select'
},
'model.inUse': {
hook: 'remove',
type: 'booleanAttribute',
name: 'disabled',
}
},
events: {
'change [data-hook=type-name]' : 'handleRenameType',
'change [data-target=type-defaults]' : 'updateView',
'change [data-hook=type-name]' : 'updateDepsOptions',
'change [data-target=type-defaults]' : 'updateViewer',
'change [data-hook=td-fixed]' : 'setTDFixed',
'change [data-hook=type-geometry]' : 'updateView',
'click [data-hook=select]' : 'selectType',
'click [data-hook=unassign-all]' : 'handleUnassignParticles',
'click [data-hook=delete-type]' : 'handleDeleteType',
'click [data-hook=delete-all]' : 'handleDeleteTypeAndParticle',
'click [data-hook=remove]' : 'handleDeleteType',
},
initialize: function (attrs, options) {
View.prototype.initialize.apply(this, arguments);
Expand All @@ -66,24 +68,10 @@ module.exports = View.extend({
app.documentSetup();
},
handleDeleteType: function (e) {
let type = Number(e.target.dataset.type);
this.model.collection.removeType(this.model);
this.parent.parent.deleteType(this.model.typeID);
},
handleDeleteTypeAndParticle: function (e) {
let type = Number(e.target.dataset.type);
let typeID = this.model.typeID;
let actions = this.model.collection.parent.actions;
this.model.collection.removeType(this.model);
this.parent.parent.deleteType(this.model.typeID, {unassign: false});
},
handleRenameType: function (e) {
this.updateView();
let type = Number(e.target.parentElement.parentElement.dataset.target);
let name = e.target.value;
this.parent.parent.renameType(type, name);
},
handleUnassignParticles: function () {
this.model.numParticles = 0;
this.parent.parent.unassignAllParticles(this.model.typeID);
actions.trigger('update-type-options', {currName: typeID});
},
openTypeDetails: function () {
$("#collapse-type-details" + this.model.typeID).collapse("show");
Expand All @@ -93,23 +81,28 @@ module.exports = View.extend({
},
setTDFixed: function (e) {
this.model.fixed = e.target.checked;
this.updateView();
this.updateViewer();
},
update: function () {},
updateDepsOptions: function (e) {
let typeID = this.model.typeID;
this.model.name = e.target.value;
this.model.collection.parent.actions.trigger(
'update-type-options', {currName: typeID, newName: this.model.typeID}
);
},
updateValid: function () {},
updateView: function () {
updateViewer: function () {
this.parent.renderViewTypeView();
this.parent.parent.updateParticleViews({includeGeometry: true});
},
subviews: {
inputTypeID: {
inputName: {
hook: "type-name",
prepareView: function (el) {
return new InputView({
parent: this,
required: true,
name: 'name',
modelKey: 'name',
tests: [tests.invalidChar],
valueType: 'string',
value: this.model.name
Expand Down
9 changes: 9 additions & 0 deletions client/domain-view/views/types-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ module.exports = View.extend({
$(this.queryByHook('view-domain-types')).addClass('active');
}else{
this.renderEditTypeView();
this.collection.on("update-inuse", this.updateInUse, this);
this.collection.parent.trigger('update-type-deps');
}
this.toggleDomainError();
this.renderViewTypeView();
Expand All @@ -57,6 +59,7 @@ module.exports = View.extend({
},
handleAddDomainType: function () {
let name = this.collection.addType();
this.collection.parent.actions.trigger('update-type-options', {currName: name});
this.parent.addType(name);
},
renderEditTypeView: function () {
Expand Down Expand Up @@ -101,5 +104,11 @@ module.exports = View.extend({
errorMsg.addClass('component-valid');
errorMsg.removeClass('component-invalid');
}
},
updateInUse: function ({deps=null}={}) {
if(deps === null) { return; }
this.collection.forEach((type) => {
type.inUse = deps.includes(type.name);
});
}
});
4 changes: 4 additions & 0 deletions client/models/domain-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ module.exports = State.extend({
volume: 'number'
},
session: {
inUse: {
type: 'boolean',
default: false,
},
numParticles: 'number',
selected: {
type: 'boolean',
Expand Down
28 changes: 0 additions & 28 deletions client/templates/includes/editDomainType.pug

This file was deleted.

84 changes: 0 additions & 84 deletions client/views/edit-domain-type.js

This file was deleted.

0 comments on commit e829c4e

Please sign in to comment.