Skip to content

Commit

Permalink
Merge pull request #1 from hamidzr/decorator
Browse files Browse the repository at this point in the history
Decorator
  • Loading branch information
hamidzr authored Nov 30, 2017
2 parents 685f5b3 + c5af299 commit 5bad8b6
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 1 deletion.
1 change: 1 addition & 0 deletions webgme/config/config.webgme.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var config = require('webgme/config/config.default'),

// The paths can be loaded from the webgme-setup.json
config.plugin.basePaths.push(__dirname + '/../src/plugins');
config.visualization.decoratorPaths.push(__dirname + '/../src/decorators');



Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*globals define, _*/
/*jshint browser: true, camelcase: false*/
/**
* This decorator inherits from the ModelDecorator.DiagramDesignerWidget.
* With no changes to the methods - it will functions just like the ModelDecorator.
*
* For more methods see the ModelDecorator.DiagramDesignerWidget.js in the webgme repository.
*
* @author pmeijer / https://github.com/pmeijer
*/

define([
'js/RegistryKeys',
'js/Constants',
'js/Controls/DropDownMenu',
'decorators/ModelDecorator/DiagramDesigner/ModelDecorator.DiagramDesignerWidget',
'jquery',
'underscore'
], function (
REGISTRY_KEYS,
CONSTANTS,
DropDownMenu,
ModelDecoratorDiagramDesignerWidget) {

'use strict';

var FSMDecorator,
DECORATOR_ID = 'FSMDecorator',
COMMAND_META_TYPES = ['Start', 'Move', 'Turn', 'Stop'];

FSMDecorator = function (options) {
var opts = _.extend({}, options);

ModelDecoratorDiagramDesignerWidget.apply(this, [opts]);

this.logger.debug('FSMDecorator ctor');



this.dropDown = new DropDownMenu({
size:'micro',
sort: true
});

this.dropDown.setTitle('Next Action:');
};

FSMDecorator.prototype = Object.create(ModelDecoratorDiagramDesignerWidget.prototype);
FSMDecorator.prototype.constructor = FSMDecorator;
FSMDecorator.prototype.DECORATORID = DECORATOR_ID;

FSMDecorator.prototype.on_addTo = function () {
var self = this,
client = this._control._client,
nodeObj = client.getNode(this._metaInfo[CONSTANTS.GME_ID]),
META = {};

client.getAllMetaNodes()
.forEach(function (metaObj) {
META[metaObj.getAttribute('name')] = metaObj.getId()
});

this.logger.debug('This node was added to the canvas', nodeObj);

// Call the base-class method..
ModelDecoratorDiagramDesignerWidget.prototype.on_addTo.apply(this, arguments);

// this.$resultIndicator = $('<button>', {
// text:'<<interface>>'
// });
//
// this.$resultIndicator.click(function () {
// nodeObj.getParentId();
// client.startTransaction();
// var newNodeId = client.createNode({
// parentId: nodeObj.getParentId(),
// baseId: "/7" // hard-code single typ
// });
// client.setPointer(connectionId, 'src', nodeObjId);
// // client.setPointer(connectionId, 'dst', newTargetId);
// client.completeTransaction();
// });
//this.$el.append(this.$resultIndicator);

this.dropDown.onItemClicked = function (value) {
client.startTransaction();

var newCommandId = client.createNode({
parentId: nodeObj.getParentId(),
baseId: value
});

client.setRegistry(newCommandId, 'position', {
x: nodeObj.getRegistry('position').x + 200,
y: nodeObj.getRegistry('position').y
});

var newConnectionId = client.createNode({
parentId: nodeObj.getParentId(),
baseId: META.Transition
});

client.setPointer(newConnectionId, 'src', nodeObj.getId());
client.setPointer(newConnectionId, 'dst', newCommandId);

client.completeTransaction();
};

if (META.hasOwnProperty('Transition') === true) {

this.$el.append(this.dropDown.getEl());
COMMAND_META_TYPES.forEach(function (commandTypeName) {
if (META.hasOwnProperty(commandTypeName)) {
self.dropDown.addItem({
value: META[commandTypeName],
text: commandTypeName
});
} else {
self.logger.error(commandTypeName + ' not among META!');
}
});
} else {
self.logger.error('Transition not among META!');
}
};

FSMDecorator.prototype.destroy = function () {
ModelDecoratorDiagramDesignerWidget.prototype.destroy.apply(this, arguments);
};

FSMDecorator.prototype.update = function () {
var client = this._control._client,
nodeObj = client.getNode(this._metaInfo[CONSTANTS.GME_ID]);

this.logger.debug('This node is on the canvas and received an update event', nodeObj);

ModelDecoratorDiagramDesignerWidget.prototype.update.apply(this, arguments);
};

return FSMDecorator;
});
39 changes: 39 additions & 0 deletions webgme/src/decorators/FSMDecorator/FSMDecorator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*globals define, _*/
/*jshint browser: true, camelcase: false*/
/**
* @author pmeijer / https://github.com/pmeijer
*/

define([
'js/Decorators/DecoratorBase',
'./DiagramDesigner/FSMDecorator.DiagramDesignerWidget',
'./PartBrowser/FSMDecorator.PartBrowserWidget'
], function (DecoratorBase, FSMDecoratorDiagramDesignerWidget, FSMDecoratorPartBrowserWidget) {

'use strict';

var FSMDecorator,
DECORATOR_ID = 'FSMDecorator';

FSMDecorator = function (params) {
var opts = _.extend({loggerName: this.DECORATORID}, params);

DecoratorBase.apply(this, [opts]);

this.logger.debug('FSMDecorator ctor');
};

_.extend(FSMDecorator.prototype, DecoratorBase.prototype);
FSMDecorator.prototype.DECORATORID = DECORATOR_ID;

/*********************** OVERRIDE DecoratorBase MEMBERS **************************/

FSMDecorator.prototype.initializeSupportedWidgetMap = function () {
this.supportedWidgetMap = {
DiagramDesigner: FSMDecoratorDiagramDesignerWidget,
PartBrowser: FSMDecoratorPartBrowserWidget
};
};

return FSMDecorator;
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*globals define, _*/
/*jshint browser: true*/
/**
* This decorator inherits from the ModelDecorator.PartBrowserWidget.
* With no changes to the methods - it will functions just like the ModelDecorator.
*
* For more methods see the ModelDecorator.PartBrowserWidget.js in the webgme repository.
*
* @author pmeijer / https://github.com/pmeijer
*/

define([
'decorators/ModelDecorator/PartBrowser/ModelDecorator.PartBrowserWidget',
'jquery',
'underscore'
], function (ModelDecoratorPartBrowserWidget) {

'use strict';

var FSMDecoratorPartBrowserWidget,
DECORATOR_ID = 'FSMDecoratorPartBrowserWidget';

FSMDecoratorPartBrowserWidget = function (options) {
var opts = _.extend({}, options);

ModelDecoratorPartBrowserWidget.apply(this, [opts]);

this.logger.debug('FSMDecoratorPartBrowserWidget ctor');
};

_.extend(FSMDecoratorPartBrowserWidget.prototype, ModelDecoratorPartBrowserWidget.prototype);
FSMDecoratorPartBrowserWidget.prototype.DECORATORID = DECORATOR_ID;

/*********************** OVERRIDE DiagramDesignerWidgetDecoratorBase MEMBERS **************************/

FSMDecoratorPartBrowserWidget.prototype.beforeAppend = function () {
ModelDecoratorPartBrowserWidget.prototype.beforeAppend.apply(this, arguments);
};

FSMDecoratorPartBrowserWidget.prototype.afterAppend = function () {
ModelDecoratorPartBrowserWidget.prototype.afterAppend.apply(this, arguments);
};

FSMDecoratorPartBrowserWidget.prototype.update = function () {
ModelDecoratorPartBrowserWidget.prototype.update.apply(this, arguments);
};

return FSMDecoratorPartBrowserWidget;
});
8 changes: 7 additions & 1 deletion webgme/webgme-setup.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
"src": "src/plugins/CommandManager",
"test": "test/plugins/CommandManager"
}
},
"decorators": {
"FSMDecorator": {
"src": "src/decorators/FSMDecorator"
}
}
},
"dependencies": {
Expand All @@ -19,6 +24,7 @@
"project": "webgme-icore"
}
},
"plugins": {}
"plugins": {},
"decorators": {}
}
}

0 comments on commit 5bad8b6

Please sign in to comment.