Skip to content
This repository has been archived by the owner on May 31, 2021. It is now read-only.

Commit

Permalink
Basic support for constraints
Browse files Browse the repository at this point in the history
Each node can be right a constraint or a barrier to entry
  • Loading branch information
cdaniel committed May 29, 2017
1 parent c4c1c9e commit 0974fb6
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 41 deletions.
6 changes: 3 additions & 3 deletions build-ui/js/canvas-wrapper.js

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions build-ui/js/google-app.js

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions build-ui/js/l-p-app.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src-server/workspace/image-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function safeStringify(obj) {
var r = process.cwd();
var script = fs.readFileSync(r + '/build-ui/js/canvas-wrapper.js');
var css = fs.readFileSync(r + '/build-ui/css/bootstrap.min.css');
var glyphs = fs.readFileSync(r + '/build-ui/fonts/glyphicons-halflings-regular.svg');

function renderFullPage(opts) {
return "<!doctype html><html><head><style>" + css + "</style></head><body><div id=\"root\" style=\"background:white\">"
Expand Down
8 changes: 6 additions & 2 deletions src-server/workspace/model/map-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ module.exports = function(conn) {
return this.save();
};

_MapSchema.methods.addNode = function(name, x, y, type, workspace, description, inertia, responsiblePerson) {
_MapSchema.methods.addNode = function(name, x, y, type, workspace, description, inertia, responsiblePerson, constraint) {
var Node = require('./node-schema')(conn);

var _this = this;
Expand All @@ -156,6 +156,7 @@ module.exports = function(conn) {
description: description,
inertia: inertia,
responsiblePerson: responsiblePerson,
constraint : constraint
}).save()
.then(function(node) {
_this.nodes.push(node._id);
Expand All @@ -169,7 +170,7 @@ module.exports = function(conn) {
});
};

_MapSchema.methods.changeNode = function(name, x, y, type, desiredNodeId, description, inertia, responsiblePerson) {
_MapSchema.methods.changeNode = function(name, x, y, type, desiredNodeId, description, inertia, responsiblePerson, constraint) {
var _this = this;
var Node = require('./node-schema')(conn);
return Node.findOne({
Expand Down Expand Up @@ -197,6 +198,9 @@ module.exports = function(conn) {
if (responsiblePerson) {
node.responsiblePerson = responsiblePerson;
}
if (constraint !== null && constraint !== undefined) {
node.constraint = constraint;
}
return q.allSettled([node.save(), _this.populate({
path: 'nodes',
model: 'Node'
Expand Down
1 change: 1 addition & 0 deletions src-server/workspace/model/node-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module.exports = function(conn){
x: Schema.Types.Number,
y: Schema.Types.Number,
type: Schema.Types.String,
constraint: Schema.Types.Number, // 0 - none, 10 - constraint, 20 - barrier
inboundDependencies: [{
type: Schema.Types.ObjectId,
ref: 'Node'
Expand Down
6 changes: 4 additions & 2 deletions src-server/workspace/workspace-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ module.exports = function(authGuardian, mongooseConnection) {
var x = req.body.x;
var y = req.body.y;
var type = req.body.type;
var constraint = req.body.constraint;
var parentMap = new ObjectId(mapID);

WardleyMap.findOne({ //this is check that the person logged in can actually write to workspace
Expand All @@ -487,7 +488,7 @@ module.exports = function(authGuardian, mongooseConnection) {
return map.verifyAccess(owner);
})
.then(function(map) {
return map.addNode(name, x, y, type, new ObjectId(workspaceID), description, inertia, responsiblePerson);
return map.addNode(name, x, y, type, new ObjectId(workspaceID), description, inertia, responsiblePerson, constraint);
})
.fail(function(e) {
return defaultAccessDenied(res, e);
Expand Down Expand Up @@ -697,6 +698,7 @@ module.exports = function(authGuardian, mongooseConnection) {
var desiredNodeId = new ObjectId(req.params.nodeID);
var description = req.body.description;
var inertia = req.body.inertia;
var constraint = req.body.constraint;
var responsiblePerson = req.body.responsiblePerson;

// find a map with a node
Expand All @@ -711,7 +713,7 @@ module.exports = function(authGuardian, mongooseConnection) {
return map.verifyAccess(owner);
})
.then(function(map) {
return map.changeNode(name, x, y, type, desiredNodeId, description, inertia, responsiblePerson);
return map.changeNode(name, x, y, type, desiredNodeId, description, inertia, responsiblePerson, constraint);
})
.then(function(result) {
return result[1].value.formJSON();
Expand Down
14 changes: 14 additions & 0 deletions src-ui/map-editor/dialogs/create-new-node-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ var CreateNewNodeDialog = React.createClass({
render: function() {
var show = this.state.open;
var inertia = this.internalState.inertia;
var constraint = this.internalState.constraint;
if(constraint === null || constraint === undefined){
constraint = 0;
}
return (
<div>
<Modal show={show} onHide={this._close}>
Expand Down Expand Up @@ -105,6 +109,16 @@ var CreateNewNodeDialog = React.createClass({
<Radio inline value={1} checked={inertia==1} onChange={this._handleDialogChange.bind(this, 'inertia')}>Huge</Radio>
</Col>
</FormGroup>
<FormGroup controlId="constraint">
<Col sm={2}>
<ControlLabel>Limitation</ControlLabel>
</Col>
<Col sm={9}>
<Radio inline checked={ constraint==0 || !constraint} value={0} onChange={this._handleDialogChange.bind(this, 'constraint')}>None</Radio>{' '}
<Radio inline value={10} checked={constraint==10} onChange={this._handleDialogChange.bind(this, 'constraint')}>Constraint</Radio>{' '}
<Radio inline value={20} checked={constraint==20} onChange={this._handleDialogChange.bind(this, 'constraint')}>Barrier to entry</Radio>{' '}
</Col>
</FormGroup>
<FormGroup controlId="description">
<Col sm={2}>
<ControlLabel>Description</ControlLabel>
Expand Down
19 changes: 17 additions & 2 deletions src-ui/map-editor/dialogs/edit-node-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ var EditNodeDialog = React.createClass({
this.internalState.type,
this.internalState.responsiblePerson,
this.internalState.inertia,
this.internalState.description
this.internalState.description,
this.internalState.constraint
);
this.internalState = {};
},
Expand Down Expand Up @@ -83,7 +84,11 @@ var EditNodeDialog = React.createClass({
var description = this.internalState.description;
var responsiblePerson = this.internalState.responsiblePerson;
var inertia = this.internalState.inertia;

var constraint = this.internalState.constraint;
if(constraint === null || constraint === undefined){
constraint = 0;
}
console.log('cons', constraint);
var typeGroup = type != Constants.SUBMAP ? (<FormGroup controlId="type">
<Col sm={2}>
<ControlLabel>Type</ControlLabel>
Expand Down Expand Up @@ -133,6 +138,16 @@ var EditNodeDialog = React.createClass({
<Radio inline checked={inertia == 1} value={1} onChange={this._handleDialogChange.bind(this, 'inertia')}>Huge</Radio>
</Col>
</FormGroup>
<FormGroup controlId="constraint">
<Col sm={2}>
<ControlLabel>Limitation</ControlLabel>
</Col>
<Col sm={9}>
<Radio inline checked={ constraint==0 || !constraint} value={0} onChange={this._handleDialogChange.bind(this, 'constraint')}>None</Radio>{' '}
<Radio inline value={10} checked={constraint==10} onChange={this._handleDialogChange.bind(this, 'constraint')}>Constraint</Radio>{' '}
<Radio inline value={20} checked={constraint==20} onChange={this._handleDialogChange.bind(this, 'constraint')}>Barrier to entry</Radio>{' '}
</Col>
</FormGroup>
<FormGroup controlId="description">
<Col sm={2}>
<ControlLabel>Description</ControlLabel>
Expand Down
11 changes: 10 additions & 1 deletion src-ui/map-editor/map-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,15 @@ var MapComponent = React.createClass({
});
return <div style={style}></div>;
},
renderName(node){
if(node.constraint == 20){
return <span>{node.name}<Glyphicon glyph="minus-sign"/></span>;
}
if(node.constraint == 10){
return <span>{node.name}<Glyphicon glyph="exclamation-sign"/></span>;
}
return node.name;
},
render: function() {
var node = this.props.node;

Expand All @@ -365,7 +374,7 @@ var MapComponent = React.createClass({
position: 'absolute',
cursor: 'pointer'
});
var name = node.name;
var name = this.renderName(node);
var menu = this.renderMenu();
var shouldBeDraggable = this.props.focused;
var _this = this;
Expand Down
13 changes: 7 additions & 6 deletions src-ui/map-editor/single-map-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ var SingleMapActions = {
},

updateNode: function(workspaceId, mapId, nodeId, pos,
name, type, person, inertia, description){
name, type, person, inertia, description, constraint){
if(!nodeId){
console.error('missing node id');
return;
Expand All @@ -329,11 +329,12 @@ var SingleMapActions = {
mapId: mapId,
nodeId :nodeId,
pos : pos ? pos : null,
name,
type,
person,
inertia,
description
name : name,
type : type,
person : person,
inertia : inertia,
description: description,
constraint : constraint
}
});
},
Expand Down
4 changes: 3 additions & 1 deletion src-ui/map-editor/single-map-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ export default class SingleWorkspaceStore extends Store {
this.editNodeDialog.responsiblePerson = nodes[i].responsiblePerson;
this.editNodeDialog.inertia = nodes[i].inertia;
this.editNodeDialog.description = nodes[i].description;
this.editNodeDialog.constraint = nodes[i].constraint;
this.editNodeDialog.workspaceId = this.getWorkspaceId();
this.editNodeDialog.mapId = this.getMapId();
this.editNodeDialog.nodeId = data.nodeID;
Expand Down Expand Up @@ -502,12 +503,13 @@ export default class SingleWorkspaceStore extends Store {
payload.x = data.pos.x;
payload.y = data.pos.y;
}
if(data.name || data.type || data.person || data.inertia || data.description){
if(data.name || data.type || data.person || data.inertia || data.description || data.constraint !== undefined ){
payload.name = data.name;
payload.type = data.type;
payload.responsiblePerson = data.person;
payload.inertia = data.inertia;
payload.description = data.description;
payload.constraint = data.constraint;
}
$.ajax({
type: 'PUT',
Expand Down
12 changes: 10 additions & 2 deletions src-ui/minimal-canvas/map-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@ var MapComponent = React.createClass({
});
return <div style={style}></div>;
},

renderName(node){
if(node.constraint == 20){
return <span>{node.name}<img alt="Minus" width="10" height="10" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAYAAACpSkzOAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA+5pVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0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GxlPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PjBen84AAADMSURBVHjavJaNDYQgDIXFCRiBERjBERnNETqCG/RoUgwSwd6dvCYvJqbtF7E/OGZeLOacC/kRmteU48mUQEA9aeIkCcW1I1KfMMzVAXgN5i8lMd4Eyhaz9h8gRRIbhyCFHH9Aio4W1h7X/gKk/jJ/B0ovQs5/dgFpdfEkhRqUJoJSDaKJICpDYeaxnccnoG3gEEfdftMavTzbEGSFVLAuaF0wFtaHiR2tmR58CVcMsPJGNyxmBMGGKnRNwBYfdJVDLyezrlsOdYH8CDAAn5YfwrN58ucAAAAASUVORK5CYII=" /></span>;
}
if(node.constraint == 10){
return <span>{node.name}<img alt="Exclamation" width="10" height="10" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAYAAACpSkzOAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA+5pVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVz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8xX9TkbgcAKDXGlXOhmgE+a7lchoEYl3NFV0SsIDK44t6WAXvGIkEqTl3YJwbtiNGdkzGVkA6Eyb7dywOlcQjuO1w/WzHqNefUyoDT7VUa76OOn13LJaD8iPAAMABaJvADxmgE8AAAAASUVORK5CYII=" /></span>;
}
return node.name;
},
render: function() {
var node = this.props.node;

Expand All @@ -61,7 +69,7 @@ var MapComponent = React.createClass({
position: 'absolute',
cursor: 'pointer'
});
var name = node.name;
var name = this.renderName(node);
var id = this.props.id;
var inertia = this.renderInertia(this.props.inertia);
return (
Expand Down

0 comments on commit 0974fb6

Please sign in to comment.