Skip to content

Commit

Permalink
Added panelPaths to config. Fixes #625
Browse files Browse the repository at this point in the history
Updated panel basePaths to be consistent with plugins/addons. #625

Added alias WIP #625

WIP #625
  • Loading branch information
brollb committed Oct 19, 2015
1 parent abd0b5b commit d6792fd
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 11 deletions.
2 changes: 2 additions & 0 deletions config/config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ var path = require('path'),
decoratorPaths: [path.join(__dirname, '../src/client/decorators')],
visualizerDescriptors: [path.join(__dirname, '../src/client/js/Visualizers.json')],

panelPaths: [path.join(__dirname, '../src/client/js/Panels')],

layout: {
default: 'DefaultLayout',
basePaths: [path.join(__dirname, '../src/client/js/Layouts')]
Expand Down
1 change: 1 addition & 0 deletions config/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ function validateConfig(configOrFileName) {
expectedKeys.push('visualization');
assertObject('config.visualization', config.visualization);
assertArray('config.visualization.decoratorPaths', config.visualization.decoratorPaths);
assertArray('config.visualization.panelPaths', config.visualization.panelPaths);
assertArray('config.visualization.visualizerDescriptors', config.visualization.visualizerDescriptors);
assertObject('config.visualization.layout', config.visualization.layout);
assertString('config.visualization.layout.default', config.visualization.layout.default);
Expand Down
5 changes: 2 additions & 3 deletions src/client/js/LayoutManager/LayoutManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ define(['js/logger', 'js/Loader/LoaderCircles'], function (Logger, LoaderCircles

'use strict';

var LayoutManager,
PANEL_PATH = 'js/Panels/';
var LayoutManager;

LayoutManager = function () {
this._currentLayout = undefined;
Expand Down Expand Up @@ -67,7 +66,7 @@ define(['js/logger', 'js/Loader/LoaderCircles'], function (Logger, LoaderCircles
var self = this,
panel = params.panel,
container = params.container,
rPath = PANEL_PATH + panel, // FIXME: This will be a problem...
rPath = ['panel', panel].join('/'),
containerSizeUpdateFn,
fn;

Expand Down
2 changes: 1 addition & 1 deletion src/client/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ require.config({
executor: '/common/executor',
plugin: '/plugin',
layout: '/layout',
panels: '/panels',
panel: '/panel',

//node_modules
jszip: 'lib/jszip/jszip',
Expand Down
60 changes: 53 additions & 7 deletions src/server/standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,51 @@ function StandAloneServer(gmeConfig) {
}
}

function getGoodExtraAssetRouteFor(component, basePaths) {
// Check for good extra asset
return function(req, res) {
res.sendFile(Path.join(__baseDir, req.path), function (err) {
if (err && err.code !== 'ECONNRESET') {
//this means that it is probably plugin/pluginName or plugin/pluginName/relativePath format
// so we try to look for those in our config
//first we check if we have the plugin registered in our config
var urlArray = req.url.split('/'),
pluginName = urlArray[2] || null,
basePath,
baseAndPathExist,
relPath;

relPath = getRelPathFromUrlArray(urlArray);
basePath = getBasePathByName(pluginName, basePaths);
baseAndPathExist = typeof basePath === 'string' && typeof relPath === 'string';
if (baseAndPathExist &&
webgmeUtils.isGoodExtraAsset(pluginName, Path.join(basePath, pluginName))) {
expressFileSending(res, Path.resolve(Path.join(basePath, relPath)));
} else {
res.sendStatus(404);
}
}
});
};
}

function getRelPathFromUrlArray(urlArray) {
urlArray.shift();
urlArray.shift();
urlArray.shift();
var relPath = urlArray.join('/');
if (!Path.extname(relPath)) { // js file by default
relPath += '.js';
}
return relPath;
}

/**
* Unlike `getGoodExtraAssetRouteFor`, `getRouteFor` does not assume that the
* resource hosts a main file which has the same structure as the parent directory.
* That is, there are examples of panels (such as SplitPanel) in which the
* main file does not adhere to the format "NAME/NAME+'Panel'"
*/
function getRouteFor(component, basePaths) {
//first we try to give back the common plugin/modules
return function(req, res) {
Expand All @@ -397,9 +442,8 @@ function StandAloneServer(gmeConfig) {
var urlArray = req.url.split('/'),
pluginName = urlArray[2] || null,
basePath,
relPath = '';
relPath;

urlArray.shift();
urlArray.shift();
urlArray.shift();
relPath = urlArray.join('/');
Expand All @@ -423,9 +467,7 @@ function StandAloneServer(gmeConfig) {
var additional = FS.readdirSync(basePaths[i]);
for (var j = 0; j < additional.length; j++) {
if (additional[j] === pluginName) {
if (webgmeUtils.isGoodExtraAsset(additional[j], Path.join(basePaths[i], additional[j]))) {
return basePaths[i];
}
return basePaths[i];
}
}
}
Expand Down Expand Up @@ -705,11 +747,15 @@ function StandAloneServer(gmeConfig) {

// Plugin paths
logger.debug('creating plugin specific routing rules');
__app.get(/^\/plugin\/.*/, getRouteFor('plugin', gmeConfig.plugin.basePaths));
__app.get(/^\/plugin\/.*/, getGoodExtraAssetRouteFor('plugin', gmeConfig.plugin.basePaths));

// Layout paths
logger.debug('creating layout specific routing rules');
__app.get(/^\/layout\/.*/, getRouteFor('layout', gmeConfig.visualization.layout.basePaths));
__app.get(/^\/layout\/.*/, getGoodExtraAssetRouteFor('layout', gmeConfig.visualization.layout.basePaths));

// Panel paths
logger.debug('creating path specific routing rules');
__app.get(/^\/panel\/.*/, getRouteFor('panel', gmeConfig.visualization.panelPaths));

logger.debug('creating external library specific routing rules');
gmeConfig.server.extlibExcludes.forEach(function (regExStr) {
Expand Down
22 changes: 22 additions & 0 deletions webgme.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,28 @@ function addToRequireJsPaths(gmeConfig) {
addFromBasePath(gmeConfig.plugin.basePaths, 'plugin');
addFromBasePath(gmeConfig.addOn.basePaths, 'addon');
addFromBasePath(gmeConfig.visualization.layout.basePaths, 'layout');

// Panels are structured a little differently and may not have
// PANEL_NAME/PANEL_NAME.js like plugins, addons or layouts
var paths = gmeConfig.visualization.panelPaths,
panelPaths = {},
itemPath,
items;

for (var i = paths.length; i--;) {
items = fs.readdirSync(paths[i]);
// Add all contained directories
for (var j = items.length; j--;) {
itemPath = path.join(paths[i], items[j]);
if (fs.statSync(itemPath).isDirectory()) {
panelPaths['panel/' + items[j]] = path.relative(requireJsBase, paths[i]);
}
}
}
requirejs.config({
paths: panelPaths
});

addFromRequireJsPath(gmeConfig.requirejsPaths);
}

Expand Down

0 comments on commit d6792fd

Please sign in to comment.