Skip to content

Commit

Permalink
WIP #468 Updated templates
Browse files Browse the repository at this point in the history
  • Loading branch information
brollb committed Sep 17, 2015
1 parent de82c48 commit 7b665a7
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 87 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
/*globals define, _, WebGMEGlobal*/
/*globals define, WebGMEGlobal*/
/*jshint browser: true*/

/**
* Generated by VisualizerGenerator <%=version%> from webgme on <%=date%>.
*/

define(['js/logger',
'js/util',
'js/Constants',
'js/Utils/GMEConcepts',
'js/NodePropertyNames'
], function (Logger,
util,
CONSTANTS,
GMEConcepts,
nodePropertyNames) {
Expand All @@ -26,45 +24,35 @@ define(['js/logger',

this._client = options.client;

//initialize core collections and variables
// Initialize core collections and variables
this._widget = options.widget;

this._currentNodeId = null;
this._currentNodeParentId = undefined;

this._displayModelsOnly = false;

this._initWidgetEventHandlers();

this._logger.debug('Created');
};

<%=visualizerID%>Control.prototype._initWidgetEventHandlers = function () {
var self = this;

this._widget.onBackgroundDblClick = function () {
if (self._currentNodeParentId) {
WebGMEGlobal.State.registerActiveObject(self._currentNodeParentId);
}
};

// Update territory example
//self._selfPatterns[id] = {children: 1};
//self._client.updateTerritory(self._territoryId, self._selfPatterns);
this._widget.onNodeDblClick = function (id) {
this._widget.onNodeClick = function (id) {
// Change the current active object
WebGMEGlobal.State.registerActiveObject(id);
};
};

/* * * * * * * * Visualizer content update callbacks * * * * * * * */
// One major concept here is with managing the territory. The territory
// defines the parts of the project that the visualizer is interested in
// (this allows the browser to then only load those relevant parts).
<%=visualizerID%>Control.prototype.selectedObjectChanged = function (nodeId) {
var desc = this._getObjectDescriptor(nodeId),
self = this;

this._logger.debug('activeObject nodeId \'' + nodeId + '\'');

//remove current territory patterns
// Remove current territory patterns
if (this._currentNodeId) {
this._client.removeUI(this._territoryId);
}
Expand All @@ -73,9 +61,9 @@ define(['js/logger',
this._currentNodeParentId = undefined;

if (this._currentNodeId || this._currentNodeId === CONSTANTS.PROJECT_ROOT_ID) {
//put new node's info into territory rules
// Put new node's info into territory rules
this._selfPatterns = {};
this._selfPatterns[nodeId] = {children: 0};
this._selfPatterns[nodeId] = {children: 0}; // Territory "rule"

this._widget.setTitle(desc.name.toUpperCase());

Expand All @@ -90,7 +78,8 @@ define(['js/logger',
this._territoryId = this._client.addUI(this, function (events) {
self._eventCallback(events);
});
//update the territory

// Update the territory
this._client.updateTerritory(this._territoryId, this._selfPatterns);

setTimeout(function () {
Expand All @@ -100,6 +89,7 @@ define(['js/logger',
}
};

// This next function retrieves the relevant node information for the widget
<%=visualizerID%>Control.prototype._getObjectDescriptor = function (nodeId) {
var nodeObj = this._client.getNode(nodeId),
baseId,
Expand All @@ -120,12 +110,13 @@ define(['js/logger',
objDescriptor.childrenIds = nodeObj.getChildrenIds();
objDescriptor.childrenNum = objDescriptor.childrenIds.length;
objDescriptor.parentId = nodeObj.getParentId();
objDescriptor.isConnection = GMEConcepts.isConnection(nodeId);
objDescriptor.isConnection = GMEConcepts.isConnection(nodeId); // GMEConcepts can be helpful
}

return objDescriptor;
};

/* * * * * * * * Node Event Handling * * * * * * * */
<%=visualizerID%>Control.prototype._eventCallback = function (events) {
var i = events ? events.length : 0,
e;
Expand All @@ -152,7 +143,6 @@ define(['js/logger',
this._logger.debug('_eventCallback \'' + events.length + '\' items - DONE');
};

// PUBLIC METHODS
<%=visualizerID%>Control.prototype._onLoad = function (gmeId) {
var description = this._getObjectDescriptor(gmeId);
this._widget.addNode(description);
Expand Down Expand Up @@ -195,11 +185,11 @@ define(['js/logger',
this._hideToolbarItems();
};

/* * * * * * * * * * Updating the toolbar * * * * * * * * * */
<%=visualizerID%>Control.prototype._displayToolbarItems = function () {
var i;

if (this._toolbarInitialized === true) {
for (i = 0; i < this._toolbarItems.length; i++) {
for (var i = this._toolbarItems.length; i--;) {
this._toolbarItems[i].show();
}
} else {
Expand All @@ -208,35 +198,32 @@ define(['js/logger',
};

<%=visualizerID%>Control.prototype._hideToolbarItems = function () {
var i;

if (this._toolbarInitialized === true) {
for (i = 0; i < this._toolbarItems.length; i++) {
for (var i = this._toolbarItems.length; i--;) {
this._toolbarItems[i].hide();
}
}
};

<%=visualizerID%>Control.prototype._removeToolbarItems = function () {
var i;

if (this._toolbarInitialized === true) {
for (i = 0; i < this._toolbarItems.length; i++) {
for (var i = this._toolbarItems.length; i--;) {
this._toolbarItems[i].destroy();
}
}
};

<%=visualizerID%>Control.prototype._initializeToolbar = function () {
// TODO: Maybe change this
var toolBar = WebGMEGlobal.Toolbar,
self = this;

this._toolbarItems = [];

this._toolbarItems.push(toolBar.addSeparator());

/************** GOTO PARENT IN HIERARCHY BUTTON ****************/
/************** Go to hierarchical parent button ****************/
this.$btnModelHierarchyUp = toolBar.addButton({
title: 'Go to parent',
icon: 'glyphicon glyphicon-circle-arrow-up',
Expand All @@ -246,22 +233,17 @@ define(['js/logger',
});
this._toolbarItems.push(this.$btnModelHierarchyUp);
this.$btnModelHierarchyUp.hide();
/************** END OF - GOTO PARENT IN HIERARCHY BUTTON ****************/

/************** Checkbox example *******************/

this.$cbShowConnection = toolBar.addCheckBox({
title: 'toggle checkbox',
icon: 'gme icon-gme_diagonal-arrow',
checkChangedFn: function (data, checked) {
// TODO: Checkbox has been clicked!
console.log('Checkbox has been clicked!');
}
});

this._toolbarItems.push(this.$cbShowConnection);
/************** END OF - MODEL / CONNECTION filter *******************/


this._toolbarInitialized = true;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@

define(['js/PanelBase/PanelBaseWithHeader',
'js/PanelManager/IActivePanel',
'js/Widgets/<%= visualizerID %>/<%= visualizerID %>Widget',
'./<%= visualizerID %>Control'
'widgets/<%=visualizerID%>Example/<%=visualizerID%>Widget',
'./<%=visualizerID%>Control'
], function (PanelBaseWithHeader,
IActivePanel,
<%= visualizerID %>Widget,
<%= visualizerID %>Control) {
<%=visualizerID%>Widget,
<%=visualizerID%>Control) {
'use strict';

var <%= visualizerID %>Panel;
var <%=visualizerID%>Panel;

<%= visualizerID %>Panel = function (layoutManager, params) {
<%=visualizerID%>Panel = function (layoutManager, params) {
var options = {};
//set properties from options
options[PanelBaseWithHeader.OPTIONS.LOGGER_INSTANCE_NAME] = '<%= visualizerID %>Panel';
options[PanelBaseWithHeader.OPTIONS.LOGGER_INSTANCE_NAME] = '<%=visualizerID%>Panel';
options[PanelBaseWithHeader.OPTIONS.FLOATING_TITLE] = true;

//call parent's constructor
Expand All @@ -30,26 +30,26 @@ define(['js/PanelBase/PanelBaseWithHeader',
//initialize UI
this._initialize();

this.logger.debug('<%= visualizerID %>Panel ctor finished');
this.logger.debug('<%=visualizerID%>Panel ctor finished');
};

//inherit from PanelBaseWithHeader
_.extend(<%= visualizerID %>Panel.prototype, PanelBaseWithHeader.prototype);
_.extend(<%= visualizerID %>Panel.prototype, IActivePanel.prototype);
_.extend(<%=visualizerID%>Panel.prototype, PanelBaseWithHeader.prototype);
_.extend(<%=visualizerID%>Panel.prototype, IActivePanel.prototype);

<%= visualizerID %>Panel.prototype._initialize = function () {
<%=visualizerID%>Panel.prototype._initialize = function () {
var self = this;

//set Widget title
this.setTitle('');

this.widget = new <%= visualizerID %>Widget(this.$el);
this.widget = new <%=visualizerID%>Widget(this.$el);

this.widget.setTitle = function (title) {
self.setTitle(title);
};

this.control = new <%= visualizerID %>Control({
this.control = new <%=visualizerID%>Control({
client: this._client,
widget: this.widget
});
Expand All @@ -59,19 +59,19 @@ define(['js/PanelBase/PanelBaseWithHeader',

/* OVERRIDE FROM WIDGET-WITH-HEADER */
/* METHOD CALLED WHEN THE WIDGET'S READ-ONLY PROPERTY CHANGES */
<%= visualizerID %>Panel.prototype.onReadOnlyChanged = function (isReadOnly) {
<%=visualizerID%>Panel.prototype.onReadOnlyChanged = function (isReadOnly) {
//apply parent's onReadOnlyChanged
PanelBaseWithHeader.prototype.onReadOnlyChanged.call(this, isReadOnly);

};

<%= visualizerID %>Panel.prototype.onResize = function (width, height) {
<%=visualizerID%>Panel.prototype.onResize = function (width, height) {
this.logger.debug('onResize --> width: ' + width + ', height: ' + height);
this.widget.onWidgetContainerResize(width, height);
};

/* * * * * * * * Visualizer life cycle callbacks * * * * * * * */
<%= visualizerID %>Panel.prototype.destroy = function () {
<%=visualizerID%>Panel.prototype.destroy = function () {
this.control.destroy();
this.widget.destroy();

Expand All @@ -80,19 +80,19 @@ define(['js/PanelBase/PanelBaseWithHeader',
WebGMEGlobal.Toolbar.refresh();
};

<%= visualizerID %>Panel.prototype.onActivate = function () {
<%=visualizerID%>Panel.prototype.onActivate = function () {
this.widget.onActivate();
this.control.onActivate();
WebGMEGlobal.KeyboardManager.setListener(this.widget);
WebGMEGlobal.Toolbar.refresh();
};

<%= visualizerID %>Panel.prototype.onDeactivate = function () {
<%=visualizerID%>Panel.prototype.onDeactivate = function () {
this.widget.onDeactivate();
this.control.onDeactivate();
WebGMEGlobal.KeyboardManager.setListener(undefined);
WebGMEGlobal.Toolbar.refresh();
};

return <%= visualizerID %>Panel;
return <%=visualizerID%>Panel;
});
Loading

0 comments on commit 7b665a7

Please sign in to comment.