Comparar commits

..

61 Commits

Autor SHA1 Mensagem Data
Brian Broll 1abbecc54c v0.13.0 2016-08-15 10:07:40 -05:00
Brian Broll af2f34545b Added basic table literal support. Fixes #652 (#689) 2016-08-12 17:05:03 -05:00
Brian Broll f7499c4599 Added more robust layer parsing to LayerEditor. Fixes #670 (#688)
WIP #670 Added most LayerParser fn-ality

WIP Fixed error w/ changing arch editors

WIP #670 Added pointer, setter support in layer editor

WIP #670 Updated for layer-as-args

WIP #670 Fixed ctor_arg_order setting

WIP #670 Removed unused fn
2016-08-12 15:59:10 -05:00
Brian Broll ad52fe7d70 Removed containing dir info from stack trace. Fixes #668 (#687) 2016-08-12 15:30:16 -05:00
Brian Broll 5ddeb6f331 Added layers-as-arguments. Fixes #654 (#684)
WIP #654 Added LayerDecorator

WIP #654

WIP #654 Added support for adding/removing layers

WIP #654 Fixed the text for the layers

WIP #654 Refactored content text

WIP #654 Only delete target if it's a child

WIP #654 Updated for layers-as-args

WIP #654 Made a better name for layer args

WIP #654 Added explicit arg types

WIP #654 Changed argindex -> ctor_arg_order

WIP #654 Added support for layers-as-args in GenArch

WIP #654 Added import fn-ality

WIP #654 Updated visualizers for layer support

WIP #654 Fixed code climate issues

WIP #654 Fixed setter detection

WIP #654 Updated tests

WIP #654 Updated tests
2016-08-12 14:28:54 -05:00
Brian Broll 7cd3d961cf Added naming executions. Fixes #683 (#685)
WIP #683 Removed issue from merge w/ master

WIP #683 Updated googlenet test
2016-08-12 13:43:26 -05:00
Brian Broll c38b38b4a1 Added more logging to better debug failures in the future. Fixes #660 (#680)
WIP #660 Added more logs

WIP #660 Added more logs during execution creation

WIP #660 Added more logging for starting executions
2016-08-12 09:54:13 -05:00
Brian Broll 6ae73ece70 Added edit icon for custom layers. Fixes #678 (#679) 2016-08-11 21:33:16 -05:00
Brian Broll b5512d8228 Added better error handling when blob changed. Fixes #659 (#677) 2016-08-11 17:03:48 -05:00
Brian Broll 89c871412a Remove territory ui on ExecIndex destroy. Fixes #673 (#676) 2016-08-11 16:42:13 -05:00
JimnyCricket 33e28aa3f1 Filter non-numbers before graphing. Fixes #671 (#672)
WIP #671 Fixed code climate issues
2016-08-11 16:16:07 -05:00
Brian Broll 3899c3cb16 Added attr type inference in parser. Fixes #655 (#669)
WIP #655 Added type inference based on defaults

WIP #655 removed extra console.log

WIP #655 Inferring type from assertions

WIP #655 Fixed some parsing bugs

WIP #655 Added better type inference

WIP #655 Using types in metamodel creation

WIP #655 Added types

WIP #655 Updated nn library

WIP #655 Fixed code climate issues
2016-08-11 13:22:06 -05:00
Brian Broll eb4f97e9b5 Added check for points before graphing. Fixes #663 (#665)
WIP #663 Removed empty point text
2016-08-11 12:29:14 -05:00
JimnyCricket 16e37043f4 Added type checking for x,y in graph. Fixes #664 (#666)
Changed to single assertion with more info

WIP #664 "Expected" -> "expected"
2016-08-11 11:45:32 -05:00
Brian Broll 261ffd1eba Update README.md (#657) 2016-08-10 15:20:10 -05:00
Brian Broll 9167b33e18 Added configurable worker.cache.dir and worker.cache.useBlob. Fixes #638 (#653)
WIP #638 Added config schema

WIP #638 Added default cache location

WIP #638 Added useBlob fn-ality

WIP #638 Added type checking

WIP #638 Fixed config merge issue

WIP #638 Create worker cache parent dir if needed
2016-08-10 08:23:44 -05:00
Brian Broll 6f7f0d01e5 Added check for undefined value. Fixes #650 (#651) 2016-08-09 16:39:20 -05:00
Brian Broll c11b1fe812 Added blob.dir configuration. Fixes #639 (#649)
WIP #639 Added config schema

WIP #639 Added blob.dir config value
2016-08-09 14:57:32 -05:00
Brian Broll 306425cae1 Added implicit require 'nn' to ImportTorch. Fixes #644 (#647)
WIP #644 Added test
2016-08-09 14:14:04 -05:00
Brian Broll 6d70728b54 Added recurrent layers. Fixes #477 (#645)
WIP #477 Added skipArgs and rnn parsing support

WIP #477 Added update script and updated CreateTorchMeta

WIP #477 Run update script after nn-parser

WIP #477 Simplified nn-parser usage (just 'rnn' or 'nn')

WIP #477 Added 'all' option

WIP #477 Updated the nn project

WIP #477 `require 'rnn'` => nop in importer

WIP #477 Updated gen arch

WIP #477 Updated update --torch

WIP #477 Added rnn installation to torch install

WIP #477 Fixed code climate issues
2016-08-09 13:50:19 -05:00
Brian Broll fadb654883 Create worker dir if doesn't exist. Fixes #643 (#646) 2016-08-09 13:49:13 -05:00
Brian Broll 6528bbdbc6 Clearing output viewer territory on destroy. Fixes #622 (#642) 2016-08-09 07:50:19 -05:00
Brian Broll 23852de607 Set the cache to blob in 'local' mode. Fixes #637 (#640) 2016-08-08 12:43:37 -05:00
Brian Broll 9cf66a0e02 Added caching support to workers. Fixes #616 (#636)
WIP #616 Added cache dir if doesn't exist

WIP #616 Removed data from execution files

WIP #616 Added pointer files to data download

WIP #616 Fixed symlink creation
2016-08-08 12:16:30 -05:00
Brian Broll ad19e0fb57 v0.12.0 2016-08-08 08:30:01 -05:00
Brian Broll 14f222bf6f Merge branch '624-large-files-fail-exec' 2016-08-04 15:23:00 -05:00
Brian Broll 95141d1a42 Added image counter for uploading. Fixes #625 (#632) 2016-08-04 15:14:26 -05:00
Brian Broll 93aaf72372 Added explicit data download on worker. Fixes #624
WIP #624 Missing parens
2016-08-04 15:11:02 -05:00
Brian Broll 47a6612ed0 Added anchor detection on output type click. Fixes #626 (#631) 2016-08-04 14:37:15 -05:00
Brian Broll fe48af8bf4 Created unique worker config and cleanup on close. Fixes #618 (#623) 2016-08-04 10:55:06 -05:00
Brian Broll 78ca4f8762 Added error logs for more complex errors. Fixes #620 (#621)
WIP #620 Added error message to stdout

WIP #620 Added colors and console message
2016-08-04 10:01:36 -05:00
Brian Broll a7e08aa279 Update attributes on cancel job. Fixes #617 (#619)
WIP #617 moved client edits out of promise

WIP #617 Made 'isRunning' more robust

WIP #617 Fixed client calls
2016-08-04 08:37:09 -05:00
Brian Broll e2980d616f Filter out all non-alphanumeric or _ chars in execution. Fixes #612 (#614) 2016-08-03 16:55:02 -05:00
Brian Broll 96f2090d9e Removed long error message on failed exec. Fixes #608 (#611) 2016-08-03 15:55:04 -05:00
Brian Broll 8a86a114db Updated Materialize to explicit require (~global). Fixes #607 (#610) 2016-08-03 15:44:31 -05:00
Brian Broll cb757da118 Added torch config dir check before update. Fixes #606 (#609) 2016-08-03 15:36:43 -05:00
Brian Broll 31711e079a Enabled autoMerge. Fixes #332 Fixes #346 (#605) 2016-08-03 14:02:11 -05:00
Brian Broll 16ebb83ae6 Hiding restart button when running. Fixes #597 (#604) 2016-08-03 13:49:17 -05:00
Brian Broll 65304b2645 Changed SNAPSHOT->DEBUG. Fixes #601 (#603) 2016-08-03 13:18:41 -05:00
Brian Broll b44c6a104b Added execution canceling. Fixes #481 (#602)
WIP #481 Added buttons and jobId, secret setting

WIP #481 Added 'jobId', 'secret' to Job

WIP #481 Canceling job exec support

WIP #481 Added canceling executing pipelines

WIP #481 Fixed canceling pipelines

WIP #481 Improved result messages from executions

WIP #481 Updated decorator and status setting for ExecJob

WIP #481 Updated job colors in lists

WIP #481 Updated pipeline library

WIP #481 Fixed code climate issues
2016-08-03 12:42:55 -05:00
Brian Broll a8e5876f83 Updated fab icon colors. Fixes #588 (#599) 2016-08-03 08:41:24 -05:00
Brian Broll 2d9d1e71c0 Added "complete" notification if exec forked. Fixes #596 (#598)
WIP #596 Added quotes around job, exec, branch for consistency
2016-08-03 08:37:24 -05:00
Brian Broll 475bdfed50 Added notification on fork to ExecuteJob. Fixes #591 (#595)
WIP #591 Added notification on fork to ExecuteJob

WIP #591 Fixed fork name creation
2016-08-03 08:16:04 -05:00
Brian Broll c36f12ccb2 Added Execution dashboard. Fixes #587 (#594)
WIP #587 Added toggling embedded viz

WIP #587 Added ExecutionIndex

WIP #587 Added exec table and rows

WIP #587 Added status colors

WIP #587 Added color coded by status

WIP #587 Retrieved graphs for each execution

WIP #587 Added lineGraph object in right split

WIP #587 Fixed lineGraph resize and added multiple lines

WIP #587 Fixed line updates/removal

WIP #587 Added execution selection

WIP #587 Added execution toggling

WIP #587 Fixed untoggle-able after update

WIP #587 Fixed exec status color updates

WIP #578 Exec name click -> navigate to the given execution

WIP #587 Added pipeline names

WIP #587 Added default 'checking' and pipeline name updates

WIP #587 Fixed the deselection of running execs

WIP #587 Fixed initial pipeline names

WIP #587 Added toggling visualizers

WIP #587 Fixed positioning

WIP #587 Added more logs and fixed pipeline name finding

WIP #587 Fixed project switching and obj changed

WIP #587 Improved perf of chart
2016-08-02 16:42:28 -05:00
Brian Broll 0b8b5b8adf Added decimal to number chars in graph plotting. Fixes #589 (#590) 2016-08-02 11:56:50 -05:00
Brian Broll e981c97c71 v0.11.0 2016-08-01 09:21:51 -05:00
Brian Broll 748461f3c6 Added more flexible ansi code detection. Fixes #582 (#584)
WIP #582 Added better ansi regex

WIP #582 Fixed infinite loop
2016-08-01 09:17:22 -05:00
Brian Broll a51f55dd66 Added operation 'attributes' autocompletions. Fixes #578 (#581) 2016-07-31 17:36:05 -05:00
Brian Broll 7ba2c59265 Propagate the exit code of child process to parent. Fixes #579 (#580) 2016-07-31 07:57:45 -05:00
Brian Broll dcc833a957 Update README.md 2016-07-30 13:11:53 -05:00
Brian Broll 8c35af6554 Added output icons in the job editor. Fixes #576 (#577) 2016-07-30 12:58:12 -05:00
Brian Broll 70fe60a45d Added 'deepforge.image(<name>, <tensor>)' support. Fixes #519 (#575)
WIP #519 Added saving image file on worker

WIP #519 Added wrapper for the intermediate data results

WIP #519 filename->name and silenced blobClient logs

WIP #519 Removed old debug log

WIP #519 Added Image metadata creation

WIP #519 Added ImageViewer

WIP #519 Added zoom fn-ality

WIP #519 Added 'Image' node

WIP #519 Updated pipeline libraries

WIP #519 Added 'image' to deepforge autocomplete

WIP #519 Added no-image image

WIP #519 Fixed image updating

WIP #519 Added better origin url detection

WIP #519 Fixed code climate issues

WIP #519 fixed code climate issues
2016-07-30 11:06:46 -05:00
Brian Broll 98c64fc37a Added custom class inheritance support. Fixes #412 (#573)
WIP #412 Added inheritance setting/unsetting based on code

WIP #412 Fixed ordering of the base class loading

WIP #412 Set test timeout to 5s
2016-07-29 12:04:46 -05:00
Brian Broll efa88194a1 Merged 'snapshot', 'debug' options. Fixes #570 (#572) 2016-07-29 11:38:07 -05:00
Brian Broll f1a5fb18e9 Added basic torch, deepforge code completion. Fixes #565 (#567)
WIP #565 Added entire ace lib. Added dummy completer

WIP #565 Added torch, deepforge completion

WIP #565 Fixed code climate issue

WIP #565 Fixed nodejs ci version
2016-07-28 16:16:54 -05:00
Brian Broll 084f79c51a Removed connection selection in op interface. Fixes #566 (#568) 2016-07-28 15:21:13 -05:00
Brian Broll 2561b1c43a Removed special characters during metadata cmds. Fixes #562 (#563)
WIP #562 Added cleaning the ansi codes from metadata cmds

WIP #562 Fixed point parsing

WIP #562 Cleaning x,y point text
2016-07-28 13:17:03 -05:00
Brian Broll a0b20408fd Fixed running ExecutePipeline on server. Fixes #558 (#561)
WIP #558 Fixed running ExecutePipeline on server

WIP #558 attempted to implement ExecutePipeline tests...

WIP #558 Fixed running ExecutePipeline on server

WIP #558 Removed extra TODO and extra files
2016-07-27 18:18:11 -05:00
Brian Broll 5f3bf23a6a Added xor example. Fixes #557 (#560)
WIP #557 xor example

WIP #557 Added test, train and manual train pipelines
2016-07-27 13:10:15 -05:00
Brian Broll 4badd0d001 Added check for existing artifact w/ same name, hash. Fixes #544 (#555)
WIP #544 Fixed code climate issue
2016-07-27 09:36:29 -05:00
Brian Broll 383eda1f2b Added 'setter' support and default attr detection. Fixes #541 Fixes #553 (#554)
WIP #541 Refactored nn-parser for better reusability

WIP #541 Added setter support to the parser script

WIP #541 Added check for class method match

WIP #541 Added default detection

WIP #541 Added setter support in CreateTorchMeta

WIP #541 Added setters to layer-args.js

WIP #541 Added setter support in ImportTorch

WIP #541 Updated ImportTorch tests

WIP setPointer -> setBase

WIP #541 Updated ImportTorch examples

WIP #541 added setter attributes

WIP #541 Added setter support for GenArch

WIP #541 Updated the GenArch tests

WIP #541 Fixed utils tests

WIP #541 Updated nn library

WIP #541 Removed 'const' setters w/ only one value

WIP #541 Added setter creation test

WIP #541 Updated to use torch from deepforge config, if exists

WIP #541 Fixed code climate issues

WIP #541 skipping broken tests until webgme error is resolved

WIP #541 Updated nn seed after removing meaningless 'const' setters
2016-07-27 09:36:21 -05:00
1113 arquivos alterados com 318218 adições e 21147 exclusões
+1 -2
Ver Arquivo
@@ -2,5 +2,4 @@ language: node_js
services: mongodb
sudo: false
node_js:
- "4.1.1"
- "4.2.5"
- "6.2.1"
+3 -1
Ver Arquivo
@@ -18,7 +18,9 @@ curl -o- https://raw.githubusercontent.com/dfst/deepforge/master/install.sh | ba
Next, start deepforge with `deepforge start`!
Finally, navigate to [http://localhost:8888](http://localhost:8888) to start using DeepForge! For more, detailed instructions,check out our [wiki](https://github.com/dfst/deepforge/wiki/Installation-Guide).
Finally, navigate to [http://localhost:8888](http://localhost:8888) to start using DeepForge! For more, detailed instructions, check out the [wiki](https://github.com/dfst/deepforge/wiki/Installation-Guide).
Also, be sure to check out the other available features of the `deepforge` cli; it can be used to update, manage your torch installation, uninstall deepforge and run individual components!
## Interested in contributing?
Contributions are welcome! Either fork the project and submit some PR's or shoot me an email about getting more involved!
+9
Ver Arquivo
@@ -2,6 +2,15 @@
"torch": {
"dir": "~/.deepforge/torch"
},
"blob": {
"dir": "~/.deepforge/blob"
},
"worker": {
"cache": {
"useBlob": true,
"dir": "~/.deepforge/worker/cache"
}
},
"mongo": {
"dir": "~/.deepforge/data"
}
+90 -33
Ver Arquivo
@@ -3,7 +3,7 @@
var Command = require('commander').Command,
program = new Command(),
childProcess = require('child_process'),
spawn = childProcess.spawn,
rawSpawn = childProcess.spawn,
execSync = childProcess.execSync,
path = require('path'),
fs = require('fs'),
@@ -11,7 +11,7 @@ var Command = require('commander').Command,
exists = require('exists-file'),
forever = require('forever-monitor'),
DEFAULT_CONFIG = require('./config.json'),
assign = require('lodash.assign'),
merge = require('lodash.merge'),
config,
configDir = path.join(process.env.HOME, '.deepforge'),
@@ -20,7 +20,12 @@ var Command = require('commander').Command,
localConfig,
rm_rf = require('rimraf'),
p = dir => dir.replace(/^~/, process.env.HOME); // resolve '~' to '$HOME'
p = dir => {
if (typeof dir === 'string') {
return dir.replace(/^~/, process.env.HOME); // resolve '~' to '$HOME'
}
return dir;
};
// Check for any commands
if (process.argv.length === 2) {
@@ -39,17 +44,17 @@ if (!exists.sync(configPath)) {
}
localConfig = require(configPath);
config = assign(DEFAULT_CONFIG, require(configPath));
config = merge({}, DEFAULT_CONFIG, localConfig);
var getConfigValue = function(id) {
var getConfigValue = function(id, srcConfig) {
var keys = id.split('.'),
value = config;
value = srcConfig || config;
for (var i = 0; i < keys.length; i++) {
value = value[keys[i]];
if (!value) {
if (!value.hasOwnProperty(keys[i])) {
return null;
}
value = value[keys[i]];
}
return value;
};
@@ -59,7 +64,8 @@ var storeConfig = function(id, value) {
var keys = id.split('.').filter(k => k),
lastKey = keys.pop(),
currentObj = localConfig,
current = getConfigValue(id);
current = getConfigValue(id),
expType = typeof getConfigValue(id, DEFAULT_CONFIG);
// Check if it is a valid key
if (current === null) {
@@ -73,11 +79,35 @@ var storeConfig = function(id, value) {
currentObj = currentObj[keys[i]];
}
if (expType !== 'string') {
try { // try to downcast
value = JSON.parse(value);
} catch (e) {
console.log(`Invalid value: "${value}" (expected ${expType})`);
return;
}
}
currentObj[lastKey] = value;
fs.writeFileSync(configPath, JSON.stringify(localConfig, null, 2));
return true;
};
(function() { // Load config to env
var envToConf = require('./envConfig.json');
Object.keys(envToConf).forEach(env => {
var cKey = envToConf[env];
process.env[env] = process.env[env] || p(getConfigValue(cKey));
});
// Special cases
if (process.env.DEEPFORGE_WORKER_USE_BLOB === 'true' &&
exists.sync(process.env.DEEPFORGE_BLOB_DIR)) {
process.env.DEEPFORGE_WORKER_CACHE = process.env.DEEPFORGE_BLOB_DIR + '/wg-content';
}
})();
program
.version('v' + version)
.description('Command line interface for managing deepforge');
@@ -115,7 +145,7 @@ var checkMongo = function(args) {
};
var startMongo = function(args, silent) {
var job = spawn('mongod', ['--dbpath', p(config.mongo.dir)], {
var job = rawSpawn('mongod', ['--dbpath', p(config.mongo.dir)], {
cwd: process.env.HOME
});
if (!silent) {
@@ -166,7 +196,8 @@ var _checkTorch = function(resolve, reject) {
process.chdir(tgtDir);
spawnMany([
'bash install-deps',
'./install.sh'
'./install.sh',
'luarocks install rnn'
], () => {
storeConfig('torch.dir', tgtDir);
resolve(true);
@@ -192,7 +223,7 @@ var spawnMany = function(cmds, succ, err) {
rawCmd = cmds.shift();
args = rawCmd.split(' ');
cmd = args.shift();
job = spawn(cmd, args);
job = rawSpawn(cmd, args);
job.stdout.on('data', data => process.stdout.write(data));
job.stderr.on('data', data => process.stderr.write(data));
job.on('close', code => {
@@ -206,6 +237,28 @@ var spawnMany = function(cmds, succ, err) {
};
var spawn = function(cmd, args, opts) {
var promise,
err;
args = args || [];
promise = new Promise((resolve, reject) => {
var job = opts ? rawSpawn(cmd, args, opts) : rawSpawn(cmd, args);
job.stdout.on('data', data => process.stdout.write(data));
job.stderr.on('data', data => process.stderr.write(data));
job.on('close', code => {
if (err) {
reject(err);
} else {
resolve(code);
}
});
job.on('error', e => err = e);
});
return promise;
};
program.command('start')
.description('start deepforge locally (default) or specific components')
.option('-p, --port <port>', 'specify the port to use')
@@ -264,7 +317,6 @@ program
.option('-s, --server', 'update deepforge')
.action(args => {
var pkg = 'deepforge',
job,
latestVersion;
// Install the project
@@ -287,16 +339,11 @@ program
}
}
job = spawn('npm', ['install', '-g', pkg]);
job.stdout.on('data', data => process.stdout.write(data.toString()));
job.stderr.on('data', data => process.stderr.write(data.toString()));
job.on('close', code => {
if (!code) {
spawn('npm', ['install', '-g', pkg])
.then(() => {
console.log('Upgrade successful!');
} else {
console.log('Upgrade failed w/ error code: ' + code);
}
});
})
.catch(code => console.log('Upgrade failed w/ error code: ' + code));
}
if (args.torch || !args.server) {
@@ -305,18 +352,28 @@ program
if (!justInstalled) {
// Upgrade torch
console.log('Upgrading torch...');
job = spawn('bash', ['./update.sh'], {
cwd: p(config.torch.dir)
});
job.stdout.on('data', data => process.stdout.write(data.toString()));
job.stderr.on('data', data => process.stderr.write(data.toString()));
job.on('close', code => {
if (!code) {
console.log(`Checking for torch in ${config.torch.dir}`);
// Verify that torch is installed in the config's location
if (!exists.sync(path.join(config.torch.dir, 'update.sh'))) {
// config is incorrect!
console.log('Could not find torch installation. Please update the deepforge config with:');
console.log('');
console.log(' deepforge config torch.dir ~/path/to/torch/install');
console.log('');
return;
}
spawn('bash', ['./update.sh'], {cwd: p(config.torch.dir)})
.catch(err => console.log('Upgrade failed w/ error code: ' + err.code))
.then(() => {
console.log('About to update rnn package...');
// Update rnn
return spawn('luarocks', ['install', 'rnn']);
})
.then(() => {
console.log('Upgrade successful!');
} else {
console.log('Upgrade failed w/ error code: ' + code);
}
});
})
.catch(code => console.log('Upgrade failed w/ error code: ' + code));
}
});
}
+5
Ver Arquivo
@@ -0,0 +1,5 @@
{
"DEEPFORGE_BLOB_DIR": "blob.dir",
"DEEPFORGE_WORKER_CACHE": "worker.cache.dir",
"DEEPFORGE_WORKER_USE_BLOB": "worker.cache.useBlob"
}
+8 -1
Ver Arquivo
@@ -4,7 +4,14 @@ var spawn = require('child_process').spawn,
execJob,
path = require('path'),
env = {cwd: path.join(__dirname, '..')},
workerJob = null;
workerJob = null,
gmeConfig = require(__dirname + '/../config');
// Set the cache to the blob
console.log(gmeConfig);
if (gmeConfig.blob.type === 'FS') {
process.env.DEEPFORGE_WORKER_CACHE = path.resolve(gmeConfig.blob.fsDir + '/wg-content');
}
process.env.NODE_ENV = 'local';
execJob = spawn('npm', [
+23 -2
Ver Arquivo
@@ -4,15 +4,29 @@ var path = require('path'),
fs = require('fs'),
childProcess = require('child_process'),
spawn = childProcess.spawn,
rm_rf = require('rimraf'),
projectConfig = require(__dirname + '/../config'),
executorSrc = path.join(__dirname, '..', 'node_modules', 'webgme', 'src',
'server', 'middleware', 'executor', 'worker'),
workerPath = path.join(__dirname, '..', 'src', 'worker'),
workerConfigPath = path.join(workerPath, 'config.json'),
workerConfigPath = path.join(workerPath, 'config_' + Date.now() + '.json'),
workerTmp = path.join(workerPath, 'tmp'),
address,
config = {};
var createDir = function(dir) {
try {
fs.statSync(dir);
} catch (e) {
// Create dir
fs.mkdirSync(dir);
return true;
}
return false;
};
createDir(workerPath);
createDir(workerTmp);
// Check torch support
var result = childProcess.spawnSync('th', ['--help']);
if (result.error) {
@@ -22,7 +36,15 @@ if (result.error) {
process.exit(1);
}
var cleanUp = function() {
console.log('removing config ', workerConfigPath);
rm_rf.sync(workerConfigPath);
};
var startExecutor = function() {
process.on('SIGINT', cleanUp);
process.on('uncaughtException', cleanUp);
// Start the executor
var execJob = spawn('node', [
'node_worker.js',
@@ -42,7 +64,6 @@ var createConfigJson = function() {
}
config[address] = {};
// TODO: Check if the config already exists
fs.writeFile(workerConfigPath, JSON.stringify(config), startExecutor);
};
+5
Ver Arquivo
@@ -9,7 +9,10 @@ require('dotenv').load({silent: true});
// Add/overwrite any additional settings here
config.server.port = +process.env.PORT || config.server.port;
config.mongo.uri = process.env.MONGO_URI || config.mongo.uri;
config.blob.fsDir = process.env.DEEPFORGE_BLOB_DIR || config.blob.fsDir;
config.requirejsPaths.deepforge = './src/common';
config.requirejsPaths.ace = './src/visualizers/widgets/TextEditor/lib/ace';
config.seedProjects.defaultProject = 'project';
config.plugin.allowBrowserExecution = true;
@@ -20,5 +23,7 @@ config.executor.clearOldDataAtStartUp = true;
config.visualization.extraCss.push('deepforge/styles/global.css');
config.storage.autoMerge.enable = true;
validateConfig(config);
module.exports = config;
+1
Ver Arquivo
@@ -20,6 +20,7 @@ config.seedProjects.basePaths.push('src/seeds/pipeline');
config.seedProjects.basePaths.push('src/seeds/devPipelineTests');
config.seedProjects.basePaths.push('src/seeds/project');
config.seedProjects.basePaths.push('src/seeds/cifar10');
config.seedProjects.basePaths.push('src/seeds/xor');
+4 -4
Ver Arquivo
@@ -12,23 +12,23 @@
"watch-test": "./node_modules/nodemon/bin/nodemon.js --exec 'node ./node_modules/mocha/bin/mocha --recursive test'",
"build-nn": "node ./utils/nn-parser.js"
},
"version": "0.10.1",
"version": "0.13.0",
"dependencies": {
"commander": "^2.9.0",
"dotenv": "^2.0.0",
"exists-file": "^2.1.0",
"forever-monitor": "^1.7.0",
"lodash.assign": "^4.0.9",
"lodash.difference": "^4.1.2",
"lodash.merge": "^4.5.1",
"nodemon": "^1.9.2",
"rimraf": "^2.4.0",
"webgme": "^2.0.0",
"webgme-autoviz": "dfst/webgme-autoviz",
"webgme-breadcrumbheader": "^2.1.0",
"webgme-chflayout": "^2.0.0",
"webgme-easydag": "dfst/webgme-easydag",
"webgme-fab": "dfst/webgme-fab",
"webgme-simple-nodes": "^2.0.0",
"rimraf": "^2.4.0"
"webgme-simple-nodes": "^2.1.0"
},
"devDependencies": {
"chai": "^3.0.0",
+7 -1
Ver Arquivo
@@ -4,7 +4,13 @@ define({
// DeepForge metadata creation in dist execution
START_CMD: 'deepforge-cmd',
IMAGE: 'IMG',
GRAPH_CREATE: 'GRAPH',
GRAPH_PLOT: 'PLOT',
GRAPH_CREATE_LINE: 'LINE'
GRAPH_CREATE_LINE: 'LINE',
// Code Generation Constants
CTOR_ARGS_ATTR: 'ctor_arg_order'
});
+380
Ver Arquivo
@@ -0,0 +1,380 @@
/* globals define*/
(function(root, factory){
if(typeof define === 'function' && define.amd) {
define(['./lua'], function(luajs){
return (root.LayerParser = factory(luajs));
});
} else if(typeof module === 'object' && module.exports) {
var luajs = require('./lua');
module.exports = (root.LayerParser = factory(luajs));
}
}(this, function(luajs) {
var LayerParser = {};
//////////////////////// Setters ////////////////////////
var returnsSelf = function(fnNode){
var stats = fnNode.block.stats,
last = stats[stats.length-1];
if (last.type === 'stat.return') {
return last.nret[0].type === 'variable' && last.nret[0].val === 'self';
}
return false;
};
var isAttrSetter = function(node){
if (node.type === 'stat.assignment' && node.lefts.length === 1) {
var left = node.lefts[0];
return left.type === 'expr.index' && left.self.val === 'self';
}
return false;
};
var getSettingAttrName = function(node){
if (isAttrSetter(node)) {
var left = node.lefts[0];
return left.key.val;
}
return null;
};
var getSettingAttrValue = function(node){
if (isAttrSetter(node)) {
return node.right;
}
return null;
};
var isSetterMethod = function(curr, parent, className){
if (parent && parent.type === 'stat.method') {
// is it a fn w/ two statements (stats)
if (parent.self.val === className && curr.type === 'function' &&
curr.block.stats.length === 2) {
// Is the first statement setting a value?
return returnsSelf(curr) && getSettingAttrName(curr.block.stats[0]); // does it return itself?
}
}
return false;
};
var isFnArg = function(method, name) {
return method.args.indexOf(name) !== -1;
};
var getSetterSchema = function(node, method) {
var setterType,
setterFn,
value = getSettingAttrValue(node);
if (value[0].type === 'variable' && isFnArg(method.func, value[0].val)) {
setterType = 'arg';
setterFn = method.key.val;
} else {
setterType = 'const';
setterFn = {};
setterFn[value[0].val] = method.key.val;
}
return {
setterType,
setterFn
};
};
//////////////////////// Setters END ////////////////////////
var isInitFn = function(node, className) {
if (node.type === 'stat.method' && node.self.val === className) {
return node.key.val === '__init';
}
return false;
};
var getClassAttrDefs = function(method) {
var fn = method.func,
dict = {},
attr,
right,
value;
luajs.codegen.traverse(curr => {
if (isAttrSetter(curr)) {
// Store the value if it is set to a constant
attr = curr.lefts[0].key.val;
right = curr.right[0];
if (right.type.indexOf('const.') !== -1) {
value = right.val;
if (right.type === 'const.nil') {
value = null;
}
dict[attr] = value;
}
}
})(fn);
return dict;
};
var getAttrsAndVals = function(method) {
// Given a method, get the 'self' attributes and the default values
var fn = method.func,
dict = {},
varName,
value,
varUsageCnt = {};
// Get the variables that are used only once (or updating themselves)
luajs.codegen.traverse(curr => {
if (curr.type === 'variable') {
varUsageCnt[curr.val] = varUsageCnt[curr.val] ?
varUsageCnt[curr.val] + 1 : 1;
}
})(method);
luajs.codegen.traverse(curr => {
// If the variable is only used once and is 'or'-ed w/ a constant
// during this use, we can infer that this is the default value
if (curr.type === 'expr.op' && curr.op === 'op.or' &&
curr.left.type === 'variable' && curr.right.type.indexOf('const') !== -1) {
varName = curr.left.val;
if (varUsageCnt[varName] === 1) {
value = curr.right.type === 'const.nil' ? null : curr.right;
dict[varName] = value;
}
}
})(fn);
return dict;
};
var copyNodeValues = function(attrs, from, to) {
var value;
for (var i = attrs.length; i--;) {
value = from[attrs[i]] || null;
if (value) {
value = (value && value.hasOwnProperty('val')) ? value.val : value;
to[attrs[i]] = value;
}
}
return to;
};
var getTypeCheckInfo = function(cond) {
var caller,
method,
target,
expType;
// Check for torch.isTypeOf:
if (cond.type === 'expr.call' && cond.func.type === 'expr.index') {
caller = cond.func.self.val;
method = cond.func.key.val;
if (cond.type === 'expr.call' && caller === 'torch') {
target = cond.args[0].val;
if (method === 'isTypeOf' && target) {
expType = cond.args[1].val;
return {
target,
type: expType
};
}
}
} else if (cond.type === 'expr.op') { // torch.type() === ''
// Check right side, too!
var sides = [cond.left, cond.right],
side,
otherSide;
for (var i = sides.length; i--;) {
side = sides[i];
otherSide = sides[(i+1)%2];
if (side.type === 'expr.call' && side.func.type === 'expr.index') {
// Is it torch?
caller = side.func.self.val;
method = side.func.key.val;
if (caller === 'torch' && method === 'type') {
if (side.args[0].type === 'variable') {
target = side.args[0].val;
if (otherSide.type === 'const.string') {
expType = otherSide.val;
return {
target: target,
type: expType
};
}
}
}
}
}
return null;
}
};
var isError = function(stat) {
var fn;
if (stat.type === 'stat.expr' && stat.expr.type === 'expr.call') {
fn = stat.expr.func.val;
return fn === 'error';
}
return false;
};
var inferParamTypes = function(node, paramDefs) {
var types = {},
check,
cond;
// Infer from assertions
luajs.codegen.traverse(curr => {
// check for 'assert's that check type
if (curr.type === 'expr.call' && curr.func.val === 'assert') {
cond = curr.args[0];
check = getTypeCheckInfo(cond);
if (check) {
types[check.target] = check.type;
}
} else if (curr.type === 'stat.if' && curr.cond.op === 'uop.not') {
// if statements throwing errors on type mismatch
cond = curr.cond.operand; // non-negated version
// Check that it throws an error on true
if (curr.tblock.stats.some(isError)) {
check = getTypeCheckInfo(cond);
if (check) {
types[check.target] = check.type;
}
}
}
})(node);
// Infer from defaults
Object.keys(paramDefs).forEach(param => {
var val = paramDefs[param];
if (val) { // initialized to 'null' doesn't help us...
types[param] = val.type.replace('const.', '');
}
});
return types;
};
var findTorchClass = function(ast){
var torchClassArgs, // args for `torch.class(...)`
name = '',
baseType,
params,
setters = {},
defaults = {},
paramDefs,
attrDefs;
if(ast.type == 'function'){
ast.block.stats.forEach(function(func){
if(func.type == 'stat.local' && func.right && func.right[0] &&
func.right[0].func && func.right[0].func.self &&
func.right[0].func.self.val == 'torch' &&
func.right[0].func.key.val == 'class'){
torchClassArgs = func.right[0].args.map(arg => arg.val);
name = torchClassArgs[0];
if(name !== ''){
name = name.replace('nn.', '');
if (torchClassArgs.length > 1) {
baseType = torchClassArgs[1].replace('nn.', '');
}
}
}
});
}
// Get the setters, defaults and type info (inferred)
var setterNames,
schema,
types,
values;
luajs.codegen.traverse((curr, parent) => {
var firstLine,
attrName;
// Record the setter functions
if (isSetterMethod(curr, parent, name)) {
firstLine = curr.block.stats[0];
// just use the attribute attrName for now...
attrName = getSettingAttrName(firstLine);
// merge schemas
schema = getSetterSchema(firstLine, parent);
if (setters[attrName] && setters[attrName].setterType === 'const') { // merge
for (var val in schema.setterFn) {
setters[attrName].setterFn[val] = schema.setterFn[val];
}
} else {
setters[attrName] = schema;
}
} else if (isInitFn(curr, name)) { // Record the defaults
paramDefs = getAttrsAndVals(curr);
attrDefs = getClassAttrDefs(curr);
types = inferParamTypes(curr, paramDefs);
// get ctor args
params = curr.func.args;
if(params.length === 0 && curr.func.varargs){
params.push('params');
}
}
})(ast);
// Get the defaults for the params from defs
if (paramDefs && params) {
copyNodeValues(params, paramDefs, defaults);
}
// Get the defaults for the setters from attrDefs
if (attrDefs) {
setterNames = Object.keys(setters);
copyNodeValues(setterNames, attrDefs, defaults);
}
// Remove any const setters w/ only one value and no default
setterNames = Object.keys(setters);
for (var i = setterNames.length; i--;) {
schema = setters[setterNames[i]];
if (schema.setterType === 'const') {
values = Object.keys(schema.setterFn);
if (values.length === 1 &&
// boolean setters can have the default value inferred
values[0] !== 'true' && values[0] !== 'false' &&
!defaults[setterNames[i]]) {
delete setters[setterNames[i]];
}
}
}
return {
name,
baseType,
params,
setters,
types,
defaults
};
};
LayerParser.parse = function(text) {
try {
var ast = luajs.parser.parse(text);
return findTorchClass(ast);
} catch (e) {
return null;
}
};
return LayerParser;
}));
+3 -1
Ver Arquivo
@@ -1,10 +1,12 @@
/* globals Materialize, WebGMEGlobal, define*/
/* globals WebGMEGlobal, define*/
// This file creates the DeepForge namespace and defines basic actions
define([
'panel/FloatingActionButton/styles/Materialize',
'js/RegistryKeys',
'js/Panels/MetaEditor/MetaEditorConstants',
'js/Constants'
], function(
Materialize,
REGISTRY_KEYS,
META_CONSTANTS,
CONSTANTS
+30 -11
Ver Arquivo
@@ -1,6 +1,8 @@
/* globals define*/
define([
'deepforge/Constants'
], function(
Constants
) {
'use strict';
@@ -15,32 +17,49 @@ define([
return result;
};
var isArgument = function(arg) {
return arg.hasOwnProperty('argindex');
};
var sortByIndex = function(a, b) {
return a.argindex > b.argindex;
var isSetter = function(arg) {
return arg.hasOwnProperty('setterType');
};
var createLayerDict = function(core, meta) {
var node,
names = Object.keys(meta),
layers = {};
layers = {},
setters,
ctorData,
ctorArgs,
attrs;
for (var i = names.length; i--;) {
node = meta[names[i]];
layers[names[i]] = core.getValidAttributeNames(node)
ctorData = core.getAttribute(node, Constants.CTOR_ARGS_ATTR);
attrs = core.getValidAttributeNames(node);
layers[names[i]] = {};
if (ctorData) {
ctorArgs = ctorData.split(',')
.map(attr => prepAttribute(core, node, attr));
// Get the constructor args
layers[names[i]].args = ctorArgs;
} else {
layers[names[i]].args = [];
}
layers[names[i]].setters = {};
setters = attrs
.map(attr => prepAttribute(core, node, attr))
.filter(isArgument)
.sort(sortByIndex);
.filter(isSetter);
for (var j = setters.length; j--;) {
layers[names[i]].setters[setters[j].name] = setters[j];
}
}
return layers;
};
// When provided with the META, create the given LayerDict object
// - Sort (and filter) by argindex
// - Filter out the ctor args (in order)
// - add name attribute to schema
// - store this array under the META name
-546
Ver Arquivo
@@ -1,546 +0,0 @@
# This file should actually be an alternative way of viewing the metamodel.
#
# This contains metadata about the Torch nn library used for
# creating the metamodel
#
# By default...
# - all attributes are a number
# - default values are optional
# - all booleans default to false
# - list attributes are specified with WORD...WORD
# - if `ignore` is set, the attribute is not added to the metamodel
# This should have tests to verify that this document is up to date...
# TODO
Containers:
- Concat:
- dim:
min: 1 # TODO: Figure out exactly how this works
Module:
- SpatialBatchNormalization:
- input:
infer: dimensionality # change this to `infer: 'dimensionality'`
- eps:
default: 0.00001
- momentum:
default: 0.1
- affine:
default: true
- BatchNormalization:
- input:
infer: dimensionality # change this to `infer: 'dimensionality'`
- eps:
default: 0.00001
- momentum:
default: 0.1
- affine:
default: true
- Threshold:
- threshold:
type: float
default: 1e-6
- value:
type: float
default: 0
- inplace:
type: boolean
default: false
ConvLayer:
- TemporalConvolution:
- inputFrameSize:
min: 1
- outputFrameSize:
min: 1
- kernelWidth:
min: 1
- step:
default: 1
- TemporalMaxPooling:
- kernelWidth:
min: 1
- step: # FIXME: defaults to 'kernelWidth'
min: 1
- TemporalSubSampling:
- inputFrameSize:
min: 1
- kernelWidth:
min: 1
- step:
min: 1
# TODO: What is the default?
- LookupTable:
- nIndex:
min: 1
- sizes:
min: 1
# Spatial Modules
- SpatialConvolutionMM:
- nInputPlane: # TODO: Infer this
min: 1
- nOutputPlane:
min: 1
- kernelWidth:
min: 1
- kernelHeight:
min: 1
- strideWidth:
min: 1
default: 1
- strideHeight:
min: 1
default: 1
- padWidth:
min: 0
default: 0
- padHeight: # FIXME: this defaults to padWidth - not 0
min: 0
default: 0
- SpatialConvolution:
- nInputPlane:
min: 1
- nOutputPlane:
min: 1
- kernelWidth:
min: 1
- kernelHeight:
min: 1
- strideWidth:
min: 1
default: 1
- strideHeight:
min: 1
default: 1
- SpatialConvolutionMap:
- connectionMatrix:
min: 1
- kernelWidth:
min: 1
- kernelHeight:
min: 1
- strideWidth:
min: 1
default: 1
- strideHeight:
min: 1
default: 1
- SpatialLPPooling:
- nInputPlane:
min: 1
- norm:
min: 1
- kernelWidth:
min: 1
- kernelHeight:
min: 1
- strideWidth:
min: 1
default: 1
- strideHeight:
min: 1
default: 1
- SpatialMaxPooling:
- kernelWidth:
min: 1
- kernelHeight:
min: 1
- strideWidth:
min: 1
default: 1
- strideHeight:
min: 1
default: 1
- SpatialAveragePooling:
- kernelWidth:
min: 1
- kernelHeight:
min: 1
- strideWidth:
min: 1
default: 1
- strideHeight:
min: 1
default: 1
- SpatialAdaptiveMaxPooling: # output is width x height
- width:
min: 1
- height:
min: 1
- SpatialSubSampling:
- nInputPlane:
min: 1
- kernelWidth:
min: 1
- kernelHeight:
min: 1
- strideWidth:
min: 1
default: 1
- strideHeight:
min: 1
default: 1
- SpatialUpSamplingNearest:
- scale: # upscale ratio
min: 1
- SpatialZeroPadding:
- left:
min: 0
- right:
min: 0
- top:
min: 0
- bottom:
min: 0
- SpatialSubtractiveNormalization:
- nInputPlane:
min: 1
- kernel:
min: 1
- SpatialCrossMapLRN:
- size:
min: 1
- alpha:
default: 0.0001
- beta:
default: 0.75
- k:
default: 1
- SpatialConvolutionLocal:
- nInputPlane:
min: 1
- nOutputPlane:
min: 1
- inputWidth: # TODO: infer this
min: 1
- inputHeight: # TODO: infer this
min: 1
- kernelWidth:
min: 1
- kernelHeight:
min: 1
- strideWidth:
min: 1
default: 1
- strideHeight:
min: 1
default: 1
- padWidth:
min: 0
default: 0
- padHeight: # FIXME: this defaults to padWidth - not 0
min: 0
default: 0
- SpatialDropout:
- probability:
default: 0.5
- SpatialFractionalMaxPooling:
- poolWidth:
- min: 2
- poolHeight:
- min: 2
- outWidth: # Optionally, these could be ratioW/H FIXME
- min: 1
- outHeight:
- min: 1
- SpatialDivisiveNormalization:
- nInputPlane: # TODO: infer this
- default: 1
- kernel: # TODO: this is a tensor type...
- threshold:
- default: 0.0001
- thresval:
- default: 0.0001 # FIXME: this defaults to "threshold"
- SpatialContrastiveNormalization:
- nInputPlane: # TODO: infer this
- default: 1
- kernel: # TODO: this is a tensor type...
- threshold:
- default: 0.0001
- thresval:
- default: 0.0001 # FIXME: this defaults to "threshold"
- SpatialFullConvolution:
- nInputPlane: # TODO: should infer this
min: 1
- nOutputPlane:
min: 1
- kernelWidth:
min: 1
- kernelHeight:
min: 1
- strideWidth:
min: 1
default: 1
- strideHeight:
min: 1
default: 1
- padWidth:
min: 0
default: 0
- padHeight:
min: 0
default: 0
- adjWidth:
min: 0
default: 0
- adjHeight:
min: 0
default: 0
# Additional constraint:
# Volumetric Modules
- VolumetricConvolution:
- nInputPlane:
min: 1
- nOutputPlane:
min: 1
- kernelTime:
min: 1
- kernelWidth:
min: 1
- kernelHeight:
min: 1
- strideTime:
min: 1
default: 1
- strideWidth:
min: 1
default: 1
- strideHeight:
min: 1
default: 1
- VolumetricMaxPooling:
- kernelTime:
min: 1
- kernelWidth:
min: 1
- kernelHeight:
min: 1
- strideTime:
min: 1
default: 1
- strideWidth:
min: 1
default: 1
- strideHeight:
min: 1
default: 1
SimpleLayer:
- Linear: # FIXME: These should contain the actual args
- input:
infer: dimensionality
- output:
min: 1
- SparseLinear:
- input:
infer: dimensionality
- output:
min: 1
- Dropout:
- probability:
type: float
- Abs:
- Add:
- isScalar:
type: boolean
- Mul:
- CMul:
- size: null
- Max:
- dimension:
min: 0
- Min:
- dimension:
min: 0
- Mean:
- dimension:
min: 0
- Sum:
- dimension:
min: 0
- Euclidean:
- output:
min: 0
- WeightedEuclidean:
- output:
min: 0
- Identity:
- Copy: # Casts types
- inputType:
type: string
- outputType:
type: string
- forceCopy:
type: boolean
- Narrow:
- dimension:
min: 0
- offset:
min: 0
- length:
min: 0
- Replicate:
- nFeature:
min: 0
- Reshape:
- dimensions:
type: list
- View:
- sizes: # list
type: list
min: 0
- Select:
- dimensions:
type: list
- Exp
- Square
- Sqrt
- Power:
- p: null
- MM:
- transA:
type: boolean
- transB:
type: boolean
TransferLayer:
- HardTanh
- HardShrink:
- lambda:
type: float
- SoftShrink:
- lambda:
type: float
- SoftMax
- SoftMin
- SoftPlus
- SoftSign # Typo in the docs on this one
- LogSigmoid
- LogSoftMax # Also in Criterion?
- Sigmoid
- Tanh
- ReLU
- PReLU # Missing from docs
- RReLU # Missing from docs
- LeakyReLU # Missing from docs
- AddConstant:
- scalar:
type: float
- MulConstant:
- scalar:
type: float
min: 1
- inplace:
default: false
Criterion:
- BCECriterion
- WeightedMSECriterion
- SmoothL1Criterion
- MSECriterion
- AbsCriterion
- MultiCriterion
- DistKLDivCriterion
- HingeEmbeddingCriterion
- CriterionTable
- MultiMarginCriterion
- MultiLabelMarginCriterion
- L1HingeEmbeddingCriterion
- CosineEmbeddingCriterion
- MarginRankingCriterion
- CrossEntropyCriterion
- MarginCriterion
- ClassNLLCriterion
- ParallelCriterion
MiscLayers:
- Jacobian
- ConcatTable
- CMulTable
- CAddTable
- TanhShrink
- Padding:
- dim:
- pad:
min: 0
- nInputDim: # TODO: infer?
min: 1
- value:
min: 0
default: 0
# TODO: Add the following layers
#VolumetricMaxUnpooling
# Takes a poolingModule as an arg...
#MixtureTable
#NarrowTable
#SplitTable
#DotProduct
#DepthConcat
#Parallel
#Log
#hessian
#ELU
#CSubTable
#VolumetricAveragePooling
#StochasticGradient
#Bilinear
#VolumetricFullConvolution
#SparseJacobian
#Contiguous
#L1Cost
#JoinTable
#CosineDistance
#Index
#L1Penalty
#Cosine
#Clamp
#SpatialConvolutionMM
#LogSigmoid
#ParallelTable
#CDivTable
#SpatialFullConvolutionMap
#GradientReversal
#SpatialMaxUnpooling
#Transpose
#Normalize
#SpatialSoftMax
#SelectTable
#FlattenTable
# CONTAINERS and TableLayouts
# Some of these are captured by the visual structure of the architecture and are not needed
# as explicit layers in the metamodel
#TableLayer:
#- ConcatTable
#Container:
+30 -8
Ver Arquivo
@@ -106,21 +106,30 @@ define([
};
LocalExecutor.prototype.Save = function(node) {
var nodeId = this.core.getPath(node),
parentNode;
var parentNode,
currNameHashPairs;
// Get the input node
this.logger.info('Calling save operation!');
return this._getSaveDir()
.then(_saveDir => {
parentNode = _saveDir;
return this.core.loadChildren(_saveDir);
})
.then(artifacts => {
currNameHashPairs = artifacts
.map(node => [
this.core.getAttribute(node, 'name'),
this.core.getAttribute(node, 'data')
]);
return this.getInputs(node);
})
.then(inputs => {
var ids = inputs.map(i => this.core.getPath(i[2])),
allDataNodes,
dataNodes;
dataNodes = Object.keys(this.nodes)
allDataNodes = Object.keys(this.nodes)
.map(id => this.nodes[id])
.filter(node => this.isMetaTypeOf(node, this.META.Transporter))
.filter(node =>
@@ -129,10 +138,18 @@ define([
.map(node => this.core.getPointerPath(node, 'src'))
.map(id => this.nodes[id]);
// Remove nodes that already exist
dataNodes = allDataNodes.filter(dataNode => {
var hash = this.core.getAttribute(dataNode, 'data'),
name = this.core.getOwnAttribute(node, 'saveName') ||
this.core.getAttribute(dataNode, 'name');
return !(currNameHashPairs
.find(pair => pair[0] === name && pair[1] === hash));
});
// get the input node
if (dataNodes.length === 0) {
this.logger.error(`Could not find data to save! ${nodeId}`);
} else {
if (dataNodes.length !== 0) {
var newNodes = this.core.copyNodes(dataNodes, parentNode),
newName = this.core.getOwnAttribute(node, 'saveName');
if (newName) {
@@ -140,9 +157,14 @@ define([
this.core.setAttribute(node, 'name', newName)
);
}
var hashes = dataNodes.map(n => this.core.getAttribute(n, 'data'));
this.logger.info(`saving hashes: ${hashes.map(h => `"${h}"`)}`);
} else if (allDataNodes.length === 0) {
this.logger.warn('No data nodes found!');
} else {
this.logger.info('Using cached artifact(s)');
}
var hashes = dataNodes.map(n => this.core.getAttribute(n, 'data'));
this.logger.info(`saving hashes: ${hashes.map(h => `"${h}"`)}`);
this.onOperationComplete(node);
});
};
+54 -19
Ver Arquivo
@@ -1,7 +1,9 @@
/*globals define, WebGMEGlobal*/
/*globals define, requirejs*/
define([
'plugin/util',
'q'
], function(
PluginUtils,
Q
) {
var PtrCodeGen = function() {
@@ -14,34 +16,67 @@ define([
var metanode = this.core.getMetaType(ptrNode),
pluginId;
this.logger.debug(`loaded pointer target of ${ptrId}: ${ptrNode}`);
pluginId = this.core.getRegistry(ptrNode, 'validPlugins').split(' ').shift();
this.logger.info(`generating code for ${this.core.getAttribute(ptrNode, 'name')} using ${pluginId}`);
var context = WebGMEGlobal.Client.getCurrentPluginContext(pluginId);
context.managerConfig.namespace = this.core.getNamespace(metanode);
context.managerConfig.activeNode = this.core.getPath(ptrNode);
var context = {
namespace: this.core.getNamespace(metanode),
activeNode: this.core.getPath(ptrNode)
};
// Load and run the plugin
return Q.nfcall(this.executePlugin.bind(this), pluginId, context);
return this.executePlugin(pluginId, context);
})
.then(hashes => hashes[0]); // Grab the first asset for now
};
PtrCodeGen.prototype.executePlugin = function(pluginId, config, callback) {
// Call the Interpreter manager in a Q.ninvoke friendly way
// I need to create a custom context for the given plugin:
// - Set the activeNode to the given referenced node
// - If the activeNode is namespaced, set META to the given namespace
//
// FIXME: Check if it is running in the browser or on the server
WebGMEGlobal.Client.runBrowserPlugin(pluginId, config, (err, result) => {
if (!result.success) {
return callback(result.getError());
}
this.logger.info('Finished calling ' + pluginId);
callback(null, result.artifacts);
PtrCodeGen.prototype.createPlugin = function(pluginId) {
var deferred = Q.defer(),
pluginPath = [
'plugin',
pluginId,
pluginId,
pluginId
].join('/');
requirejs([pluginPath], Plugin => {
var plugin = new Plugin();
deferred.resolve(plugin);
}, err => {
this.logger.error(`Could not load ${pluginId}: ${err}`);
deferred.reject(err);
});
return deferred.promise;
};
PtrCodeGen.prototype.configurePlugin = function(plugin, opts) {
var logger = this.logger.fork(plugin.getName());
return PluginUtils.loadNodesAtCommitHash(
this.project,
this.core,
this.commitHash,
this.logger,
opts
).then(config => {
plugin.initialize(logger, this.blobClient, this.gmeConfig);
config.core = this.core;
plugin.configure(config);
return plugin;
});
};
PtrCodeGen.prototype.executePlugin = function(pluginId, config) {
return this.createPlugin(pluginId)
.then(plugin => this.configurePlugin(plugin, config))
.then(plugin => {
return Q.ninvoke(plugin, 'main');
})
.then(result => {
this.logger.info('Finished calling ' + pluginId);
return result.artifacts;
});
};
return PtrCodeGen;
+4
Ver Arquivo
@@ -22,3 +22,7 @@
.create-node text {
font-style: italic;
}
.job-canceled {
background-color: #ffe0b2;
}
+39
Ver Arquivo
@@ -0,0 +1,39 @@
/* globals define*/
define([
], function(
) {
var isBoolean = txt => {
return typeof txt === 'boolean' || (txt === 'false' || txt === 'true');
};
var getSetterSchema = function(name, setters, defaults) {
var values,
schema = setters[name];
if (defaults.hasOwnProperty(name)) {
schema.default = defaults[name];
}
schema.type = 'string';
if (schema.setterType === 'const') {
values = Object.keys(schema.setterFn);
schema.isEnum = true;
schema.enumValues = values;
if (values.every(isBoolean)) {
if (!defaults.hasOwnProperty(name) && values.length === 1) {
// there is only a method to toggle the flag to true/false,
// then the default must be the other one
schema.default = values[0] === 'true' ? false : true;
}
if (isBoolean(schema.default)) {
schema.type = 'boolean';
}
}
}
return schema;
};
return {
getSetterSchema: getSetterSchema
};
});
+19
Ver Arquivo
@@ -0,0 +1,19 @@
/* globals define*/
define({
getDisplayTime: timestamp => {
var today = new Date().toLocaleDateString(),
date = new Date(timestamp).toLocaleDateString();
if (date === today) {
date = `Today (${new Date(timestamp).toLocaleTimeString()})`;
}
return date;
},
ClassForJobStatus: {
success: 'success',
canceled: 'job-canceled',
failed: 'danger',
pending: '',
running: 'warning'
}
});
@@ -1,10 +1,6 @@
/*globals define, _*/
/*jshint browser: true, camelcase: false*/
/**
* @author brollb / https://github.com/brollb
*/
define([
'decorators/EllipseDecorator/EasyDAG/EllipseDecorator.EasyDAGWidget',
'css!./JobDecorator.EasyDAGWidget.css'
@@ -20,6 +16,7 @@ define([
pending: '#9e9e9e',
queued: '#cfd8dc',
running: '#fff59d',
canceled: '#ffcc80',
success: '#66bb6a',
fail: '#e57373'
};
@@ -35,6 +32,8 @@ define([
status: true,
execFiles: true,
stdout: true,
secret: true,
jobId: true,
debug: true
};
EllipseDecorator.call(this, options);
@@ -0,0 +1,110 @@
/*globals define, _, WebGMEGlobal*/
/*jshint browser: true, camelcase: false*/
define([
'decorators/EllipseDecorator/EasyDAG/EllipseDecorator.EasyDAGWidget',
'deepforge/Constants',
'./LayerField'
], function (
EllipseDecorator,
Constants,
LayerField
) {
'use strict';
var LayerDecorator,
DECORATOR_ID = 'LayerDecorator';
// Layer nodes need to be able to...
// - show their ports
// - highlight ports
// - unhighlight ports
// - report the location of specific ports
LayerDecorator = function (options) {
options.skipAttributes = {name: true};
options.skipAttributes[Constants.CTOR_ARGS_ATTR] = true;
EllipseDecorator.call(this, options);
};
_.extend(LayerDecorator.prototype, EllipseDecorator.prototype);
LayerDecorator.prototype.DECORATOR_ID = DECORATOR_ID;
LayerDecorator.prototype.PointerField = LayerField;
LayerDecorator.prototype.getDisplayName = function() {
return this._node.name;
};
// Create the pointer fields and change the event handlers
LayerDecorator.prototype.createPointerFields = function() {
var i = this.fields.length,
y,
ptr;
// Get the fields
y = EllipseDecorator.prototype.createPointerFields.apply(this, arguments);
while (i < this.fields.length) {
// Update the event handlers
ptr = this.fields[i].name;
// TODO: This should be changed in EasyDAG
this.fields[i].selectTarget = this.getValidNestedLayers.bind(this, ptr);
i++;
}
return y;
};
LayerDecorator.prototype.getValidNestedLayers = function(ptr) {
var tgtId = this._node.pointers[ptr];
if (tgtId) {
WebGMEGlobal.State.registerActiveObject(tgtId);
} else {
this.createLayerArg(ptr);
}
};
LayerDecorator.prototype.createLayerArg = function(ptr) {
// Find the Architecture node type
var metanodes = this.client.getAllMetaNodes(),
base = metanodes.find(node => node.getAttribute('name') === 'Architecture'),
baseId,
msg = `Creating layers for "${ptr}" of ${this._node.name}`,
tgtId;
if (!base) {
return this.logger.error('Could not find "Architecture" type!');
}
// Create a nested "architecture" node and set the ptr target to it
baseId = base.getId();
this.client.startTransaction(msg);
tgtId = this.client.createChild({
parentId: this._node.id,
baseId: baseId
});
this.client.setAttributes(tgtId, 'name', `${ptr} (${this._node.name})`);
this.savePointer(ptr, tgtId);
this.client.completeTransaction();
WebGMEGlobal.State.registerActiveObject(tgtId);
};
LayerDecorator.prototype.savePointer = function(ptr, to) {
if (!to) { // delete the current target
var currentId = this._node.pointers[ptr],
name = this._node.name;
// If the target is contained in the current node, delete it!
if (currentId.indexOf(this._node.id) === 0) {
this.client.startTransaction(`Removing layer for ${ptr} of ${name}`);
this.client.delMoreNodes([currentId]);
this.client.completeTransaction();
this.logger.info(`Removed ${ptr} and deleted target (${currentId})`);
} else {
this.logger.info(`Removed ${ptr} (external architecture)`);
}
} else { // create and set the node
EllipseDecorator.prototype.savePointer.apply(this, arguments);
}
};
return LayerDecorator;
});
@@ -0,0 +1,29 @@
/* globals define, _ */
define([
'decorators/EllipseDecorator/EasyDAG/PointerField'
], function(
PointerField
) {
// The LayerField behaves the same as PointerFields but it shows "click to view"
// if it has a value
var LayerField = function() {
PointerField.apply(this, arguments);
};
_.extend(LayerField.prototype, PointerField.prototype);
LayerField.prototype.getContent = function(content) {
return content && 'click to view';
};
LayerField.prototype.createContent = function(w, y, content) {
PointerField.prototype.createContent.call(this, w, y, this.getContent(content));
this.$content.attr('font-style', 'italic');
};
LayerField.prototype.setValue = function(content) {
PointerField.prototype.setValue.call(this, this.getContent(content));
};
return LayerField;
});
@@ -0,0 +1,39 @@
/*globals define, _*/
/*jshint browser: true, camelcase: false*/
define([
'js/Decorators/DecoratorBase',
'./EasyDAG/LayerDecorator.EasyDAGWidget'
], function (
DecoratorBase,
LayerDecoratorEasyDAGWidget
) {
'use strict';
var LayerDecorator,
__parent__ = DecoratorBase,
__parent_proto__ = DecoratorBase.prototype,
DECORATOR_ID = 'LayerDecorator';
LayerDecorator = function (params) {
var opts = _.extend({loggerName: this.DECORATORID}, params);
__parent__.apply(this, [opts]);
this.logger.debug('LayerDecorator ctor');
};
_.extend(LayerDecorator.prototype, __parent_proto__);
LayerDecorator.prototype.DECORATORID = DECORATOR_ID;
/*********************** OVERRIDE DecoratorBase MEMBERS **************************/
LayerDecorator.prototype.initializeSupportedWidgetMap = function () {
this.supportedWidgetMap = {
EasyDAG: LayerDecoratorEasyDAGWidget
};
};
return LayerDecorator;
});
+37 -8
Ver Arquivo
@@ -79,7 +79,11 @@ define([
};
CreateExecution.prototype.createExecution = function (node) {
var name = this.core.getAttribute(node, 'name');
// Get the user supplied name
var name = this.core.getAttribute(node, 'name'),
config = this.getCurrentConfig(),
basename = config.name || (name + '_execution');
// Given a pipeline, copy all the operations to a custom job
// - Copy the operations
@@ -95,39 +99,52 @@ define([
return this.getExecutionDir()
.then(execDir => {
var execDirId = this.core.getPath(execDir),
execTypeId = this.core.getPath(this.META.Execution);
this.logger.debug(`Creating execution node in ${execDirId} (type is ${execTypeId})`);
tgtNode = this.core.createNode({
base: this.META.Execution,
parent: execDir
});
// Get a unique name
return this.getUniqueExecName(name + '_execution');
this.logger.debug(`About to get a unique name starting w/ ${basename}`);
return this.getUniqueExecName(basename);
})
.then(execName => {
var isSnapshot = this.getCurrentConfig().snapshot;
var isSnapshot = !this.getCurrentConfig().debug,
originName = this.core.getAttribute(this.activeNode, 'name'),
oId = this.core.getPath(this.activeNode),
tgtId = this.core.getPath(tgtNode);
this.logger.debug(`Creating execution ${execName}`);
this.logger.debug(`Configuring execution attributes (${execName})`);
// Set all the metadata for the new execution
this.core.setAttribute(tgtNode, 'name', execName);
this.core.setAttribute(tgtNode, 'snapshot', isSnapshot);
this.core.setAttribute(tgtNode, 'tagname', execName);
this.core.setAttribute(tgtNode, 'createdAt', Date.now());
this.logger.debug(`Setting origin pipeline to ${originName} (${oId})`);
this.core.setPointer(tgtNode, 'origin', this.activeNode);
this.logger.debug(`Adding ${tgtId} to execution list of ${originName} (${oId})`);
this.core.addMember(this.activeNode, 'executions', tgtNode);
this.logger.debug(`Creating tag "${execName}"`);
return this.project.createTag(
execName.replace(/[ -]/g, '_'),
execName,
this.currentHash
);
})
.then(() => this.core.loadChildren(node))
.then(children => {
var execName = this.core.getAttribute(tgtNode, 'name');
if (!children.length) {
this.logger.warn('No children in pipeline. Will proceed anyway');
}
this.logger.debug(`Copying operations to "${execName}"`);
return this.copyOperations(children, tgtNode);
})
.then(copiedPairs => {
@@ -138,6 +155,7 @@ define([
.filter(pair => this.core.isTypeOf(pair[0], this.META.Operation));
// Create a mapping of old names to new names
this.logger.debug('Creating mapping of old->new');
return Q.all(opTuples.map(pair =>
// Add the input/output mappings to the dataMapping
this.addDataToMap(originals[pair[1]], pair[0], dataMapping)
@@ -145,22 +163,29 @@ define([
);
})
.then(() => { // datamapping is set!
this.logger.debug('Updating references...');
this.updateReferences(copies, dataMapping);
this.logger.debug('Placing operations in Job containers');
this.boxOperations(opTuples.map(o => o[0]), tgtNode);
this.logger.debug('Finished! Saving...');
return this.save(`Created execution from ${name}`);
})
.then(() => tgtNode); // return tgtNode
};
CreateExecution.prototype.getUniqueExecName = function (basename) {
var name = basename,
taken = {},
var taken = {},
name,
i = 2;
basename = basename.replace(/[^\da-zA-Z_]/g, '_');
name = basename;
// Get a unique name wrt the tags and the other executions
return this.project.getTags()
.then(tags => {
Object.keys(tags).forEach(name => taken[name] = true);
this.logger.debug(`Existing tags are ${Object.keys(tags).join(',')}`);
// Get the other executions
return this.getExecutionDir();
@@ -171,19 +196,22 @@ define([
})
.then(execs => {
var names = execs.map(exec => this.core.getAttribute(exec, 'name'));
this.logger.debug(`Existing names are ${names.join(',')}`);
names.forEach(name => taken[name] = true);
while (taken[name]) {
name = basename + '_' + (i++);
}
this.logger.debug(`Unique name is "${name}"`);
return name;
});
};
CreateExecution.prototype.copyOperations = function (nodes, dst) {
var snapshot = this.getCurrentConfig().snapshot;
var snapshot = !this.getCurrentConfig().debug;
if (snapshot) {
this.logger.debug('Execution is a snapshot -> severing the inheritance');
return Q.all(nodes.map(node => {
if (this.isLocalOperation(node) ||
this.isMetaTypeOf(node, this.META.Transporter)) {
@@ -198,6 +226,7 @@ define([
);
} else if (nodes.length) {
this.logger.debug('Execution is not a snapshot -> doing a simple copy');
var copies = this.core.copyNodes(nodes, dst);
return nodes.map((node, i) => [node, copies[i]]);
}
+182 -157
Ver Arquivo
@@ -1,31 +1,25 @@
/*globals define*/
/*jshint node:true, browser:true*/
/**
* Generated by PluginGenerator 0.14.0 from webgme on Tue Mar 15 2016 21:19:45 GMT-0500 (CDT).
*/
define([
'plugin/PluginConfig',
'plugin/PluginBase',
'deepforge/js-yaml.min',
'common/util/guid',
'deepforge/Constants',
'deepforge/utils',
'js/RegistryKeys',
'js/Constants',
'js/Panels/MetaEditor/MetaEditorConstants',
'underscore',
'text!deepforge/layers.json',
'./schemas/index',
'text!./metadata.json'
], function (
PluginConfig,
PluginBase,
yaml,
generateGuid,
Constants,
utils,
REGISTRY_KEYS,
CONSTANTS,
META_CONSTANTS,
_,
DEFAULT_LAYERS,
Schemas,
metadata
) {
'use strict';
@@ -61,110 +55,102 @@ define([
* @param {function(string, plugin.PluginResult)} callback - the result callback
*/
CreateTorchMeta.prototype.main = function (callback) {
// Use self to access core, project, result, logger etc from PluginBase.
// These are all instantiated at this point.
var self = this;
if (!this.META.Language) {
callback('"Language" container required to run plugin', this.result);
return callback('"Language" container required to run plugin', this.result);
}
// Extra layer names
this.getJsonLayers((err, text) => {
if (err) {
return callback(err, this.result);
// The format is...
// - (Abstract) CategoryLayerTypes
// - LayerName
// - Attributes (if exists)
var layers,
content = {},
categories,
config = this.getCurrentConfig(),
nodes = {};
try {
layers = this.getJsonLayers();
} catch (e) {
return callback('JSON parse error: ' + e, this.result);
}
layers.forEach(layer => {
if (!content[layer.type]) {
content[layer.type] = [];
}
// The format is...
// - (Abstract) CategoryLayerTypes
// - LayerName
// - Attributes (if exists)
var content = {},
categories,
config = this.getCurrentConfig(),
nodes = {},
layers;
try {
layers = JSON.parse(text);
} catch (e) {
return callback('JSON parse error: ' + e, this.result);
}
layers.forEach(layer => {
if (!content[layer.type]) {
content[layer.type] = [];
}
content[layer.type].push(layer);
});
categories = Object.keys(content);
// Create the base class, if needed
if (!this.META.Layer) {
this.META.Layer = this.createMetaNode('Layer', this.META.FCO);
}
// Create the category nodes
categories
.forEach(name => {
// Create a tab for each
this.metaSheets[name] = this.createMetaSheetTab(name);
this.sheetCounts[name] = 0;
nodes[name] = this.createMetaNode(name, this.META.Layer, name);
});
// Make them abstract
categories
.forEach(name => this.core.setRegistry(nodes[name], 'isAbstract', true));
if (config.removeOldLayers) {
var isNewLayer = {},
newLayers = layers.map(layer => layer.name),
oldLayers,
oldNames;
newLayers = newLayers.concat(categories); // add the category nodes
newLayers.forEach(name => isNewLayer[name] = true);
// Set the newLayer nodes 'base' to 'Layer' so we don't accidentally
// delete them
newLayers
.map(name => this.META[name])
.filter(layer => !!layer)
.forEach(layer => this.core.setPointer(layer, 'base', this.META.Layer));
oldLayers = Object.keys(this.META)
.filter(name => name !== 'Layer')
.map(name => this.META[name])
.filter(node => this.isMetaTypeOf(node, this.META.Layer))
.filter(node => !isNewLayer[this.core.getAttribute(node, 'name')]);
oldNames = oldLayers.map(l => this.core.getAttribute(l, 'name'));
// Get the old layer names
this.logger.debug(`Removing layers: ${oldNames.join(', ')}`);
oldLayers.forEach(layer => this.core.deleteNode(layer));
}
// Create the actual nodes
categories.forEach(cat => {
content[cat]
.forEach(layer => {
var attrs = layer.params,
name = layer.name;
nodes[name] = this.createMetaNode(name, nodes[cat], cat, attrs);
// Make the node non-abstract
this.core.setRegistry(nodes[name], 'isAbstract', false);
});
});
self.save('CreateTorchMeta updated model.', function (err) {
if (err) {
callback(err, self.result);
return;
}
self.result.setSuccess(true);
callback(null, self.result);
});
content[layer.type].push(layer);
});
categories = Object.keys(content);
// Create the base class, if needed
if (!this.META.Layer) {
this.META.Layer = this.createMetaNode('Layer', this.META.FCO);
}
// Create the category nodes
categories
.forEach(name => {
// Create a tab for each
this.metaSheets[name] = this.createMetaSheetTab(name);
this.sheetCounts[name] = 0;
nodes[name] = this.createMetaNode(name, this.META.Layer, name);
});
// Make them abstract
categories
.forEach(name => this.core.setRegistry(nodes[name], 'isAbstract', true));
if (config.removeOldLayers) {
var isNewLayer = {},
newLayers = layers.map(layer => layer.name),
oldLayers,
oldNames;
newLayers = newLayers.concat(categories); // add the category nodes
newLayers.forEach(name => isNewLayer[name] = true);
// Set the newLayer nodes 'base' to 'Layer' so we don't accidentally
// delete them
newLayers
.map(name => this.META[name])
.filter(layer => !!layer)
.forEach(layer => this.core.setBase(layer, this.META.Layer));
oldLayers = Object.keys(this.META)
.filter(name => name !== 'Layer')
.map(name => this.META[name])
.filter(node => this.isMetaTypeOf(node, this.META.Layer))
.filter(node => !isNewLayer[this.core.getAttribute(node, 'name')]);
oldNames = oldLayers.map(l => this.core.getAttribute(l, 'name'));
// Get the old layer names
this.logger.debug(`Removing layers: ${oldNames.join(', ')}`);
oldLayers.forEach(layer => this.core.deleteNode(layer));
}
// Create the actual nodes
categories.forEach(cat => {
content[cat]
.forEach(layer => {
var name = layer.name,
node;
node = this.createMetaNode(name, nodes[cat], cat, layer);
// Make the node non-abstract
if (node) {
this.core.setRegistry(node, 'isAbstract', false);
nodes[name] = node;
}
});
});
this.save('CreateTorchMeta updated model.')
.then(() => {
this.result.setSuccess(true);
callback(null, this.result);
})
.fail(err => callback(err, this.result));
};
CreateTorchMeta.prototype.removeFromMeta = function (nodeId) {
@@ -206,28 +192,45 @@ define([
return sheet.SetID;
};
CreateTorchMeta.prototype.getJsonLayers = function (callback) {
var config = this.getCurrentConfig();
CreateTorchMeta.prototype.getJsonLayers = function () {
var config = this.getCurrentConfig(),
schema = config.layerSchema;
if (config.layerNameHash) {
this.blobClient.getObject(config.layerNameHash, (err, buffer) => {
if (err) {
return callback(err, this.result);
}
var text = String.fromCharCode.apply(null, new Uint8Array(buffer));
return callback(null, text);
});
} else {
return callback(null, DEFAULT_LAYERS);
if (schema === 'all') {
return Object.keys(Schemas).map(key => JSON.parse(Schemas[key]))
.reduce((l1, l2) => l1.concat(l2), []);
}
return JSON.parse(Schemas[schema]);
};
CreateTorchMeta.prototype.createMetaNode = function (name, base, tabName, attrs) {
// Some helper methods w/ attribute handling
var LUA_TO_GME = {
boolean: 'boolean',
number: 'float',
string: 'string'
};
var isLayerAttribute = type => type && type.substring(0, 3) === 'nn.';
CreateTorchMeta.prototype.createMetaNode = function (name, base, tabName, layer) {
var node = this.META[name],
nodeId = node && this.core.getPath(node),
tabId = this.metaSheets[tabName],
position = this.getPositionFor(name, tabName);
position = this.getPositionFor(name, tabName),
setters = {},
defaults = {},
types = {},
type,
attrs,
desc;
if (layer) {
attrs = layer.params;
setters = layer.setters;
defaults = layer.defaults;
types = layer.types || types;
}
if (!tabId) {
this.logger.error(`No meta sheet for ${tabName}`);
}
@@ -244,7 +247,7 @@ define([
} else {
// Remove from meta
this.removeFromMeta(nodeId);
this.core.setPointer(node, 'base', base);
this.core.setBase(node, base);
}
// Add it to the meta sheet
@@ -269,14 +272,16 @@ define([
if (attrs) { // Add the attributes
// Remove attributes not in the given list
var currentAttrs = this.core.getValidAttributeNames(node),
rmAttrs;
defVal,
rmAttrs,
simpleAttrs,
rmPtrs;
rmAttrs = _.difference(currentAttrs, attrs) // old attribute names
.filter(attr => attr !== 'name');
simpleAttrs = attrs.filter(name => !isLayerAttribute(types[name]));
rmAttrs = _.difference(currentAttrs, simpleAttrs) // old attribute names
.filter(attr => attr !== 'name')
.filter(attr => !setters[attr]);
if (rmAttrs.length) {
this.logger.debug(`Removing ${rmAttrs.join(', ')} from ${name}`);
}
rmAttrs.forEach(attr => {
this.core.delAttributeMeta(node, attr);
if (this.core.getOwnAttribute(node, attr) !== undefined) {
@@ -284,11 +289,38 @@ define([
}
});
attrs.forEach((name, index) => {
var desc = {};
desc.argindex = index;
desc.default = '';
this.addAttribute(name, node, desc);
// Remove all old pointers
rmPtrs = _.difference(this.core.getPointerNames(node), currentAttrs)
.filter(ptr => ptr !== 'base');
if (rmPtrs.length + rmAttrs.length) {
this.logger.debug(`Removing ${rmPtrs.concat(rmAttrs).join(', ')} from ${name}`);
}
rmPtrs.forEach(ptr => this.core.delPointerMeta(node, ptr));
attrs.forEach(name => {
desc = {};
defVal = defaults.hasOwnProperty(name) ? defaults[name] : '';
type = LUA_TO_GME[types[name]];
if (type) {
desc.type = type;
}
if (isLayerAttribute(types[name])) { // Check if it is an nn layer type
// If so, create a pointer rather than attribute
this.addLayerAttribute(name, node);
this.logger.debug(`${name} is a layer type attribute`);
} else {
this.addAttribute(name, node, desc, defVal);
}
});
this.core.setAttribute(node, Constants.CTOR_ARGS_ATTR, attrs.join(','));
// Add the setters to the meta
Object.keys(setters).forEach(name => {
desc = utils.getSetterSchema(name, setters, defaults);
defVal = desc.default;
delete desc.default;
this.addAttribute(name, node, desc, defVal);
});
}
this.logger.debug(`added ${name} to the meta`);
@@ -323,41 +355,34 @@ define([
};
};
CreateTorchMeta.prototype.addAttribute = function (name, node, def) {
var initial,
schema = {};
CreateTorchMeta.prototype.addLayerAttribute = function (name, node) {
// No default value support for now...
// Create a pointer of the given type on the node
this.core.setPointerMetaTarget(node, name, this.META.Architecture, 1, 1);
this.core.setPointerMetaLimits(node, name, 1, 1);
};
schema.type = def.type || 'string';
CreateTorchMeta.prototype.addAttribute = function (name, node, schema, defVal) {
schema.type = schema.type || 'string';
if (schema.type === 'list') { // FIXME: add support for lists
schema.type = 'string';
}
if (def.min !== undefined) {
schema.min = +def.min;
if (schema.min !== undefined) {
schema.min = +schema.min;
}
if (def.max !== undefined) {
if (schema.max !== undefined) {
// Set the min, max
schema.max = +def.max;
schema.max = +schema.max;
}
// Add the infer flag
if (def.infer) {
schema.infer = def.infer;
}
// Add the argindex flag
schema.argindex = def.argindex;
// Create the attribute and set the schema
this.core.setAttributeMeta(node, name, schema);
// Determine a default value
initial = def.hasOwnProperty('default') ? def.default : def.min || null;
if (schema.type === 'boolean') {
initial = initial !== null ? initial : false;
if (defVal) {
this.core.setAttribute(node, name, defVal);
}
this.core.setAttribute(node, name, initial);
};
return CreateTorchMeta;
+23 -18
Ver Arquivo
@@ -7,24 +7,29 @@
"src": "",
"class": "glyphicon glyphicon-ok-circle"
},
"disableServerSideExecution": false,
"disableServerSideExecution": true,
"disableBrowserSideExecution": false,
"configStructure": [
{
"name": "layerNameHash",
"displayName": "Torch Layers",
"description": "Yaml file of torch layer descriptors (optional)",
"value": "",
"valueType": "asset",
"readOnly": false
},
{
"name": "removeOldLayers",
"displayName": "Delete old layers",
"description": "Delete all layers not in the current description",
"value": true,
"valueType": "boolean",
"readOnly": false
}
{
"name": "layerSchema",
"displayName": "Torch Libraries",
"description": "Torch nn libraries to create layers from",
"value": "all",
"valueItems": [
"nn",
"rnn",
"all"
],
"valueType": "string",
"readOnly": false
},
{
"name": "removeOldLayers",
"displayName": "Delete old layers",
"description": "Delete all layers not in the current description",
"value": true,
"valueType": "boolean",
"readOnly": false
}
]
}
}
+13
Ver Arquivo
@@ -0,0 +1,13 @@
/*globals define*/
define([
'text!./nn.json',
'text!./rnn.json'
], function(
nn,
rnn
) {
return {
nn: nn,
rnn: rnn
};
});
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
+178
Ver Arquivo
@@ -0,0 +1,178 @@
[
{
"name": "CopyGrad",
"baseType": "Identity",
"setters": {},
"defaults": {},
"type": "RNN"
},
{
"name": "FastLSTM",
"baseType": "LSTM",
"params": [
"inputSize",
"outputSize",
"rho",
"eps",
"momentum",
"affine"
],
"setters": {},
"types": {
"eps": "number",
"momentum": "number"
},
"defaults": {
"momentum": 0.1,
"eps": 0.1
},
"type": "RNN"
},
{
"name": "LSTM",
"baseType": "AbstractRecurrent",
"params": [
"inputSize",
"outputSize",
"rho",
"cell2gate"
],
"setters": {},
"types": {
"rho": "number"
},
"defaults": {
"rho": 9999
},
"type": "RNN"
},
{
"name": "LinearNoBias",
"baseType": "Linear",
"params": [
"inputSize",
"outputSize"
],
"setters": {},
"types": {},
"defaults": {},
"type": "Simple"
},
{
"name": "LookupTableMaskZero",
"baseType": "LookupTable",
"params": [
"nIndex",
"nOutput"
],
"setters": {},
"types": {},
"defaults": {},
"type": "RNN"
},
{
"name": "NormStabilizer",
"baseType": "AbstractRecurrent",
"params": [
"beta"
],
"setters": {},
"defaults": {},
"type": "RNN"
},
{
"name": "Recurrent",
"baseType": "AbstractRecurrent",
"params": [
"start",
"input",
"feedback",
"transfer",
"rho",
"merge"
],
"setters": {},
"types": {
"start": "nn.Module",
"transfer": "nn.Module",
"feedback": "nn.Module",
"input": "nn.Module"
},
"defaults": {},
"type": "RNN"
},
{
"name": "SAdd",
"baseType": "Module",
"params": [
"addend",
"negate"
],
"setters": {},
"types": {},
"defaults": {},
"type": "RNN"
},
{
"name": "SeqBRNN",
"baseType": "Container",
"params": [
"inputDim",
"hiddenDim",
"batchFirst"
],
"setters": {},
"types": {},
"defaults": {},
"type": "RNN"
},
{
"name": "SeqGRU",
"baseType": "Module",
"params": [
"inputSize",
"outputSize"
],
"setters": {},
"types": {},
"defaults": {},
"type": "RNN"
},
{
"name": "SeqLSTM",
"baseType": "Module",
"params": [
"inputsize",
"hiddensize",
"outputsize"
],
"setters": {},
"types": {},
"defaults": {},
"type": "RNN"
},
{
"name": "SeqLSTMP",
"baseType": "SeqLSTM",
"params": [
"inputsize",
"hiddensize",
"outputsize"
],
"setters": {},
"types": {},
"defaults": {},
"type": "RNN"
},
{
"name": "SeqReverseSequence",
"baseType": "Module",
"params": [
"dim"
],
"setters": {},
"types": {},
"defaults": {},
"type": "RNN"
}
]
@@ -0,0 +1,37 @@
/* eslint-disable no-console */
// Update the metadata and schemas/index based on the new schemas in schemas/
// Update metadata
var fs = require('fs'),
path = require('path'),
schemas,
metadata = require('./metadata.json'),
schemaList;
schemas = fs.readdirSync(__dirname + '/schemas/')
.filter(name => path.extname(name) === '.json')
.map(name => name.replace(/\.json$/, ''));
console.log('Discovered schemas: ' + schemas.join(', '));
schemaList = metadata.configStructure.find(struct => struct.name === 'layerSchema');
schemaList.valueItems = schemas.concat('all');
console.log('Updating metadata...');
fs.writeFileSync(__dirname + '/metadata.json', JSON.stringify(metadata, null, 2));
// Update index.js
var index =
`/*globals define*/
define([
${schemas.map(s => `'text!./${s}.json'`).join(',\n ')}
], function(
${schemas.map(s => s).join(',\n ')}
) {
return {
${schemas.map(s => s + ': ' + s).join(',\n ')}
};
});`;
console.log('Updating index.js...');
fs.writeFileSync(__dirname + '/schemas/index.js', index);
+253 -62
Ver Arquivo
@@ -2,6 +2,7 @@
/*jshint node:true, browser:true*/
define([
'common/storage/constants',
'text!./metadata.json',
'executor/ExecutorClient',
'plugin/PluginBase',
@@ -12,6 +13,7 @@ define([
'q',
'underscore'
], function (
STORAGE_CONSTANTS,
pluginMetadata,
ExecutorClient,
PluginBase,
@@ -46,6 +48,7 @@ define([
this._markForDeletion = {}; // id -> node
this._oldMetadataByName = {}; // name -> id
this.lastAppliedCmd = {};
this.canceled = false;
};
/**
@@ -79,10 +82,43 @@ define([
}
this._callback = callback;
this.currentForkName = null;
this.prepare()
.then(() => this.executeJob(this.activeNode));
};
ExecuteJob.prototype.updateForkName = function (basename) {
basename = basename + '_fork';
basename = basename.replace(/[- ]/g, '_');
return this.project.getBranches().then(branches => {
var names = Object.keys(branches),
name = basename,
i = 2;
while (names.indexOf(name) !== -1) {
name = basename + '_' + i;
i++;
}
this.forkName = name;
});
};
// Override 'save' to notify the user on fork
ExecuteJob.prototype.save = function (msg) {
var name = this.core.getAttribute(this.activeNode, 'name');
return this.updateForkName(name)
.then(() => PluginBase.prototype.save.call(this, msg))
.then(result => {
var msg;
if (result.status === STORAGE_CONSTANTS.FORKED) {
msg = `"${name}" execution has forked to "${result.forkName}"`;
this.currentForkName = result.forkName;
this.sendNotification(msg);
}
});
};
ExecuteJob.prototype.getConnections = function (nodes) {
var conns = [];
for (var i = nodes.length; i--;) {
@@ -129,6 +165,8 @@ define([
name,
id,
idsToDelete = [],
type,
base,
child;
this.lastAppliedCmd[nodeId] = 0;
@@ -142,9 +180,16 @@ define([
if (this.isMetaTypeOf(child, this.META.Metadata)) {
id = this.core.getPath(child);
name = this.core.getAttribute(child, 'name');
base = this.core.getBase(child);
type = this.core.getAttribute(base, 'name');
this._markForDeletion[nodeId][id] = child;
this._oldMetadataByName[nodeId][name] = id;
// namespace by metadata type
if (!this._oldMetadataByName[nodeId][type]) {
this._oldMetadataByName[nodeId][type] = {};
}
this._oldMetadataByName[nodeId][type][name] = id;
// children of metadata nodes get deleted
idsToDelete = idsToDelete
@@ -168,6 +213,24 @@ define([
}
delete this.lastAppliedCmd[nodeId];
delete this._markForDeletion[nodeId];
this.core.delAttribute(job, 'jobId');
this.core.delAttribute(job, 'secret');
};
ExecuteJob.prototype.resultMsg = function(msg) {
this.sendNotification(msg);
this.createMessage(null, msg);
};
ExecuteJob.prototype.onOperationCanceled = function(op) {
var job = this.core.getParent(op),
name = this.core.getAttribute(op, 'name'),
msg = `"${name}" canceled!`;
this.core.setAttribute(job, 'status', 'canceled');
this.resultMsg(msg);
this.onComplete(op, null);
};
ExecuteJob.prototype.onOperationFail =
@@ -177,8 +240,8 @@ define([
exec = this.core.getParent(job),
name = this.core.getAttribute(job, 'name'),
jobId = this.core.getPath(job),
status = err ? 'fail' : 'success',
msg = err ? `${name} execution failed: ${err}` :
status = err ? 'fail' : (this.canceled ? 'canceled' : 'success'),
msg = err ? `${name} execution failed!` :
`${name} executed successfully!`,
promise = Q();
@@ -186,8 +249,16 @@ define([
this.logger.info(`Setting ${name} (${jobId}) status to ${status}`);
this.clearOldMetadata(job);
if (this.currentForkName) {
// notify client that the job has completed
this.sendNotification(`"${name}" execution completed on branch "${this.currentForkName}"`);
}
if (err) {
this.logger.warn(`${name} failed: ${err}`);
this.core.setAttribute(exec, 'status', 'failed');
} else if (this.canceled) {
// Should I set this to 'canceled'?
this.core.setAttribute(exec, 'status', 'canceled');
} else {
// Check if all the other jobs are successful. If so, set the
// execution status to 'success'
@@ -213,6 +284,7 @@ define([
});
}
this.createMessage(null, msg);
promise
.then(() => this.save(msg))
.then(() => {
@@ -230,6 +302,24 @@ define([
children.find(child => this.isMetaTypeOf(child, this.META.Operation)));
};
ExecuteJob.prototype.onBlobRetrievalFail = function (node, input, err) {
var job = this.core.getParent(node),
e = `Failed to retrieve "${input}" (${err})`,
consoleErr = `Failed to execute operation: ${e}`;
consoleErr += [
'\n\nA couple things to check out:\n',
'- Has the location of DeepForge\'s blob changed?',
' (Configurable using "blob.dir" in the deepforge config' +
' or setting the DEEPFORGE_BLOB_DIR environment variable)\n',
'- Was this project created using a different blob location?'
].join('\n ');
this.core.setAttribute(job, 'stdout', consoleErr);
this.onOperationFail(node, `Blob retrieval failed for "${name}": ${e}`);
};
ExecuteJob.prototype.executeJob = function (job) {
return this.getOperation(job).then(node => {
var jobId = this.core.getPath(job),
@@ -263,37 +353,46 @@ define([
var hash = files.inputAssets[input];
// data asset for "input"
return this.blobClient.getMetadata(hash);
return this.blobClient.getMetadata(hash)
.fail(err => this.onBlobRetrievalFail(job, input, err));
})
);
})
.then(mds => {
// get (input, filename) tuples
// Record the large files
var inputData = {};
mds.forEach((metadata, i) => {
// add the hashes for each input
var input = inputs[i],
name = metadata.name,
hash = files.inputAssets[input];
data['inputs/' + input + '/' + name] = hash;
inputData['inputs/' + input + '/data'] = {
req: hash,
cache: metadata.content
};
});
delete files.inputAssets;
files['input-data.json'] = JSON.stringify(inputData, null, 2);
// Add pointer assets
Object.keys(files.ptrAssets)
.forEach(path => data[path] = files.ptrAssets[path]);
delete files.ptrAssets;
// Add the executor config
return this.getOutputs(node);
})
.then(outputArgs => {
var config,
outputs,
fileList,
ptrFiles = Object.keys(files.ptrAssets),
file;
files['start.js'] = _.template(Templates.START)(CONSTANTS);
delete files.ptrAssets;
fileList = Object.keys(files).concat(ptrFiles);
outputs = outputArgs.map(pair => pair[0])
.map(name => {
return {
@@ -309,18 +408,17 @@ define([
},
{
name: name + '-all-files',
resultPatterns: []
resultPatterns: fileList
}
);
config = {
cmd: 'bash',
args: ['run.sh'],
cmd: 'node',
args: ['start.js'],
outputInterval: OUTPUT_INTERVAL,
resultArtifacts: outputs
};
files['executor_config.json'] = JSON.stringify(config, null, 4);
files['run.sh'] = Templates.BASH;
// Save the artifact
// Remove empty hashes
@@ -373,7 +471,13 @@ define([
this.logger.debug(`Making a commit from ${this.currentHash}`);
this.save(`Queued "${name}" operation in ${this.pipelineName}`)
.then(() => executor.createJob({hash}))
.then(() => this.watchOperation(executor, hash, opNode, job))
.then(info => {
this.core.setAttribute(job, 'jobId', info.hash);
if (info.secret) { // o.w. it is a cached job!
this.core.setAttribute(job, 'secret', info.secret);
}
return this.watchOperation(executor, hash, opNode, job);
})
.catch(err => this.logger.error(`Could not execute "${name}": ${err}`));
};
@@ -427,6 +531,7 @@ define([
isClass,
metanodes,
classNodes,
inheritanceLvl = {},
code;
this.logger.info('Creating custom layer file...');
@@ -435,13 +540,31 @@ define([
classNodes = metanodes.filter(node => {
var base = this.core.getBase(node),
baseId = this.core.getPath(base);
baseId = this.core.getPath(base),
count = 1;
return isClass[baseId];
// Count the sets back to a class node
while (base) {
if (isClass[baseId]) {
inheritanceLvl[this.core.getPath(node)] = count;
return true;
}
base = this.core.getBase(base);
baseId = this.core.getPath(base);
count++;
}
return false;
});
// Get the code definitions for each
code = classNodes.map(node =>
// Sort by levels of inheritance...
code = classNodes.sort((a, b) => {
var aId = this.core.getPath(a),
bId = this.core.getPath(b);
return inheritanceLvl[aId] > inheritanceLvl[bId];
}).map(node =>
`require './${this.core.getAttribute(node, 'name')}.lua'`
).join('\n');
@@ -542,12 +665,18 @@ define([
})
.then(_tplContents => {
tplContents = _tplContents;
var hashes = inputs
// storing the hash for now...
.map(pair =>
files.inputAssets[pair[0]] = this.core.getAttribute(pair[2], 'data')
);
return Q.all(hashes.map(h => this.blobClient.getMetadata(h)));
var hashes = inputs.map(pair => {
var hash = this.core.getAttribute(pair[2], 'data');
files.inputAssets[pair[0]] = hash;
return {
hash: hash,
name: pair[0]
};
});
return Q.all(hashes.map(pair =>
this.blobClient.getMetadata(pair.hash)
.fail(err => this.onBlobRetrievalFail(node, pair.name, err))));
})
.then(metadatas => {
// Create the deserializer
@@ -666,7 +795,7 @@ define([
return cb(null, files);
})
.fail(e => {
this.logger.error(`Could not generate pointer files for ${this.core.getAttribute(node, 'name')}: ${JSON.stringify(e)}`);
this.logger.error(`Could not generate pointer files for ${this.core.getAttribute(node, 'name')}: ${e.toString()}`);
return cb(e);
});
};
@@ -675,7 +804,19 @@ define([
var jobId = this.core.getPath(job),
opId = this.core.getPath(op),
info,
name;
secret,
name = this.core.getAttribute(job, 'name');
// If canceled, stop the operation
if (this.canceled) {
secret = this.core.getAttribute(job, 'secret');
if (secret) {
executor.cancelJob(hash, secret);
this.core.delAttribute(job, 'secret');
this.canceled = true;
return this.onOperationCanceled(op);
}
}
return executor.getInfo(hash)
.then(_info => { // Update the job's stdout
@@ -689,8 +830,7 @@ define([
return executor.getOutput(hash, currentLine, actualLine+1)
.then(outputLines => {
var stdout = this.core.getAttribute(job, 'stdout'),
output = outputLines.map(o => o.output).join(''),
jobName = this.core.getAttribute(job, 'name');
output = outputLines.map(o => o.output).join('');
// parse deepforge commands
output = this.parseForMetadataCmds(job, output);
@@ -698,7 +838,7 @@ define([
if (output) {
stdout += output;
this.core.setAttribute(job, 'stdout', stdout);
return this.save(`Received stdout for ${jobName}`);
return this.save(`Received stdout for ${name}`);
}
});
}
@@ -708,7 +848,6 @@ define([
if (info.status === 'RUNNING' &&
this.core.getAttribute(job, 'status') !== 'running') {
name = this.core.getAttribute(job, 'name');
this.core.setAttribute(job, 'status', 'running');
this.save(`Started "${name}" operation in ${this.pipelineName}`);
}
@@ -720,26 +859,40 @@ define([
return;
}
name = this.core.getAttribute(job, 'name');
this.core.setAttribute(job, 'execFiles', info.resultHashes[name + '-all-files']);
return this.blobClient.getArtifact(info.resultHashes.stdout)
.then(artifact => {
var stdoutHash = artifact.descriptor.content[STDOUT_FILE].content;
return this.blobClient.getObjectAsString(stdoutHash);
})
.then(stdout => {
// Parse the remaining code
stdout = this.parseForMetadataCmds(job, stdout, true);
this.core.setAttribute(job, 'stdout', stdout);
if (info.status !== 'SUCCESS') {
// Download all files
this.result.addArtifact(info.resultHashes[name + '-all-files']);
// Set the job to failed! Store the error
this.onOperationFail(op, `Operation "${opId}" failed! ${JSON.stringify(info)}`);
} else {
this.onDistOperationComplete(op, info);
}
});
if (info.status === 'CANCELED') {
// If it was cancelled, the pipeline has been stopped
this.logger.debug(`"${name}" has been CANCELED!`);
this.canceled = true;
return this.onOperationCanceled(op);
}
if (info.status === 'SUCCESS' || info.status === 'FAILED_TO_EXECUTE') {
this.core.setAttribute(job, 'execFiles', info.resultHashes[name + '-all-files']);
return this.blobClient.getArtifact(info.resultHashes.stdout)
.then(artifact => {
var stdoutHash = artifact.descriptor.content[STDOUT_FILE].content;
return this.blobClient.getObjectAsString(stdoutHash);
})
.then(stdout => {
// Parse the remaining code
stdout = this.parseForMetadataCmds(job, stdout, true);
this.core.setAttribute(job, 'stdout', stdout);
if (info.status !== 'SUCCESS') {
// Download all files
this.result.addArtifact(info.resultHashes[name + '-all-files']);
// Set the job to failed! Store the error
this.onOperationFail(op, `Operation "${opId}" failed! ${JSON.stringify(info)}`);
} else {
this.onDistOperationComplete(op, info);
}
});
} else { // something bad happened...
var err = `Failed to execute operation "${opId}": ${info.status}`,
consoleErr = `Failed to execute operation: ${info.status}`;
this.core.setAttribute(job, 'stdout', consoleErr);
this.logger.error(err);
this.onOperationFail(op, err);
}
})
.catch(err => this.logger.error(`Could not get op info for ${opId}: ${err}`));
};
@@ -832,11 +985,13 @@ define([
args,
result = [],
cmdCnt = 0,
ansiRegex = /\[\d+(;\d+)?m/g,
cmd;
for (var i = 0; i < lines.length; i++) {
// Check for a deepforge command
if (lines[i].indexOf(CONSTANTS.START_CMD) === 0) {
if (lines[i].indexOf(CONSTANTS.START_CMD) !== -1) {
lines[i] = lines[i].replace(ansiRegex, '');
cmdCnt++;
args = lines[i].split(/\s+/);
args.shift();
@@ -858,23 +1013,14 @@ define([
ExecuteJob.prototype[CONSTANTS.GRAPH_CREATE] = function (job, id) {
var graph,
name = Array.prototype.slice.call(arguments, 2).join(' '),
jobId = this.core.getPath(job),
oldMetadata = this._oldMetadataByName[jobId],
oldId;
jobId = this.core.getPath(job);
id = jobId + '/' + id;
this.logger.info(`Creating graph ${id} named ${name}`);
// Check if the graph already exists
if (oldMetadata && oldMetadata[name]) {
oldId = oldMetadata[name];
graph = this._markForDeletion[jobId][oldId];
// Reset points
this.core.setAttribute(graph, 'points', '');
delete this._markForDeletion[jobId][oldId];
} else { // create new graph
graph = this._getExistingMetadata(jobId, 'Graph', name);
if (!graph) {
graph = this.core.createNode({
base: this.META.Graph,
parent: job
@@ -890,6 +1036,7 @@ define([
ExecuteJob.prototype[CONSTANTS.GRAPH_PLOT] = function (job, id, x, y) {
var jobId = this.core.getPath(job),
nonNum = /[^\d\.]*/g,
graph,
points;
@@ -902,6 +1049,9 @@ define([
return;
}
// Clean the points by removing and special characters
x = x.replace(nonNum, '');
y = y.replace(nonNum, '');
points = this.core.getAttribute(graph, 'points');
points += `${x},${y};`;
this.core.setAttribute(graph, 'points', points);
@@ -923,5 +1073,46 @@ define([
this._metadata[jobId + '/' + id] = line;
};
ExecuteJob.prototype[CONSTANTS.IMAGE] = function (job, hash) {
var jobId = this.core.getPath(job),
name = Array.prototype.slice.call(arguments, 2).join(' '),
id = jobId + '/IMAGE/' + name,
imageNode = this._metadata[id]; // Look for the metadata imageNode
id = jobId + '/' + id;
this.logger.info(`Creating graph ${id} named ${name}`);
if (!imageNode) {
// Check if the imageNode already exists
imageNode = this._getExistingMetadata(jobId, 'Image', name);
if (!imageNode) {
imageNode = this.core.createNode({
base: this.META.Image,
parent: job
});
this.core.setAttribute(imageNode, 'name', name);
}
this._metadata[id] = imageNode;
}
this.core.setAttribute(imageNode, 'data', hash);
};
ExecuteJob.prototype._getExistingMetadata = function (jobId, type, name) {
var oldMetadata = this._oldMetadataByName[jobId] &&
this._oldMetadataByName[jobId][type],
node,
id;
if (oldMetadata && oldMetadata[name]) {
id = oldMetadata[name];
node = this._markForDeletion[jobId][id];
delete this._markForDeletion[jobId][id];
}
return node || null;
};
return ExecuteJob;
});
@@ -19,6 +19,7 @@ function deepforge._cmd(...)
print(cmd)
end
-- Graph support
Graph = torch.class('deepforge.Graph')
function Graph:__init(name)
@@ -36,6 +37,7 @@ function _Line:__init(graphId, name, opts)
end
function _Line:add(x, y)
assert(type(x) == "number" and type(y) == "number", "adding point (" .. tostring(x) .. ", " .. tostring(y) .. ") to " .. self.name .. " failed: expected (number, number)")
deepforge._cmd('<%= GRAPH_PLOT %>', self.id, x, y)
end
@@ -43,4 +45,21 @@ function Graph:line(name, opts)
return deepforge._Line(self.id, name, opts)
end
-- Image support
function deepforge.image(name, tensor)
require 'image'
require 'paths'
-- save it in the tmp directory
local filename = name .. '.png'
local path = paths.concat('metadata', filename)
if paths.dir('metadata') == nil then
paths.mkdir('metadata')
end
image.save(path, tensor)
deepforge._cmd("<%= IMAGE %>", name)
end
return deepforge
@@ -1,6 +1,6 @@
require 'paths'
local path = 'inputs/<%= name %>/<%= filename %>'
local abs_path = paths.concat('inputs', '<%= name %>', '<%= filename %>')
local path = 'inputs/<%= name %>/data'
local abs_path = paths.concat('inputs', '<%= name %>', 'data')
<%= code %>
+3 -2
Ver Arquivo
@@ -1,11 +1,13 @@
/*globals define*/
define([
'text!./start.ejs',
'text!./entry.ejs',
'text!./main.ejs',
'text!./deepforge.ejs',
'text!./serialize.ejs',
'text!./deserialize.ejs'
], function(
START,
ENTRY,
MAIN,
DEEPFORGE,
@@ -13,9 +15,8 @@ define([
DESERIALIZE
) {
var BASH = 'th init.lua 2>&1';
return {
BASH,
START,
ENTRY,
MAIN,
SERIALIZE,
+224
Ver Arquivo
@@ -0,0 +1,224 @@
// A wrapper for the torch script which:
// - merges stdout, stderr
// - receives some commands and uploads intermediate data
var spawn = require('child_process').spawn,
fs = require('fs'),
path = require('path'),
log = console.error,
logger = {};
// Create the stderr only logger
['error', 'warn', 'info', 'log', 'debug'].forEach(method => logger[method] = log);
// Get the BlobClient...
var COMMAND_PREFIX = '<%= START_CMD %>',
IMAGE = '<%= IMAGE %>',
requirejs = require('webgme').requirejs,
remainingImageCount = 0,
exitCode = null;
requirejs([
'q',
'blob/BlobClient'
], function(
Q,
BlobClient
) {
var url = process.env.ORIGIN_URL || 'http://127.0.0.1:8888',
CACHE_DIR = process.env.DEEPFORGE_WORKER_CACHE || './worker-cache',
protocol = url.split('://').shift(),
address,
port = (url.split(':') || ['80']).pop();
address = url.replace(protocol + '://', '')
.replace(':' + port, '');
// Create CACHE_DIR if it doesn't exist
var prepareCache = function() {
var dirs = CACHE_DIR.replace(/\/$/, '').split('/'),
cacheParent;
dirs.pop();
cacheParent = dirs.join('/');
return makeIfNeeded(cacheParent).then(() => makeIfNeeded(CACHE_DIR));
};
var makeIfNeeded = function(dir) {
var deferred = Q.defer(),
job;
log(`makeIfNeeded: ${JSON.stringify(dir)}`);
fs.lstat(dir, (err, stat) => {
if (err || !stat.isDirectory()) {
fs.mkdir(dir, err => {
if (err) {
return deferred.reject(err);
}
deferred.resolve();
});
} else {
deferred.resolve();
}
});
return deferred.promise;
};
var blobClient = new BlobClient({
server: address,
httpsecure: protocol === 'https',
serverPort: port,
logger: logger
});
var checkFinished = () => {
if (exitCode !== null && remainingImageCount === 0) {
log('finished!');
process.exit(exitCode);
}
};
var uploadImage = function(line) {
var args = line.split(/\s+/),
name = args.slice(2).join(' ').replace(/\s+$/, ''),
filename = 'metadata/' + name + '.png';
// Upload the image from metadata/
remainingImageCount++;
fs.readFile(filename, (err, content) => {
if (err) {
logger.error(`Could not read ${filename}: ${err}`);
return;
}
// Add hash to the image command
log('about to putFile', filename);
blobClient.putFile(filename, content)
.then(hash => {
args.splice(2, 0, hash);
console.log(args.join(' '));
log('printing cmd:', args.join(' '));
--remainingImageCount;
log('finished uploading ' + filename + ' ' + remainingImageCount + ' remain');
checkFinished();
})
.fail(err => logger.error(`${filename} upload failed: ${err}`));
});
};
var onStderr = function(data) {
var text = data.toString();
// Filter out directory label from stack traces
process.stdout.write(text.replace(/\.\.\.\/.*\/(main|deepforge|init).lua/g, '$1'));
};
var onStdout = function(data) {
var lines = data.toString().split('\n'),
result = [],
cmdStart;
// Check for commands...
for (var i = 0; i < lines.length; i++) {
cmdStart = lines[i].indexOf(COMMAND_PREFIX);
if (cmdStart !== -1 && lines[i].indexOf(IMAGE) !== -1) {
uploadImage(lines[i]);
} else {
result.push(lines[i]);
}
}
process.stdout.write(result.join('\n'));
};
var createCacheDir = function(hash) {
var dir = hash.substring(0, 2);
return makeIfNeeded(CACHE_DIR + '/' + dir);
};
var dataCachePath = function(hash) {
var dir = hash.substring(0, 2),
filename = hash.substring(2),
cachePath = `${CACHE_DIR}/${dir}/${filename}`;
// Get the path for data in the cache
return cachePath;
};
var makeSymLink = function(target, src) {
var deferred = Q.defer(),
job;
src = path.resolve(src);
target = path.resolve(target);
fs.stat(src, err => {
if (err.code === 'ENOENT') {
logger.debug(`creating symlink "ln -s ${target} ${src}"`);
job = spawn('ln', ['-s', target, src || '.']);
job.on('exit', code => {
if (code) {
deferred.reject(`Could not create symlink ${target} -> ${src||'.'}`);
return;
}
deferred.resolve();
});
}
deferred.resolve();
});
return deferred.promise;
};
var getData = function(ipath, hashes) {
// Download the data and put it in the given path
var deferred = Q.defer(),
inputName = ipath.split('/')[1],
cachePath = dataCachePath(hashes.cache);
logger.debug(`retrieving ${ipath}`);
fs.lstat(cachePath, (err, cacheStats) => {
// Check if the data exists in the cache
if (!err && cacheStats.isFile()) {
logger.info(`${inputName} already cached. Skipping retrieval from blob`);
return makeSymLink(cachePath, ipath).then(deferred.resolve);
}
createCacheDir(hashes.cache)
.then(() => blobClient.getObject(hashes.req))
.then(buffer => fs.writeFile(cachePath, buffer, (err, result) => {
if (err) {
logger.error('Retrieving ' + ipath + ' failed!');
return deferred.reject(`Could not write to ${ipath}: ${err}`);
}
// Create the symlink
logger.info('Retrieved ' + ipath);
return makeSymLink(cachePath, ipath).then(deferred.resolve);
}))
.fail(err => deferred.reject(`Could not retrieve "${inputName}" (${err})`));
});
return deferred.promise;
};
// Download the large files
var inputData = JSON.parse(fs.readFileSync('./input-data.json')),
inputPaths = Object.keys(inputData);
// Request the data from the blob
prepareCache()
.then(() => Q.all(inputPaths.map(ipath => getData(ipath, inputData[ipath]))))
.then(() => {
// Run 'th init.lua' and merge the stdout, stderr
var job = spawn('th', ['init.lua']);
job.stdout.on('data', onStdout);
job.stderr.on('data', onStderr);
job.on('close', code => {
exitCode = code;
log('script finished w/ exit code:', code);
checkFinished();
});
})
.fail(err => {
console.log(`Data retrieval failed: ${err}`);
process.exit(1);
});
});
+39 -24
Ver Arquivo
@@ -74,6 +74,7 @@ define([
// - keep track if the pipeline has errored
// - if so, don't start any more jobs
this.pipelineError = null;
this.canceled = false;
this.runningJobs = 0;
// metadata records
@@ -103,17 +104,18 @@ define([
// If starting with a pipeline, we will create an Execution first
startPromise = this.createExecution(this.activeNode)
.then(execNode => {
this.logger.debug(`Finished creating execution "${this.core.getAttribute(execNode, 'name')}"`);
this.activeNode = execNode;
});
} else if (this.core.isTypeOf(this.activeNode, this.META.Execution)) {
this.logger.debug('Restarting execution');
startPromise = Q();
} else {
return callback('Current node is not a Pipeline or Execution!', this.result);
}
// Set debug and the final callback
this.debug = true; // this.getCurrentConfig().debug;
this._callback = callback;
this.currentForkName = null;
startPromise
.then(() => this.core.loadSubTree(this.activeNode))
@@ -122,41 +124,29 @@ define([
.filter(n => this.core.getParent(n) === this.activeNode);
this.pipelineName = this.core.getAttribute(this.activeNode, 'name');
this.logger.debug(`Loaded subtree of ${this.pipelineName}. About to build cache`);
this.buildCache(subtree);
this.logger.debug('Parsing execution for job inter-dependencies');
this.parsePipeline(children); // record deps, etc
this.logger.debug('Clearing old results');
return this.clearResults();
})
.then(() => this.executePipeline())
.fail(e => this.logger.error(e));
};
ExecutePipeline.prototype.updateForkName = function () {
var basename = this.pipelineName + '_fork';
return this.project.getBranches().then(branches => {
var names = Object.keys(branches),
name = basename,
i = 2;
while (names.indexOf(name) !== -1) {
name = basename + '_' + i;
i++;
}
this.forkName = name;
});
};
// Override 'save' to prevent race conditions while saving
ExecutePipeline.prototype.save = function (msg) {
// When 'save' is called, it should still finish any current save op
// before continuing
this._currentSave = this._currentSave
.then(() => this.updateForkName())
.then(() => this.updateForkName(this.pipelineName))
.then(() => CreateExecution.prototype.save.call(this, msg))
.then(result => {
var msg;
if (result.status === STORAGE_CONSTANTS.FORKED) {
this.currentForkName = result.forkName;
msg = `"${this.pipelineName}" execution has forked to "${result.forkName}"`;
this.sendNotification(msg);
}
@@ -289,8 +279,17 @@ define([
this.onPipelineComplete(err);
};
ExecutePipeline.prototype.onOperationCanceled = function(op) {
var job = this.core.getParent(op);
this.core.setAttribute(job, 'status', 'canceled');
this.runningJobs--;
this.logger.debug(`${this.core.getAttribute(job, 'name')} has been canceled`);
this.onPipelineComplete();
};
ExecutePipeline.prototype.onPipelineComplete = function(err) {
var name = this.core.getAttribute(this.activeNode, 'name');
var name = this.core.getAttribute(this.activeNode, 'name'),
msg = `"${this.pipelineName}" `;
if (err) {
this.runningJobs--;
@@ -298,17 +297,33 @@ define([
this.pipelineError = this.pipelineError || err;
if (this.pipelineError && this.runningJobs > 0) {
this.logger.info('Pipeline errored but is waiting for the running ' +
this.logger.debug(`${this.runningJobs} remaining jobs`);
if ((this.pipelineError || this.canceled) && this.runningJobs > 0) {
var action = this.pipelineError ? 'error' : 'cancel';
this.logger.info(`Pipeline ${action}ed but is waiting for the running ` +
'jobs to finish');
return;
}
if (this.currentForkName) {
// notify client that the job has completed
this.sendNotification(`"${this.pipelineName}" execution completed on branch "${this.currentForkName}"`);
}
if (this.pipelineError) {
msg += 'failed!';
} else if (this.canceled) {
msg += 'canceled!';
} else {
msg += 'finished!';
}
this.logger.debug(`Pipeline "${name}" complete!`);
this.core.setAttribute(this.activeNode, 'status',
(!this.pipelineError ? 'success' : 'failed'));
(this.pipelineError ? 'failed' : (this.canceled ? 'canceled' : 'success')));
this._finished = true;
this.resultMsg(msg);
this.save('Pipeline execution finished')
.then(() => {
this.result.setSuccess(!this.pipelineError);
@@ -325,7 +340,7 @@ define([
this.logger.info(`About to execute ${readyOps.length} operations`);
// If the pipeline has errored don't start any more jobs
if (this.pipelineError) {
if (this.pipelineError || this.canceled) {
if (this.runningJobs === 0) {
this.onPipelineComplete();
}
+6 -6
Ver Arquivo
@@ -11,17 +11,17 @@
"disableBrowserSideExecution": true,
"configStructure": [
{
"name": "snapshot",
"displayName": "Snapshot",
"description": "Freeze the operation definitions and attributes at current value",
"value": true,
"valueType": "boolean",
"name": "name",
"displayName": "Execution name",
"description": "Optional name for this execution instance",
"value": "",
"valueType": "string",
"readOnly": false
},
{
"name": "debug",
"displayName": "Debug Mode",
"description": "Download all files for each operation",
"description": "Allow for operation editing after creation",
"value": false,
"valueType": "boolean",
"readOnly": false
@@ -1,22 +1,16 @@
/*globals define*/
/*jshint node:true, browser:true*/
/**
* Generated by PluginGenerator 0.14.0 from webgme on Sun Mar 20 2016 16:49:12 GMT-0500 (CDT).
*/
define([
'SimpleNodes/SimpleNodes',
'SimpleNodes/Constants',
'deepforge/layer-args',
'./dimensionality',
'underscore',
'text!./metadata.json'
], function (
PluginBase,
Constants,
createLayerDict,
dimensionality,
_,
metadata
) {
@@ -46,7 +40,7 @@ define([
this.addCustomLayersToMeta();
this.LayerDict = createLayerDict(this.core, this.META);
this.uniqueId = 2;
this._oldTemplateSettings = _.templateSettings;
this.varnames = {};
return PluginBase.prototype.main.apply(this, arguments);
};
@@ -60,25 +54,36 @@ define([
.forEach(node => this.META[this.core.getAttribute(node, 'name')] = node);
};
GenerateArchitecture.prototype.hoist = function (code) {
this.definitions.push(code);
};
GenerateArchitecture.prototype.createOutputFiles = function (tree) {
var layers = tree[Constants.CHILDREN],
//initialLayers,
result = {},
code = 'require \'nn\'\n';
code = '';
this.definitions = [
'require \'nn\'',
'require \'rnn\''
];
//initialLayers = layers.filter(layer => layer[Constants.PREV].length === 0);
// Add an index to each layer
layers.forEach((l, index) => l[INDEX] = index);
// Define custom layers
if (this.getCurrentConfig().standalone) {
this.logger.debug('Generating layer definitions');
code += this.genLayerDefinitions(layers);
}
this.logger.debug('Generating architecture code...');
code += this.genArchCode(layers);
this.logger.debug('Prepending hoisted code...');
code = this.definitions.join('\n') + '\n' + code;
result[tree.name + '.lua'] = code;
_.templateSettings = this._oldTemplateSettings; // FIXME: Fix this in SimpleNodes
this.logger.debug(`Finished generating ${tree.name}.lua`);
return result;
};
@@ -89,10 +94,38 @@ define([
].join('\n');
};
GenerateArchitecture.prototype.genRawArchCode = function (layers, name) {
var result = '';
if (layers.length > 1) {
return this.createSequential(layers[0], name).code;
} else if (name) {
result = `\nlocal ${name} = `;
}
result += this.createLayer(layers[0]);
return result;
};
GenerateArchitecture.prototype.getVarName = function (base) {
// Check "this.varnames"
var name = base,
i = 2;
while (this.varnames[name]) {
name = base + '_' + (i++);
}
this.varnames[name] = true;
return name;
};
GenerateArchitecture.prototype.createLayer = function (layer) {
var args = this.createArgString(layer);
return `nn.${layer.name}${args}`;
};
GenerateArchitecture.prototype.createSequential = function (layer, name) {
var next = layer[Constants.NEXT][0],
args,
template,
snippet,
snippets,
code = `\nlocal ${name} = nn.Sequential()`,
@@ -107,10 +140,8 @@ define([
next = layer; // the given layer will be added by the caller
break;
} else { // add the given layer
args = this.createArgString(layer);
template = _.template(name + ':add(nn.{{= name }}' + args + ')');
snippet = template(layer);
code += '\n' + snippet;
snippet = this.createLayer(layer);
code += `\n${name}:add(${snippet})`;
}
@@ -119,7 +150,7 @@ define([
this.logger.debug(`detected fork of size ${layer[Constants.NEXT].length}`);
snippets = layer[Constants.NEXT].map(nlayer =>
this.createSequential(nlayer, 'net_'+(this.uniqueId++)));
this.createSequential(nlayer, this.getVarName('net')));
code += '\n' + snippets.map(snippet => snippet.code).join('\n');
// Make sure all snippets end at the same concat node
@@ -157,7 +188,7 @@ define([
// merge the elements in the group
if (snippets.length) { // prepare next iteration
result = this.createSequential(next, 'net_'+(this.uniqueId++));
result = this.createSequential(next, this.getVarName('net'));
code += result.code;
group = [result];
this.logger.debug('updating group ('+ snippets.length+ ' left)');
@@ -177,11 +208,70 @@ define([
};
};
GenerateArchitecture.abbr = function (word) {
word = word.substring(0, 1).toUpperCase() + word.substring(1);
return word.split(/[a-z]+/g).join('').toLowerCase();
};
GenerateArchitecture.prototype.getValue = function (arg, layer) {
var content = layer[arg];
if (typeof content === 'object') { // layer as arg
if (content[Constants.CHILDREN].length) {
// Generate the code for the children of layer[arg]
var name = this.getVarName(GenerateArchitecture.abbr(arg)),
layers;
this.logger.debug(`Adding layer arg for ${arg} (${layer.name})`);
try {
layers = this.genRawArchCode(layer[arg][Constants.CHILDREN], name);
} catch (e) {
this.logger.error(`Layer arg creation failed: ${e}`);
return null;
}
// hoist layer definitions to the top of the file
this.hoist(layers);
return name;
} else {
return null;
}
}
return content;
};
GenerateArchitecture.prototype.createArgString = function (layer) {
return '(' + this.LayerDict[layer.name]
.map(arg => layer[arg.name])
var setters = this.LayerDict[layer.name].setters,
setterNames = Object.keys(this.LayerDict[layer.name].setters),
base = layer[Constants.BASE],
desc,
fn,
layerCode;
this.logger.debug(`Creating arg string for ${layer.name}`);
layerCode = '(' + this.LayerDict[layer.name].args
.map(arg => this.getValue(arg.name, layer))
.filter(GenerateArchitecture.isSet)
.join(', ') + ')';
.join(', ') + ')';
// Add any setters
// For each setter, check if it has been changed (and needs to be set)
for (var i = setterNames.length; i--;) {
desc = setters[setterNames[i]];
if (desc.setterType === 'const') {
// if the value is not the default, add the given fn
if (layer[setterNames[i]] !== base[setterNames[i]]) {
fn = desc.setterFn[layer[setterNames[i]]];
layerCode += `:${fn}()`;
}
} else if (layer[setterNames[i]] !== null && layer[setterNames[i]] !== undefined) {
fn = desc.setterFn;
layerCode += `:${fn}(${layer[setterNames[i]]})`;
}
}
this.logger.debug(`Created nn.${layer.name}${layerCode}`);
return layerCode;
};
GenerateArchitecture.isSet = function (value) {
@@ -1,52 +0,0 @@
/* globals define */
define([
'SimpleNodes/Constants',
'deepforge/lua'
], function(
Constants,
luajs
) {
'use strict';
var dimensionality = function(node) {
var transform = node.dimensionalityTransform;
return dimensionality[transform](node);
};
// If 'same', return the input dimensions
dimensionality.same = function(node) {
var prev = node[Constants.PREV][0];
return dimensionality(prev);
};
dimensionality.custom = function(node) {
var luaFn = node.calculateDimensionality,
cxt = luajs.newContext(),
layer, // lua layer
bin,
dims;
cxt.loadStdLib();
// - cross compile to js
bin = cxt.loadString(luaFn);
bin(); // load the calc fn to global context
// Create the layer
layer = new luajs.types.LuaTable();
var attrs = Object.keys(node).filter(attr => attr.indexOf('_') !== 0);
for (var i = attrs.length; i--;) {
layer.set(attrs[i], node[attrs[i]]);
}
cxt._G.set('layer', layer);
// call the function with layer and input dimensions
bin = cxt.loadString('return calcDims(layer)');
dims = bin()[0]; // TODO: Add support for multiple dimensions
// TODO: return a fn if it depends on the previous value
return dims;
};
return dimensionality;
});
+3 -15
Ver Arquivo
@@ -1,18 +1,12 @@
/*globals define*/
/*jshint node:true, browser:true*/
/**
* Generated by PluginGenerator 0.14.0 from webgme on Thu Mar 10 2016 04:16:02 GMT-0600 (CST).
*/
define([
'deepforge/layer-args',
'deepforge/lua',
'./nn',
'plugin/PluginBase',
'text!./metadata.json'
], function (
LayerDict,
luajs,
createNNSearcher,
PluginBase,
@@ -78,11 +72,10 @@ define([
this.loadNNMock();
// Cross compile to js and run
src = 'require \'nn\'\n' + src; // guarantee it loads nn
this.bin = this.context.loadString(src);
this.bin();
this.afterExecution();
return this.save('ImportTorch updated model.');
})
.then(() => { // changes saved successfully
@@ -107,15 +100,10 @@ define([
this.context._G.get('package').set('searchers', [function(name) {
if (name === 'nn') {
return lib;
} else {
return () => {};
}
}]);
// Some scripts don't include `require 'nn'`. I may have to add the
// "nn" package to the global scope...
};
ImportTorch.prototype.afterExecution = function () {
// TODO
};
return ImportTorch;
+148 -17
Ver Arquivo
@@ -7,7 +7,7 @@ define([
], function(
createLayerDict,
assert,
luajs
lua
) {
'use strict';
@@ -19,7 +19,8 @@ define([
LayerDict = createLayerDict(core, META),
helpers = context.__helpers,
oldSet = helpers.__set,
isSetting = false;
isSetting = false,
connsFrom = {};
// Override the helper's '__set' method to detect
// if the code is in the middle of a "set".
@@ -29,24 +30,68 @@ define([
isSetting = false;
};
var stringify = function(table) {
var strings = table.array.map(val => {
if (val instanceof lua.types.LuaTable) {
return stringify(val);
} else {
return val;
}
});
return '{' + strings.join(', ') + '}';
};
var allConnectedTo = function(current) {
var connectedIds = {},
node,
id;
while (current.length) {
node = current.shift();
id = core.getGuid(node);
if (connectedIds[id]) {
continue;
}
connectedIds[id] = node;
if (connsFrom[id]) {
current = current.concat(connsFrom[id]);
}
}
// Return an array of all things connected to the
// given node
return Object.keys(connectedIds).map(key => connectedIds[key]);
};
var connect = function(src, dst) {
var conn = core.createNode({
var conn,
id;
conn = core.createNode({
parent: parent,
base: META.Connection
});
core.setPointer(conn, 'src', src);
core.setPointer(conn, 'dst', dst);
// Record this
id = core.getGuid(src);
if (!connsFrom[id]) {
connsFrom[id] = [];
}
connsFrom[id].push(conn, dst);
};
// nn drawing library
var Layer = function(base, attrs, args) {
this._base = base;
this._attrs = attrs;
for (var i = 0; i < attrs.length; i++) {
this[attrs[i].name] = args[i];
}
// inputs/outputs used for being added to containers
this._values = args;
this._cachedNode = null;
this._inputs = [this._node()];
this._outputs = [this._node()];
@@ -55,6 +100,10 @@ define([
Layer.prototype._node = function() {
var name,
node,
nodes,
cntr,
layer,
cntrName,
value;
if (this._cachedNode) {
@@ -70,16 +119,42 @@ define([
for (var i = this._attrs.length; i--;) {
name = this._attrs[i].name;
value = this[name];
if ((typeof value) === 'object') {
// special lua.js object
value = value.valueOf();
}
value = this._values[i];
// TODO: Update this to check if inferred and the value matches
// our inferred value. If so, skip it
if (value !== undefined/*&& !this._attrs[i].infer*/) {
core.setAttribute(node, name, value);
if (value instanceof lua.types.LuaTable) {
layer = value.get('_node');
if (layer) { // layer arg!
// add all the inputs, outputs (and connected elements) to
// be in an "Architecture" node in the current node
cntr = core.createNode({
base: META.Architecture,
parent: node
});
cntrName = `${name} (${this._base})`;
logger.debug(`Naming layer arg ${cntrName}`);
core.setAttribute(cntr, 'name', cntrName);
// Move all connecting elements of the value to
// the cntr
nodes = allConnectedTo(layer._inputs.concat(layer._outputs));
for (var j = nodes.length; j--;) {
core.moveNode(nodes[j], cntr);
}
core.setPointer(node, name, cntr);
logger.debug(`Moving ${nodes.length} to ${name}(${this._base})`);
} else { // Something like {1, 2, 3}
value = stringify(value);
logger.debug(`Setting ${name} to ${value} (${this._base})`);
core.setAttribute(node, name, value);
}
} else { // attribute value
if ((typeof value) === 'object') {
// special lua.js object
value = value.valueOf();
}
if (value !== undefined) {
logger.debug(`Setting ${name} to ${value} (${this._base})`);
core.setAttribute(node, name, value);
}
}
}
@@ -87,6 +162,13 @@ define([
return node;
};
Layer.prototype._setAttribute = function(name, self, value) {
var node = this._node();
logger.info(`Setting ${name} to ${value}`);
core.setAttribute(node, name, value);
return self;
};
// Each container will have `inputs` and `outputs`
var Container = function() {
// inputs and outputs are webgme nodes
@@ -153,16 +235,59 @@ define([
Sequential: Sequential
};
var getValue = function(txt) {
if (txt === 'true') {
return true;
}
if (txt === 'false') {
return false;
}
if (/^\d+$/.test(txt)) {
return +txt;
}
return txt;
};
var addSetterMethods = function(table, attr, dict) {
var desc = dict[attr],
layer = table.get('_node'),
vals,
value,
fn;
if (desc.setterType === 'arg') {
fn = desc.setterFn;
table.set(fn, layer._setAttribute.bind(layer, attr));
} else {
vals = Object.keys(desc.setterFn);
for (var i = vals.length; i--;) {
fn = desc.setterFn[vals[i]];
value = getValue(vals[i]);
table.set(fn, layer._setAttribute.bind(layer, attr, table, value));
}
}
};
var CreateLayer = function(type) {
var res = luajs.newContext()._G,
var res = lua.newContext()._G,
attrs = [].slice.call(arguments, 1),
ltGet = luajs.types.LuaTable.prototype.get,
ltGet = lua.types.LuaTable.prototype.get,
setters = [],
args = [],
node;
if (LayerDict[type]) {
args = LayerDict[type].args;
setters = Object.keys(LayerDict[type].setters);
}
if (LAYERS[type]) {
node = new LAYERS[type](LayerDict[type] || [], attrs);
node = new LAYERS[type](args, attrs);
} else { // Call generic Layer with type name
node = new Layer(type, LayerDict[type] || [], attrs);
node = new Layer(type, args, attrs);
}
res.set('_node', node);
@@ -178,6 +303,12 @@ define([
}
}
// add setters
// look up the setters
for (var i = setters.length; i--;) {
addSetterMethods(res, setters[i], LayerDict[type].setters);
}
// Override get
res.get = function noNilGet(value) {
var result = ltGet.call(this, value);
@@ -197,7 +328,7 @@ define([
}
// TODO: Create the nn object
var nn = luajs.newContext()._G,
var nn = lua.newContext()._G,
names = Object.keys(LayerDict);
for (var i = names.length; i--;) {
Arquivo binário não exibido.
Arquivo binário não exibido.
Arquivo binário não exibido.
Arquivo binário não exibido.
Arquivo binário não exibido.
Arquivo binário não exibido.
Arquivo binário não exibido.
+12
Ver Arquivo
@@ -88,5 +88,17 @@
"title": "LineGraph",
"panel": "panels/LineGraph/LineGraphPanel",
"DEBUG_ONLY": false
},
{
"id": "ImageViewer",
"title": "ImageViewer",
"panel": "panels/ImageViewer/ImageViewerPanel",
"DEBUG_ONLY": false
},
{
"id": "ExecutionIndex",
"title": "ExecutionIndex",
"panel": "panels/ExecutionIndex/ExecutionIndexPanel",
"DEBUG_ONLY": false
}
]
@@ -2,12 +2,14 @@
/*jshint browser: true*/
define([
'deepforge/Constants',
'deepforge/globals',
'panels/EasyDAG/EasyDAGControl',
'js/NodePropertyNames',
'js/Utils/ComponentSettings',
'underscore'
], function (
Constants,
DeepForge,
EasyDAGControl,
nodePropertyNames,
@@ -38,6 +40,7 @@ define([
_.extend(ArchEditorControl.prototype, EasyDAGControl.prototype);
ArchEditorControl.prototype.TERRITORY_RULE = {children: 1};
ArchEditorControl.prototype.DEFAULT_DECORATOR = 'LayerDecorator';
ArchEditorControl.prototype.getComponentId = function() {
return 'ArchEditor';
};
@@ -59,12 +62,24 @@ define([
if (!desc.isConnection) {
var allAttrs = desc.attributes,
names = Object.keys(allAttrs),
schema;
ctorInfo = desc.attributes[Constants.CTOR_ARGS_ATTR],
ctorAttrs = ctorInfo ? ctorInfo.value.split(','): [],
schema,
i;
desc.attributes = {};
for (var i = names.length; i--;) {
// add ctor attributes
for (i = 0; i < ctorAttrs.length; i++) {
if (allAttrs[ctorAttrs[i]]) { // (not a ref to a layer)
desc.attributes[ctorAttrs[i]] = allAttrs[ctorAttrs[i]];
}
}
for (i = names.length; i--;) {
// check if it is a setter
schema = this._client.getAttributeSchema(id, names[i]);
if (names[i] === 'name' || schema.hasOwnProperty('argindex')) {
if (names[i] === 'name' || schema.setterType) {
desc.attributes[names[i]] = allAttrs[names[i]];
}
}
@@ -163,7 +178,7 @@ define([
ArchEditorControl.prototype.getCreateNewDecorator = function() {
return this._client.decoratorManager.getDecoratorForWidget(
'EllipseDecorator',
'LayerDecorator',
'EasyDAG'
);
};
@@ -3,10 +3,12 @@
define([
'panels/TextEditor/TextEditorControl',
'deepforge/lua',
'underscore',
'text!./DefaultCodeTemplate.ejs'
], function (
TextEditorControl,
lua,
_,
CODE_TEMPLATE
) {
@@ -53,19 +55,95 @@ define([
match = returned.match(/[a-zA-Z0-9_]+/),
node = this._client.getNode(id),
nodeName = node.getAttribute('name'),
name;
baseName = null,
basePath,
name,
ast;
if (match) {
name = match[0];
}
// Check if the base needs to be updated
try {
ast = lua.parser.parse(text);
lua.codegen.traverse(curr => {
// Check for inheritance of the given type
if (curr.type === 'expr.call') {
var object = curr.func.self.val,
method = curr.func.key.val,
child,
base;
if (object === 'torch' && method === 'class') {
child = curr.args[0];
base = curr.args[1];
// If the first argument is the given class, get the base
if (child.type === 'const.string' && child.val === name) {
if (base && base.type === 'const.string') {
baseName = base.val;
}
}
}
}
})(ast);
// Get the base path from the base name
basePath = this.getBasePathFromName(baseName);
if (!basePath) {
this._logger.warn(`Could not find base type matching the name ${baseName}`);
}
} catch(e) {
this._logger.warn(`Invalid lua code. Parser failed: ${e}`);
}
this._client.startTransaction(`Updating class "${name || nodeName}"`);
if (name) {
this._client.setAttributes(id, 'name', name);
}
if (basePath) {
this._client.setBase(id, basePath);
} else { // Set base back to 'Complex'
while (node && (node.getAttribute('name') !== 'Complex' ||
node.isAbstract() !== true)) {
node = this._client.getNode(node.getBaseId());
}
if (node) { // node is the base class type
this._client.setBase(id, node.getId());
} else {
this._logger.warn(`Could not find the base class type from ${id}`);
}
}
TextEditorControl.prototype.saveTextFor.call(this, id, text);
this._client.completeTransaction();
};
ClassCodeEditorControl.prototype.getBasePathFromName = function (baseName) {
var metanodes = this._client.getAllMetaNodes(),
nameMatches = [],
classNode,
i;
for (i = metanodes.length; i--;) {
if (metanodes[i].getAttribute('name') === baseName) {
nameMatches.push(metanodes[i]);
}
if (metanodes[i].getAttribute('name') === 'Complex') {
classNode = metanodes[i];
}
}
for (i = nameMatches.length; i--;) {
if (this._client.isTypeOf(nameMatches[i].getId(), classNode.getId())) {
return nameMatches[i].getId();
}
}
return null;
};
return ClassCodeEditorControl;
});
@@ -0,0 +1,302 @@
/*globals define, WebGMEGlobal*/
/*jshint browser: true*/
define([
'js/Constants'
], function (
CONSTANTS
) {
'use strict';
var ExecutionIndexControl;
ExecutionIndexControl = function (options) {
this._logger = options.logger.fork('Control');
this._client = options.client;
this._embedded = options.embedded;
// Initialize core collections and variables
this._widget = options.widget;
this._currentNodeId = null;
this.displayedExecutions = {};
this._linesForExecution = {};
this._lineToExec = {};
this._pipelineNames = {};
this._initWidgetEventHandlers();
this._logger.debug('ctor finished');
};
ExecutionIndexControl.prototype._initWidgetEventHandlers = function () {
this._widget.setExecutionDisplayed = this.setExecutionDisplayed.bind(this);
};
ExecutionIndexControl.prototype.setExecutionDisplayed = function (id, bool) {
var lines = this._linesForExecution[id] || [],
action = bool ? 'addNode' : 'removeNode';
// If removing, just get the ids
lines = bool ? lines : lines.map(line => line.id);
this._logger.info(`setting execution ${id} to ${bool ? 'displayed' : 'hidden'}`);
this.displayedExecutions[id] = bool;
// update the given lines
for (var i = lines.length; i--;) {
this._widget[action](lines[i]);
}
};
ExecutionIndexControl.prototype.clearTerritory = function () {
if (this._territoryId) {
this._client.removeUI(this._territoryId);
this._territoryId = null;
}
};
/* * * * * * * * Visualizer content update callbacks * * * * * * * */
ExecutionIndexControl.prototype.selectedObjectChanged = function (nodeId) {
var self = this;
self._logger.debug('activeObject nodeId \'' + nodeId + '\'');
// Remove current territory patterns
self.clearTerritory();
self._currentNodeId = nodeId;
if (typeof self._currentNodeId === 'string') {
// Create a territory for the executions
self._selfPatterns = {};
self._territoryId = self._client.addUI(self, function (events) {
self._eventCallback(events);
});
// Update the territory
self._selfPatterns[nodeId] = {children: 4};
self._client.updateTerritory(self._territoryId, self._selfPatterns);
}
};
// This next function retrieves the relevant node information for the widget
ExecutionIndexControl.prototype._getObjectDescriptor = function (nodeId) {
var node = this._client.getNode(nodeId),
childIds,
desc,
base,
type;
if (node) {
base = this._client.getNode(node.getBaseId());
type = base.getAttribute('name');
desc = {
id: node.getId(),
type: type,
name: node.getAttribute('name')
};
if (type === 'Execution') {
desc.status = node.getAttribute('status');
desc.originTime = node.getAttribute('createdAt');
desc.originId = node.getPointer('origin').to;
desc.pipelineName = this._pipelineNames[desc.originId];
this._logger.debug(`Looking up pipeline name for ${desc.name}: ${desc.pipelineName}`);
// Create a territory for this origin and update it!
this._selfPatterns[desc.originId] = {children: 0};
setTimeout(() => this._client.updateTerritory(this._territoryId, this._selfPatterns), 0);
} else if (type === 'Line') {
desc = this.getLineDesc(node);
} else if (type === 'Pipeline') {
desc.execs = node.getMemberIds('executions');
this._pipelineNames[desc.id] = desc.name;
} else if (type === 'Graph') {
childIds = node.getChildrenIds();
desc.lines = childIds.map(id => {
var n = this._client.getNode(id);
return this.getLineDesc(n);
});
}
}
return desc;
};
ExecutionIndexControl.prototype.getLineDesc = function (node) {
var id = node.getId(),
graphId = node.getParentId(),
jobId = this._client.getNode(graphId).getParentId(),
execId = this._client.getNode(jobId).getParentId(),
points,
desc;
points = node.getAttribute('points').split(';')
.filter(data => !!data) // remove any ''
.map(pair => {
var nums = pair.split(',').map(num => parseFloat(num));
return {
x: nums[0],
y: nums[1]
};
});
desc = {
id: id,
//execName: execName,
execId: execId,
lineName: node.getAttribute('name'),
name: node.getAttribute('name'),
type: 'line',
points: points
};
// Update records
if (!this._linesForExecution[execId]) {
this._linesForExecution[execId] = [];
}
this._linesForExecution[execId].push(desc);
this._lineToExec[id] = execId;
return desc;
};
/* * * * * * * * Node Event Handling * * * * * * * */
ExecutionIndexControl.prototype._eventCallback = function (events) {
var event;
events = events.filter(event => event.eid !== this._currentNodeId);
this._logger.debug('received \'' + events.length + '\' events');
for (var i = events.length; i--;) {
event = events[i];
switch (event.etype) {
case CONSTANTS.TERRITORY_EVENT_LOAD:
this._onLoad(event.eid);
break;
case CONSTANTS.TERRITORY_EVENT_UPDATE:
this._onUpdate(event.eid);
break;
case CONSTANTS.TERRITORY_EVENT_UNLOAD:
this._onUnload(event.eid);
break;
default:
break;
}
}
this._logger.debug('finished processing events!');
};
ExecutionIndexControl.prototype._onLoad = function (gmeId) {
var desc = this._getObjectDescriptor(gmeId);
this._logger.debug(`Loading node of type ${desc.type}`);
if (desc.type === 'Execution') {
this._logger.debug('Adding node to widget...');
this._logger.debug('desc:', desc);
this._widget.addNode(desc);
} else if (desc.type === 'line' && this.isLineDisplayed(desc)) {
this._widget.addNode(desc);
} else if (desc.type === 'Pipeline') {
this.updatePipelineNames(desc);
}
};
ExecutionIndexControl.prototype._onUpdate = function (gmeId) {
var desc = this._getObjectDescriptor(gmeId);
if (desc.type === 'Execution') {
this._widget.updateNode(desc);
} else if (desc.type === 'line' && this.isLineDisplayed(desc)) {
this._widget.updateNode(desc);
} else if (desc.type === 'Pipeline') {
this.updatePipelineNames(desc);
}
};
ExecutionIndexControl.prototype.updatePipelineNames = function (desc) {
// Get all associated executions and update their pipeline name
this._logger.debug('updating pipeline name for ' + desc.execs.join(', '));
for (var i = desc.execs.length; i--;) {
this._widget.updatePipelineName(desc.execs[i], desc.name);
}
if (desc.execs.length === 0) {
// Executions have been deleted - no longer relevant
this._logger.debug('pipeline has 0 executions... removing it', desc.id);
delete this._selfPatterns[desc.id];
delete this._pipelineNames[desc.id];
}
};
ExecutionIndexControl.prototype._onUnload = function (id) {
var execId = this._lineToExec[id];
if (execId) { // it is a line
delete this._lineToExec[id];
for (var k = this._linesForExecution[execId].length; k--;) {
if (this._linesForExecution[execId][k].id === id) {
this._linesForExecution[execId].splice(k, 1);
break;
}
}
}
this._widget.removeNode(id);
};
ExecutionIndexControl.prototype.isLineDisplayed = function (line) {
// lines are only displayed if their execution is checked
return this.displayedExecutions[line.execId];
};
ExecutionIndexControl.prototype._stateActiveObjectChanged = function (model, activeObjectId) {
if (this._currentNodeId === activeObjectId) {
// The same node selected as before - do not trigger
} else {
this.selectedObjectChanged(activeObjectId);
}
};
/* * * * * * * * Visualizer life cycle callbacks * * * * * * * */
ExecutionIndexControl.prototype.destroy = function () {
this._detachClientEventListeners();
this.clearTerritory();
};
ExecutionIndexControl.prototype._attachClientEventListeners = function () {
this._detachClientEventListeners();
if (!this._embedded) {
WebGMEGlobal.State.on('change:' + CONSTANTS.STATE_ACTIVE_OBJECT,
this._stateActiveObjectChanged, this);
}
};
ExecutionIndexControl.prototype._detachClientEventListeners = function () {
if (!this._embedded) {
WebGMEGlobal.State.off('change:' + CONSTANTS.STATE_ACTIVE_OBJECT,
this._stateActiveObjectChanged);
}
};
ExecutionIndexControl.prototype.onActivate = function () {
this._attachClientEventListeners();
if (typeof this._currentNodeId === 'string') {
WebGMEGlobal.State.registerSuppressVisualizerFromNode(true);
WebGMEGlobal.State.registerActiveObject(this._currentNodeId);
WebGMEGlobal.State.registerSuppressVisualizerFromNode(false);
}
};
ExecutionIndexControl.prototype.onDeactivate = function () {
this._detachClientEventListeners();
};
return ExecutionIndexControl;
});
@@ -0,0 +1,93 @@
/*globals define, _, WebGMEGlobal*/
/*jshint browser: true*/
define([
'js/PanelBase/PanelBase',
'js/PanelManager/IActivePanel',
'widgets/ExecutionIndex/ExecutionIndexWidget',
'./ExecutionIndexControl'
], function (
PanelBase,
IActivePanel,
ExecutionIndexWidget,
ExecutionIndexControl
) {
'use strict';
var ExecutionIndexPanel;
ExecutionIndexPanel = function (layoutManager, params) {
var options = {};
//set properties from options
options[PanelBase.OPTIONS.LOGGER_INSTANCE_NAME] = 'ExecutionIndexPanel';
options[PanelBase.OPTIONS.FLOATING_TITLE] = true;
//call parent's constructor
PanelBase.apply(this, [options, layoutManager]);
this._client = params.client;
this._embedded = params.embedded;
//initialize UI
this._initialize();
this.logger.debug('ctor finished');
};
//inherit from PanelBase
_.extend(ExecutionIndexPanel.prototype, PanelBase.prototype);
_.extend(ExecutionIndexPanel.prototype, IActivePanel.prototype);
ExecutionIndexPanel.prototype._initialize = function () {
//set Widget title
this.widget = new ExecutionIndexWidget(this.logger, this.$el);
this.control = new ExecutionIndexControl({
logger: this.logger,
client: this._client,
embedded: this._embedded,
widget: this.widget
});
this.onActivate();
};
/* OVERRIDE FROM WIDGET-WITH-HEADER */
/* METHOD CALLED WHEN THE WIDGET'S READ-ONLY PROPERTY CHANGES */
ExecutionIndexPanel.prototype.onReadOnlyChanged = function (isReadOnly) {
//apply parent's onReadOnlyChanged
PanelBase.prototype.onReadOnlyChanged.call(this, isReadOnly);
};
ExecutionIndexPanel.prototype.onResize = function (width, height) {
this.logger.debug('onResize --> width: ' + width + ', height: ' + height);
this.widget.onWidgetContainerResize(width, height);
};
/* * * * * * * * Visualizer life cycle callbacks * * * * * * * */
ExecutionIndexPanel.prototype.destroy = function () {
this.control.destroy();
this.widget.destroy();
PanelBase.prototype.destroy.call(this);
WebGMEGlobal.KeyboardManager.setListener(undefined);
WebGMEGlobal.Toolbar.refresh();
};
ExecutionIndexPanel.prototype.onActivate = function () {
this.widget.onActivate();
this.control.onActivate();
WebGMEGlobal.KeyboardManager.setListener(this.widget);
WebGMEGlobal.Toolbar.refresh();
};
ExecutionIndexPanel.prototype.onDeactivate = function () {
this.widget.onDeactivate();
this.control.onDeactivate();
WebGMEGlobal.KeyboardManager.setListener(undefined);
WebGMEGlobal.Toolbar.refresh();
};
return ExecutionIndexPanel;
});
@@ -1,11 +1,13 @@
/*globals DeepForge, define, $, Materialize, WebGMEGlobal*/
/*globals DeepForge, define, $, WebGMEGlobal*/
// These are actions defined for specific meta types. They are evaluated from
// the context of the ForgeActionButton
define([
'panel/FloatingActionButton/styles/Materialize',
'q',
'js/RegistryKeys',
'deepforge/globals'
], function(
Materialize,
Q,
REGISTRY_KEYS
) {
@@ -103,6 +105,7 @@ define([
name: `Return to ${fromType}`,
icon: 'input',
priority: 2,
color: 'teal',
filter: () => {
return DeepForge.last[fromType];
},
@@ -112,6 +115,7 @@ define([
name: `Delete ${type} Definition`,
icon: 'delete',
priority: 1,
color: 'red',
action: function() {
// Delete and go to the last pipeline?
var node = this.client.getNode(this._currentNodeId),
@@ -139,6 +143,11 @@ define([
name: 'Restart ' + name,
icon: 'replay',
priority: 1000,
color: 'red',
filter: function() {
// Only show if stopped!
return !this.isRunning();
},
action: function(event) {
this.runExecutionPlugin(pluginId, event.shiftKey);
}
@@ -215,9 +224,46 @@ define([
icon: 'play_for_work',
priority: 1,
href: download.execFiles
},
// Stop execution button
{
name: 'Stop Current Job',
icon: 'stop',
priority: 1001,
filter: function() {
return this.isRunning();
},
action: function() {
this.stopJob();
}
}
],
Execution: [
makeRestartButton('Execution', 'ExecutePipeline'),
// Stop execution button
{
name: 'Stop Running Execution',
icon: 'stop',
priority: 1001,
filter: function() {
return this.isRunning();
},
action: function() {
// Stop every running job
var execNode = this.client.getNode(this._currentNodeId),
jobIds = execNode.getChildrenIds(),
msg = `Canceling ${execNode.getAttribute('name')} execution`;
this.client.startTransaction(msg);
jobIds.map(id => this.client.getNode(id))
.filter(job => this.isRunning(job)) // get running jobs
.forEach(job => this.stopJob(job)); // stop them
this.client.setAttributes(execNode.getId(), 'status', 'canceled');
this.client.completeTransaction();
}
}
],
Execution: [makeRestartButton('Execution', 'ExecutePipeline')],
Pipeline: [
{
name: 'Create new node',
@@ -1,8 +1,10 @@
/*globals DeepForge, $, Materialize, define, _ */
/*globals DeepForge, $, WebGMEGlobal, window, define, _ */
/*jshint browser: true*/
define([
'panel/FloatingActionButton/styles/Materialize',
'blob/BlobClient',
'executor/ExecutorClient',
'js/Constants',
'panel/FloatingActionButton/FloatingActionButton',
'deepforge/viz/PipelineControl',
@@ -15,7 +17,9 @@ define([
'text!./PluginConfig.json',
'deepforge/globals'
], function (
Materialize,
BlobClient,
ExecutorClient,
CONSTANTS,
PluginButton,
PipelineControl,
@@ -33,6 +37,11 @@ define([
var ForgeActionButton= function (layoutManager, params) {
PluginButton.call(this, layoutManager, params);
this._pluginConfig = JSON.parse(PluginConfig);
this._executor = new ExecutorClient({
logger: this.logger.fork('ExecutorClient'),
serverPort: WebGMEGlobal.gmeConfig.server.port,
httpsecure: window.location.protocol === 'https:'
});
this._client = this.client;
this._actions = [];
this._blobClient = new BlobClient({
@@ -60,7 +69,7 @@ define([
if (!base) { // must be ROOT or FCO
basename = node.getAttribute('name') || 'ROOT_NODE';
actions = (ACTIONS[basename] || [])
.filter(action => !action.filter || action.filter());
.filter(action => !action.filter || action.filter.call(this));
return actions;
}
@@ -69,7 +78,7 @@ define([
base = this.client.getNode(base.getBaseId());
actions = ACTIONS[basename];
if (actions) {
actions = actions.filter(action => !action.filter || action.filter());
actions = actions.filter(action => !action.filter || action.filter.call(this));
}
}
@@ -328,14 +337,67 @@ define([
context.managerConfig.namespace = 'pipeline';
method = useSecondary ? 'runBrowserPlugin' : 'runServerPlugin';
this.client[method](pluginId, context, err => {
if (err) {
return Materialize.toast(`${name} failed!`, 4000);
this.client[method](pluginId, context, (err, result) => {
var msg = err ? `${name} failed!` : `${name} executed successfully!`,
duration = err ? 4000 : 2000;
// Check if it was canceled - if so, show that type of message
if (result) {
msg = result.messages[0].message;
duration = 4000;
}
Materialize.toast(`${name} executed successfully!`, 2000);
Materialize.toast(msg, duration);
});
};
ForgeActionButton.prototype.isRunning = function(node) {
var baseId,
base,
type;
node = node || this.client.getNode(this._currentNodeId);
baseId = node.getBaseId();
base = this.client.getNode(baseId);
type = base.getAttribute('name');
if (type === 'Execution') {
return node.getAttribute('status') === 'running';
} else if (type === 'Job') {
return this.isRunningJob(node);
}
return false;
};
ForgeActionButton.prototype.isRunningJob = function(job) {
var status = job.getAttribute('status');
return (status === 'running' || status === 'pending') &&
job.getAttribute('secret') && job.getAttribute('jobId');
};
ForgeActionButton.prototype.stopJob = function(job) {
var jobHash,
jobId,
secret;
job = job || this.client.getNode(this._currentNodeId);
jobId = job.getId();
jobHash = job.getAttribute('jobId');
secret = job.getAttribute('secret');
if (!jobHash || !secret) {
this.logger.error('Cannot stop job. Missing jobHash or secret');
return;
}
this.client.delAttributes(jobId, 'jobId');
this.client.delAttributes(jobId, 'secret');
this.client.setAttributes(jobId, 'status', 'canceled');
return this._executor.cancelJob(jobHash, secret)
.then(() => this.logger.info(`${jobHash} has been cancelled!`))
.fail(err => this.logger.error(`Job cancel failed: ${err}`));
};
return ForgeActionButton;
});
@@ -5,6 +5,7 @@
},
"ExecutePipeline": {
"icon": "play_arrow",
"color": "green",
"priority": 1
},
"ImportTorch": {
@@ -0,0 +1,136 @@
/*globals define, WebGMEGlobal*/
/*jshint browser: true*/
define([
'blob/BlobClient',
'js/Constants',
'js/Utils/GMEConcepts',
'js/NodePropertyNames'
], function (
BlobClient,
CONSTANTS,
GMEConcepts,
nodePropertyNames
) {
'use strict';
var ImageViewerControl;
ImageViewerControl = function (options) {
this._logger = options.logger.fork('Control');
this._client = options.client;
// Initialize core collections and variables
this._widget = options.widget;
this.blobClient = new BlobClient({
logger: this._logger.fork('BlobClient')
});
this._currentNodeId = null;
this._logger.debug('ctor finished');
};
/* * * * * * * * 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).
ImageViewerControl.prototype.selectedObjectChanged = function (nodeId) {
this._logger.debug('activeObject nodeId \'' + nodeId + '\'');
// Remove current territory patterns
if (this._currentNodeId) {
this._client.removeUI(this._territoryId);
}
this._currentNodeId = nodeId;
if (typeof this._currentNodeId === 'string') {
// Put new node's info into territory rules
this._selfPatterns = {};
this._selfPatterns[nodeId] = {children: 0}; // Territory "rule"
this._territoryId = this._client.addUI(this, this._eventCallback.bind(this));
this._client.updateTerritory(this._territoryId, this._selfPatterns);
}
};
// This next function retrieves the relevant node information for the widget
ImageViewerControl.prototype._getObjectDescriptor = function (nodeId) {
var nodeObj = this._client.getNode(nodeId),
objDescriptor,
hash;
if (nodeObj) {
objDescriptor = {
id: undefined,
name: undefined
};
objDescriptor.id = nodeObj.getId();
objDescriptor.name = nodeObj.getAttribute(nodePropertyNames.Attributes.name);
// Get the blob url
hash = nodeObj.getAttribute('data');
if (hash) {
objDescriptor.src = this.blobClient.getDownloadURL(hash);
}
}
return objDescriptor;
};
/* * * * * * * * Node Event Handling * * * * * * * */
ImageViewerControl.prototype._eventCallback = function (events) {
var i = events ? events.length : 0,
event;
this._logger.debug('_eventCallback \'' + i + '\' items');
while (i--) {
event = events[i];
switch (event.etype) {
case CONSTANTS.TERRITORY_EVENT_LOAD:
this._onLoad(event.eid);
break;
case CONSTANTS.TERRITORY_EVENT_UPDATE:
this._onUpdate(event.eid);
break;
case CONSTANTS.TERRITORY_EVENT_UNLOAD:
this._onUnload(event.eid);
break;
default:
break;
}
}
this._logger.debug('_eventCallback \'' + events.length + '\' items - DONE');
};
ImageViewerControl.prototype._onUpdate =
ImageViewerControl.prototype._onLoad = function (gmeId) {
var description = this._getObjectDescriptor(gmeId);
this._widget.updateImage(description.src);
};
ImageViewerControl.prototype._onUnload = function (gmeId) {
this._widget.removeImage(gmeId);
};
/* * * * * * * * Visualizer life cycle callbacks * * * * * * * */
ImageViewerControl.prototype.onActivate = function () {
if (typeof this._currentNodeId === 'string') {
WebGMEGlobal.State.registerSuppressVisualizerFromNode(true);
WebGMEGlobal.State.registerActiveObject(this._currentNodeId);
WebGMEGlobal.State.registerSuppressVisualizerFromNode(false);
}
};
ImageViewerControl.prototype.destroy =
ImageViewerControl.prototype.onDeactivate = function () {
};
return ImageViewerControl;
});
@@ -0,0 +1,99 @@
/*globals define, _, WebGMEGlobal*/
/*jshint browser: true*/
/**
* Generated by VisualizerGenerator 1.7.0 from webgme on Sat Jul 30 2016 07:12:17 GMT-0500 (CDT).
*/
define(['js/PanelBase/PanelBaseWithHeader',
'js/PanelManager/IActivePanel',
'widgets/ImageViewer/ImageViewerWidget',
'./ImageViewerControl'
], function (PanelBaseWithHeader,
IActivePanel,
ImageViewerWidget,
ImageViewerControl) {
'use strict';
var ImageViewerPanel;
ImageViewerPanel = function (layoutManager, params) {
var options = {};
//set properties from options
options[PanelBaseWithHeader.OPTIONS.LOGGER_INSTANCE_NAME] = 'ImageViewerPanel';
options[PanelBaseWithHeader.OPTIONS.FLOATING_TITLE] = true;
//call parent's constructor
PanelBaseWithHeader.apply(this, [options, layoutManager]);
this._client = params.client;
//initialize UI
this._initialize();
this.logger.debug('ctor finished');
};
//inherit from PanelBaseWithHeader
_.extend(ImageViewerPanel.prototype, PanelBaseWithHeader.prototype);
_.extend(ImageViewerPanel.prototype, IActivePanel.prototype);
ImageViewerPanel.prototype._initialize = function () {
var self = this;
//set Widget title
this.setTitle('');
this.widget = new ImageViewerWidget(this.logger, this.$el);
this.widget.setTitle = function (title) {
self.setTitle(title);
};
this.control = new ImageViewerControl({
logger: this.logger,
client: this._client,
widget: this.widget
});
this.onActivate();
};
/* OVERRIDE FROM WIDGET-WITH-HEADER */
/* METHOD CALLED WHEN THE WIDGET'S READ-ONLY PROPERTY CHANGES */
ImageViewerPanel.prototype.onReadOnlyChanged = function (isReadOnly) {
//apply parent's onReadOnlyChanged
PanelBaseWithHeader.prototype.onReadOnlyChanged.call(this, isReadOnly);
};
ImageViewerPanel.prototype.onResize = function (width, height) {
this.logger.debug('onResize --> width: ' + width + ', height: ' + height);
this.widget.onWidgetContainerResize(width, height);
};
/* * * * * * * * Visualizer life cycle callbacks * * * * * * * */
ImageViewerPanel.prototype.destroy = function () {
this.control.destroy();
this.widget.destroy();
PanelBaseWithHeader.prototype.destroy.call(this);
WebGMEGlobal.KeyboardManager.setListener(undefined);
WebGMEGlobal.Toolbar.refresh();
};
ImageViewerPanel.prototype.onActivate = function () {
this.widget.onActivate();
this.control.onActivate();
WebGMEGlobal.KeyboardManager.setListener(this.widget);
WebGMEGlobal.Toolbar.refresh();
};
ImageViewerPanel.prototype.onDeactivate = function () {
this.widget.onDeactivate();
this.control.onDeactivate();
WebGMEGlobal.KeyboardManager.setListener(undefined);
WebGMEGlobal.Toolbar.refresh();
};
return ImageViewerPanel;
});
@@ -2,9 +2,15 @@
/*jshint browser: true*/
define([
'panels/TextEditor/TextEditorControl'
'panels/TextEditor/TextEditorControl',
'deepforge/LayerParser',
'deepforge/utils',
'deepforge/Constants'
], function (
TextEditorControl
TextEditorControl,
LayerParser,
utils,
Constants
) {
'use strict';
@@ -50,62 +56,120 @@ define([
};
LayerEditorControl.prototype.saveTextFor = function (id, text) {
var r = /:__init\((.*)\)/,
match = text.match(r),
textMatch = match && match[1],
node = this._client.getNode(id),
var node = this._client.getNode(id),
currentAttrs = node.getValidAttributeNames(),
attributes = [],
msg = `Updating layer definition for ${node.getAttribute('name')}`;
types,
ctorAttrs = [],
setterNames,
schema,
currentPtrs = {base: true},
type,
ptr,
msg = `Updating layer definition for ${node.getAttribute('name')}`,
i;
// Parse the attributes and update the node!
if (textMatch) {
attributes = textMatch.split(',')
.map(arg => arg.replace(/\s+/g, '')) // trim white space
.filter(arg => !!arg); // no empty strings!
// Parse the ctorAttrs and update the node!
var layerSchema = LayerParser.parse(text);
if (!layerSchema) {
return TextEditorControl.prototype.saveTextFor.call(this, id, text);
}
if (layerSchema.params) {
ctorAttrs = layerSchema.params;
} else { // inheriting __init
attributes = this.getInheritedAttrs(text);
ctorAttrs = this.getInheritedAttrs(layerSchema);
}
this._client.startTransaction(msg);
TextEditorControl.prototype.saveTextFor.call(this, id, text);
this._client.setAttributes(id, 'name', layerSchema.name);
this._logger.debug(`Setting ctor args to ${ctorAttrs.join(',')}`);
this._client.setAttributes(id, Constants.CTOR_ARGS_ATTR, ctorAttrs.join(','));
types = layerSchema.types || {};
schema = this.getPointerMeta();
// Handle pointer types
for (i = ctorAttrs.length; i--;) {
type = types[ctorAttrs[i]];
if (type && type.substring(0, 3) === 'nn.') {
ptr = ctorAttrs.splice(i, 1)[0];
this._client.setPointerMeta(id, ptr, schema);
currentPtrs[ptr] = true;
}
}
// Remove old pointers
node.getPointerNames().filter(ptr => !currentPtrs[ptr])
.forEach(ptr => this._client.deleteMetaPointer(id, ptr));
// Remove old attributes
_.difference(currentAttrs, attributes)
setterNames = Object.keys(layerSchema.setters);
_.difference(currentAttrs, ctorAttrs, setterNames)
.forEach(attr => this._client.removeAttributeSchema(id, attr));
attributes.forEach((attr, i) =>
this._client.setAttributeSchema(id, attr, {type: 'string', argindex: i}));
// Add setters
for (i = setterNames.length; i--;) {
schema = utils.getSetterSchema(setterNames[i], layerSchema.setters, layerSchema.defaults);
// Get setter attr schema
if (schema.hasOwnProperty('default')) {
this._client.setAttributes(id, setterNames[i], schema.default);
delete schema.default;
}
if (types[setterNames[i]]) {
schema.type = types[setterNames[i]];
}
this._client.setAttributeSchema(id, setterNames[i], schema);
}
ctorAttrs.forEach(attr =>
this._client.setAttributeSchema(id, attr, {
type: types[attr] || 'string'
})
);
this._client.completeTransaction();
};
LayerEditorControl.prototype.getInheritedAttrs = function (code) {
LayerEditorControl.prototype.getPointerMeta = function () {
var archNode = this._client.getAllMetaNodes()
.find(node => node.getAttribute('name') === 'Architecture');
if (!archNode) {
throw 'Could not find the "Architecture" node!';
}
return {
min: 1,
max: 1,
items: [
{
id: archNode.getId(),
max: 1
}
]
};
};
LayerEditorControl.prototype.getInheritedAttrs = function (layerSchema) {
// Get the base class
var r = /torch.class\((.*)\)/,
match = code.match(r),
baseType,
metanode,
textMatch = match && match[1];
var metanode;
if (textMatch) {
baseType = textMatch.split(',')[1]
.replace(/^\s*['"]nn\./, '')
.replace(/['"]\s*$/, '');
this._logger.debug(`inheriting the attributes from ${baseType}`);
if (layerSchema.baseType) {
this._logger.debug(`inheriting the attributes from ${layerSchema.baseType}`);
// Get the meta node and valid attribute names
metanode = this._client.getAllMetaNodes()
.find(node => node.getAttribute('name') === baseType);
.find(node => node.getAttribute('name') === layerSchema.baseType);
if (metanode) {
return metanode.getValidAttributeNames()
.filter(attr => attr !== 'name');
} else {
// Check if the type is known by torch
this._logger.warn(`Unknown base type ${baseType}. Assuming attributes are []`);
this._logger.warn(`Unknown base type ${layerSchema.baseType}. Assuming attributes are []`);
}
}
return [];
@@ -83,17 +83,20 @@ define([
// Check if it is a line
if (desc.id !== this._currentNodeId) {
var points = (node.getAttribute('points') || '').split(';')
.map(pair => {
var nums = pair.split(','),
x = +nums[0],
y = +nums[1];
var rawPoints = node.getAttribute('points') || '',
points = rawPoints.split(';')
.filter(data => !!data) // remove any ''
.map(pair => {
var nums = pair.split(','),
x = parseFloat(nums[0]),
y = parseFloat(nums[1]);
return {
x: x,
y:y
};
});
return {
x: x,
y:y
};
});
desc.type = 'line';
desc.points = points;
}
@@ -65,6 +65,8 @@ define([
return null;
}
};
this._widget.toggleEmbeddedPanel = () => this.toggleEmbeddedPanel();
};
/* * * * * * * * Visualizer content update callbacks * * * * * * * */
+43 -10
Ver Arquivo
@@ -9,6 +9,7 @@ define([
'widgets/MainView/MainViewWidget',
'./MainViewControl',
'panels/PipelineIndex/PipelineIndexPanel',
'panels/ExecutionIndex/ExecutionIndexPanel',
'deepforge/globals'
], function (
PanelBaseWithHeader,
@@ -16,6 +17,7 @@ define([
MainViewWidget,
MainViewControl,
PipelineIndexPanel,
ExecutionIndexPanel,
DeepForge
) {
'use strict';
@@ -38,12 +40,14 @@ define([
this.$nav = $('<div>', {id: 'nav-container'});
this.$el.css({padding: 0});
this.embeddedPanel = new PipelineIndexPanel(layoutManager, params);
this.$embedded = this.embeddedPanel.$el;
this.$embedded.addClass('embedded');
this.$el.append(this.$nav, this.$embedded);
this.embeddedPanels = [
PipelineIndexPanel,
ExecutionIndexPanel
];
this.nextPanelIndex = 0;
this._lm = layoutManager;
this._params = params;
this.$el.append(this.$nav);
this._initialize();
this.logger.debug('ctor finished');
@@ -66,15 +70,42 @@ define([
widget: this.widget
});
var controlObjectChanged = this.control.selectedObjectChanged;
this.control.selectedObjectChanged = nodeId => {
this.embeddedPanel.control.selectedObjectChanged(DeepForge.places.MyPipelines);
return controlObjectChanged.call(this.control, nodeId);
this.control.toggleEmbeddedPanel = this.toggleEmbeddedPanel.bind(this);
var selectedObjectChanged = this.control.selectedObjectChanged;
this.control.selectedObjectChanged = id => {
this.embeddedPanel.control.selectedObjectChanged(this.getEmbeddedNode());
selectedObjectChanged.call(this.control, id);
};
this.toggleEmbeddedPanel(true);
this.onActivate();
};
MainViewPanel.prototype.getEmbeddedNode = function() {
return this.nextPanelIndex === 1 ? DeepForge.places.MyPipelines : DeepForge.places.MyExecutions;
};
MainViewPanel.prototype.toggleEmbeddedPanel = function (silent) {
var Panel = this.embeddedPanels[this.nextPanelIndex];
this.nextPanelIndex = (this.nextPanelIndex + 1) % this.embeddedPanels.length;
if (this.embeddedPanel) { // Remove current
this.embeddedPanel.destroy();
this.$embedded.remove();
}
this.embeddedPanel = new Panel(this._lm, this._params);
this.$embedded = this.embeddedPanel.$el;
this.$embedded.addClass('main-view-embedded');
this.$el.append(this.$embedded);
// Call on Resize and selectedObjectChanged
this.onResize(this.width, this.height);
if (!silent) {
this.embeddedPanel.control.selectedObjectChanged(this.getEmbeddedNode());
}
};
/* OVERRIDE FROM WIDGET-WITH-HEADER */
/* METHOD CALLED WHEN THE WIDGET'S READ-ONLY PROPERTY CHANGES */
MainViewPanel.prototype.onReadOnlyChanged = function (isReadOnly) {
@@ -98,6 +129,8 @@ define([
margin: 'inherit'
});
this.embeddedPanel.onResize(embeddedWidth, height);
this.width = width;
this.height = height;
};
/* * * * * * * * Visualizer life cycle callbacks * * * * * * * */
@@ -28,7 +28,11 @@ define([
TextEditorControl.prototype
);
// Override ObjectDescriptor
OperationCodeEditorControl.prototype._initWidgetEventHandlers = function () {
TextEditorControl.prototype._initWidgetEventHandlers.call(this);
this._widget.getOperationAttributes = this.getOperationAttributes.bind(this);
};
OperationCodeEditorControl.prototype.TERRITORY_RULE = {children: 3};
OperationCodeEditorControl.prototype._getObjectDescriptor = function (id) {
var desc = TextEditorControl.prototype._getObjectDescriptor.call(this, id),
@@ -58,6 +62,22 @@ define([
}
};
OperationCodeEditorControl.prototype.getOperationAttributes = function () {
var node = this._client.getNode(this._currentNodeId),
attrs = node.getValidAttributeNames(),
rmAttrs = ['name', 'code', CONSTANTS.LINE_OFFSET],
i;
for (var j = rmAttrs.length; j--;) {
i = attrs.indexOf(rmAttrs[j]);
if (i > -1) {
attrs.splice(i, 1);
}
}
return attrs;
};
// Line offset handling
OperationCodeEditorControl.prototype.offsetNodeChanged = function (id) {
// Create a territory for this node
@@ -5,6 +5,7 @@
// metadata, provides a pagination bar in the lower left to page through
// the metadata results
define([
'text!./icons.json',
'js/PanelBase/PanelBaseWithHeader',
'js/PanelManager/IActivePanel',
'panels/LogViewer/LogViewerPanel',
@@ -13,6 +14,7 @@ define([
'text!api/visualizers',
'css!./OutputViewer.css'
], function (
IconTxt,
PanelBaseWithHeader,
IActivePanel,
LogViewer,
@@ -23,7 +25,8 @@ define([
'use strict';
var OutputViewerPanel,
Visualizers = JSON.parse(VisualizersJSON);
Visualizers = JSON.parse(VisualizersJSON),
IconFor = JSON.parse(IconTxt);
OutputViewerPanel = function (layoutManager, params) {
var options = {};
@@ -64,7 +67,7 @@ define([
this.$pagerList = $('<ul>', {class: 'pagination'});
// Add the console item
var logviewer = $('<li class="active"><a>Console</a></li>');
var logviewer = $('<li class="active"><a><span class="glyphicon glyphicon-console"></span> Console</a></li>');
this.$logviewer = logviewer.find('a');
this.$selected = this.$logviewer;
this.$pagerList.append(logviewer);
@@ -89,13 +92,18 @@ define([
OutputViewerPanel.prototype.selectOutput = function (element) {
if (this.$selected !== element) {
// Update the panel
var dataId = element.data('id');
while (element.prop('tagName').toLowerCase() !== 'a' && element.length) {
element = element.parent();
}
dataId = element.data('id');
this.$selected.parent().removeClass('active');
element.parent().addClass('active');
this.$selected = element;
// Update the panel
var dataId = element.data('id');
if (dataId) {
this.loadOutputFor(dataId);
} else { // Set the logviewer
@@ -218,10 +226,8 @@ define([
};
OutputViewerPanel.prototype.onUpdate = function (nodeId) {
var name = this._client.getNode(nodeId).getAttribute('name');
if (this._pages[nodeId]) {
this._pages[nodeId].find('a').text(name);
this.updatePage(nodeId);
}
};
@@ -249,14 +255,29 @@ define([
}
};
OutputViewerPanel.prototype.updatePage = function (nodeId) {
var node = this._client.getNode(nodeId),
baseId = node.getBaseId(),
base = this._client.getNode(baseId),
type = base.getAttribute('name'),
name = node.getAttribute('name'),
icon = IconFor[type] || 'info-sign',
anchor = this._pages[nodeId].find('a'),
span = document.createElement('span');
span.className = 'glyphicon glyphicon-' + icon;
anchor.empty();
anchor.html(span.outerHTML + ' ' + name);
};
OutputViewerPanel.prototype.addToPager = function (name, nodeId) {
var $el = $('<li>'),
$a = $('<a>');
$a.text(name);
$a.attr('data-id', nodeId);
$el.append($a);
this._pages[nodeId] = $el;
this.updatePage(nodeId);
this.$pager.removeClass('empty');
this.$pagerList.append($el);
@@ -284,6 +305,7 @@ define([
/* * * * * * * * Visualizer life cycle callbacks * * * * * * * */
OutputViewerPanel.prototype.destroy = function () {
this.activePanel.destroy();
this.clearTerritory();
PanelBaseWithHeader.prototype.destroy.call(this);
WebGMEGlobal.KeyboardManager.setListener(undefined);
WebGMEGlobal.Toolbar.refresh();
@@ -0,0 +1,5 @@
{
"Image": "picture",
"Console": "console",
"Graph": "random"
}
@@ -5,6 +5,7 @@ define([
'deepforge/globals',
'widgets/EasyDAG/EasyDAGWidget',
'widgets/EasyDAG/AddNodeDialog',
'./SelectionManager',
'./Layer',
'q',
'underscore',
@@ -13,6 +14,7 @@ define([
DeepForge,
EasyDAGWidget,
AddNodeDialog,
SelectionManager,
Layer,
Q,
_
@@ -31,6 +33,7 @@ define([
_.extend(ArchEditorWidget.prototype, EasyDAGWidget.prototype);
ArchEditorWidget.prototype.ItemClass = Layer;
ArchEditorWidget.prototype.SelectionManager = SelectionManager;
ArchEditorWidget.prototype.onCreateInitialNode = function() {
var nodes = this.getValidInitialNodes();
@@ -0,0 +1,52 @@
/* globals _, WebGMEGlobal, define*/
define([
'widgets/EasyDAG/SelectionManager',
'deepforge/viz/Buttons'
], function(
ManagerBase,
Buttons
) {
var client = WebGMEGlobal.Client;
var SelectionManager = function() {
ManagerBase.apply(this, arguments);
};
_.extend(SelectionManager.prototype, ManagerBase.prototype);
SelectionManager.prototype.createActionButtons = function(width, height) {
var disabled,
btn;
ManagerBase.prototype.createActionButtons.call(this, width, height);
if (!this.selectedItem.isConnection) {
disabled = !this._isCustomLayer();
// Check that the base type
btn = new Buttons.GoToBase({
$pEl: this.$selection,
context: this._widget,
item: this.selectedItem,
disabled: disabled,
x: width,
y: 0
});
}
return btn;
};
SelectionManager.prototype._isCustomLayer = function() {
var node = client.getNode(this.selectedItem.id),
attrNames;
if (node) {
attrNames = node.getAttributeNames();
return attrNames.indexOf('code') !== -1;
}
return false;
};
return SelectionManager;
});
@@ -0,0 +1,12 @@
<table class="table">
<thead>
<tr>
<td></td>
<td>Name</td>
<td>Creation Date</td>
<td>Origin Pipeline</td>
</tr>
</thead>
<tbody class="execs-content">
</tbody>
</table>
@@ -0,0 +1,226 @@
/*globals define, WebGMEGlobal, $*/
/*jshint browser: true*/
define([
'deepforge/viz/Utils',
'widgets/LineGraph/LineGraphWidget',
'text!./ExecTable.html',
'css!./styles/ExecutionIndexWidget.css'
], function (
Utils,
LineGraphWidget,
TableHtml
) {
'use strict';
var ExecutionIndexWidget,
WIDGET_CLASS = 'execution-index';
ExecutionIndexWidget = function (logger, container) {
this._logger = logger.fork('Widget');
this.$el = container;
this.nodes = {};
this.graphs = {};
this._initialize();
this._logger.debug('ctor finished');
};
ExecutionIndexWidget.prototype._initialize = function () {
// set widget class
this.$el.addClass(WIDGET_CLASS);
// Create split screen
this.$left = $('<div>', {class: 'left'});
this.$right = $('<div>', {class: 'right'});
this.$el.append(this.$left, this.$right);
// Create the table
this.$table = $(TableHtml);
this.$table.on('click', '.exec-row', event => this.onExecutionClicked(event));
this.$table.on('click', '.node-nav', event => this.navToNode(event));
this.$left.append(this.$table);
this.$execList = this.$table.find('.execs-content');
// Create the graph in the right half
this.lineGraph = new LineGraphWidget(this._logger, this.$right);
this.defaultSelection = null;
this.hasRunning = false;
};
ExecutionIndexWidget.prototype.navToNode = function (event) {
var id = event.target.getAttribute('data-id');
if (typeof id === 'string') {
WebGMEGlobal.State.registerActiveObject(id);
event.stopPropagation();
}
this._logger.warn('No node id found for node-nav!');
};
ExecutionIndexWidget.prototype.onExecutionClicked = function (event) {
var target = event.target,
checked,
id;
while (!target.getAttribute('data-id')) {
if (!target.parentNode) {
this._logger.error('could not find execution id for ' + event);
return;
}
target = target.parentNode;
}
id = target.getAttribute('data-id');
checked = this.nodes[id].$checkbox.checked;
if (event.target.tagName.toLowerCase() !== 'input') {
this.setSelect(id, !checked);
} else {
this.setExecutionDisplayed(id, checked);
}
};
ExecutionIndexWidget.prototype.onWidgetContainerResize = function (width, height) {
this.$left.css({
width: width/2,
height: height
});
this.$right.css({
left: width/2,
width: width/2,
height: height
});
this.lineGraph.onWidgetContainerResize(width/2, height);
this._logger.debug('Widget is resizing...');
};
// Adding/Removing/Updating items
ExecutionIndexWidget.prototype.addNode = function (desc) {
if (desc.type === 'Execution') {
// Add node to a table of nodes
this.addExecLine(desc);
this.updateSelected(desc);
} else if (desc.type === 'line') {
desc.type = 'line';
this.lineGraph.addNode(desc);
}
};
ExecutionIndexWidget.prototype.updatePipelineName = function (execId, name) {
if (this.nodes[execId]) {
this.nodes[execId].$pipeline.text(name);
}
};
ExecutionIndexWidget.prototype.addExecLine = function (desc) {
var row = $('<tr>', {class: 'exec-row', 'data-id': desc.id}),
checkBox = $('<input>', {type: 'checkbox'}),
statusClass = Utils.ClassForJobStatus[desc.status],
fields,
pipeline,
name,
td;
pipeline = $('<a>', {
class: 'node-nav',
'data-id': desc.originId
}).text(desc.pipelineName || 'view pipeline');
name = $('<a>', {class: 'node-nav', 'data-id': desc.id}).text(desc.name);
fields = [
checkBox,
name,
Utils.getDisplayTime(desc.originTime),
pipeline
];
for (var i = 0; i < fields.length; i++) {
td = $('<td>');
if ((typeof fields[i]) === 'string') {
td.text(fields[i]);
} else {
td.append(fields[i]);
}
row.append(td);
}
this._logger.debug(`Adding execution ${desc.name} (${desc.id}) to list`);
this.$execList.append(row);
row.addClass(statusClass);
this.nodes[desc.id] = {
statusClass: statusClass,
$el: row,
$checkbox: checkBox[0],
$pipeline: pipeline,
$name: name
};
};
ExecutionIndexWidget.prototype.removeNode = function (id) {
if (this.nodes[id]) {
this.nodes[id].$el.remove();
} else if (this.graphs[id]) {
delete this.graphs[id];
}
delete this.nodes[id];
this.lineGraph.removeNode(id); // 'nop' if node is not line
};
ExecutionIndexWidget.prototype.updateSelected = function (desc) {
// If the running pipeline has been unselected, don't reselect it!
if (desc.status === 'running') {
this.hasRunning = true;
this.setSelect(desc.id, true);
if (this.defaultSelection) {
this.setSelect(this.defaultSelection, false);
}
} else if (!this.hasRunning && !this.defaultSelection) {
this.defaultSelection = desc.id;
this.setSelect(desc.id, true);
}
};
ExecutionIndexWidget.prototype.setSelect = function (id, checked) {
this.nodes[id].$checkbox.checked = checked;
this.setExecutionDisplayed(id, checked);
};
ExecutionIndexWidget.prototype.updateNode = function (desc) {
var node = this.nodes[desc.id];
if (node) {
node.$name.text(desc.name);
node.$el.removeClass(node.statusClass);
node.$el.addClass(Utils.ClassForJobStatus[desc.status]);
if (Utils.ClassForJobStatus[desc.status] !== node.statusClass) {
// Only update the selection if the status has changed.
// ie, it has started running
this.updateSelected(desc);
}
this._logger.debug(`setting execution ${desc.id} to ${desc.status}`);
node.statusClass = Utils.ClassForJobStatus[desc.status];
} else if (desc.type === 'line') {
this.lineGraph.updateNode(desc);
}
};
/* * * * * * * * Visualizer life cycle callbacks * * * * * * * */
ExecutionIndexWidget.prototype.destroy = function () {
};
ExecutionIndexWidget.prototype.onActivate = function () {
this._logger.debug('ExecutionIndexWidget has been activated');
};
ExecutionIndexWidget.prototype.onDeactivate = function () {
this._logger.debug('ExecutionIndexWidget has been deactivated');
};
return ExecutionIndexWidget;
});
@@ -0,0 +1,21 @@
/**
* This file is for any css that you may want for this visualizer.
*
* Ideally, you would use the scss file also provided in this directory
* and then generate this file automatically from that. However, you can
* simply write css if you prefer
*/
.execution-index.panel-body {
padding: 0;
}
.execution-index .left {
position: absolute;
background-color: #eee;
}
.execution-index .right {
position: absolute;
background-color: #eee;
}
@@ -0,0 +1,7 @@
/**
* This file is for any scss that you may want for this visualizer.
*/
.execution-index {
outline: none;
}
@@ -48,8 +48,8 @@ define([
var title = nodeName === undefined ? this._currentTitle : nodeName;
this._currentTitle = title;
if (this.isSnapshot) {
title += ' (SNAPSHOT)';
if (!this.isSnapshot) {
title += ' (DEBUG)';
}
this._setTitle(title);
@@ -0,0 +1,107 @@
/*globals define, $*/
/*jshint browser: true*/
define([
'css!./styles/ImageViewerWidget.css'
], function (
) {
'use strict';
var ImageViewerWidget,
NO_IMAGE_URL = 'extlib/src/visualizers/widgets/ImageViewer/no-image.gif',
WIDGET_CLASS = 'image-viewer';
ImageViewerWidget = function (logger, container) {
this._logger = logger.fork('Widget');
this.$el = container;
this._initialize();
this._logger.debug('ctor finished');
};
ImageViewerWidget.prototype._initialize = function () {
// set widget class
this.$el.addClass(WIDGET_CLASS);
this.zoom = 1;
this.left = 0;
this.top = 0;
this.width = 0;
this.height = 0;
this.img = {
width: 0,
height: 0
};
this.$image = $('<img>');
this.$el.append(this.$image);
this.$image.on('load', () => {
this.img.width = this.$image.width();
this.img.height = this.$image.height();
this.centerImage();
});
this.updateImage(NO_IMAGE_URL);
// Zoom functionality
this.$el[0].onwheel = event => {
if (event.ctrlKey || event.metaKey || event.altKey) {
var dz = -event.deltaY/20;
this.zoom += dz;
this.centerImage();
event.stopPropagation();
event.preventDefault();
}
};
};
ImageViewerWidget.prototype.centerImage = function () {
var left,
top;
this.left = this.width/2 - (this.img.width*this.zoom/2);
this.top = this.height/2 - (this.img.height*this.zoom/2);
left = this.left/this.zoom;
top = this.top/this.zoom;
this.$image.css({
left: left,
top: top,
zoom: this.zoom
});
};
ImageViewerWidget.prototype.onWidgetContainerResize = function (width, height) {
this.$el.css({
width: width,
height: height
});
this.width = width;
this.height = height;
this.centerImage();
};
ImageViewerWidget.prototype.updateImage = function (url) {
url = url || NO_IMAGE_URL;
this.zoom = 1;
this.$image.attr('src', url);
};
ImageViewerWidget.prototype.removeImage = function () {
// Change to 'no picture' image
this.updateImage(NO_IMAGE_URL);
};
/* * * * * * * * Visualizer life cycle callbacks * * * * * * * */
ImageViewerWidget.prototype.destroy = function () {
};
ImageViewerWidget.prototype.onActivate = function () {
this._logger.debug('ImageViewerWidget has been activated');
};
ImageViewerWidget.prototype.onDeactivate = function () {
this._logger.debug('ImageViewerWidget has been deactivated');
};
return ImageViewerWidget;
});
Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 3.7 KiB

@@ -0,0 +1,5 @@
.image-viewer img {
position: absolute;
image-rendering: pixelated;
}
@@ -1,4 +1,4 @@
/*globals define, d3, nv */
/*globals define, d3, nv, _ */
/*jshint browser: true*/
define([
@@ -16,7 +16,7 @@ define([
this.$el = container;
this.lineData = [];
this.lineData = {};
this._initialize();
this._logger.debug('ctor finished');
@@ -35,7 +35,6 @@ define([
this.$chart = d3.select(this.$el[0]).append('svg');
nv.addGraph(() => {
var chart = nv.models.lineChart()
//.margin({left: 100})
.useInteractiveGuideline(true)
.showLegend(true)
.showYAxis(true)
@@ -82,20 +81,20 @@ define([
values: desc.points
};
}
this.updateChartData();
this.refreshChart();
}
};
LineGraphWidget.prototype.removeNode = function (id) {
delete this.lineData[id];
this.updateChartData();
this.refreshChart();
};
LineGraphWidget.prototype.updateNode = function (desc) {
if (desc && this.lineData[desc.id]) {
this.lineData[desc.id].values = desc.points;
this.lineData[desc.id].key = desc.name;
this.updateChartData();
this.refreshChart();
}
};
@@ -115,6 +114,9 @@ define([
}
};
LineGraphWidget.prototype.refreshChart =
_.debounce(LineGraphWidget.prototype.updateChartData, 50);
LineGraphWidget.prototype.updateChart = function () {
if (this.chart) {
this.chart.update();
@@ -64,7 +64,7 @@ define([
// Get the editor text and update wrt ansi colors
LogViewerWidget.renderAnsiFromText = function(remaining) {
var r = /\[0(;3([0-7]))?m/,
var r = /\[[0-6][0-9]?(;[0-9]([0-7]))?m/,
match,
ansiCode,
text,
@@ -77,7 +77,9 @@ define([
match = remaining.match(r);
if (match) {
ansiCode = match[0];
nextColor = ANSI_COLORS[match[2]] || null;
if (match[1] && match[1][1] === '3') { // foreground color
nextColor = ANSI_COLORS[match[2]] || null;
}
text = remaining.substring(0, match.index);
remaining = remaining.substring(match.index+ansiCode.length);
} else {
@@ -17,12 +17,17 @@ define([
var MainViewWidget,
WIDGET_CLASS = 'main-view',
CreateListItem = _.template(ListItem);
CreateListItem = _.template(ListItem),
ToggleLabels = [
'Executions',
'Pipelines'
];
MainViewWidget = function (logger, container) {
this._logger = logger.fork('Widget');
this.$el = container;
this.$el.addClass(WIDGET_CLASS);
this.toggleIndex = 0;
this.initialize();
this._logger.debug('ctor finished');
};
@@ -32,6 +37,19 @@ define([
this.$nav = $(NavBarHTML);
this.$el.append(this.$nav);
// Execution support
this.$toggle = this.$nav.find('#toggle-main');
this.$toggleLabel = this.$nav.find('.toggle-label');
this.$toggle.on('click', () => {
if (this._closed) { // shouldn't be clicked when closed (but it is possible)
return;
}
this.toggleEmbeddedPanel();
// Update the toggle name
this.toggleIndex = (this.toggleIndex + 1) % 2;
this.$toggleLabel.text(ToggleLabels[this.toggleIndex]);
});
this.$archlist = this.$nav.find('#arch-list-content');
this.$artifacts = this.$nav.find('#artifact-list-content');
@@ -1,6 +1,13 @@
<nav class="side-nav fixed closed hide-list">
<li class="pull-right side-nav-control">
<span class="glyphicon glyphicon-menu-hamburger" aria-hidden="true"></span>
</li >
<li class="no-padding" id="toggle-main">
<ul>
<li class="no-padding">
<a class="toggle-label">Executions</a>
</li>
</ul>
</li>
<li class="no-padding">
<ul class="collapsible" data-collapsible="accordion">
@@ -1,3 +1,7 @@
.main-view-embedded {
position: absolute;
}
.main-view .side-nav-control {
padding-right: 1em;
padding-top: 1em;
@@ -1,10 +1,6 @@
/*globals define */
/*jshint browser: true*/
/**
* Generated by VisualizerGenerator 1.7.0 from webgme on Wed May 18 2016 12:00:46 GMT-0500 (CDT).
*/
define([
'widgets/TextEditor/TextEditorWidget',
'underscore',
@@ -46,7 +42,7 @@ define([
header.push('-- The following will be executed when the operation is run:');
// Add info about outputs
outputs = desc.outputs.map(pair => `-- ${pair[0]} = <some ${pair[1]}>`)
outputs = desc.outputs.map(pair => `-- ${pair[0]} = <${pair[1]}>`)
.join('\n');
if (outputs.length) {
@@ -80,5 +76,27 @@ define([
this.editor.setOption('firstLineNumber', actualOffset);
};
OperationCodeEditorWidget.prototype.getCompleter = function () {
var completer = TextEditorWidget.prototype.getCompleter.call(this),
getBasicCompletions = completer.getCompletionsFor,
self = this;
completer.getCompletionsFor = function(obj) {
if (obj === 'attributes') {
return self.getOperationAttributes().map(attr => {
return {
name: attr,
value: attr,
score: 4,
meta: 'operation'
};
});
} else {
return getBasicCompletions.apply(this, arguments);
}
};
return completer;
};
return OperationCodeEditorWidget;
});
@@ -100,5 +100,12 @@ define([
this.addRefTo(target.node.id);
};
OperationInterfaceEditorWidget.prototype.addConnection = function(desc) {
EasyDAG.prototype.addConnection.call(this, desc);
// Remove connection selection
var conn = this.connections[desc.id];
conn.$el.on('click', null);
};
return OperationInterfaceEditorWidget;
});
@@ -1,14 +1,11 @@
/*globals WebGMEGlobal, $, define*/
/*jshint browser: true*/
/**
* Generated by VisualizerGenerator 1.7.0 from webgme on Thu May 19 2016 14:04:47 GMT-0500 (CDT).
*/
define([
'widgets/EasyDAG/AddNodeDialog',
'widgets/EasyDAG/EasyDAGWidget',
'deepforge/viz/PipelineControl',
'deepforge/viz/Utils',
'deepforge/globals',
'./OperationNode',
'./Connection',
@@ -19,6 +16,7 @@ define([
AddNodeDialog,
EasyDAGWidget,
PipelineControl,
Utils,
DeepForge,
OperationNode,
Connection,
@@ -35,12 +33,7 @@ define([
DEFAULT: 'default',
CONNECTING: 'connecting'
},
UPLOAD_ARTIFACT_ID = '__UPLOAD_ARTIFACT__',
STATUS_TO_CLASS = {
running: 'warning',
success: 'success',
failed: 'danger'
};
UPLOAD_ARTIFACT_ID = '__UPLOAD_ARTIFACT__';
PipelineEditorWidget = function (logger, container, execCntr) {
EasyDAGWidget.call(this, logger, container);
@@ -321,14 +314,10 @@ define([
var row = $('<tr>'),
title = $('<td>', {class: 'execution-name'}),
timestamp = $('<td>'),
className = STATUS_TO_CLASS[exec.status] || '',
today = new Date().toLocaleDateString(),
date = new Date(exec.createdAt).toLocaleDateString(),
className = Utils.ClassForJobStatus[exec.status] || '',
date = Utils.getDisplayTime(exec.createdAt),
rmIcon = $(REMOVE_ICON);
if (date === today) {
date = `Today (${new Date(exec.createdAt).toLocaleTimeString()})`;
}
timestamp.text(date);
title.append($('<a>').text(exec.name));
@@ -2,12 +2,14 @@
/*jshint browser: true*/
define([
'./lib/ace',
'ace/ace',
'underscore',
'./completer',
'css!./styles/TextEditorWidget.css'
], function (
ace,
_
_,
Completer
) {
'use strict';
@@ -28,13 +30,11 @@ define([
// Get the config from component settings for themes
this.editor.getSession().setOptions(this.getSessionOptions());
this.editor.setOptions(this.getEditorOptions());
this.addExtensions();
this.editor.$blockScrolling = Infinity;
this.DELAY = 750;
this.silent = false;
// this.editor.setTheme('ace/theme/monokai');
this.editor.on('change', () => {
if (!this.silent) {
this.onChange();
@@ -50,8 +50,22 @@ define([
this._logger.debug('ctor finished');
};
TextEditorWidget.prototype.addExtensions = function () {
require(['ace/ext/language_tools'], () => {
this.editor.setOptions(this.getEditorOptions());
this.completer = this.getCompleter();
this.editor.completers = [this.completer];
});
};
TextEditorWidget.prototype.getCompleter = function () {
return new Completer(this.editor.completers);
};
TextEditorWidget.prototype.getEditorOptions = function () {
return {
enableBasicAutocompletion: true,
enableLiveAutocompletion: true,
fontSize: '12pt'
};
};
@@ -0,0 +1,73 @@
/*globals define*/
// Given a global object/lib, provide the keys to autocomplete
define([
'q',
'text!./deepforge.json'
], function(
Q,
DeepForgeMethods
) {
var MethodsByClass = JSON.parse(DeepForgeMethods),
CommentRegex = /(--.*\n|\[\[--(.\n\s)*--\]\])/gm;
var MethodCompleter = function(completers) {
this._defaultCompleters = completers;
this.completionsByClass = {};
Object.keys(MethodsByClass).forEach(object => {
this.completionsByClass[object] = MethodsByClass[object].map(method => {
return {
name: method,
value: method,
score: 4,
meta: object
};
});
});
};
MethodCompleter.prototype.getCompletions = function(editor, session, pos, prefix, callback) {
// If adding a method (static or class) to an object, try to look up the
// object and retrieve the methods/fields. Otherwise, fall back to default
// completers
var prevChar = session.getTokenAt(pos.row, pos.column-1),
prevTextRange,
obj,
completions;
if (prevChar && (prevChar.value === '.' || prevChar.value === ':')) {
prevTextRange = session.getAWordRange(pos.row, pos.column - (prefix.length+1));
obj = session.getTextRange(prevTextRange);
completions = this.getCompletionsFor(obj, session, pos);
if (completions) {
return callback(null, completions);
}
}
return this.getDefaultCompletions.apply(this, arguments);
};
MethodCompleter.prototype.getCompletionsFor = function(obj/*, session, pos*/) {
return this.completionsByClass[obj];
};
MethodCompleter.prototype.getDefaultCompletions = function(editor, session, pos, prefix, callback) {
var completePromises = this._defaultCompleters.map(completer =>
Q.ninvoke(completer, 'getCompletions', editor, session, pos, prefix));
Q.all(completePromises).then(completions => {
callback(null, this.filterCompletions(editor, completions.reduce((l1, l2) => l1.concat(l2), [])));
})
.fail(err => callback(err));
};
MethodCompleter.prototype.filterCompletions = function(editor, completions) {
var text = editor.getValue(),
code = text.replace(CommentRegex, '');
// Remove words that only show up in comments
return completions.filter(completion => code.indexOf(completion.value) !== -1);
};
return MethodCompleter;
});
@@ -0,0 +1,226 @@
{
"deepforge": [
"Graph",
"image"
],
"torch": [
"deserialize",
"cat",
"cdata",
"newmetatable",
"atan2",
"log",
"zero",
"logNormal",
"sigmoid",
"getnumcores",
"cross",
"deserializeFromStorage",
"inverse",
"updateerrorhandlers",
"isTypeOf",
"ByteStorage",
"prod",
"ger",
"eq",
"getnumthreads",
"ByteTensor",
"Timer",
"addmv",
"lerp",
"match",
"Allocator",
"xcorr2",
"neg",
"histc",
"pstrf",
"bernoulli",
"MemoryFile",
"cremainder",
"Storage",
"ge",
"kthvalue",
"geometric",
"sin",
"topk",
"baddbmm",
"fill",
"linspace",
"sum",
"numel",
"orgqr",
"test",
"cmul",
"_heaptracking",
"getconstructortable",
"version",
"fmod",
"FloatTensor",
"mean",
"isTensor",
"ShortStorage",
"cmin",
"addcdiv",
"mm",
"Tester",
"xcorr3",
"ShortTensor",
"lt",
"triu",
"repeatTensor",
"data",
"CmdLine",
"eye",
"loadobj",
"mul",
"sqrt",
"LongTensor",
"saveobj",
"trunc",
"isequal",
"floor",
"serialize",
"load",
"save",
"permute",
"totable",
"csub",
"gesv",
"PipeFile",
"LongStorage",
"chunk",
"split",
"Tensor",
"diag",
"std",
"viewAs",
"view",
"conv3",
"expandAs",
"File",
"expand",
"uniform",
"all",
"renorm",
"rsqrt",
"typename",
"scatter",
"setdefaulttensortype",
"addbmm",
"class",
"symeig",
"remainder",
"clamp",
"getmetatable",
"packageLuaPath",
"updatethreadlocals",
"metatype",
"setRNGState",
"getRNGState",
"manualSeed",
"initialSeed",
"zeros",
"median",
"cosh",
"pushudata",
"geqrf",
"_gen",
"Generator",
"ormqr",
"FloatStorage",
"seed",
"qr",
"reshape",
"potrs",
"cpow",
"abs",
"dist",
"svd",
"mod",
"eig",
"IntTensor",
"cdiv",
"pow",
"gt",
"randperm",
"include",
"exponential",
"atan",
"nonzero",
"normal",
"multinomial",
"randn",
"any",
"equal",
"dot",
"range",
"rand",
"addr",
"trtrs",
"cinv",
"tan",
"frac",
"serializeToStorage",
"ceil",
"squeeze",
"var",
"tanh",
"setmetatable",
"cumsum",
"cauchy",
"ne",
"sinh",
"cos",
"potrf",
"DoubleStorage",
"CharStorage",
"asin",
"exp",
"log1p",
"pointer",
"addcmul",
"add",
"type",
"sign",
"div",
"mode",
"toc",
"norm",
"gather",
"tic",
"gels",
"mv",
"getdefaulttensortype",
"isStorage",
"logspace",
"factory",
"CharTensor",
"setnumthreads",
"IntStorage",
"TestSuite",
"cumprod",
"potri",
"le",
"setenv",
"tril",
"getenv",
"acos",
"addmm",
"isatty",
"min",
"max",
"cmax",
"DoubleTensor",
"sort",
"trace",
"ones",
"cfmod",
"round",
"bmm",
"DiskFile",
"conv2",
"setheaptracking",
"cmod",
"random"
]
}
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
@@ -0,0 +1,132 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
/**
* The main class required to set up an Ace instance in the browser.
*
* @class Ace
**/
define(function(require, exports, module) {
"use strict";
require("./lib/fixoldbrowsers");
var dom = require("./lib/dom");
var event = require("./lib/event");
var Editor = require("./editor").Editor;
var EditSession = require("./edit_session").EditSession;
var UndoManager = require("./undomanager").UndoManager;
var Renderer = require("./virtual_renderer").VirtualRenderer;
// The following require()s are for inclusion in the built ace file
require("./worker/worker_client");
require("./keyboard/hash_handler");
require("./placeholder");
require("./multi_select");
require("./mode/folding/fold_mode");
require("./theme/textmate");
require("./ext/error_marker");
exports.config = require("./config");
/**
* Provides access to require in packed noconflict mode
* @param {String} moduleName
* @returns {Object}
**/
exports.require = require;
if (typeof define === "function")
exports.define = define;
/**
* Embeds the Ace editor into the DOM, at the element provided by `el`.
* @param {String | DOMElement} el Either the id of an element, or the element itself
*
**/
exports.edit = function(el) {
if (typeof el == "string") {
var _id = el;
el = document.getElementById(_id);
if (!el)
throw new Error("ace.edit can't find div #" + _id);
}
if (el && el.env && el.env.editor instanceof Editor)
return el.env.editor;
var value = "";
if (el && /input|textarea/i.test(el.tagName)) {
var oldNode = el;
value = oldNode.value;
el = dom.createElement("pre");
oldNode.parentNode.replaceChild(el, oldNode);
} else if (el) {
value = dom.getInnerText(el);
el.innerHTML = "";
}
var doc = exports.createEditSession(value);
var editor = new Editor(new Renderer(el));
editor.setSession(doc);
var env = {
document: doc,
editor: editor,
onResize: editor.resize.bind(editor, null)
};
if (oldNode) env.textarea = oldNode;
event.addListener(window, "resize", env.onResize);
editor.on("destroy", function() {
event.removeListener(window, "resize", env.onResize);
env.editor.container.env = null; // prevent memory leak on old ie
});
editor.container.env = editor.env = env;
return editor;
};
/**
* Creates a new [[EditSession]], and returns the associated [[Document]].
* @param {Document | String} text {:textParam}
* @param {TextMode} mode {:modeParam}
*
**/
exports.createEditSession = function(text, mode) {
var doc = new EditSession(text, mode);
doc.setUndoManager(new UndoManager());
return doc;
}
exports.EditSession = EditSession;
exports.UndoManager = UndoManager;
exports.version = "1.2.4";
});
@@ -0,0 +1,227 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
"use strict";
var oop = require("./lib/oop");
var EventEmitter = require("./lib/event_emitter").EventEmitter;
/**
*
* Defines a floating pointer in the document. Whenever text is inserted or deleted before the cursor, the position of the anchor is updated.
*
* @class Anchor
**/
/**
* Creates a new `Anchor` and associates it with a document.
*
* @param {Document} doc The document to associate with the anchor
* @param {Number} row The starting row position
* @param {Number} column The starting column position
*
* @constructor
**/
var Anchor = exports.Anchor = function(doc, row, column) {
this.$onChange = this.onChange.bind(this);
this.attach(doc);
if (typeof column == "undefined")
this.setPosition(row.row, row.column);
else
this.setPosition(row, column);
};
(function() {
oop.implement(this, EventEmitter);
/**
* Returns an object identifying the `row` and `column` position of the current anchor.
* @returns {Object}
**/
this.getPosition = function() {
return this.$clipPositionToDocument(this.row, this.column);
};
/**
*
* Returns the current document.
* @returns {Document}
**/
this.getDocument = function() {
return this.document;
};
/**
* experimental: allows anchor to stick to the next on the left
*/
this.$insertRight = false;
/**
* Fires whenever the anchor position changes.
*
* Both of these objects have a `row` and `column` property corresponding to the position.
*
* Events that can trigger this function include [[Anchor.setPosition `setPosition()`]].
*
* @event change
* @param {Object} e An object containing information about the anchor position. It has two properties:
* - `old`: An object describing the old Anchor position
* - `value`: An object describing the new Anchor position
*
**/
this.onChange = function(delta) {
if (delta.start.row == delta.end.row && delta.start.row != this.row)
return;
if (delta.start.row > this.row)
return;
var point = $getTransformedPoint(delta, {row: this.row, column: this.column}, this.$insertRight);
this.setPosition(point.row, point.column, true);
};
function $pointsInOrder(point1, point2, equalPointsInOrder) {
var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column;
return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter);
}
function $getTransformedPoint(delta, point, moveIfEqual) {
// Get delta info.
var deltaIsInsert = delta.action == "insert";
var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row);
var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column);
var deltaStart = delta.start;
var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range.
// DELTA AFTER POINT: No change needed.
if ($pointsInOrder(point, deltaStart, moveIfEqual)) {
return {
row: point.row,
column: point.column
};
}
// DELTA BEFORE POINT: Move point by delta shift.
if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) {
return {
row: point.row + deltaRowShift,
column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0)
};
}
// DELTA ENVELOPS POINT (delete only): Move point to delta start.
// TODO warn if delta.action != "remove" ?
return {
row: deltaStart.row,
column: deltaStart.column
};
}
/**
* Sets the anchor position to the specified row and column. If `noClip` is `true`, the position is not clipped.
* @param {Number} row The row index to move the anchor to
* @param {Number} column The column index to move the anchor to
* @param {Boolean} noClip Identifies if you want the position to be clipped
*
**/
this.setPosition = function(row, column, noClip) {
var pos;
if (noClip) {
pos = {
row: row,
column: column
};
} else {
pos = this.$clipPositionToDocument(row, column);
}
if (this.row == pos.row && this.column == pos.column)
return;
var old = {
row: this.row,
column: this.column
};
this.row = pos.row;
this.column = pos.column;
this._signal("change", {
old: old,
value: pos
});
};
/**
* When called, the `"change"` event listener is removed.
*
**/
this.detach = function() {
this.document.removeEventListener("change", this.$onChange);
};
this.attach = function(doc) {
this.document = doc || this.document;
this.document.on("change", this.$onChange);
};
/**
* Clips the anchor position to the specified row and column.
* @param {Number} row The row index to clip the anchor to
* @param {Number} column The column index to clip the anchor to
*
**/
this.$clipPositionToDocument = function(row, column) {
var pos = {};
if (row >= this.document.getLength()) {
pos.row = Math.max(0, this.document.getLength() - 1);
pos.column = this.document.getLine(pos.row).length;
}
else if (row < 0) {
pos.row = 0;
pos.column = 0;
}
else {
pos.row = row;
pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
}
if (column < 0)
pos.column = 0;
return pos;
};
}).call(Anchor.prototype);
});
@@ -0,0 +1,223 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
if (typeof process !== "undefined") {
require("amd-loader");
}
define(function(require, exports, module) {
"use strict";
var Document = require("./document").Document;
var Anchor = require("./anchor").Anchor;
var Range = require("./range").Range;
var assert = require("./test/assertions");
module.exports = {
"test create anchor" : function() {
var doc = new Document("juhu");
var anchor = new Anchor(doc, 0, 0);
assert.position(anchor.getPosition(), 0, 0);
assert.equal(anchor.getDocument(), doc);
},
"test insert text in same row before cursor should move anchor column": function() {
var doc = new Document("juhu\nkinners");
var anchor = new Anchor(doc, 1, 4);
doc.insert({row: 1, column: 1}, "123");
assert.position(anchor.getPosition(), 1, 7);
},
"test insert text at anchor should not move anchor when insertRight is true": function() {
var doc = new Document("juhu\nkinners");
var anchor = new Anchor(doc, 1, 4);
anchor.$insertRight = true;
doc.insert({row: 1, column: 4}, "123");
assert.position(anchor.getPosition(), 1, 4);
},
"test insert lines before cursor should move anchor row": function() {
var doc = new Document("juhu\nkinners");
var anchor = new Anchor(doc, 1, 4);
doc.insertFullLines(1, ["123", "456"]);
assert.position(anchor.getPosition(), 3, 4);
},
"test insert lines at anchor position should move anchor down": function() {
var doc = new Document("juhu\nkinners");
var anchor = new Anchor(doc, 1, 0);
doc.insertLines(1, ["line"]);
assert.position(anchor.getPosition(), 2, 0);
},
"test insert lines at anchor position should not move anchor down when insertRight is true and column is 0": function() {
var doc = new Document("juhu\nkinners");
var anchor = new Anchor(doc, 1, 0);
anchor.$insertRight = true;
doc.insertLines(1, ["line"]);
assert.position(anchor.getPosition(), 1, 0);
},
"test insert lines at anchor row should move anchor down when column > 0": function() {
var doc = new Document("juhu\nkinners");
var anchor = new Anchor(doc, 1, 2);
anchor.$insertRight = true;
doc.insertLines(1, ["line"]);
assert.position(anchor.getPosition(), 2, 2);
},
"test insert new line before cursor should move anchor column": function() {
var doc = new Document("juhu\nkinners");
var anchor = new Anchor(doc, 1, 4);
doc.insertMergedLines({row: 0, column: 0}, ['', '']);
assert.position(anchor.getPosition(), 2, 4);
},
"test insert new line in anchor line before anchor should move anchor column and row": function() {
var doc = new Document("juhu\nkinners");
var anchor = new Anchor(doc, 1, 4);
doc.insertMergedLines({row: 1, column: 2}, ['', '']);
assert.position(anchor.getPosition(), 2, 2);
},
"test delete text in anchor line before anchor should move anchor column": function() {
var doc = new Document("juhu\nkinners");
var anchor = new Anchor(doc, 1, 4);
doc.remove(new Range(1, 1, 1, 3));
assert.position(anchor.getPosition(), 1, 2);
},
"test remove range which contains the anchor should move the anchor to the start of the range": function() {
var doc = new Document("juhu\nkinners");
var anchor = new Anchor(doc, 0, 3);
doc.remove(new Range(0, 1, 1, 3));
assert.position(anchor.getPosition(), 0, 1);
},
"test delete character before the anchor should have no effect": function() {
var doc = new Document("juhu\nkinners");
var anchor = new Anchor(doc, 1, 4);
doc.remove(new Range(1, 4, 1, 5));
assert.position(anchor.getPosition(), 1, 4);
},
"test delete lines in anchor line before anchor should move anchor row": function() {
var doc = new Document("juhu\n1\n2\nkinners");
var anchor = new Anchor(doc, 3, 4);
doc.removeFullLines(1, 2);
assert.position(anchor.getPosition(), 1, 4);
},
"test remove new line before the cursor": function() {
var doc = new Document("juhu\nkinners");
var anchor = new Anchor(doc, 1, 4);
doc.removeNewLine(0);
assert.position(anchor.getPosition(), 0, 8);
},
"test delete range which contains the anchor should move anchor to the end of the range": function() {
var doc = new Document("juhu\nkinners");
var anchor = new Anchor(doc, 1, 4);
doc.remove(new Range(0, 2, 1, 2));
assert.position(anchor.getPosition(), 0, 4);
},
"test delete line which contains the anchor should move anchor to the end of the range": function() {
var doc = new Document("juhu\nkinners\n123");
var anchor = new Anchor(doc, 1, 5);
doc.removeFullLines(1, 1);
assert.position(anchor.getPosition(), 1, 0);
},
"test remove after the anchor should have no effect": function() {
var doc = new Document("juhu\nkinners\n123");
var anchor = new Anchor(doc, 1, 2);
doc.remove(new Range(1, 4, 2, 2));
assert.position(anchor.getPosition(), 1, 2);
},
"test anchor changes triggered by document changes should emit change event": function(next) {
var doc = new Document("juhu\nkinners\n123");
var anchor = new Anchor(doc, 1, 5);
anchor.on("change", function(e) {
assert.position(anchor.getPosition(), 0, 0);
next();
});
doc.remove(new Range(0, 0, 2, 1));
},
"test only fire change event if position changes": function() {
var doc = new Document("juhu\nkinners\n123");
var anchor = new Anchor(doc, 1, 5);
anchor.on("change", function(e) {
assert.fail();
});
doc.remove(new Range(2, 0, 2, 1));
},
"test insert/remove lines at the end of the document": function() {
var doc = new Document("juhu\nkinners\n123");
var anchor = new Anchor(doc, 2, 4);
doc.removeFullLines(0, 3);
assert.position(anchor.getPosition(), 0, 0);
doc.insertFullLines(0, ["a", "b", "c"]);
assert.position(anchor.getPosition(), 3, 0);
assert.equal(doc.getValue(), "a\nb\nc\n");
}
};
});
if (typeof module !== "undefined" && module === require.main) {
require("asyncjs").test.testcase(module.exports).exec()
}
@@ -0,0 +1,108 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
"use strict";
function throwDeltaError(delta, errorText){
console.log("Invalid Delta:", delta);
throw "Invalid Delta: " + errorText;
}
function positionInDocument(docLines, position) {
return position.row >= 0 && position.row < docLines.length &&
position.column >= 0 && position.column <= docLines[position.row].length;
}
function validateDelta(docLines, delta) {
// Validate action string.
if (delta.action != "insert" && delta.action != "remove")
throwDeltaError(delta, "delta.action must be 'insert' or 'remove'");
// Validate lines type.
if (!(delta.lines instanceof Array))
throwDeltaError(delta, "delta.lines must be an Array");
// Validate range type.
if (!delta.start || !delta.end)
throwDeltaError(delta, "delta.start/end must be an present");
// Validate that the start point is contained in the document.
var start = delta.start;
if (!positionInDocument(docLines, delta.start))
throwDeltaError(delta, "delta.start must be contained in document");
// Validate that the end point is contained in the document (remove deltas only).
var end = delta.end;
if (delta.action == "remove" && !positionInDocument(docLines, end))
throwDeltaError(delta, "delta.end must contained in document for 'remove' actions");
// Validate that the .range size matches the .lines size.
var numRangeRows = end.row - start.row;
var numRangeLastLineChars = (end.column - (numRangeRows == 0 ? start.column : 0));
if (numRangeRows != delta.lines.length - 1 || delta.lines[numRangeRows].length != numRangeLastLineChars)
throwDeltaError(delta, "delta.range must match delta lines");
}
exports.applyDelta = function(docLines, delta, doNotValidate) {
// disabled validation since it breaks autocompletion popup
// if (!doNotValidate)
// validateDelta(docLines, delta);
var row = delta.start.row;
var startColumn = delta.start.column;
var line = docLines[row] || "";
switch (delta.action) {
case "insert":
var lines = delta.lines;
if (lines.length === 1) {
docLines[row] = line.substring(0, startColumn) + delta.lines[0] + line.substring(startColumn);
} else {
var args = [row, 1].concat(delta.lines);
docLines.splice.apply(docLines, args);
docLines[row] = line.substring(0, startColumn) + docLines[row];
docLines[row + delta.lines.length - 1] += line.substring(startColumn);
}
break;
case "remove":
var endColumn = delta.end.column;
var endRow = delta.end.row;
if (row === endRow) {
docLines[row] = line.substring(0, startColumn) + line.substring(endColumn);
} else {
docLines.splice(
row, endRow - row + 1,
line.substring(0, startColumn) + docLines[endRow].substring(endColumn)
);
}
break;
}
}
});
@@ -0,0 +1,498 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2012, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
"use strict";
var HashHandler = require("./keyboard/hash_handler").HashHandler;
var AcePopup = require("./autocomplete/popup").AcePopup;
var util = require("./autocomplete/util");
var event = require("./lib/event");
var lang = require("./lib/lang");
var dom = require("./lib/dom");
var snippetManager = require("./snippets").snippetManager;
var Autocomplete = function() {
this.autoInsert = false;
this.autoSelect = true;
this.exactMatch = false;
this.gatherCompletionsId = 0;
this.keyboardHandler = new HashHandler();
this.keyboardHandler.bindKeys(this.commands);
this.blurListener = this.blurListener.bind(this);
this.changeListener = this.changeListener.bind(this);
this.mousedownListener = this.mousedownListener.bind(this);
this.mousewheelListener = this.mousewheelListener.bind(this);
this.changeTimer = lang.delayedCall(function() {
this.updateCompletions(true);
}.bind(this));
this.tooltipTimer = lang.delayedCall(this.updateDocTooltip.bind(this), 50);
};
(function() {
this.$init = function() {
this.popup = new AcePopup(document.body || document.documentElement);
this.popup.on("click", function(e) {
this.insertMatch();
e.stop();
}.bind(this));
this.popup.focus = this.editor.focus.bind(this.editor);
this.popup.on("show", this.tooltipTimer.bind(null, null));
this.popup.on("select", this.tooltipTimer.bind(null, null));
this.popup.on("changeHoverMarker", this.tooltipTimer.bind(null, null));
return this.popup;
};
this.getPopup = function() {
return this.popup || this.$init();
};
this.openPopup = function(editor, prefix, keepPopupPosition) {
if (!this.popup)
this.$init();
this.popup.setData(this.completions.filtered);
editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
var renderer = editor.renderer;
this.popup.setRow(this.autoSelect ? 0 : -1);
if (!keepPopupPosition) {
this.popup.setTheme(editor.getTheme());
this.popup.setFontSize(editor.getFontSize());
var lineHeight = renderer.layerConfig.lineHeight;
var pos = renderer.$cursorLayer.getPixelPosition(this.base, true);
pos.left -= this.popup.getTextLeftOffset();
var rect = editor.container.getBoundingClientRect();
pos.top += rect.top - renderer.layerConfig.offset;
pos.left += rect.left - editor.renderer.scrollLeft;
pos.left += renderer.gutterWidth;
this.popup.show(pos, lineHeight);
} else if (keepPopupPosition && !prefix) {
this.detach();
}
};
this.detach = function() {
this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler);
this.editor.off("changeSelection", this.changeListener);
this.editor.off("blur", this.blurListener);
this.editor.off("mousedown", this.mousedownListener);
this.editor.off("mousewheel", this.mousewheelListener);
this.changeTimer.cancel();
this.hideDocTooltip();
this.gatherCompletionsId += 1;
if (this.popup && this.popup.isOpen)
this.popup.hide();
if (this.base)
this.base.detach();
this.activated = false;
this.completions = this.base = null;
};
this.changeListener = function(e) {
var cursor = this.editor.selection.lead;
if (cursor.row != this.base.row || cursor.column < this.base.column) {
this.detach();
}
if (this.activated)
this.changeTimer.schedule();
else
this.detach();
};
this.blurListener = function(e) {
// we have to check if activeElement is a child of popup because
// on IE preventDefault doesn't stop scrollbar from being focussed
var el = document.activeElement;
var text = this.editor.textInput.getElement();
var fromTooltip = e.relatedTarget && e.relatedTarget == this.tooltipNode;
var container = this.popup && this.popup.container;
if (el != text && el.parentNode != container && !fromTooltip
&& el != this.tooltipNode && e.relatedTarget != text
) {
this.detach();
}
};
this.mousedownListener = function(e) {
this.detach();
};
this.mousewheelListener = function(e) {
this.detach();
};
this.goTo = function(where) {
var row = this.popup.getRow();
var max = this.popup.session.getLength() - 1;
switch(where) {
case "up": row = row <= 0 ? max : row - 1; break;
case "down": row = row >= max ? -1 : row + 1; break;
case "start": row = 0; break;
case "end": row = max; break;
}
this.popup.setRow(row);
};
this.insertMatch = function(data, options) {
if (!data)
data = this.popup.getData(this.popup.getRow());
if (!data)
return false;
if (data.completer && data.completer.insertMatch) {
data.completer.insertMatch(this.editor, data);
} else {
// TODO add support for options.deleteSuffix
if (this.completions.filterText) {
var ranges = this.editor.selection.getAllRanges();
for (var i = 0, range; range = ranges[i]; i++) {
range.start.column -= this.completions.filterText.length;
this.editor.session.remove(range);
}
}
if (data.snippet)
snippetManager.insertSnippet(this.editor, data.snippet);
else
this.editor.execCommand("insertstring", data.value || data);
}
this.detach();
};
this.commands = {
"Up": function(editor) { editor.completer.goTo("up"); },
"Down": function(editor) { editor.completer.goTo("down"); },
"Ctrl-Up|Ctrl-Home": function(editor) { editor.completer.goTo("start"); },
"Ctrl-Down|Ctrl-End": function(editor) { editor.completer.goTo("end"); },
"Esc": function(editor) { editor.completer.detach(); },
"Return": function(editor) { return editor.completer.insertMatch(); },
"Shift-Return": function(editor) { editor.completer.insertMatch(null, {deleteSuffix: true}); },
"Tab": function(editor) {
var result = editor.completer.insertMatch();
if (!result && !editor.tabstopManager)
editor.completer.goTo("down");
else
return result;
},
"PageUp": function(editor) { editor.completer.popup.gotoPageUp(); },
"PageDown": function(editor) { editor.completer.popup.gotoPageDown(); }
};
this.gatherCompletions = function(editor, callback) {
var session = editor.getSession();
var pos = editor.getCursorPosition();
var line = session.getLine(pos.row);
var prefix = util.getCompletionPrefix(editor);
this.base = session.doc.createAnchor(pos.row, pos.column - prefix.length);
this.base.$insertRight = true;
var matches = [];
var total = editor.completers.length;
editor.completers.forEach(function(completer, i) {
completer.getCompletions(editor, session, pos, prefix, function(err, results) {
if (!err && results)
matches = matches.concat(results);
// Fetch prefix again, because they may have changed by now
var pos = editor.getCursorPosition();
var line = session.getLine(pos.row);
callback(null, {
prefix: prefix,
matches: matches,
finished: (--total === 0)
});
});
});
return true;
};
this.showPopup = function(editor) {
if (this.editor)
this.detach();
this.activated = true;
this.editor = editor;
if (editor.completer != this) {
if (editor.completer)
editor.completer.detach();
editor.completer = this;
}
editor.on("changeSelection", this.changeListener);
editor.on("blur", this.blurListener);
editor.on("mousedown", this.mousedownListener);
editor.on("mousewheel", this.mousewheelListener);
this.updateCompletions();
};
this.updateCompletions = function(keepPopupPosition) {
if (keepPopupPosition && this.base && this.completions) {
var pos = this.editor.getCursorPosition();
var prefix = this.editor.session.getTextRange({start: this.base, end: pos});
if (prefix == this.completions.filterText)
return;
this.completions.setFilter(prefix);
if (!this.completions.filtered.length)
return this.detach();
if (this.completions.filtered.length == 1
&& this.completions.filtered[0].value == prefix
&& !this.completions.filtered[0].snippet)
return this.detach();
this.openPopup(this.editor, prefix, keepPopupPosition);
return;
}
// Save current gatherCompletions session, session is close when a match is insert
var _id = this.gatherCompletionsId;
this.gatherCompletions(this.editor, function(err, results) {
// Only detach if result gathering is finished
var detachIfFinished = function() {
if (!results.finished) return;
return this.detach();
}.bind(this);
var prefix = results.prefix;
var matches = results && results.matches;
if (!matches || !matches.length)
return detachIfFinished();
// Wrong prefix or wrong session -> ignore
if (prefix.indexOf(results.prefix) !== 0 || _id != this.gatherCompletionsId)
return;
this.completions = new FilteredList(matches);
if (this.exactMatch)
this.completions.exactMatch = true;
this.completions.setFilter(prefix);
var filtered = this.completions.filtered;
// No results
if (!filtered.length)
return detachIfFinished();
// One result equals to the prefix
if (filtered.length == 1 && filtered[0].value == prefix && !filtered[0].snippet)
return detachIfFinished();
// Autoinsert if one result
if (this.autoInsert && filtered.length == 1 && results.finished)
return this.insertMatch(filtered[0]);
this.openPopup(this.editor, prefix, keepPopupPosition);
}.bind(this));
};
this.cancelContextMenu = function() {
this.editor.$mouseHandler.cancelContextMenu();
};
this.updateDocTooltip = function() {
var popup = this.popup;
var all = popup.data;
var selected = all && (all[popup.getHoveredRow()] || all[popup.getRow()]);
var doc = null;
if (!selected || !this.editor || !this.popup.isOpen)
return this.hideDocTooltip();
this.editor.completers.some(function(completer) {
if (completer.getDocTooltip)
doc = completer.getDocTooltip(selected);
return doc;
});
if (!doc)
doc = selected;
if (typeof doc == "string")
doc = {docText: doc};
if (!doc || !(doc.docHTML || doc.docText))
return this.hideDocTooltip();
this.showDocTooltip(doc);
};
this.showDocTooltip = function(item) {
if (!this.tooltipNode) {
this.tooltipNode = dom.createElement("div");
this.tooltipNode.className = "ace_tooltip ace_doc-tooltip";
this.tooltipNode.style.margin = 0;
this.tooltipNode.style.pointerEvents = "auto";
this.tooltipNode.tabIndex = -1;
this.tooltipNode.onblur = this.blurListener.bind(this);
}
var tooltipNode = this.tooltipNode;
if (item.docHTML) {
tooltipNode.innerHTML = item.docHTML;
} else if (item.docText) {
tooltipNode.textContent = item.docText;
}
if (!tooltipNode.parentNode)
document.body.appendChild(tooltipNode);
var popup = this.popup;
var rect = popup.container.getBoundingClientRect();
tooltipNode.style.top = popup.container.style.top;
tooltipNode.style.bottom = popup.container.style.bottom;
if (window.innerWidth - rect.right < 320) {
tooltipNode.style.right = window.innerWidth - rect.left + "px";
tooltipNode.style.left = "";
} else {
tooltipNode.style.left = (rect.right + 1) + "px";
tooltipNode.style.right = "";
}
tooltipNode.style.display = "block";
};
this.hideDocTooltip = function() {
this.tooltipTimer.cancel();
if (!this.tooltipNode) return;
var el = this.tooltipNode;
if (!this.editor.isFocused() && document.activeElement == el)
this.editor.focus();
this.tooltipNode = null;
if (el.parentNode)
el.parentNode.removeChild(el);
};
}).call(Autocomplete.prototype);
Autocomplete.startCommand = {
name: "startAutocomplete",
exec: function(editor) {
if (!editor.completer)
editor.completer = new Autocomplete();
editor.completer.autoInsert = false;
editor.completer.autoSelect = true;
editor.completer.showPopup(editor);
// prevent ctrl-space opening context menu on firefox on mac
editor.completer.cancelContextMenu();
},
bindKey: "Ctrl-Space|Ctrl-Shift-Space|Alt-Space"
};
var FilteredList = function(array, filterText) {
this.all = array;
this.filtered = array;
this.filterText = filterText || "";
this.exactMatch = false;
};
(function(){
this.setFilter = function(str) {
if (str.length > this.filterText && str.lastIndexOf(this.filterText, 0) === 0)
var matches = this.filtered;
else
var matches = this.all;
this.filterText = str;
matches = this.filterCompletions(matches, this.filterText);
matches = matches.sort(function(a, b) {
return b.exactMatch - a.exactMatch || b.score - a.score;
});
// make unique
var prev = null;
matches = matches.filter(function(item){
var caption = item.snippet || item.caption || item.value;
if (caption === prev) return false;
prev = caption;
return true;
});
this.filtered = matches;
};
this.filterCompletions = function(items, needle) {
var results = [];
var upper = needle.toUpperCase();
var lower = needle.toLowerCase();
loop: for (var i = 0, item; item = items[i]; i++) {
var caption = item.value || item.caption || item.snippet;
if (!caption) continue;
var lastIndex = -1;
var matchMask = 0;
var penalty = 0;
var index, distance;
if (this.exactMatch) {
if (needle !== caption.substr(0, needle.length))
continue loop;
}else{
// caption char iteration is faster in Chrome but slower in Firefox, so lets use indexOf
for (var j = 0; j < needle.length; j++) {
// TODO add penalty on case mismatch
var i1 = caption.indexOf(lower[j], lastIndex + 1);
var i2 = caption.indexOf(upper[j], lastIndex + 1);
index = (i1 >= 0) ? ((i2 < 0 || i1 < i2) ? i1 : i2) : i2;
if (index < 0)
continue loop;
distance = index - lastIndex - 1;
if (distance > 0) {
// first char mismatch should be more sensitive
if (lastIndex === -1)
penalty += 10;
penalty += distance;
}
matchMask = matchMask | (1 << index);
lastIndex = index;
}
}
item.matchMask = matchMask;
item.exactMatch = penalty ? 0 : 1;
item.score = (item.score || 0) - penalty;
results.push(item);
}
return results;
};
}).call(FilteredList.prototype);
exports.Autocomplete = Autocomplete;
exports.FilteredList = FilteredList;
});
@@ -0,0 +1,347 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2012, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
"use strict";
var Renderer = require("../virtual_renderer").VirtualRenderer;
var Editor = require("../editor").Editor;
var Range = require("../range").Range;
var event = require("../lib/event");
var lang = require("../lib/lang");
var dom = require("../lib/dom");
var $singleLineEditor = function(el) {
var renderer = new Renderer(el);
renderer.$maxLines = 4;
var editor = new Editor(renderer);
editor.setHighlightActiveLine(false);
editor.setShowPrintMargin(false);
editor.renderer.setShowGutter(false);
editor.renderer.setHighlightGutterLine(false);
editor.$mouseHandler.$focusWaitTimout = 0;
editor.$highlightTagPending = true;
return editor;
};
var AcePopup = function(parentNode) {
var el = dom.createElement("div");
var popup = new $singleLineEditor(el);
if (parentNode)
parentNode.appendChild(el);
el.style.display = "none";
popup.renderer.content.style.cursor = "default";
popup.renderer.setStyle("ace_autocomplete");
popup.setOption("displayIndentGuides", false);
popup.setOption("dragDelay", 150);
var noop = function(){};
popup.focus = noop;
popup.$isFocused = true;
popup.renderer.$cursorLayer.restartTimer = noop;
popup.renderer.$cursorLayer.element.style.opacity = 0;
popup.renderer.$maxLines = 8;
popup.renderer.$keepTextAreaAtCursor = false;
popup.setHighlightActiveLine(false);
// set default highlight color
popup.session.highlight("");
popup.session.$searchHighlight.clazz = "ace_highlight-marker";
popup.on("mousedown", function(e) {
var pos = e.getDocumentPosition();
popup.selection.moveToPosition(pos);
selectionMarker.start.row = selectionMarker.end.row = pos.row;
e.stop();
});
var lastMouseEvent;
var hoverMarker = new Range(-1,0,-1,Infinity);
var selectionMarker = new Range(-1,0,-1,Infinity);
selectionMarker.id = popup.session.addMarker(selectionMarker, "ace_active-line", "fullLine");
popup.setSelectOnHover = function(val) {
if (!val) {
hoverMarker.id = popup.session.addMarker(hoverMarker, "ace_line-hover", "fullLine");
} else if (hoverMarker.id) {
popup.session.removeMarker(hoverMarker.id);
hoverMarker.id = null;
}
};
popup.setSelectOnHover(false);
popup.on("mousemove", function(e) {
if (!lastMouseEvent) {
lastMouseEvent = e;
return;
}
if (lastMouseEvent.x == e.x && lastMouseEvent.y == e.y) {
return;
}
lastMouseEvent = e;
lastMouseEvent.scrollTop = popup.renderer.scrollTop;
var row = lastMouseEvent.getDocumentPosition().row;
if (hoverMarker.start.row != row) {
if (!hoverMarker.id)
popup.setRow(row);
setHoverMarker(row);
}
});
popup.renderer.on("beforeRender", function() {
if (lastMouseEvent && hoverMarker.start.row != -1) {
lastMouseEvent.$pos = null;
var row = lastMouseEvent.getDocumentPosition().row;
if (!hoverMarker.id)
popup.setRow(row);
setHoverMarker(row, true);
}
});
popup.renderer.on("afterRender", function() {
var row = popup.getRow();
var t = popup.renderer.$textLayer;
var selected = t.element.childNodes[row - t.config.firstRow];
if (selected == t.selectedNode)
return;
if (t.selectedNode)
dom.removeCssClass(t.selectedNode, "ace_selected");
t.selectedNode = selected;
if (selected)
dom.addCssClass(selected, "ace_selected");
});
var hideHoverMarker = function() { setHoverMarker(-1) };
var setHoverMarker = function(row, suppressRedraw) {
if (row !== hoverMarker.start.row) {
hoverMarker.start.row = hoverMarker.end.row = row;
if (!suppressRedraw)
popup.session._emit("changeBackMarker");
popup._emit("changeHoverMarker");
}
};
popup.getHoveredRow = function() {
return hoverMarker.start.row;
};
event.addListener(popup.container, "mouseout", hideHoverMarker);
popup.on("hide", hideHoverMarker);
popup.on("changeSelection", hideHoverMarker);
popup.session.doc.getLength = function() {
return popup.data.length;
};
popup.session.doc.getLine = function(i) {
var data = popup.data[i];
if (typeof data == "string")
return data;
return (data && data.value) || "";
};
var bgTokenizer = popup.session.bgTokenizer;
bgTokenizer.$tokenizeRow = function(row) {
var data = popup.data[row];
var tokens = [];
if (!data)
return tokens;
if (typeof data == "string")
data = {value: data};
if (!data.caption)
data.caption = data.value || data.name;
var last = -1;
var flag, c;
for (var i = 0; i < data.caption.length; i++) {
c = data.caption[i];
flag = data.matchMask & (1 << i) ? 1 : 0;
if (last !== flag) {
tokens.push({type: data.className || "" + ( flag ? "completion-highlight" : ""), value: c});
last = flag;
} else {
tokens[tokens.length - 1].value += c;
}
}
if (data.meta) {
var maxW = popup.renderer.$size.scrollerWidth / popup.renderer.layerConfig.characterWidth;
var metaData = data.meta;
if (metaData.length + data.caption.length > maxW - 2) {
// trim meta to fit this popup and add ellipsis
metaData = metaData.substr(0, maxW - data.caption.length - 3) + "\u2026"
}
tokens.push({type: "rightAlignedText", value: metaData});
}
return tokens;
};
bgTokenizer.$updateOnChange = noop;
bgTokenizer.start = noop;
popup.session.$computeWidth = function() {
return this.screenWidth = 0;
};
popup.$blockScrolling = Infinity;
// public
popup.isOpen = false;
popup.isTopdown = false;
popup.data = [];
popup.setData = function(list) {
popup.setValue(lang.stringRepeat("\n", list.length), -1);
popup.data = list || [];
popup.setRow(0);
};
popup.getData = function(row) {
return popup.data[row];
};
popup.getRow = function() {
return selectionMarker.start.row;
};
popup.setRow = function(line) {
line = Math.max(0, Math.min(this.data.length, line));
if (selectionMarker.start.row != line) {
popup.selection.clearSelection();
selectionMarker.start.row = selectionMarker.end.row = line || 0;
popup.session._emit("changeBackMarker");
popup.moveCursorTo(line || 0, 0);
if (popup.isOpen)
popup._signal("select");
}
};
popup.on("changeSelection", function() {
if (popup.isOpen)
popup.setRow(popup.selection.lead.row);
popup.renderer.scrollCursorIntoView();
});
popup.hide = function() {
this.container.style.display = "none";
this._signal("hide");
popup.isOpen = false;
};
popup.show = function(pos, lineHeight, topdownOnly) {
var el = this.container;
var screenHeight = window.innerHeight;
var screenWidth = window.innerWidth;
var renderer = this.renderer;
// var maxLines = Math.min(renderer.$maxLines, this.session.getLength());
var maxH = renderer.$maxLines * lineHeight * 1.4;
var top = pos.top + this.$borderSize;
var allowTopdown = top > screenHeight / 2 && !topdownOnly;
if (allowTopdown && top + lineHeight + maxH > screenHeight) {
renderer.$maxPixelHeight = top - 2 * this.$borderSize;
el.style.top = "";
el.style.bottom = screenHeight - top + "px";
popup.isTopdown = false;
} else {
top += lineHeight;
renderer.$maxPixelHeight = screenHeight - top - 0.2 * lineHeight;
el.style.top = top + "px";
el.style.bottom = "";
popup.isTopdown = true;
}
el.style.display = "";
this.renderer.$textLayer.checkForSizeChanges();
var left = pos.left;
if (left + el.offsetWidth > screenWidth)
left = screenWidth - el.offsetWidth;
el.style.left = left + "px";
this._signal("show");
lastMouseEvent = null;
popup.isOpen = true;
};
popup.getTextLeftOffset = function() {
return this.$borderSize + this.renderer.$padding + this.$imageSize;
};
popup.$imageSize = 0;
popup.$borderSize = 1;
return popup;
};
dom.importCssString("\
.ace_editor.ace_autocomplete .ace_marker-layer .ace_active-line {\
background-color: #CAD6FA;\
z-index: 1;\
}\
.ace_editor.ace_autocomplete .ace_line-hover {\
border: 1px solid #abbffe;\
margin-top: -1px;\
background: rgba(233,233,253,0.4);\
}\
.ace_editor.ace_autocomplete .ace_line-hover {\
position: absolute;\
z-index: 2;\
}\
.ace_editor.ace_autocomplete .ace_scroller {\
background: none;\
border: none;\
box-shadow: none;\
}\
.ace_rightAlignedText {\
color: gray;\
display: inline-block;\
position: absolute;\
right: 4px;\
text-align: right;\
z-index: -1;\
}\
.ace_editor.ace_autocomplete .ace_completion-highlight{\
color: #000;\
text-shadow: 0 0 0.01em;\
}\
.ace_editor.ace_autocomplete {\
width: 280px;\
z-index: 200000;\
background: #fbfbfb;\
color: #444;\
border: 1px lightgray solid;\
position: fixed;\
box-shadow: 2px 3px 5px rgba(0,0,0,.2);\
line-height: 1.4;\
}");
exports.AcePopup = AcePopup;
});
@@ -0,0 +1,78 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2012, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
var Range = require("../range").Range;
var splitRegex = /[^a-zA-Z_0-9\$\-\u00C0-\u1FFF\u2C00-\uD7FF\w]+/;
function getWordIndex(doc, pos) {
var textBefore = doc.getTextRange(Range.fromPoints({row: 0, column:0}, pos));
return textBefore.split(splitRegex).length - 1;
}
/**
* Does a distance analysis of the word `prefix` at position `pos` in `doc`.
* @return Map
*/
function wordDistance(doc, pos) {
var prefixPos = getWordIndex(doc, pos);
var words = doc.getValue().split(splitRegex);
var wordScores = Object.create(null);
var currentWord = words[prefixPos];
words.forEach(function(word, idx) {
if (!word || word === currentWord) return;
var distance = Math.abs(prefixPos - idx);
var score = words.length - distance;
if (wordScores[word]) {
wordScores[word] = Math.max(score, wordScores[word]);
} else {
wordScores[word] = score;
}
});
return wordScores;
}
exports.getCompletions = function(editor, session, pos, prefix, callback) {
var wordScore = wordDistance(session, pos, prefix);
var wordList = Object.keys(wordScore);
callback(null, wordList.map(function(word) {
return {
caption: word,
value: word,
score: wordScore[word],
meta: "local"
};
}));
};
});
@@ -0,0 +1,89 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2012, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
"use strict";
exports.parForEach = function(array, fn, callback) {
var completed = 0;
var arLength = array.length;
if (arLength === 0)
callback();
for (var i = 0; i < arLength; i++) {
fn(array[i], function(result, err) {
completed++;
if (completed === arLength)
callback(result, err);
});
}
};
var ID_REGEX = /[a-zA-Z_0-9\$\-\u00A2-\uFFFF]/;
exports.retrievePrecedingIdentifier = function(text, pos, regex) {
regex = regex || ID_REGEX;
var buf = [];
for (var i = pos-1; i >= 0; i--) {
if (regex.test(text[i]))
buf.push(text[i]);
else
break;
}
return buf.reverse().join("");
};
exports.retrieveFollowingIdentifier = function(text, pos, regex) {
regex = regex || ID_REGEX;
var buf = [];
for (var i = pos; i < text.length; i++) {
if (regex.test(text[i]))
buf.push(text[i]);
else
break;
}
return buf;
};
exports.getCompletionPrefix = function (editor) {
var pos = editor.getCursorPosition();
var line = editor.session.getLine(pos.row);
var prefix;
editor.completers.forEach(function(completer) {
if (completer.identifierRegexps) {
completer.identifierRegexps.forEach(function(identifierRegex) {
if (!prefix && identifierRegex)
prefix = this.retrievePrecedingIdentifier(line, pos.column, identifierRegex);
}.bind(this));
}
}.bind(this));
return prefix || this.retrievePrecedingIdentifier(line, pos.column);
};
});
@@ -0,0 +1,248 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
"use strict";
var oop = require("./lib/oop");
var EventEmitter = require("./lib/event_emitter").EventEmitter;
/**
* Tokenizes the current [[Document `Document`]] in the background, and caches the tokenized rows for future use.
*
* If a certain row is changed, everything below that row is re-tokenized.
*
* @class BackgroundTokenizer
**/
/**
* Creates a new `BackgroundTokenizer` object.
* @param {Tokenizer} tokenizer The tokenizer to use
* @param {Editor} editor The editor to associate with
*
* @constructor
**/
var BackgroundTokenizer = function(tokenizer, editor) {
this.running = false;
this.lines = [];
this.states = [];
this.currentLine = 0;
this.tokenizer = tokenizer;
var self = this;
this.$worker = function() {
if (!self.running) { return; }
var workerStart = new Date();
var currentLine = self.currentLine;
var endLine = -1;
var doc = self.doc;
var startLine = currentLine;
while (self.lines[currentLine])
currentLine++;
var len = doc.getLength();
var processedLines = 0;
self.running = false;
while (currentLine < len) {
self.$tokenizeRow(currentLine);
endLine = currentLine;
do {
currentLine++;
} while (self.lines[currentLine]);
// only check every 5 lines
processedLines ++;
if ((processedLines % 5 === 0) && (new Date() - workerStart) > 20) {
self.running = setTimeout(self.$worker, 20);
break;
}
}
self.currentLine = currentLine;
if (startLine <= endLine)
self.fireUpdateEvent(startLine, endLine);
};
};
(function(){
oop.implement(this, EventEmitter);
/**
* Sets a new tokenizer for this object.
*
* @param {Tokenizer} tokenizer The new tokenizer to use
*
**/
this.setTokenizer = function(tokenizer) {
this.tokenizer = tokenizer;
this.lines = [];
this.states = [];
this.start(0);
};
/**
* Sets a new document to associate with this object.
* @param {Document} doc The new document to associate with
**/
this.setDocument = function(doc) {
this.doc = doc;
this.lines = [];
this.states = [];
this.stop();
};
/**
* Fires whenever the background tokeniziers between a range of rows are going to be updated.
*
* @event update
* @param {Object} e An object containing two properties, `first` and `last`, which indicate the rows of the region being updated.
*
**/
/**
* Emits the `'update'` event. `firstRow` and `lastRow` are used to define the boundaries of the region to be updated.
* @param {Number} firstRow The starting row region
* @param {Number} lastRow The final row region
*
**/
this.fireUpdateEvent = function(firstRow, lastRow) {
var data = {
first: firstRow,
last: lastRow
};
this._signal("update", {data: data});
};
/**
* Starts tokenizing at the row indicated.
*
* @param {Number} startRow The row to start at
*
**/
this.start = function(startRow) {
this.currentLine = Math.min(startRow || 0, this.currentLine, this.doc.getLength());
// remove all cached items below this line
this.lines.splice(this.currentLine, this.lines.length);
this.states.splice(this.currentLine, this.states.length);
this.stop();
// pretty long delay to prevent the tokenizer from interfering with the user
this.running = setTimeout(this.$worker, 700);
};
this.scheduleStart = function() {
if (!this.running)
this.running = setTimeout(this.$worker, 700);
}
this.$updateOnChange = function(delta) {
var startRow = delta.start.row;
var len = delta.end.row - startRow;
if (len === 0) {
this.lines[startRow] = null;
} else if (delta.action == "remove") {
this.lines.splice(startRow, len + 1, null);
this.states.splice(startRow, len + 1, null);
} else {
var args = Array(len + 1);
args.unshift(startRow, 1);
this.lines.splice.apply(this.lines, args);
this.states.splice.apply(this.states, args);
}
this.currentLine = Math.min(startRow, this.currentLine, this.doc.getLength());
this.stop();
};
/**
* Stops tokenizing.
*
**/
this.stop = function() {
if (this.running)
clearTimeout(this.running);
this.running = false;
};
/**
* Gives list of tokens of the row. (tokens are cached)
*
* @param {Number} row The row to get tokens at
*
*
*
**/
this.getTokens = function(row) {
return this.lines[row] || this.$tokenizeRow(row);
};
/**
* [Returns the state of tokenization at the end of a row.]{: #BackgroundTokenizer.getState}
*
* @param {Number} row The row to get state at
**/
this.getState = function(row) {
if (this.currentLine == row)
this.$tokenizeRow(row);
return this.states[row] || "start";
};
this.$tokenizeRow = function(row) {
var line = this.doc.getLine(row);
var state = this.states[row - 1];
var data = this.tokenizer.getLineTokens(line, state, row);
if (this.states[row] + "" !== data.state + "") {
this.states[row] = data.state;
this.lines[row + 1] = null;
if (this.currentLine > row + 1)
this.currentLine = row + 1;
} else if (this.currentLine == row) {
this.currentLine = row + 1;
}
return this.lines[row] = data.tokens;
};
}).call(BackgroundTokenizer.prototype);
exports.BackgroundTokenizer = BackgroundTokenizer;
});
@@ -0,0 +1,128 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
if (typeof process !== "undefined") {
require("amd-loader");
}
define(function(require, exports, module) {
"use strict";
var EditSession = require("./edit_session").EditSession;
var JavaScriptMode = require("./mode/javascript").Mode;
var Range = require("./range").Range;
var assert = require("./test/assertions");
function forceTokenize(session){
for (var i = 0, l = session.getLength(); i < l; i++)
session.getTokens(i)
}
function testStates(session, states) {
for (var i = 0, l = session.getLength(); i < l; i++)
assert.equal(session.bgTokenizer.states[i], states[i])
assert.ok(l == states.length)
}
module.exports = {
"test background tokenizer update on session change" : function() {
var doc = new EditSession([
"/*",
"*/",
"var juhu"
]);
doc.setMode("./mode/javascript")
forceTokenize(doc)
testStates(doc, ["comment1", "start", "no_regex"])
doc.remove(new Range(0,2,1,2))
testStates(doc, [null, "no_regex"])
forceTokenize(doc)
testStates(doc, ["comment1", "comment1"])
doc.insert({row:0, column:2}, "\n*/")
testStates(doc, [undefined, undefined, "comment1"])
forceTokenize(doc)
testStates(doc, ["comment1", "start", "no_regex"])
},
"test background tokenizer sends update event" : function() {
var doc = new EditSession([
"/*",
"var",
"juhu",
"*/"
]);
doc.setMode("./mode/javascript");
var updateEvent = null;
doc.bgTokenizer.on("update", function(e) {
updateEvent = e.data;
});
function checkEvent(first, last) {
assert.ok(!updateEvent, "unneccessary update event");
doc.bgTokenizer.running = 1;
doc.bgTokenizer.$worker();
assert.ok(updateEvent);
assert.equal([first, last] + "",
[updateEvent.first, updateEvent.last] + "")
updateEvent = null;
}
forceTokenize(doc);
var comment = "comment1";
testStates(doc, [comment, comment, comment, "start"]);
doc.remove(new Range(0,0,0,2));
testStates(doc, [comment, comment, comment, "start"]);
checkEvent(0, 3);
testStates(doc, ["start", "no_regex", "no_regex", "regex"]);
// insert /* and and press down several times quickly
doc.insert({row:0, column:0}, "/*");
doc.getTokens(0);
doc.getTokens(1);
doc.getTokens(2);
checkEvent(0, 3);
forceTokenize(doc);
testStates(doc, [comment, comment, comment, "start"]);
}
};
});
if (typeof module !== "undefined" && module === require.main) {
require("asyncjs").test.testcase(module.exports).exec()
}
@@ -0,0 +1,118 @@
define(function(require, exports, module) {
"use strict";
var oop = require("../lib/oop");
var MultiHashHandler = require("../keyboard/hash_handler").MultiHashHandler;
var EventEmitter = require("../lib/event_emitter").EventEmitter;
/**
* @class CommandManager
*
**/
/**
* new CommandManager(platform, commands)
* @param {String} platform Identifier for the platform; must be either `"mac"` or `"win"`
* @param {Array} commands A list of commands
*
**/
var CommandManager = function(platform, commands) {
MultiHashHandler.call(this, commands, platform);
this.byName = this.commands;
this.setDefaultHandler("exec", function(e) {
return e.command.exec(e.editor, e.args || {});
});
};
oop.inherits(CommandManager, MultiHashHandler);
(function() {
oop.implement(this, EventEmitter);
this.exec = function(command, editor, args) {
if (Array.isArray(command)) {
for (var i = command.length; i--; ) {
if (this.exec(command[i], editor, args)) return true;
}
return false;
}
if (typeof command === "string")
command = this.commands[command];
if (!command)
return false;
if (editor && editor.$readOnly && !command.readOnly)
return false;
var e = {editor: editor, command: command, args: args};
e.returnValue = this._emit("exec", e);
this._signal("afterExec", e);
return e.returnValue === false ? false : true;
};
this.toggleRecording = function(editor) {
if (this.$inReplay)
return;
editor && editor._emit("changeStatus");
if (this.recording) {
this.macro.pop();
this.removeEventListener("exec", this.$addCommandToMacro);
if (!this.macro.length)
this.macro = this.oldMacro;
return this.recording = false;
}
if (!this.$addCommandToMacro) {
this.$addCommandToMacro = function(e) {
this.macro.push([e.command, e.args]);
}.bind(this);
}
this.oldMacro = this.macro;
this.macro = [];
this.on("exec", this.$addCommandToMacro);
return this.recording = true;
};
this.replay = function(editor) {
if (this.$inReplay || !this.macro)
return;
if (this.recording)
return this.toggleRecording(editor);
try {
this.$inReplay = true;
this.macro.forEach(function(x) {
if (typeof x == "string")
this.exec(x, editor);
else
this.exec(x[0], editor, x[1]);
}, this);
} finally {
this.$inReplay = false;
}
};
this.trimMacro = function(m) {
return m.map(function(x){
if (typeof x[0] != "string")
x[0] = x[0].name;
if (!x[1])
x = x[0];
return x;
});
};
}).call(CommandManager.prototype);
exports.CommandManager = CommandManager;
});
@@ -0,0 +1,199 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
if (typeof process !== "undefined") {
require("amd-loader");
}
define(function(require, exports, module) {
"use strict";
var CommandManager = require("./command_manager").CommandManager;
var keys = require("../lib/keys");
var assert = require("../test/assertions");
module.exports = {
setUp: function() {
this.command = {
name: "gotoline",
bindKey: {
mac: "Command-L",
win: "Ctrl-L"
},
called: false,
exec: function(editor) { this.called = true; }
};
this.cm = new CommandManager("mac", [this.command]);
},
"test: register command": function() {
this.cm.exec("gotoline");
assert.ok(this.command.called);
},
"test: mac hotkeys": function() {
var command = this.cm.findKeyCommand(keys.KEY_MODS.command, "l");
assert.equal(command, this.command);
var command = this.cm.findKeyCommand(keys.KEY_MODS.ctrl, "l");
assert.equal(command, undefined);
},
"test: win hotkeys": function() {
var cm = new CommandManager("win", [this.command]);
var command = cm.findKeyCommand(keys.KEY_MODS.command, "l");
assert.equal(command, undefined);
var command = cm.findKeyCommand(keys.KEY_MODS.ctrl, "l");
assert.equal(command, this.command);
},
"test: remove command by object": function() {
this.cm.removeCommand(this.command);
this.cm.exec("gotoline");
assert.ok(!this.command.called);
var command = this.cm.findKeyCommand(keys.KEY_MODS.command, "l");
assert.equal(command, null);
},
"test: remove command by name": function() {
this.cm.removeCommand("gotoline");
this.cm.exec("gotoline");
assert.ok(!this.command.called);
var command = this.cm.findKeyCommand(keys.KEY_MODS.command, "l");
assert.equal(command, null);
},
"test: adding a new command with the same name as an existing one should remove the old one first": function() {
var command = {
name: "gotoline",
bindKey: {
mac: "Command-L",
win: "Ctrl-L"
},
called: false,
exec: function(editor) { this.called = true; }
};
this.cm.addCommand(command);
this.cm.exec("gotoline");
assert.ok(command.called);
assert.ok(!this.command.called);
assert.equal(this.cm.findKeyCommand(keys.KEY_MODS.command, "l"), command);
},
"test: adding commands and recording a macro": function() {
var called = "";
this.cm.addCommands({
togglerecording: function(editor) {
editor.cm.toggleRecording(editor);
},
replay: function(editor) {
editor.cm.replay();
},
cm1: function(editor, arg) {
called += "1" + (arg || "");
},
cm2: function(editor) {
called += "2";
}
});
var statusUpdateEmitted = false;
this._emit = function() {statusUpdateEmitted = true};
this.cm.exec("togglerecording", this);
assert.ok(this.cm.recording);
assert.ok(statusUpdateEmitted);
this.cm.exec("cm1", this, "-");
this.cm.exec("cm2");
this.cm.exec("replay", this);
assert.ok(!this.cm.recording);
assert.equal(called, "1-2");
called = "";
this.cm.exec("replay", this);
assert.equal(called, "1-2");
},
"test: bindkeys": function() {
this.cm.bindKeys({
"Ctrl-L|Command-C": "cm1",
"Ctrl-R": "cm2"
});
var command = this.cm.findKeyCommand(keys.KEY_MODS.command, "c");
assert.equal(command, "cm1");
var command = this.cm.findKeyCommand(keys.KEY_MODS.ctrl, "r");
assert.equal(command, "cm2");
this.cm.bindKeys({
"Ctrl-R": null
});
var command = this.cm.findKeyCommand(keys.KEY_MODS.ctrl, "r");
assert.equal(command, null);
},
"test: binding keys without modifiers": function() {
this.cm.bindKeys({
"R": "cm1",
"Shift-r": "cm2",
"Return": "cm4",
"Enter": "cm3"
});
var command = this.cm.findKeyCommand(-1, "r");
assert.equal(command, "cm1");
var command = this.cm.findKeyCommand(-1, "R");
assert.equal(command, "cm2");
var command = this.cm.findKeyCommand(0, "return");
assert.equal(command + "", ["cm4", "cm3"] + "");
}
};
});
if (typeof module !== "undefined" && module === require.main) {
require("asyncjs").test.testcase(module.exports).exec();
}

Alguns arquivos não foram exibidos porque demasiados arquivos foram alterados neste diff Mostrar Mais