id
int32
0
58k
repo
stringlengths
5
67
path
stringlengths
4
116
func_name
stringlengths
0
58
original_string
stringlengths
52
373k
language
stringclasses
1 value
code
stringlengths
52
373k
code_tokens
list
docstring
stringlengths
4
11.8k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
86
226
40,500
micromatch/glob-fs
index.js
function(method, arr/*, arguments*/) { var args = [].slice.call(arguments, 2); utils.arrayify(arr || []).forEach(function (obj) { this[method](obj, args); }.bind(this)); return this; }
javascript
function(method, arr/*, arguments*/) { var args = [].slice.call(arguments, 2); utils.arrayify(arr || []).forEach(function (obj) { this[method](obj, args); }.bind(this)); return this; }
[ "function", "(", "method", ",", "arr", "/*, arguments*/", ")", "{", "var", "args", "=", "[", "]", ".", "slice", ".", "call", "(", "arguments", ",", "2", ")", ";", "utils", ".", "arrayify", "(", "arr", "||", "[", "]", ")", ".", "forEach", "(", "function", "(", "obj", ")", "{", "this", "[", "method", "]", "(", "obj", ",", "args", ")", ";", "}", ".", "bind", "(", "this", ")", ")", ";", "return", "this", ";", "}" ]
Map the given `method` over `array`. @param {String} `method` @param {Array} `arr` @return {Object} `this` for chaining
[ "Map", "the", "given", "method", "over", "array", "." ]
9419fb8a112ca6554af0448cbb801c00953af8e5
https://github.com/micromatch/glob-fs/blob/9419fb8a112ca6554af0448cbb801c00953af8e5/index.js#L261-L267
40,501
micromatch/glob-fs
lib/readers.js
function(pattern, options, cb) { if (typeof options === 'function') { return this.readdir(pattern, {}, options); } this.emit('read'); this.setPattern(pattern, options); this.iteratorAsync(this.pattern.base, function (err) { if (err) return cb(err); this.emit('end', this.files); cb.call(this, null, this.files); }.bind(this)); return this; }
javascript
function(pattern, options, cb) { if (typeof options === 'function') { return this.readdir(pattern, {}, options); } this.emit('read'); this.setPattern(pattern, options); this.iteratorAsync(this.pattern.base, function (err) { if (err) return cb(err); this.emit('end', this.files); cb.call(this, null, this.files); }.bind(this)); return this; }
[ "function", "(", "pattern", ",", "options", ",", "cb", ")", "{", "if", "(", "typeof", "options", "===", "'function'", ")", "{", "return", "this", ".", "readdir", "(", "pattern", ",", "{", "}", ",", "options", ")", ";", "}", "this", ".", "emit", "(", "'read'", ")", ";", "this", ".", "setPattern", "(", "pattern", ",", "options", ")", ";", "this", ".", "iteratorAsync", "(", "this", ".", "pattern", ".", "base", ",", "function", "(", "err", ")", "{", "if", "(", "err", ")", "return", "cb", "(", "err", ")", ";", "this", ".", "emit", "(", "'end'", ",", "this", ".", "files", ")", ";", "cb", ".", "call", "(", "this", ",", "null", ",", "this", ".", "files", ")", ";", "}", ".", "bind", "(", "this", ")", ")", ";", "return", "this", ";", "}" ]
Asynchronously glob files or directories that match the given `pattern`. ```js var glob = require('glob-fs')({ gitignore: true }); glob.readdir('*.js', function (err, files) { //=> do stuff with `files` }); ``` @name .readdir @param {String} `pattern` Glob pattern @param {Object} `options` @param {Function} `cb` Callback @api public
[ "Asynchronously", "glob", "files", "or", "directories", "that", "match", "the", "given", "pattern", "." ]
9419fb8a112ca6554af0448cbb801c00953af8e5
https://github.com/micromatch/glob-fs/blob/9419fb8a112ca6554af0448cbb801c00953af8e5/lib/readers.js#L25-L39
40,502
micromatch/glob-fs
lib/readers.js
function(pattern, options) { this.emit('read'); this.setPattern(pattern, options); this.iteratorSync(this.pattern.base); this.emit('end', this.files); return this.files; }
javascript
function(pattern, options) { this.emit('read'); this.setPattern(pattern, options); this.iteratorSync(this.pattern.base); this.emit('end', this.files); return this.files; }
[ "function", "(", "pattern", ",", "options", ")", "{", "this", ".", "emit", "(", "'read'", ")", ";", "this", ".", "setPattern", "(", "pattern", ",", "options", ")", ";", "this", ".", "iteratorSync", "(", "this", ".", "pattern", ".", "base", ")", ";", "this", ".", "emit", "(", "'end'", ",", "this", ".", "files", ")", ";", "return", "this", ".", "files", ";", "}" ]
Synchronously glob files or directories that match the given `pattern`. ```js var glob = require('glob-fs')({ gitignore: true }); var files = glob.readdirSync('*.js'); //=> do stuff with `files` ``` @name .readdirSync @param {String} `pattern` Glob pattern @param {Object} `options` @returns {Array} Returns an array of files. @api public
[ "Synchronously", "glob", "files", "or", "directories", "that", "match", "the", "given", "pattern", "." ]
9419fb8a112ca6554af0448cbb801c00953af8e5
https://github.com/micromatch/glob-fs/blob/9419fb8a112ca6554af0448cbb801c00953af8e5/lib/readers.js#L59-L65
40,503
micromatch/glob-fs
lib/readers.js
function(pattern, options) { this.emit('read'); this.setPattern(pattern, options); var res = this.iteratorStream(this.pattern.base); this.emit('end', this.files); return res; }
javascript
function(pattern, options) { this.emit('read'); this.setPattern(pattern, options); var res = this.iteratorStream(this.pattern.base); this.emit('end', this.files); return res; }
[ "function", "(", "pattern", ",", "options", ")", "{", "this", ".", "emit", "(", "'read'", ")", ";", "this", ".", "setPattern", "(", "pattern", ",", "options", ")", ";", "var", "res", "=", "this", ".", "iteratorStream", "(", "this", ".", "pattern", ".", "base", ")", ";", "this", ".", "emit", "(", "'end'", ",", "this", ".", "files", ")", ";", "return", "res", ";", "}" ]
Stream files or directories that match the given glob `pattern`. ```js var glob = require('glob-fs')({ gitignore: true }); glob.readdirStream('*.js') .on('data', function (file) { console.log(file.path); }) .on('error', console.error) .on('end', function () { console.log('end'); }); ``` @name .readdirStream @param {String} `pattern` Glob pattern @param {Object} `options` @returns {Stream} @api public
[ "Stream", "files", "or", "directories", "that", "match", "the", "given", "glob", "pattern", "." ]
9419fb8a112ca6554af0448cbb801c00953af8e5
https://github.com/micromatch/glob-fs/blob/9419fb8a112ca6554af0448cbb801c00953af8e5/lib/readers.js#L90-L96
40,504
micromatch/glob-fs
lib/file.js
File
function File(file) { this.cache = new Map(); this.history = []; this.pattern = file.pattern; this.recurse = file.recurse; this.dirname = file.dirname; this.segment = file.segment; this.path = file.path; this.orig = file.path; }
javascript
function File(file) { this.cache = new Map(); this.history = []; this.pattern = file.pattern; this.recurse = file.recurse; this.dirname = file.dirname; this.segment = file.segment; this.path = file.path; this.orig = file.path; }
[ "function", "File", "(", "file", ")", "{", "this", ".", "cache", "=", "new", "Map", "(", ")", ";", "this", ".", "history", "=", "[", "]", ";", "this", ".", "pattern", "=", "file", ".", "pattern", ";", "this", ".", "recurse", "=", "file", ".", "recurse", ";", "this", ".", "dirname", "=", "file", ".", "dirname", ";", "this", ".", "segment", "=", "file", ".", "segment", ";", "this", ".", "path", "=", "file", ".", "path", ";", "this", ".", "orig", "=", "file", ".", "path", ";", "}" ]
Create a new `File` from the given `object`. @param {Object} `object` @api public
[ "Create", "a", "new", "File", "from", "the", "given", "object", "." ]
9419fb8a112ca6554af0448cbb801c00953af8e5
https://github.com/micromatch/glob-fs/blob/9419fb8a112ca6554af0448cbb801c00953af8e5/lib/file.js#L24-L33
40,505
micromatch/glob-fs
lib/pattern.js
Pattern
function Pattern(glob, options, isNegated) { utils.defineProp(this, 'cache', new Map()); this.negated = !!isNegated; this.options = options || {}; this.parse(glob); return this; }
javascript
function Pattern(glob, options, isNegated) { utils.defineProp(this, 'cache', new Map()); this.negated = !!isNegated; this.options = options || {}; this.parse(glob); return this; }
[ "function", "Pattern", "(", "glob", ",", "options", ",", "isNegated", ")", "{", "utils", ".", "defineProp", "(", "this", ",", "'cache'", ",", "new", "Map", "(", ")", ")", ";", "this", ".", "negated", "=", "!", "!", "isNegated", ";", "this", ".", "options", "=", "options", "||", "{", "}", ";", "this", ".", "parse", "(", "glob", ")", ";", "return", "this", ";", "}" ]
Create an instance of `Pattern` with the given `options`. @param {String} `glob` @param {Object} `options` @param {Boolean} `isNegated` @api public
[ "Create", "an", "instance", "of", "Pattern", "with", "the", "given", "options", "." ]
9419fb8a112ca6554af0448cbb801c00953af8e5
https://github.com/micromatch/glob-fs/blob/9419fb8a112ca6554af0448cbb801c00953af8e5/lib/pattern.js#L30-L36
40,506
SilentCicero/ethereumjs-accounts
index.js
function(str){ if(_.isUndefined(str)) str = '00'; return String(str).length % 2 ? '0' + String(str) : String(str); }
javascript
function(str){ if(_.isUndefined(str)) str = '00'; return String(str).length % 2 ? '0' + String(str) : String(str); }
[ "function", "(", "str", ")", "{", "if", "(", "_", ".", "isUndefined", "(", "str", ")", ")", "str", "=", "'00'", ";", "return", "String", "(", "str", ")", ".", "length", "%", "2", "?", "'0'", "+", "String", "(", "str", ")", ":", "String", "(", "str", ")", ";", "}" ]
Pad the given string with a prefix zero, if length is uneven. @method (formatHex) @param {String} str The string to pad for use as hex @return {String} The padded or formatted string for use as a hex string
[ "Pad", "the", "given", "string", "with", "a", "prefix", "zero", "if", "length", "is", "uneven", "." ]
265e825fd3f4d841e039336b6be0b24cb54f4a2e
https://github.com/SilentCicero/ethereumjs-accounts/blob/265e825fd3f4d841e039336b6be0b24cb54f4a2e/index.js#L94-L99
40,507
SilentCicero/ethereumjs-accounts
index.js
function(num){ if(_.isUndefined(num) || num == 0) num = '00'; if(_.isString(num) || _.isNumber(num)) num = new BigNumber(String(num)); if(isBigNumber(num)) num = num.toString(16); return formatHex(num); }
javascript
function(num){ if(_.isUndefined(num) || num == 0) num = '00'; if(_.isString(num) || _.isNumber(num)) num = new BigNumber(String(num)); if(isBigNumber(num)) num = num.toString(16); return formatHex(num); }
[ "function", "(", "num", ")", "{", "if", "(", "_", ".", "isUndefined", "(", "num", ")", "||", "num", "==", "0", ")", "num", "=", "'00'", ";", "if", "(", "_", ".", "isString", "(", "num", ")", "||", "_", ".", "isNumber", "(", "num", ")", ")", "num", "=", "new", "BigNumber", "(", "String", "(", "num", ")", ")", ";", "if", "(", "isBigNumber", "(", "num", ")", ")", "num", "=", "num", ".", "toString", "(", "16", ")", ";", "return", "formatHex", "(", "num", ")", ";", "}" ]
Prepair numbers for raw transactions. @method (formatNumber) @param {Number|String|BigNumber} The object to be used as a number @return {String} The padded, toString hex value of the number
[ "Prepair", "numbers", "for", "raw", "transactions", "." ]
265e825fd3f4d841e039336b6be0b24cb54f4a2e
https://github.com/SilentCicero/ethereumjs-accounts/blob/265e825fd3f4d841e039336b6be0b24cb54f4a2e/index.js#L110-L121
40,508
SilentCicero/ethereumjs-accounts
index.js
function(addr, format){ if(_.isUndefined(format) || !_.isString(format)) format = 'hex'; if(_.isUndefined(addr) || !_.isString(addr)) addr = '0000000000000000000000000000000000000000'; if(addr.substr(0, 2) == '0x' && format == 'raw') addr = addr.substr(2); if(addr.substr(0, 2) != '0x' && format == 'hex') addr = '0x' + addr; return addr; }
javascript
function(addr, format){ if(_.isUndefined(format) || !_.isString(format)) format = 'hex'; if(_.isUndefined(addr) || !_.isString(addr)) addr = '0000000000000000000000000000000000000000'; if(addr.substr(0, 2) == '0x' && format == 'raw') addr = addr.substr(2); if(addr.substr(0, 2) != '0x' && format == 'hex') addr = '0x' + addr; return addr; }
[ "function", "(", "addr", ",", "format", ")", "{", "if", "(", "_", ".", "isUndefined", "(", "format", ")", "||", "!", "_", ".", "isString", "(", "format", ")", ")", "format", "=", "'hex'", ";", "if", "(", "_", ".", "isUndefined", "(", "addr", ")", "||", "!", "_", ".", "isString", "(", "addr", ")", ")", "addr", "=", "'0000000000000000000000000000000000000000'", ";", "if", "(", "addr", ".", "substr", "(", "0", ",", "2", ")", "==", "'0x'", "&&", "format", "==", "'raw'", ")", "addr", "=", "addr", ".", "substr", "(", "2", ")", ";", "if", "(", "addr", ".", "substr", "(", "0", ",", "2", ")", "!=", "'0x'", "&&", "format", "==", "'hex'", ")", "addr", "=", "'0x'", "+", "addr", ";", "return", "addr", ";", "}" ]
Prepair Ethereum address for either raw transactions or browser storage. @method (formatAddress) @param {String} addr An ethereum address to prep @param {String} format The format type (i.e. 'raw' or 'hex') @return {String} The prepaired ethereum address
[ "Prepair", "Ethereum", "address", "for", "either", "raw", "transactions", "or", "browser", "storage", "." ]
265e825fd3f4d841e039336b6be0b24cb54f4a2e
https://github.com/SilentCicero/ethereumjs-accounts/blob/265e825fd3f4d841e039336b6be0b24cb54f4a2e/index.js#L133-L148
40,509
SilentCicero/ethereumjs-accounts
index.js
function(length) { var charset = "abcdef0123456789"; var i; var result = ""; var isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]'; if(window.crypto && window.crypto.getRandomValues) { values = new Uint32Array(length); window.crypto.getRandomValues(values); for(i=0; i<length; i++) { result += charset[values[i] % charset.length]; } return result; } else if(isOpera) {//Opera's Math.random is secure, see http://lists.w3.org/Archives/Public/public-webcrypto/2013Jan/0063.html for(i=0; i<length; i++) { result += charset[Math.floor(Math.random()*charset.length)]; } return result; } else throw new Error("Your browser sucks and can't generate secure random numbers"); }
javascript
function(length) { var charset = "abcdef0123456789"; var i; var result = ""; var isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]'; if(window.crypto && window.crypto.getRandomValues) { values = new Uint32Array(length); window.crypto.getRandomValues(values); for(i=0; i<length; i++) { result += charset[values[i] % charset.length]; } return result; } else if(isOpera) {//Opera's Math.random is secure, see http://lists.w3.org/Archives/Public/public-webcrypto/2013Jan/0063.html for(i=0; i<length; i++) { result += charset[Math.floor(Math.random()*charset.length)]; } return result; } else throw new Error("Your browser sucks and can't generate secure random numbers"); }
[ "function", "(", "length", ")", "{", "var", "charset", "=", "\"abcdef0123456789\"", ";", "var", "i", ";", "var", "result", "=", "\"\"", ";", "var", "isOpera", "=", "Object", ".", "prototype", ".", "toString", ".", "call", "(", "window", ".", "opera", ")", "==", "'[object Opera]'", ";", "if", "(", "window", ".", "crypto", "&&", "window", ".", "crypto", ".", "getRandomValues", ")", "{", "values", "=", "new", "Uint32Array", "(", "length", ")", ";", "window", ".", "crypto", ".", "getRandomValues", "(", "values", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<", "length", ";", "i", "++", ")", "{", "result", "+=", "charset", "[", "values", "[", "i", "]", "%", "charset", ".", "length", "]", ";", "}", "return", "result", ";", "}", "else", "if", "(", "isOpera", ")", "{", "//Opera's Math.random is secure, see http://lists.w3.org/Archives/Public/public-webcrypto/2013Jan/0063.html", "for", "(", "i", "=", "0", ";", "i", "<", "length", ";", "i", "++", ")", "{", "result", "+=", "charset", "[", "Math", ".", "floor", "(", "Math", ".", "random", "(", ")", "*", "charset", ".", "length", ")", "]", ";", "}", "return", "result", ";", "}", "else", "throw", "new", "Error", "(", "\"Your browser sucks and can't generate secure random numbers\"", ")", ";", "}" ]
Generate 16 random alpha numeric bytes. @method (randomBytes) @param {Number} length The string length that should be generated @return {String} A 16 char/UTF-8 byte string of random alpha-numeric characters
[ "Generate", "16", "random", "alpha", "numeric", "bytes", "." ]
265e825fd3f4d841e039336b6be0b24cb54f4a2e
https://github.com/SilentCicero/ethereumjs-accounts/blob/265e825fd3f4d841e039336b6be0b24cb54f4a2e/index.js#L159-L178
40,510
SilentCicero/ethereumjs-accounts
index.js
function(value){ if(_.isUndefined(value) || !_.isObject(value)) return false; return (value instanceof BigNumber) ? true : false; }
javascript
function(value){ if(_.isUndefined(value) || !_.isObject(value)) return false; return (value instanceof BigNumber) ? true : false; }
[ "function", "(", "value", ")", "{", "if", "(", "_", ".", "isUndefined", "(", "value", ")", "||", "!", "_", ".", "isObject", "(", "value", ")", ")", "return", "false", ";", "return", "(", "value", "instanceof", "BigNumber", ")", "?", "true", ":", "false", ";", "}" ]
Is the object provided a Bignumber object. @method (isBigNumber)
[ "Is", "the", "object", "provided", "a", "Bignumber", "object", "." ]
265e825fd3f4d841e039336b6be0b24cb54f4a2e
https://github.com/SilentCicero/ethereumjs-accounts/blob/265e825fd3f4d841e039336b6be0b24cb54f4a2e/index.js#L187-L192
40,511
SilentCicero/ethereumjs-accounts
index.js
function(context){ Object.defineProperty(context, 'length', { get: function() { var count = 0; // count valid accounts in browser storage _.each(this.get(), function(account, accountIndex){ if(_.isUndefined(account) || !_.isObject(account) || _.isString(account)) return; if(!_.has(account, 'encrypted') || !_.has(account, 'private')) return; count += 1; }); return count; } }); }
javascript
function(context){ Object.defineProperty(context, 'length', { get: function() { var count = 0; // count valid accounts in browser storage _.each(this.get(), function(account, accountIndex){ if(_.isUndefined(account) || !_.isObject(account) || _.isString(account)) return; if(!_.has(account, 'encrypted') || !_.has(account, 'private')) return; count += 1; }); return count; } }); }
[ "function", "(", "context", ")", "{", "Object", ".", "defineProperty", "(", "context", ",", "'length'", ",", "{", "get", ":", "function", "(", ")", "{", "var", "count", "=", "0", ";", "// count valid accounts in browser storage", "_", ".", "each", "(", "this", ".", "get", "(", ")", ",", "function", "(", "account", ",", "accountIndex", ")", "{", "if", "(", "_", ".", "isUndefined", "(", "account", ")", "||", "!", "_", ".", "isObject", "(", "account", ")", "||", "_", ".", "isString", "(", "account", ")", ")", "return", ";", "if", "(", "!", "_", ".", "has", "(", "account", ",", "'encrypted'", ")", "||", "!", "_", ".", "has", "(", "account", ",", "'private'", ")", ")", "return", ";", "count", "+=", "1", ";", "}", ")", ";", "return", "count", ";", "}", "}", ")", ";", "}" ]
Define object properties such as 'length'. @method (defineProperties) @param {Object} context The Accounts object context
[ "Define", "object", "properties", "such", "as", "length", "." ]
265e825fd3f4d841e039336b6be0b24cb54f4a2e
https://github.com/SilentCicero/ethereumjs-accounts/blob/265e825fd3f4d841e039336b6be0b24cb54f4a2e/index.js#L214-L236
40,512
raymondsze/create-react-scripts
packages/create-react-scripts/compose.js
pipe
function pipe(funcs) { return function pipeRewire(config) { const args = Array.prototype.slice.call(arguments, 1); (funcs || []).forEach(func => { if (func && typeof func === 'function') { // slice the first argument "config" config = func.apply(this, [config].concat(args)); } }); return config; }; }
javascript
function pipe(funcs) { return function pipeRewire(config) { const args = Array.prototype.slice.call(arguments, 1); (funcs || []).forEach(func => { if (func && typeof func === 'function') { // slice the first argument "config" config = func.apply(this, [config].concat(args)); } }); return config; }; }
[ "function", "pipe", "(", "funcs", ")", "{", "return", "function", "pipeRewire", "(", "config", ")", "{", "const", "args", "=", "Array", ".", "prototype", ".", "slice", ".", "call", "(", "arguments", ",", "1", ")", ";", "(", "funcs", "||", "[", "]", ")", ".", "forEach", "(", "func", "=>", "{", "if", "(", "func", "&&", "typeof", "func", "===", "'function'", ")", "{", "// slice the first argument \"config\"", "config", "=", "func", ".", "apply", "(", "this", ",", "[", "config", "]", ".", "concat", "(", "args", ")", ")", ";", "}", "}", ")", ";", "return", "config", ";", "}", ";", "}" ]
pipe rewire do not use recursion here to prevent maximum call stack
[ "pipe", "rewire", "do", "not", "use", "recursion", "here", "to", "prevent", "maximum", "call", "stack" ]
14c0b8bcf7dcf69bd7c6fa394a5d27f3b25f2ad6
https://github.com/raymondsze/create-react-scripts/blob/14c0b8bcf7dcf69bd7c6fa394a5d27f3b25f2ad6/packages/create-react-scripts/compose.js#L7-L18
40,513
raymondsze/create-react-scripts
packages/create-react-scripts/compose.js
mergeScripts
function mergeScripts(crsScripts) { const scripts = { build: path.join(__dirname, 'scripts/build.js'), start: path.join(__dirname, 'scripts/start.js'), test: path.join(__dirname, 'scripts/test.js'), }; crsScripts.forEach(scriptSet => { Object.assign(scripts, scriptSet || {}); }); return scripts; }
javascript
function mergeScripts(crsScripts) { const scripts = { build: path.join(__dirname, 'scripts/build.js'), start: path.join(__dirname, 'scripts/start.js'), test: path.join(__dirname, 'scripts/test.js'), }; crsScripts.forEach(scriptSet => { Object.assign(scripts, scriptSet || {}); }); return scripts; }
[ "function", "mergeScripts", "(", "crsScripts", ")", "{", "const", "scripts", "=", "{", "build", ":", "path", ".", "join", "(", "__dirname", ",", "'scripts/build.js'", ")", ",", "start", ":", "path", ".", "join", "(", "__dirname", ",", "'scripts/start.js'", ")", ",", "test", ":", "path", ".", "join", "(", "__dirname", ",", "'scripts/test.js'", ")", ",", "}", ";", "crsScripts", ".", "forEach", "(", "scriptSet", "=>", "{", "Object", ".", "assign", "(", "scripts", ",", "scriptSet", "||", "{", "}", ")", ";", "}", ")", ";", "return", "scripts", ";", "}" ]
merge scripts and remove the duplicates do not use recursion here to prevent maximum call stack
[ "merge", "scripts", "and", "remove", "the", "duplicates", "do", "not", "use", "recursion", "here", "to", "prevent", "maximum", "call", "stack" ]
14c0b8bcf7dcf69bd7c6fa394a5d27f3b25f2ad6
https://github.com/raymondsze/create-react-scripts/blob/14c0b8bcf7dcf69bd7c6fa394a5d27f3b25f2ad6/packages/create-react-scripts/compose.js#L22-L32
40,514
raymondsze/create-react-scripts
packages/create-react-scripts/compose.js
compose
function compose(...args) { // convert pipe to compose by reverse the array const crsConfigs = args.slice(0).reverse(); const crsConfig = { env: pipe(crsConfigs.map(c => c.env)), paths: pipe(crsConfigs.map(c => c.paths)), webpack: pipe(crsConfigs.map(c => c.webpack)), devServer: pipe(crsConfigs.map(c => c.devServer)), jest: pipe(crsConfigs.map(c => c.jest)), scripts: mergeScripts(crsConfigs.map(c => c.scripts)), }; return crsConfig; }
javascript
function compose(...args) { // convert pipe to compose by reverse the array const crsConfigs = args.slice(0).reverse(); const crsConfig = { env: pipe(crsConfigs.map(c => c.env)), paths: pipe(crsConfigs.map(c => c.paths)), webpack: pipe(crsConfigs.map(c => c.webpack)), devServer: pipe(crsConfigs.map(c => c.devServer)), jest: pipe(crsConfigs.map(c => c.jest)), scripts: mergeScripts(crsConfigs.map(c => c.scripts)), }; return crsConfig; }
[ "function", "compose", "(", "...", "args", ")", "{", "// convert pipe to compose by reverse the array", "const", "crsConfigs", "=", "args", ".", "slice", "(", "0", ")", ".", "reverse", "(", ")", ";", "const", "crsConfig", "=", "{", "env", ":", "pipe", "(", "crsConfigs", ".", "map", "(", "c", "=>", "c", ".", "env", ")", ")", ",", "paths", ":", "pipe", "(", "crsConfigs", ".", "map", "(", "c", "=>", "c", ".", "paths", ")", ")", ",", "webpack", ":", "pipe", "(", "crsConfigs", ".", "map", "(", "c", "=>", "c", ".", "webpack", ")", ")", ",", "devServer", ":", "pipe", "(", "crsConfigs", ".", "map", "(", "c", "=>", "c", ".", "devServer", ")", ")", ",", "jest", ":", "pipe", "(", "crsConfigs", ".", "map", "(", "c", "=>", "c", ".", "jest", ")", ")", ",", "scripts", ":", "mergeScripts", "(", "crsConfigs", ".", "map", "(", "c", "=>", "c", ".", "scripts", ")", ")", ",", "}", ";", "return", "crsConfig", ";", "}" ]
this function is used to compose multiple configs into one config
[ "this", "function", "is", "used", "to", "compose", "multiple", "configs", "into", "one", "config" ]
14c0b8bcf7dcf69bd7c6fa394a5d27f3b25f2ad6
https://github.com/raymondsze/create-react-scripts/blob/14c0b8bcf7dcf69bd7c6fa394a5d27f3b25f2ad6/packages/create-react-scripts/compose.js#L35-L47
40,515
raymondsze/create-react-scripts
packages/create-react-scripts/index.js
createReactScripts
function createReactScripts(scriptsDir) { // obtain the crs.config path // we allow user to use crs.config under app directory instead if scriptsDir is not provided // in this case, we do not allow customize new scripts and template const crsConfigPath = path.join(scriptsDir || process.cwd(), 'crs.config.js'); // append args so we can extract the argument after --crs-config // this is needed as we need to require the config inside script which is run by 'spawn' const crsConfigArgs = ['--crs-config']; // if crs-config exists, append to after --crs-config if (fs.existsSync(crsConfigPath)) { crsConfigArgs.push(crsConfigPath); } const spawn = require('react-dev-utils/crossSpawn'); const args = process.argv.slice(2); // should support customize scripts let crsConfig = {}; if (fs.existsSync(crsConfigPath)) { crsConfig = require(crsConfigPath); } // here eject is removed from the scripts. // it is not expected user to 'eject' while using this library. const scriptsMap = { build: path.join(__dirname, 'scripts/build.js'), start: path.join(__dirname, 'scripts/start.js'), test: path.join(__dirname, 'scripts/test.js'), }; // obtain all allowed scripts Object.assign(scriptsMap, (crsConfig || {}).scripts || {}); const scripts = Object.keys(scriptsMap); // find the script index const scriptIndex = args.findIndex(x => scripts.indexOf(x) !== -1); // obtain the script const script = scriptIndex === -1 ? args[0] : args[scriptIndex]; // extract out the node arguments const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : []; // if script is valid if (scriptsMap[script]) { // the js file path of script const scriptPath = scriptsMap[script]; // try to validate the script path is resolvable if (!fs.existsSync(scriptPath)) { console.log('Unknown script "' + script + '".'); } // execute the script like what reac-scripts do const result = spawn.sync( 'node', nodeArgs .concat(require.resolve(scriptPath)) .concat(args.slice(scriptIndex + 1)) .concat(crsConfigArgs), { stdio: 'inherit' } ); if (result.signal) { if (result.signal === 'SIGKILL') { console.log( 'The build failed because the process exited too early. ' + 'This probably means the system ran out of memory or someone called ' + '`kill -9` on the process.' ); } else if (result.signal === 'SIGTERM') { console.log( 'The build failed because the process exited too early. ' + 'Someone might have called `kill` or `killall`, or the system could ' + 'be shutting down.' ); } process.exit(1); } process.exit(result.status); return; } console.log('Unknown script "' + script + '".'); console.log('Perhaps you need to update react-scripts?'); console.log( 'See: https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#updating-to-new-releases' ); }
javascript
function createReactScripts(scriptsDir) { // obtain the crs.config path // we allow user to use crs.config under app directory instead if scriptsDir is not provided // in this case, we do not allow customize new scripts and template const crsConfigPath = path.join(scriptsDir || process.cwd(), 'crs.config.js'); // append args so we can extract the argument after --crs-config // this is needed as we need to require the config inside script which is run by 'spawn' const crsConfigArgs = ['--crs-config']; // if crs-config exists, append to after --crs-config if (fs.existsSync(crsConfigPath)) { crsConfigArgs.push(crsConfigPath); } const spawn = require('react-dev-utils/crossSpawn'); const args = process.argv.slice(2); // should support customize scripts let crsConfig = {}; if (fs.existsSync(crsConfigPath)) { crsConfig = require(crsConfigPath); } // here eject is removed from the scripts. // it is not expected user to 'eject' while using this library. const scriptsMap = { build: path.join(__dirname, 'scripts/build.js'), start: path.join(__dirname, 'scripts/start.js'), test: path.join(__dirname, 'scripts/test.js'), }; // obtain all allowed scripts Object.assign(scriptsMap, (crsConfig || {}).scripts || {}); const scripts = Object.keys(scriptsMap); // find the script index const scriptIndex = args.findIndex(x => scripts.indexOf(x) !== -1); // obtain the script const script = scriptIndex === -1 ? args[0] : args[scriptIndex]; // extract out the node arguments const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : []; // if script is valid if (scriptsMap[script]) { // the js file path of script const scriptPath = scriptsMap[script]; // try to validate the script path is resolvable if (!fs.existsSync(scriptPath)) { console.log('Unknown script "' + script + '".'); } // execute the script like what reac-scripts do const result = spawn.sync( 'node', nodeArgs .concat(require.resolve(scriptPath)) .concat(args.slice(scriptIndex + 1)) .concat(crsConfigArgs), { stdio: 'inherit' } ); if (result.signal) { if (result.signal === 'SIGKILL') { console.log( 'The build failed because the process exited too early. ' + 'This probably means the system ran out of memory or someone called ' + '`kill -9` on the process.' ); } else if (result.signal === 'SIGTERM') { console.log( 'The build failed because the process exited too early. ' + 'Someone might have called `kill` or `killall`, or the system could ' + 'be shutting down.' ); } process.exit(1); } process.exit(result.status); return; } console.log('Unknown script "' + script + '".'); console.log('Perhaps you need to update react-scripts?'); console.log( 'See: https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#updating-to-new-releases' ); }
[ "function", "createReactScripts", "(", "scriptsDir", ")", "{", "// obtain the crs.config path", "// we allow user to use crs.config under app directory instead if scriptsDir is not provided", "// in this case, we do not allow customize new scripts and template", "const", "crsConfigPath", "=", "path", ".", "join", "(", "scriptsDir", "||", "process", ".", "cwd", "(", ")", ",", "'crs.config.js'", ")", ";", "// append args so we can extract the argument after --crs-config", "// this is needed as we need to require the config inside script which is run by 'spawn'", "const", "crsConfigArgs", "=", "[", "'--crs-config'", "]", ";", "// if crs-config exists, append to after --crs-config", "if", "(", "fs", ".", "existsSync", "(", "crsConfigPath", ")", ")", "{", "crsConfigArgs", ".", "push", "(", "crsConfigPath", ")", ";", "}", "const", "spawn", "=", "require", "(", "'react-dev-utils/crossSpawn'", ")", ";", "const", "args", "=", "process", ".", "argv", ".", "slice", "(", "2", ")", ";", "// should support customize scripts", "let", "crsConfig", "=", "{", "}", ";", "if", "(", "fs", ".", "existsSync", "(", "crsConfigPath", ")", ")", "{", "crsConfig", "=", "require", "(", "crsConfigPath", ")", ";", "}", "// here eject is removed from the scripts.", "// it is not expected user to 'eject' while using this library.", "const", "scriptsMap", "=", "{", "build", ":", "path", ".", "join", "(", "__dirname", ",", "'scripts/build.js'", ")", ",", "start", ":", "path", ".", "join", "(", "__dirname", ",", "'scripts/start.js'", ")", ",", "test", ":", "path", ".", "join", "(", "__dirname", ",", "'scripts/test.js'", ")", ",", "}", ";", "// obtain all allowed scripts", "Object", ".", "assign", "(", "scriptsMap", ",", "(", "crsConfig", "||", "{", "}", ")", ".", "scripts", "||", "{", "}", ")", ";", "const", "scripts", "=", "Object", ".", "keys", "(", "scriptsMap", ")", ";", "// find the script index", "const", "scriptIndex", "=", "args", ".", "findIndex", "(", "x", "=>", "scripts", ".", "indexOf", "(", "x", ")", "!==", "-", "1", ")", ";", "// obtain the script", "const", "script", "=", "scriptIndex", "===", "-", "1", "?", "args", "[", "0", "]", ":", "args", "[", "scriptIndex", "]", ";", "// extract out the node arguments", "const", "nodeArgs", "=", "scriptIndex", ">", "0", "?", "args", ".", "slice", "(", "0", ",", "scriptIndex", ")", ":", "[", "]", ";", "// if script is valid", "if", "(", "scriptsMap", "[", "script", "]", ")", "{", "// the js file path of script", "const", "scriptPath", "=", "scriptsMap", "[", "script", "]", ";", "// try to validate the script path is resolvable", "if", "(", "!", "fs", ".", "existsSync", "(", "scriptPath", ")", ")", "{", "console", ".", "log", "(", "'Unknown script \"'", "+", "script", "+", "'\".'", ")", ";", "}", "// execute the script like what reac-scripts do", "const", "result", "=", "spawn", ".", "sync", "(", "'node'", ",", "nodeArgs", ".", "concat", "(", "require", ".", "resolve", "(", "scriptPath", ")", ")", ".", "concat", "(", "args", ".", "slice", "(", "scriptIndex", "+", "1", ")", ")", ".", "concat", "(", "crsConfigArgs", ")", ",", "{", "stdio", ":", "'inherit'", "}", ")", ";", "if", "(", "result", ".", "signal", ")", "{", "if", "(", "result", ".", "signal", "===", "'SIGKILL'", ")", "{", "console", ".", "log", "(", "'The build failed because the process exited too early. '", "+", "'This probably means the system ran out of memory or someone called '", "+", "'`kill -9` on the process.'", ")", ";", "}", "else", "if", "(", "result", ".", "signal", "===", "'SIGTERM'", ")", "{", "console", ".", "log", "(", "'The build failed because the process exited too early. '", "+", "'Someone might have called `kill` or `killall`, or the system could '", "+", "'be shutting down.'", ")", ";", "}", "process", ".", "exit", "(", "1", ")", ";", "}", "process", ".", "exit", "(", "result", ".", "status", ")", ";", "return", ";", "}", "console", ".", "log", "(", "'Unknown script \"'", "+", "script", "+", "'\".'", ")", ";", "console", ".", "log", "(", "'Perhaps you need to update react-scripts?'", ")", ";", "console", ".", "log", "(", "'See: https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#updating-to-new-releases'", ")", ";", "}" ]
This function is used to customize the react-scripts
[ "This", "function", "is", "used", "to", "customize", "the", "react", "-", "scripts" ]
14c0b8bcf7dcf69bd7c6fa394a5d27f3b25f2ad6
https://github.com/raymondsze/create-react-scripts/blob/14c0b8bcf7dcf69bd7c6fa394a5d27f3b25f2ad6/packages/create-react-scripts/index.js#L14-L97
40,516
raymondsze/create-react-scripts
packages/create-react-scripts-ssr/scripts/build-server.js
buildServer
function buildServer() { console.log(); console.log(`${chalk.cyan('SERVER-SIDE')}`); console.log('==========================================================='); fs.emptyDirSync(paths.appServerBuild); console.log('Creating a server-side production build...'); let compiler = webpack(serverlize(paths, config)); return new Promise((resolve, reject) => { compiler.run((err, stats) => { if (err) { return reject(err); } const messages = formatWebpackMessages(stats.toJson({}, true)); if (messages.errors.length) { // Only keep the first error. Others are often indicative // of the same problem, but confuse the reader with noise. if (messages.errors.length > 1) { messages.errors.length = 1; } return reject(new Error(messages.errors.join('\n\n'))); } if ( process.env.CI && (typeof process.env.CI !== 'string' || process.env.CI.toLowerCase() !== 'false') && messages.warnings.length ) { console.log( chalk.yellow( '\nTreating warnings as errors because process.env.CI = true.\n' + 'Most CI servers set it automatically.\n' ) ); return reject(new Error(messages.warnings.join('\n\n'))); } return resolve({ stats, warnings: messages.warnings, }); }); }).then( ({ stats, warnings }) => { if (warnings.length) { console.log(chalk.yellow('Compiled with warnings.\n')); console.log(warnings.join('\n\n')); console.log( '\nSearch for the ' + chalk.underline(chalk.yellow('keywords')) + ' to learn more about each warning.' ); console.log( 'To ignore, add ' + chalk.cyan('// eslint-disable-next-line') + ' to the line before.\n' ); } else { console.log(chalk.green('Compiled successfully.\n')); } console.log(`The ${chalk.cyan(path.relative(process.cwd(), paths.appServerBuild))} folder is ready.`); console.log(`You may run it in ${chalk.cyan('node')} environment`); console.log(); console.log(` ${chalk.cyan('node')} ${chalk.cyan(path.relative(process.cwd(), paths.appServerBuild))}`); console.log(); }, err => { console.log(chalk.red('Failed to compile.\n')); printBuildError(err); process.exit(1); } ); }
javascript
function buildServer() { console.log(); console.log(`${chalk.cyan('SERVER-SIDE')}`); console.log('==========================================================='); fs.emptyDirSync(paths.appServerBuild); console.log('Creating a server-side production build...'); let compiler = webpack(serverlize(paths, config)); return new Promise((resolve, reject) => { compiler.run((err, stats) => { if (err) { return reject(err); } const messages = formatWebpackMessages(stats.toJson({}, true)); if (messages.errors.length) { // Only keep the first error. Others are often indicative // of the same problem, but confuse the reader with noise. if (messages.errors.length > 1) { messages.errors.length = 1; } return reject(new Error(messages.errors.join('\n\n'))); } if ( process.env.CI && (typeof process.env.CI !== 'string' || process.env.CI.toLowerCase() !== 'false') && messages.warnings.length ) { console.log( chalk.yellow( '\nTreating warnings as errors because process.env.CI = true.\n' + 'Most CI servers set it automatically.\n' ) ); return reject(new Error(messages.warnings.join('\n\n'))); } return resolve({ stats, warnings: messages.warnings, }); }); }).then( ({ stats, warnings }) => { if (warnings.length) { console.log(chalk.yellow('Compiled with warnings.\n')); console.log(warnings.join('\n\n')); console.log( '\nSearch for the ' + chalk.underline(chalk.yellow('keywords')) + ' to learn more about each warning.' ); console.log( 'To ignore, add ' + chalk.cyan('// eslint-disable-next-line') + ' to the line before.\n' ); } else { console.log(chalk.green('Compiled successfully.\n')); } console.log(`The ${chalk.cyan(path.relative(process.cwd(), paths.appServerBuild))} folder is ready.`); console.log(`You may run it in ${chalk.cyan('node')} environment`); console.log(); console.log(` ${chalk.cyan('node')} ${chalk.cyan(path.relative(process.cwd(), paths.appServerBuild))}`); console.log(); }, err => { console.log(chalk.red('Failed to compile.\n')); printBuildError(err); process.exit(1); } ); }
[ "function", "buildServer", "(", ")", "{", "console", ".", "log", "(", ")", ";", "console", ".", "log", "(", "`", "${", "chalk", ".", "cyan", "(", "'SERVER-SIDE'", ")", "}", "`", ")", ";", "console", ".", "log", "(", "'==========================================================='", ")", ";", "fs", ".", "emptyDirSync", "(", "paths", ".", "appServerBuild", ")", ";", "console", ".", "log", "(", "'Creating a server-side production build...'", ")", ";", "let", "compiler", "=", "webpack", "(", "serverlize", "(", "paths", ",", "config", ")", ")", ";", "return", "new", "Promise", "(", "(", "resolve", ",", "reject", ")", "=>", "{", "compiler", ".", "run", "(", "(", "err", ",", "stats", ")", "=>", "{", "if", "(", "err", ")", "{", "return", "reject", "(", "err", ")", ";", "}", "const", "messages", "=", "formatWebpackMessages", "(", "stats", ".", "toJson", "(", "{", "}", ",", "true", ")", ")", ";", "if", "(", "messages", ".", "errors", ".", "length", ")", "{", "// Only keep the first error. Others are often indicative", "// of the same problem, but confuse the reader with noise.", "if", "(", "messages", ".", "errors", ".", "length", ">", "1", ")", "{", "messages", ".", "errors", ".", "length", "=", "1", ";", "}", "return", "reject", "(", "new", "Error", "(", "messages", ".", "errors", ".", "join", "(", "'\\n\\n'", ")", ")", ")", ";", "}", "if", "(", "process", ".", "env", ".", "CI", "&&", "(", "typeof", "process", ".", "env", ".", "CI", "!==", "'string'", "||", "process", ".", "env", ".", "CI", ".", "toLowerCase", "(", ")", "!==", "'false'", ")", "&&", "messages", ".", "warnings", ".", "length", ")", "{", "console", ".", "log", "(", "chalk", ".", "yellow", "(", "'\\nTreating warnings as errors because process.env.CI = true.\\n'", "+", "'Most CI servers set it automatically.\\n'", ")", ")", ";", "return", "reject", "(", "new", "Error", "(", "messages", ".", "warnings", ".", "join", "(", "'\\n\\n'", ")", ")", ")", ";", "}", "return", "resolve", "(", "{", "stats", ",", "warnings", ":", "messages", ".", "warnings", ",", "}", ")", ";", "}", ")", ";", "}", ")", ".", "then", "(", "(", "{", "stats", ",", "warnings", "}", ")", "=>", "{", "if", "(", "warnings", ".", "length", ")", "{", "console", ".", "log", "(", "chalk", ".", "yellow", "(", "'Compiled with warnings.\\n'", ")", ")", ";", "console", ".", "log", "(", "warnings", ".", "join", "(", "'\\n\\n'", ")", ")", ";", "console", ".", "log", "(", "'\\nSearch for the '", "+", "chalk", ".", "underline", "(", "chalk", ".", "yellow", "(", "'keywords'", ")", ")", "+", "' to learn more about each warning.'", ")", ";", "console", ".", "log", "(", "'To ignore, add '", "+", "chalk", ".", "cyan", "(", "'// eslint-disable-next-line'", ")", "+", "' to the line before.\\n'", ")", ";", "}", "else", "{", "console", ".", "log", "(", "chalk", ".", "green", "(", "'Compiled successfully.\\n'", ")", ")", ";", "}", "console", ".", "log", "(", "`", "${", "chalk", ".", "cyan", "(", "path", ".", "relative", "(", "process", ".", "cwd", "(", ")", ",", "paths", ".", "appServerBuild", ")", ")", "}", "`", ")", ";", "console", ".", "log", "(", "`", "${", "chalk", ".", "cyan", "(", "'node'", ")", "}", "`", ")", ";", "console", ".", "log", "(", ")", ";", "console", ".", "log", "(", "`", "${", "chalk", ".", "cyan", "(", "'node'", ")", "}", "${", "chalk", ".", "cyan", "(", "path", ".", "relative", "(", "process", ".", "cwd", "(", ")", ",", "paths", ".", "appServerBuild", ")", ")", "}", "`", ")", ";", "console", ".", "log", "(", ")", ";", "}", ",", "err", "=>", "{", "console", ".", "log", "(", "chalk", ".", "red", "(", "'Failed to compile.\\n'", ")", ")", ";", "printBuildError", "(", "err", ")", ";", "process", ".", "exit", "(", "1", ")", ";", "}", ")", ";", "}" ]
we can run the server-side build
[ "we", "can", "run", "the", "server", "-", "side", "build" ]
14c0b8bcf7dcf69bd7c6fa394a5d27f3b25f2ad6
https://github.com/raymondsze/create-react-scripts/blob/14c0b8bcf7dcf69bd7c6fa394a5d27f3b25f2ad6/packages/create-react-scripts-ssr/scripts/build-server.js#L49-L120
40,517
Jam3/three-buffer-vertex-data
index.js
rebuildAttribute
function rebuildAttribute (attrib, data, itemSize) { if (attrib.itemSize !== itemSize) return true if (!attrib.array) return true var attribLength = attrib.array.length if (Array.isArray(data) && Array.isArray(data[0])) { // [ [ x, y, z ] ] return attribLength !== data.length * itemSize } else { // [ x, y, z ] return attribLength !== data.length } return false }
javascript
function rebuildAttribute (attrib, data, itemSize) { if (attrib.itemSize !== itemSize) return true if (!attrib.array) return true var attribLength = attrib.array.length if (Array.isArray(data) && Array.isArray(data[0])) { // [ [ x, y, z ] ] return attribLength !== data.length * itemSize } else { // [ x, y, z ] return attribLength !== data.length } return false }
[ "function", "rebuildAttribute", "(", "attrib", ",", "data", ",", "itemSize", ")", "{", "if", "(", "attrib", ".", "itemSize", "!==", "itemSize", ")", "return", "true", "if", "(", "!", "attrib", ".", "array", ")", "return", "true", "var", "attribLength", "=", "attrib", ".", "array", ".", "length", "if", "(", "Array", ".", "isArray", "(", "data", ")", "&&", "Array", ".", "isArray", "(", "data", "[", "0", "]", ")", ")", "{", "// [ [ x, y, z ] ]", "return", "attribLength", "!==", "data", ".", "length", "*", "itemSize", "}", "else", "{", "// [ x, y, z ]", "return", "attribLength", "!==", "data", ".", "length", "}", "return", "false", "}" ]
Test whether the attribute needs to be re-created, returns false if we can re-use it as-is.
[ "Test", "whether", "the", "attribute", "needs", "to", "be", "re", "-", "created", "returns", "false", "if", "we", "can", "re", "-", "use", "it", "as", "-", "is", "." ]
c5318e2b6697c40920f3abc9b02a8ac979d330ee
https://github.com/Jam3/three-buffer-vertex-data/blob/c5318e2b6697c40920f3abc9b02a8ac979d330ee/index.js#L86-L98
40,518
remarkjs/remark-rehype
index.js
bridge
function bridge(destination, options) { return transformer function transformer(node, file, next) { destination.run(mdast2hast(node, options), file, done) function done(err) { next(err) } } }
javascript
function bridge(destination, options) { return transformer function transformer(node, file, next) { destination.run(mdast2hast(node, options), file, done) function done(err) { next(err) } } }
[ "function", "bridge", "(", "destination", ",", "options", ")", "{", "return", "transformer", "function", "transformer", "(", "node", ",", "file", ",", "next", ")", "{", "destination", ".", "run", "(", "mdast2hast", "(", "node", ",", "options", ")", ",", "file", ",", "done", ")", "function", "done", "(", "err", ")", "{", "next", "(", "err", ")", "}", "}", "}" ]
Bridge-mode. Runs the destination with the new hast tree.
[ "Bridge", "-", "mode", ".", "Runs", "the", "destination", "with", "the", "new", "hast", "tree", "." ]
07469598e3a2c794f51e0741b8213066b3c702c9
https://github.com/remarkjs/remark-rehype/blob/07469598e3a2c794f51e0741b8213066b3c702c9/index.js#L20-L30
40,519
Wtower/ng-gentelella
build/js/index.min.js
drawDonutHole
function drawDonutHole(layer) { if (options.series.pie.innerRadius > 0) { // subtract the center layer.save(); var innerRadius = options.series.pie.innerRadius > 1 ? options.series.pie.innerRadius : maxRadius * options.series.pie.innerRadius; layer.globalCompositeOperation = "destination-out"; // this does not work with excanvas, but it will fall back to using the stroke color layer.beginPath(); layer.fillStyle = options.series.pie.stroke.color; layer.arc(0, 0, innerRadius, 0, Math.PI * 2, false); layer.fill(); layer.closePath(); layer.restore(); // add inner stroke layer.save(); layer.beginPath(); layer.strokeStyle = options.series.pie.stroke.color; layer.arc(0, 0, innerRadius, 0, Math.PI * 2, false); layer.stroke(); layer.closePath(); layer.restore(); // TODO: add extra shadow inside hole (with a mask) if the pie is tilted. } }
javascript
function drawDonutHole(layer) { if (options.series.pie.innerRadius > 0) { // subtract the center layer.save(); var innerRadius = options.series.pie.innerRadius > 1 ? options.series.pie.innerRadius : maxRadius * options.series.pie.innerRadius; layer.globalCompositeOperation = "destination-out"; // this does not work with excanvas, but it will fall back to using the stroke color layer.beginPath(); layer.fillStyle = options.series.pie.stroke.color; layer.arc(0, 0, innerRadius, 0, Math.PI * 2, false); layer.fill(); layer.closePath(); layer.restore(); // add inner stroke layer.save(); layer.beginPath(); layer.strokeStyle = options.series.pie.stroke.color; layer.arc(0, 0, innerRadius, 0, Math.PI * 2, false); layer.stroke(); layer.closePath(); layer.restore(); // TODO: add extra shadow inside hole (with a mask) if the pie is tilted. } }
[ "function", "drawDonutHole", "(", "layer", ")", "{", "if", "(", "options", ".", "series", ".", "pie", ".", "innerRadius", ">", "0", ")", "{", "// subtract the center", "layer", ".", "save", "(", ")", ";", "var", "innerRadius", "=", "options", ".", "series", ".", "pie", ".", "innerRadius", ">", "1", "?", "options", ".", "series", ".", "pie", ".", "innerRadius", ":", "maxRadius", "*", "options", ".", "series", ".", "pie", ".", "innerRadius", ";", "layer", ".", "globalCompositeOperation", "=", "\"destination-out\"", ";", "// this does not work with excanvas, but it will fall back to using the stroke color", "layer", ".", "beginPath", "(", ")", ";", "layer", ".", "fillStyle", "=", "options", ".", "series", ".", "pie", ".", "stroke", ".", "color", ";", "layer", ".", "arc", "(", "0", ",", "0", ",", "innerRadius", ",", "0", ",", "Math", ".", "PI", "*", "2", ",", "false", ")", ";", "layer", ".", "fill", "(", ")", ";", "layer", ".", "closePath", "(", ")", ";", "layer", ".", "restore", "(", ")", ";", "// add inner stroke", "layer", ".", "save", "(", ")", ";", "layer", ".", "beginPath", "(", ")", ";", "layer", ".", "strokeStyle", "=", "options", ".", "series", ".", "pie", ".", "stroke", ".", "color", ";", "layer", ".", "arc", "(", "0", ",", "0", ",", "innerRadius", ",", "0", ",", "Math", ".", "PI", "*", "2", ",", "false", ")", ";", "layer", ".", "stroke", "(", ")", ";", "layer", ".", "closePath", "(", ")", ";", "layer", ".", "restore", "(", ")", ";", "// TODO: add extra shadow inside hole (with a mask) if the pie is tilted.", "}", "}" ]
end draw function Placed here because it needs to be accessed from multiple locations
[ "end", "draw", "function", "Placed", "here", "because", "it", "needs", "to", "be", "accessed", "from", "multiple", "locations" ]
3c45611cfa200e660aa497ba82d191231163487b
https://github.com/Wtower/ng-gentelella/blob/3c45611cfa200e660aa497ba82d191231163487b/build/js/index.min.js#L58078-L58105
40,520
Wtower/ng-gentelella
build/js/index.min.js
makeUtcWrapper
function makeUtcWrapper(d) { function addProxyMethod(sourceObj, sourceMethod, targetObj, targetMethod) { sourceObj[sourceMethod] = function() { return targetObj[targetMethod].apply(targetObj, arguments); }; }; var utc = { date: d }; // support strftime, if found if (d.strftime != undefined) { addProxyMethod(utc, "strftime", d, "strftime"); } addProxyMethod(utc, "getTime", d, "getTime"); addProxyMethod(utc, "setTime", d, "setTime"); var props = ["Date", "Day", "FullYear", "Hours", "Milliseconds", "Minutes", "Month", "Seconds"]; for (var p = 0; p < props.length; p++) { addProxyMethod(utc, "get" + props[p], d, "getUTC" + props[p]); addProxyMethod(utc, "set" + props[p], d, "setUTC" + props[p]); } return utc; }
javascript
function makeUtcWrapper(d) { function addProxyMethod(sourceObj, sourceMethod, targetObj, targetMethod) { sourceObj[sourceMethod] = function() { return targetObj[targetMethod].apply(targetObj, arguments); }; }; var utc = { date: d }; // support strftime, if found if (d.strftime != undefined) { addProxyMethod(utc, "strftime", d, "strftime"); } addProxyMethod(utc, "getTime", d, "getTime"); addProxyMethod(utc, "setTime", d, "setTime"); var props = ["Date", "Day", "FullYear", "Hours", "Milliseconds", "Minutes", "Month", "Seconds"]; for (var p = 0; p < props.length; p++) { addProxyMethod(utc, "get" + props[p], d, "getUTC" + props[p]); addProxyMethod(utc, "set" + props[p], d, "setUTC" + props[p]); } return utc; }
[ "function", "makeUtcWrapper", "(", "d", ")", "{", "function", "addProxyMethod", "(", "sourceObj", ",", "sourceMethod", ",", "targetObj", ",", "targetMethod", ")", "{", "sourceObj", "[", "sourceMethod", "]", "=", "function", "(", ")", "{", "return", "targetObj", "[", "targetMethod", "]", ".", "apply", "(", "targetObj", ",", "arguments", ")", ";", "}", ";", "}", ";", "var", "utc", "=", "{", "date", ":", "d", "}", ";", "// support strftime, if found", "if", "(", "d", ".", "strftime", "!=", "undefined", ")", "{", "addProxyMethod", "(", "utc", ",", "\"strftime\"", ",", "d", ",", "\"strftime\"", ")", ";", "}", "addProxyMethod", "(", "utc", ",", "\"getTime\"", ",", "d", ",", "\"getTime\"", ")", ";", "addProxyMethod", "(", "utc", ",", "\"setTime\"", ",", "d", ",", "\"setTime\"", ")", ";", "var", "props", "=", "[", "\"Date\"", ",", "\"Day\"", ",", "\"FullYear\"", ",", "\"Hours\"", ",", "\"Milliseconds\"", ",", "\"Minutes\"", ",", "\"Month\"", ",", "\"Seconds\"", "]", ";", "for", "(", "var", "p", "=", "0", ";", "p", "<", "props", ".", "length", ";", "p", "++", ")", "{", "addProxyMethod", "(", "utc", ",", "\"get\"", "+", "props", "[", "p", "]", ",", "d", ",", "\"getUTC\"", "+", "props", "[", "p", "]", ")", ";", "addProxyMethod", "(", "utc", ",", "\"set\"", "+", "props", "[", "p", "]", ",", "d", ",", "\"setUTC\"", "+", "props", "[", "p", "]", ")", ";", "}", "return", "utc", ";", "}" ]
To have a consistent view of time-based data independent of which time zone the client happens to be in we need a date-like object independent of time zones. This is done through a wrapper that only calls the UTC versions of the accessor methods.
[ "To", "have", "a", "consistent", "view", "of", "time", "-", "based", "data", "independent", "of", "which", "time", "zone", "the", "client", "happens", "to", "be", "in", "we", "need", "a", "date", "-", "like", "object", "independent", "of", "time", "zones", ".", "This", "is", "done", "through", "a", "wrapper", "that", "only", "calls", "the", "UTC", "versions", "of", "the", "accessor", "methods", "." ]
3c45611cfa200e660aa497ba82d191231163487b
https://github.com/Wtower/ng-gentelella/blob/3c45611cfa200e660aa497ba82d191231163487b/build/js/index.min.js#L58475-L58504
40,521
Wtower/ng-gentelella
build/js/index.min.js
dateGenerator
function dateGenerator(ts, opts) { if (opts.timezone == "browser") { return new Date(ts); } else if (!opts.timezone || opts.timezone == "utc") { return makeUtcWrapper(new Date(ts)); } else if (typeof timezoneJS != "undefined" && typeof timezoneJS.Date != "undefined") { var d = new timezoneJS.Date(); // timezone-js is fickle, so be sure to set the time zone before // setting the time. d.setTimezone(opts.timezone); d.setTime(ts); return d; } else { return makeUtcWrapper(new Date(ts)); } }
javascript
function dateGenerator(ts, opts) { if (opts.timezone == "browser") { return new Date(ts); } else if (!opts.timezone || opts.timezone == "utc") { return makeUtcWrapper(new Date(ts)); } else if (typeof timezoneJS != "undefined" && typeof timezoneJS.Date != "undefined") { var d = new timezoneJS.Date(); // timezone-js is fickle, so be sure to set the time zone before // setting the time. d.setTimezone(opts.timezone); d.setTime(ts); return d; } else { return makeUtcWrapper(new Date(ts)); } }
[ "function", "dateGenerator", "(", "ts", ",", "opts", ")", "{", "if", "(", "opts", ".", "timezone", "==", "\"browser\"", ")", "{", "return", "new", "Date", "(", "ts", ")", ";", "}", "else", "if", "(", "!", "opts", ".", "timezone", "||", "opts", ".", "timezone", "==", "\"utc\"", ")", "{", "return", "makeUtcWrapper", "(", "new", "Date", "(", "ts", ")", ")", ";", "}", "else", "if", "(", "typeof", "timezoneJS", "!=", "\"undefined\"", "&&", "typeof", "timezoneJS", ".", "Date", "!=", "\"undefined\"", ")", "{", "var", "d", "=", "new", "timezoneJS", ".", "Date", "(", ")", ";", "// timezone-js is fickle, so be sure to set the time zone before", "// setting the time.", "d", ".", "setTimezone", "(", "opts", ".", "timezone", ")", ";", "d", ".", "setTime", "(", "ts", ")", ";", "return", "d", ";", "}", "else", "{", "return", "makeUtcWrapper", "(", "new", "Date", "(", "ts", ")", ")", ";", "}", "}" ]
select time zone strategy. This returns a date-like object tied to the desired timezone
[ "select", "time", "zone", "strategy", ".", "This", "returns", "a", "date", "-", "like", "object", "tied", "to", "the", "desired", "timezone" ]
3c45611cfa200e660aa497ba82d191231163487b
https://github.com/Wtower/ng-gentelella/blob/3c45611cfa200e660aa497ba82d191231163487b/build/js/index.min.js#L58509-L58524
40,522
Wtower/ng-gentelella
build/js/index.min.js
processOptions
function processOptions(plot, options) { if (options.series.curvedLines.active) { plot.hooks.processDatapoints.unshift(processDatapoints); } }
javascript
function processOptions(plot, options) { if (options.series.curvedLines.active) { plot.hooks.processDatapoints.unshift(processDatapoints); } }
[ "function", "processOptions", "(", "plot", ",", "options", ")", "{", "if", "(", "options", ".", "series", ".", "curvedLines", ".", "active", ")", "{", "plot", ".", "hooks", ".", "processDatapoints", ".", "unshift", "(", "processDatapoints", ")", ";", "}", "}" ]
if the plugin is active register processDatapoints method
[ "if", "the", "plugin", "is", "active", "register", "processDatapoints", "method" ]
3c45611cfa200e660aa497ba82d191231163487b
https://github.com/Wtower/ng-gentelella/blob/3c45611cfa200e660aa497ba82d191231163487b/build/js/index.min.js#L59678-L59682
40,523
Wtower/ng-gentelella
build/js/index.min.js
processDatapoints
function processDatapoints(plot, series, datapoints) { var nrPoints = datapoints.points.length / datapoints.pointsize; var EPSILON = 0.005; //detects missplaced legacy parameters (prior v1.x.x) in the options object //this can happen if somebody upgrades to v1.x.x without adjusting the parameters or uses old examples var invalidLegacyOptions = hasInvalidParameters(series.curvedLines); if (!invalidLegacyOptions && series.curvedLines.apply == true && series.originSeries === undefined && nrPoints > (1 + EPSILON)) { if (series.lines.fill) { var pointsTop = calculateCurvePoints(datapoints, series.curvedLines, 1); var pointsBottom = calculateCurvePoints(datapoints, series.curvedLines, 2); //flot makes sure for us that we've got a second y point if fill is true ! //Merge top and bottom curve datapoints.pointsize = 3; datapoints.points = []; var j = 0; var k = 0; var i = 0; var ps = 2; while (i < pointsTop.length || j < pointsBottom.length) { if (pointsTop[i] == pointsBottom[j]) { datapoints.points[k] = pointsTop[i]; datapoints.points[k + 1] = pointsTop[i + 1]; datapoints.points[k + 2] = pointsBottom[j + 1]; j += ps; i += ps; } else if (pointsTop[i] < pointsBottom[j]) { datapoints.points[k] = pointsTop[i]; datapoints.points[k + 1] = pointsTop[i + 1]; datapoints.points[k + 2] = k > 0 ? datapoints.points[k - 1] : null; i += ps; } else { datapoints.points[k] = pointsBottom[j]; datapoints.points[k + 1] = k > 1 ? datapoints.points[k - 2] : null; datapoints.points[k + 2] = pointsBottom[j + 1]; j += ps; } k += 3; } } else if (series.lines.lineWidth > 0) { datapoints.points = calculateCurvePoints(datapoints, series.curvedLines, 1); datapoints.pointsize = 2; } } }
javascript
function processDatapoints(plot, series, datapoints) { var nrPoints = datapoints.points.length / datapoints.pointsize; var EPSILON = 0.005; //detects missplaced legacy parameters (prior v1.x.x) in the options object //this can happen if somebody upgrades to v1.x.x without adjusting the parameters or uses old examples var invalidLegacyOptions = hasInvalidParameters(series.curvedLines); if (!invalidLegacyOptions && series.curvedLines.apply == true && series.originSeries === undefined && nrPoints > (1 + EPSILON)) { if (series.lines.fill) { var pointsTop = calculateCurvePoints(datapoints, series.curvedLines, 1); var pointsBottom = calculateCurvePoints(datapoints, series.curvedLines, 2); //flot makes sure for us that we've got a second y point if fill is true ! //Merge top and bottom curve datapoints.pointsize = 3; datapoints.points = []; var j = 0; var k = 0; var i = 0; var ps = 2; while (i < pointsTop.length || j < pointsBottom.length) { if (pointsTop[i] == pointsBottom[j]) { datapoints.points[k] = pointsTop[i]; datapoints.points[k + 1] = pointsTop[i + 1]; datapoints.points[k + 2] = pointsBottom[j + 1]; j += ps; i += ps; } else if (pointsTop[i] < pointsBottom[j]) { datapoints.points[k] = pointsTop[i]; datapoints.points[k + 1] = pointsTop[i + 1]; datapoints.points[k + 2] = k > 0 ? datapoints.points[k - 1] : null; i += ps; } else { datapoints.points[k] = pointsBottom[j]; datapoints.points[k + 1] = k > 1 ? datapoints.points[k - 2] : null; datapoints.points[k + 2] = pointsBottom[j + 1]; j += ps; } k += 3; } } else if (series.lines.lineWidth > 0) { datapoints.points = calculateCurvePoints(datapoints, series.curvedLines, 1); datapoints.pointsize = 2; } } }
[ "function", "processDatapoints", "(", "plot", ",", "series", ",", "datapoints", ")", "{", "var", "nrPoints", "=", "datapoints", ".", "points", ".", "length", "/", "datapoints", ".", "pointsize", ";", "var", "EPSILON", "=", "0.005", ";", "//detects missplaced legacy parameters (prior v1.x.x) in the options object", "//this can happen if somebody upgrades to v1.x.x without adjusting the parameters or uses old examples", "var", "invalidLegacyOptions", "=", "hasInvalidParameters", "(", "series", ".", "curvedLines", ")", ";", "if", "(", "!", "invalidLegacyOptions", "&&", "series", ".", "curvedLines", ".", "apply", "==", "true", "&&", "series", ".", "originSeries", "===", "undefined", "&&", "nrPoints", ">", "(", "1", "+", "EPSILON", ")", ")", "{", "if", "(", "series", ".", "lines", ".", "fill", ")", "{", "var", "pointsTop", "=", "calculateCurvePoints", "(", "datapoints", ",", "series", ".", "curvedLines", ",", "1", ")", ";", "var", "pointsBottom", "=", "calculateCurvePoints", "(", "datapoints", ",", "series", ".", "curvedLines", ",", "2", ")", ";", "//flot makes sure for us that we've got a second y point if fill is true !", "//Merge top and bottom curve", "datapoints", ".", "pointsize", "=", "3", ";", "datapoints", ".", "points", "=", "[", "]", ";", "var", "j", "=", "0", ";", "var", "k", "=", "0", ";", "var", "i", "=", "0", ";", "var", "ps", "=", "2", ";", "while", "(", "i", "<", "pointsTop", ".", "length", "||", "j", "<", "pointsBottom", ".", "length", ")", "{", "if", "(", "pointsTop", "[", "i", "]", "==", "pointsBottom", "[", "j", "]", ")", "{", "datapoints", ".", "points", "[", "k", "]", "=", "pointsTop", "[", "i", "]", ";", "datapoints", ".", "points", "[", "k", "+", "1", "]", "=", "pointsTop", "[", "i", "+", "1", "]", ";", "datapoints", ".", "points", "[", "k", "+", "2", "]", "=", "pointsBottom", "[", "j", "+", "1", "]", ";", "j", "+=", "ps", ";", "i", "+=", "ps", ";", "}", "else", "if", "(", "pointsTop", "[", "i", "]", "<", "pointsBottom", "[", "j", "]", ")", "{", "datapoints", ".", "points", "[", "k", "]", "=", "pointsTop", "[", "i", "]", ";", "datapoints", ".", "points", "[", "k", "+", "1", "]", "=", "pointsTop", "[", "i", "+", "1", "]", ";", "datapoints", ".", "points", "[", "k", "+", "2", "]", "=", "k", ">", "0", "?", "datapoints", ".", "points", "[", "k", "-", "1", "]", ":", "null", ";", "i", "+=", "ps", ";", "}", "else", "{", "datapoints", ".", "points", "[", "k", "]", "=", "pointsBottom", "[", "j", "]", ";", "datapoints", ".", "points", "[", "k", "+", "1", "]", "=", "k", ">", "1", "?", "datapoints", ".", "points", "[", "k", "-", "2", "]", ":", "null", ";", "datapoints", ".", "points", "[", "k", "+", "2", "]", "=", "pointsBottom", "[", "j", "+", "1", "]", ";", "j", "+=", "ps", ";", "}", "k", "+=", "3", ";", "}", "}", "else", "if", "(", "series", ".", "lines", ".", "lineWidth", ">", "0", ")", "{", "datapoints", ".", "points", "=", "calculateCurvePoints", "(", "datapoints", ",", "series", ".", "curvedLines", ",", "1", ")", ";", "datapoints", ".", "pointsize", "=", "2", ";", "}", "}", "}" ]
only if the plugin is active
[ "only", "if", "the", "plugin", "is", "active" ]
3c45611cfa200e660aa497ba82d191231163487b
https://github.com/Wtower/ng-gentelella/blob/3c45611cfa200e660aa497ba82d191231163487b/build/js/index.min.js#L59685-L59733
40,524
Localize/node-google-translate
lib/main.js
function(apiKey) { return function(path, data, done) { var url = apiBase + path + '?' + querystring.stringify(_.extend({ 'key': apiKey }, data)); request.get(url, globalResponseHandler({ url: url }, done)); }; }
javascript
function(apiKey) { return function(path, data, done) { var url = apiBase + path + '?' + querystring.stringify(_.extend({ 'key': apiKey }, data)); request.get(url, globalResponseHandler({ url: url }, done)); }; }
[ "function", "(", "apiKey", ")", "{", "return", "function", "(", "path", ",", "data", ",", "done", ")", "{", "var", "url", "=", "apiBase", "+", "path", "+", "'?'", "+", "querystring", ".", "stringify", "(", "_", ".", "extend", "(", "{", "'key'", ":", "apiKey", "}", ",", "data", ")", ")", ";", "request", ".", "get", "(", "url", ",", "globalResponseHandler", "(", "{", "url", ":", "url", "}", ",", "done", ")", ")", ";", "}", ";", "}" ]
Closure that returns a function for making a GET request to Google with an apiKey
[ "Closure", "that", "returns", "a", "function", "for", "making", "a", "GET", "request", "to", "Google", "with", "an", "apiKey" ]
233e2c92556bb8ddf780fb4e66c5e879ccd74237
https://github.com/Localize/node-google-translate/blob/233e2c92556bb8ddf780fb4e66c5e879ccd74237/lib/main.js#L19-L24
40,525
henridf/apache-spark-node
lib/as_scala.js
buffer
function buffer(arr) { if (!Array.isArray(arr)) { return; } var l = new List(); arr.forEach(function(el) { l[syncMethodName("add")](el); }); return convert[syncMethodName("asScalaBuffer")](l); }
javascript
function buffer(arr) { if (!Array.isArray(arr)) { return; } var l = new List(); arr.forEach(function(el) { l[syncMethodName("add")](el); }); return convert[syncMethodName("asScalaBuffer")](l); }
[ "function", "buffer", "(", "arr", ")", "{", "if", "(", "!", "Array", ".", "isArray", "(", "arr", ")", ")", "{", "return", ";", "}", "var", "l", "=", "new", "List", "(", ")", ";", "arr", ".", "forEach", "(", "function", "(", "el", ")", "{", "l", "[", "syncMethodName", "(", "\"add\"", ")", "]", "(", "el", ")", ";", "}", ")", ";", "return", "convert", "[", "syncMethodName", "(", "\"asScalaBuffer\"", ")", "]", "(", "l", ")", ";", "}" ]
convert a js array into a buffer
[ "convert", "a", "js", "array", "into", "a", "buffer" ]
9210e1deab0f0a765f183fcf4f23a69aca14eb3a
https://github.com/henridf/apache-spark-node/blob/9210e1deab0f0a765f183fcf4f23a69aca14eb3a/lib/as_scala.js#L26-L36
40,526
henridf/apache-spark-node
lib/as_scala.js
map
function map(arr) { var hm = new HashMap(); Object.keys(arr).forEach(function(k) { hm.put(k, arr[k]); }); return convert[syncMethodName("asScalaMap")](hm); }
javascript
function map(arr) { var hm = new HashMap(); Object.keys(arr).forEach(function(k) { hm.put(k, arr[k]); }); return convert[syncMethodName("asScalaMap")](hm); }
[ "function", "map", "(", "arr", ")", "{", "var", "hm", "=", "new", "HashMap", "(", ")", ";", "Object", ".", "keys", "(", "arr", ")", ".", "forEach", "(", "function", "(", "k", ")", "{", "hm", ".", "put", "(", "k", ",", "arr", "[", "k", "]", ")", ";", "}", ")", ";", "return", "convert", "[", "syncMethodName", "(", "\"asScalaMap\"", ")", "]", "(", "hm", ")", ";", "}" ]
convert a js object into a map
[ "convert", "a", "js", "object", "into", "a", "map" ]
9210e1deab0f0a765f183fcf4f23a69aca14eb3a
https://github.com/henridf/apache-spark-node/blob/9210e1deab0f0a765f183fcf4f23a69aca14eb3a/lib/as_scala.js#L39-L45
40,527
bpierre/fontello-svg
index.js
svgUrl
function svgUrl(name, collection) { for (var i = 0, result; i < COLLECTION_FILTERS.length; i++) { if (COLLECTION_FILTERS[i][0].test(collection)) { result = COLLECTION_FILTERS[i][1]; collection = _.isFunction(result)? result(collection) : result; break; } } return 'https://raw.github.com/fontello/' + collection + '/master/src/svg/' + name + '.svg'; }
javascript
function svgUrl(name, collection) { for (var i = 0, result; i < COLLECTION_FILTERS.length; i++) { if (COLLECTION_FILTERS[i][0].test(collection)) { result = COLLECTION_FILTERS[i][1]; collection = _.isFunction(result)? result(collection) : result; break; } } return 'https://raw.github.com/fontello/' + collection + '/master/src/svg/' + name + '.svg'; }
[ "function", "svgUrl", "(", "name", ",", "collection", ")", "{", "for", "(", "var", "i", "=", "0", ",", "result", ";", "i", "<", "COLLECTION_FILTERS", ".", "length", ";", "i", "++", ")", "{", "if", "(", "COLLECTION_FILTERS", "[", "i", "]", "[", "0", "]", ".", "test", "(", "collection", ")", ")", "{", "result", "=", "COLLECTION_FILTERS", "[", "i", "]", "[", "1", "]", ";", "collection", "=", "_", ".", "isFunction", "(", "result", ")", "?", "result", "(", "collection", ")", ":", "result", ";", "break", ";", "}", "}", "return", "'https://raw.github.com/fontello/'", "+", "collection", "+", "'/master/src/svg/'", "+", "name", "+", "'.svg'", ";", "}" ]
Returns the URL of a Fontello SVG
[ "Returns", "the", "URL", "of", "a", "Fontello", "SVG" ]
bced088e0aaffd0f7910ade7a0253fdae32f6518
https://github.com/bpierre/fontello-svg/blob/bced088e0aaffd0f7910ade7a0253fdae32f6518/index.js#L21-L31
40,528
bpierre/fontello-svg
index.js
createGlyph
function createGlyph(name, collection, id, colors, fileFormat) { var glyph = Object.create(Glyph); if (!colors) colors = { 'black': 'rgb(0,0,0)' }; if (!fileFormat) fileFormat = "{0}-{1}-{2}.svg"; if (!id) id = name; glyph.id = id; glyph.name = name; glyph.collection = collection; glyph.url = svgUrl(glyph.name, glyph.collection); glyph.colors = colors; glyph.exists = null; glyph.fileFormat = fileFormat; return glyph; }
javascript
function createGlyph(name, collection, id, colors, fileFormat) { var glyph = Object.create(Glyph); if (!colors) colors = { 'black': 'rgb(0,0,0)' }; if (!fileFormat) fileFormat = "{0}-{1}-{2}.svg"; if (!id) id = name; glyph.id = id; glyph.name = name; glyph.collection = collection; glyph.url = svgUrl(glyph.name, glyph.collection); glyph.colors = colors; glyph.exists = null; glyph.fileFormat = fileFormat; return glyph; }
[ "function", "createGlyph", "(", "name", ",", "collection", ",", "id", ",", "colors", ",", "fileFormat", ")", "{", "var", "glyph", "=", "Object", ".", "create", "(", "Glyph", ")", ";", "if", "(", "!", "colors", ")", "colors", "=", "{", "'black'", ":", "'rgb(0,0,0)'", "}", ";", "if", "(", "!", "fileFormat", ")", "fileFormat", "=", "\"{0}-{1}-{2}.svg\"", ";", "if", "(", "!", "id", ")", "id", "=", "name", ";", "glyph", ".", "id", "=", "id", ";", "glyph", ".", "name", "=", "name", ";", "glyph", ".", "collection", "=", "collection", ";", "glyph", ".", "url", "=", "svgUrl", "(", "glyph", ".", "name", ",", "glyph", ".", "collection", ")", ";", "glyph", ".", "colors", "=", "colors", ";", "glyph", ".", "exists", "=", "null", ";", "glyph", ".", "fileFormat", "=", "fileFormat", ";", "return", "glyph", ";", "}" ]
Creates and returns a Glyph instance
[ "Creates", "and", "returns", "a", "Glyph", "instance" ]
bced088e0aaffd0f7910ade7a0253fdae32f6518
https://github.com/bpierre/fontello-svg/blob/bced088e0aaffd0f7910ade7a0253fdae32f6518/index.js#L77-L90
40,529
bpierre/fontello-svg
index.js
glyphCreator
function glyphCreator() { var unique = nodupes(); return function(name, collection, colors) { return createGlyph(name, collection, unique(name), colors); }; }
javascript
function glyphCreator() { var unique = nodupes(); return function(name, collection, colors) { return createGlyph(name, collection, unique(name), colors); }; }
[ "function", "glyphCreator", "(", ")", "{", "var", "unique", "=", "nodupes", "(", ")", ";", "return", "function", "(", "name", ",", "collection", ",", "colors", ")", "{", "return", "createGlyph", "(", "name", ",", "collection", ",", "unique", "(", "name", ")", ",", "colors", ")", ";", "}", ";", "}" ]
Returns a function to create glyphs and incrementing their IDs as needed.
[ "Returns", "a", "function", "to", "create", "glyphs", "and", "incrementing", "their", "IDs", "as", "needed", "." ]
bced088e0aaffd0f7910ade7a0253fdae32f6518
https://github.com/bpierre/fontello-svg/blob/bced088e0aaffd0f7910ade7a0253fdae32f6518/index.js#L93-L98
40,530
bpierre/fontello-svg
index.js
allGlyphs
function allGlyphs(rawGlyphs, colors, fileFormat) { var unique = nodupes(); rawGlyphs = fixNames(rawGlyphs); return rawGlyphs.map(function(rawGlyph) { var name = rawGlyph.css; var collection = rawGlyph.src; return createGlyph(name, collection, unique(name), colors, fileFormat); }); }
javascript
function allGlyphs(rawGlyphs, colors, fileFormat) { var unique = nodupes(); rawGlyphs = fixNames(rawGlyphs); return rawGlyphs.map(function(rawGlyph) { var name = rawGlyph.css; var collection = rawGlyph.src; return createGlyph(name, collection, unique(name), colors, fileFormat); }); }
[ "function", "allGlyphs", "(", "rawGlyphs", ",", "colors", ",", "fileFormat", ")", "{", "var", "unique", "=", "nodupes", "(", ")", ";", "rawGlyphs", "=", "fixNames", "(", "rawGlyphs", ")", ";", "return", "rawGlyphs", ".", "map", "(", "function", "(", "rawGlyph", ")", "{", "var", "name", "=", "rawGlyph", ".", "css", ";", "var", "collection", "=", "rawGlyph", ".", "src", ";", "return", "createGlyph", "(", "name", ",", "collection", ",", "unique", "(", "name", ")", ",", "colors", ",", "fileFormat", ")", ";", "}", ")", ";", "}" ]
Creates and returns all Glyphs from a rawGlyphs list
[ "Creates", "and", "returns", "all", "Glyphs", "from", "a", "rawGlyphs", "list" ]
bced088e0aaffd0f7910ade7a0253fdae32f6518
https://github.com/bpierre/fontello-svg/blob/bced088e0aaffd0f7910ade7a0253fdae32f6518/index.js#L124-L132
40,531
bpierre/fontello-svg
index.js
missingGlyphs
function missingGlyphs(glyphs, svgDir, cb) { async.reject(glyphs, function(glyph, cb) { var filenames = glyph.filenames().map(function(filename) { return svgDir + '/' + filename; }); async.every(filenames, fs.exists, cb); }, cb); }
javascript
function missingGlyphs(glyphs, svgDir, cb) { async.reject(glyphs, function(glyph, cb) { var filenames = glyph.filenames().map(function(filename) { return svgDir + '/' + filename; }); async.every(filenames, fs.exists, cb); }, cb); }
[ "function", "missingGlyphs", "(", "glyphs", ",", "svgDir", ",", "cb", ")", "{", "async", ".", "reject", "(", "glyphs", ",", "function", "(", "glyph", ",", "cb", ")", "{", "var", "filenames", "=", "glyph", ".", "filenames", "(", ")", ".", "map", "(", "function", "(", "filename", ")", "{", "return", "svgDir", "+", "'/'", "+", "filename", ";", "}", ")", ";", "async", ".", "every", "(", "filenames", ",", "fs", ".", "exists", ",", "cb", ")", ";", "}", ",", "cb", ")", ";", "}" ]
Filters all glyphs to returns only the ones missing on the FS
[ "Filters", "all", "glyphs", "to", "returns", "only", "the", "ones", "missing", "on", "the", "FS" ]
bced088e0aaffd0f7910ade7a0253fdae32f6518
https://github.com/bpierre/fontello-svg/blob/bced088e0aaffd0f7910ade7a0253fdae32f6518/index.js#L135-L142
40,532
alexbardas/bignumber.js
big-number.js
BigNumber
function BigNumber(initialNumber) { var index; if (!(this instanceof BigNumber)) { return new BigNumber(initialNumber); } this.number = []; this.sign = 1; this.rest = 0; // The initial number can be an array, string, number of another big number // e.g. array : [3,2,1], ['+',3,2,1], ['-',3,2,1] // number : 312 // string : '321', '+321', -321' // BigNumber : BigNumber(321) // Every character except the first must be a digit if (!isValidType(initialNumber)) { this.number = errors['invalid']; return; } if (isArray(initialNumber)) { if (initialNumber.length && initialNumber[0] === '-' || initialNumber[0] === '+') { this.sign = initialNumber[0] === '+' ? 1 : -1; initialNumber.shift(0); } for (index = initialNumber.length - 1; index >= 0; index--) { if (!this.addDigit(initialNumber[index])) return; } } else { initialNumber = initialNumber.toString(); if (initialNumber.charAt(0) === '-' || initialNumber.charAt(0) === '+') { this.sign = initialNumber.charAt(0) === '+' ? 1 : -1; initialNumber = initialNumber.substring(1); } for (index = initialNumber.length - 1; index >= 0; index--) { if (!this.addDigit(parseInt(initialNumber.charAt(index), 10))) { return; } } } }
javascript
function BigNumber(initialNumber) { var index; if (!(this instanceof BigNumber)) { return new BigNumber(initialNumber); } this.number = []; this.sign = 1; this.rest = 0; // The initial number can be an array, string, number of another big number // e.g. array : [3,2,1], ['+',3,2,1], ['-',3,2,1] // number : 312 // string : '321', '+321', -321' // BigNumber : BigNumber(321) // Every character except the first must be a digit if (!isValidType(initialNumber)) { this.number = errors['invalid']; return; } if (isArray(initialNumber)) { if (initialNumber.length && initialNumber[0] === '-' || initialNumber[0] === '+') { this.sign = initialNumber[0] === '+' ? 1 : -1; initialNumber.shift(0); } for (index = initialNumber.length - 1; index >= 0; index--) { if (!this.addDigit(initialNumber[index])) return; } } else { initialNumber = initialNumber.toString(); if (initialNumber.charAt(0) === '-' || initialNumber.charAt(0) === '+') { this.sign = initialNumber.charAt(0) === '+' ? 1 : -1; initialNumber = initialNumber.substring(1); } for (index = initialNumber.length - 1; index >= 0; index--) { if (!this.addDigit(parseInt(initialNumber.charAt(index), 10))) { return; } } } }
[ "function", "BigNumber", "(", "initialNumber", ")", "{", "var", "index", ";", "if", "(", "!", "(", "this", "instanceof", "BigNumber", ")", ")", "{", "return", "new", "BigNumber", "(", "initialNumber", ")", ";", "}", "this", ".", "number", "=", "[", "]", ";", "this", ".", "sign", "=", "1", ";", "this", ".", "rest", "=", "0", ";", "// The initial number can be an array, string, number of another big number", "// e.g. array : [3,2,1], ['+',3,2,1], ['-',3,2,1]", "// number : 312", "// string : '321', '+321', -321'", "// BigNumber : BigNumber(321)", "// Every character except the first must be a digit", "if", "(", "!", "isValidType", "(", "initialNumber", ")", ")", "{", "this", ".", "number", "=", "errors", "[", "'invalid'", "]", ";", "return", ";", "}", "if", "(", "isArray", "(", "initialNumber", ")", ")", "{", "if", "(", "initialNumber", ".", "length", "&&", "initialNumber", "[", "0", "]", "===", "'-'", "||", "initialNumber", "[", "0", "]", "===", "'+'", ")", "{", "this", ".", "sign", "=", "initialNumber", "[", "0", "]", "===", "'+'", "?", "1", ":", "-", "1", ";", "initialNumber", ".", "shift", "(", "0", ")", ";", "}", "for", "(", "index", "=", "initialNumber", ".", "length", "-", "1", ";", "index", ">=", "0", ";", "index", "--", ")", "{", "if", "(", "!", "this", ".", "addDigit", "(", "initialNumber", "[", "index", "]", ")", ")", "return", ";", "}", "}", "else", "{", "initialNumber", "=", "initialNumber", ".", "toString", "(", ")", ";", "if", "(", "initialNumber", ".", "charAt", "(", "0", ")", "===", "'-'", "||", "initialNumber", ".", "charAt", "(", "0", ")", "===", "'+'", ")", "{", "this", ".", "sign", "=", "initialNumber", ".", "charAt", "(", "0", ")", "===", "'+'", "?", "1", ":", "-", "1", ";", "initialNumber", "=", "initialNumber", ".", "substring", "(", "1", ")", ";", "}", "for", "(", "index", "=", "initialNumber", ".", "length", "-", "1", ";", "index", ">=", "0", ";", "index", "--", ")", "{", "if", "(", "!", "this", ".", "addDigit", "(", "parseInt", "(", "initialNumber", ".", "charAt", "(", "index", ")", ",", "10", ")", ")", ")", "{", "return", ";", "}", "}", "}", "}" ]
Constructor function which creates a new BigNumber object from an integer, a string, an array or other BigNumber object
[ "Constructor", "function", "which", "creates", "a", "new", "BigNumber", "object", "from", "an", "integer", "a", "string", "an", "array", "or", "other", "BigNumber", "object" ]
a17195f2cb49bcd86ebaaf8f161a03e82b94d6fc
https://github.com/alexbardas/bignumber.js/blob/a17195f2cb49bcd86ebaaf8f161a03e82b94d6fc/big-number.js#L53-L98
40,533
lorenwest/monitor-dashboard
lib/js/Page.js
function(viewClass) { var t = this, newIdNum = 1, components = t.get('components'), classParts = viewClass.split('.'), appName = classParts[0], appView = classParts[1]; // Instantiate and add the component var component = new Component({ id: Monitor.generateUniqueCollectionId(components, 'c'), viewClass: viewClass, viewOptions: UI.app[appName][appView].prototype.defaultOptions, css: { '.nm-cv': 'top:10px;' } }); components.add(component); return component; }
javascript
function(viewClass) { var t = this, newIdNum = 1, components = t.get('components'), classParts = viewClass.split('.'), appName = classParts[0], appView = classParts[1]; // Instantiate and add the component var component = new Component({ id: Monitor.generateUniqueCollectionId(components, 'c'), viewClass: viewClass, viewOptions: UI.app[appName][appView].prototype.defaultOptions, css: { '.nm-cv': 'top:10px;' } }); components.add(component); return component; }
[ "function", "(", "viewClass", ")", "{", "var", "t", "=", "this", ",", "newIdNum", "=", "1", ",", "components", "=", "t", ".", "get", "(", "'components'", ")", ",", "classParts", "=", "viewClass", ".", "split", "(", "'.'", ")", ",", "appName", "=", "classParts", "[", "0", "]", ",", "appView", "=", "classParts", "[", "1", "]", ";", "// Instantiate and add the component", "var", "component", "=", "new", "Component", "(", "{", "id", ":", "Monitor", ".", "generateUniqueCollectionId", "(", "components", ",", "'c'", ")", ",", "viewClass", ":", "viewClass", ",", "viewOptions", ":", "UI", ".", "app", "[", "appName", "]", "[", "appView", "]", ".", "prototype", ".", "defaultOptions", ",", "css", ":", "{", "'.nm-cv'", ":", "'top:10px;'", "}", "}", ")", ";", "components", ".", "add", "(", "component", ")", ";", "return", "component", ";", "}" ]
Add a new component to the Page model by component class This uses the default component attributes @method addComponent @param viewClass - Class name for the main view in the component @return component - The newly instantiated component
[ "Add", "a", "new", "component", "to", "the", "Page", "model", "by", "component", "class" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/Page.js#L59-L78
40,534
lorenwest/monitor-dashboard
lib/js/Page.js
function(options) { var t = this, opts = _.extend({trim:true, deep:true}, options), raw = Backbone.Model.prototype.toJSON.call(t, opts); return raw; }
javascript
function(options) { var t = this, opts = _.extend({trim:true, deep:true}, options), raw = Backbone.Model.prototype.toJSON.call(t, opts); return raw; }
[ "function", "(", "options", ")", "{", "var", "t", "=", "this", ",", "opts", "=", "_", ".", "extend", "(", "{", "trim", ":", "true", ",", "deep", ":", "true", "}", ",", "options", ")", ",", "raw", "=", "Backbone", ".", "Model", ".", "prototype", ".", "toJSON", ".", "call", "(", "t", ",", "opts", ")", ";", "return", "raw", ";", "}" ]
Overridden to override some options
[ "Overridden", "to", "override", "some", "options" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/Page.js#L81-L86
40,535
lorenwest/monitor-dashboard
lib/js/ComponentSettingsView.js
function() { var t = this; t.$el.append(template.apply({})); t.editor = t.$('.nm-cs-source-edit'); t.sourceButton = t.$('.nm-cs-view-source'); // Get bindings to 'name=' attributes before custom views are rendered t.componentBindings = Backbone.ModelBinder.createDefaultBindings(t.$el, 'name'); }
javascript
function() { var t = this; t.$el.append(template.apply({})); t.editor = t.$('.nm-cs-source-edit'); t.sourceButton = t.$('.nm-cs-view-source'); // Get bindings to 'name=' attributes before custom views are rendered t.componentBindings = Backbone.ModelBinder.createDefaultBindings(t.$el, 'name'); }
[ "function", "(", ")", "{", "var", "t", "=", "this", ";", "t", ".", "$el", ".", "append", "(", "template", ".", "apply", "(", "{", "}", ")", ")", ";", "t", ".", "editor", "=", "t", ".", "$", "(", "'.nm-cs-source-edit'", ")", ";", "t", ".", "sourceButton", "=", "t", ".", "$", "(", "'.nm-cs-view-source'", ")", ";", "// Get bindings to 'name=' attributes before custom views are rendered", "t", ".", "componentBindings", "=", "Backbone", ".", "ModelBinder", ".", "createDefaultBindings", "(", "t", ".", "$el", ",", "'name'", ")", ";", "}" ]
This is called once after construction to render the components onto the screen. The components change their value when the data model changes.
[ "This", "is", "called", "once", "after", "construction", "to", "render", "the", "components", "onto", "the", "screen", ".", "The", "components", "change", "their", "value", "when", "the", "data", "model", "changes", "." ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/ComponentSettingsView.js#L58-L67
40,536
lorenwest/monitor-dashboard
lib/js/ComponentSettingsView.js
function(model, componentView, customView) { var t = this, componentPane = t.$('.nm-cs-component'); // Remember the model state on entry t.model = model; t.componentView = componentView; t.monitor = model.get('monitor'); t.originalModel = t.model.toJSON({trim:false}); // Remove any inner views if (t.sourceView) { t.sourceView.remove(); } if (t.customView) { t.customView.remove(); } // Clean up prior monitorParams if (t.monitorParams) { t.monitorParams.off('change'); } // Create the custom settings view if (customView) { t.customView = new customView({ model: t.model.get('viewOptions'), monitor: t.model.get('monitor'), pageView: UI.pageView, component: t.model, componentView: componentView }); t.$('.nm-cs-view-settings').append(t.customView.el); t.customView.render(); // Attach tooltips to anything with a title UI.tooltip(t.$('*[title]')); } // Normal data binding - name to model t.modelBinder.bind(t.model, t.$el, t.componentBindings); // Bind data-view-option elements to component.viewOptions t.viewOptionBinder.bind( t.model.get('viewOptions'), componentPane, Backbone.ModelBinder.createDefaultBindings(componentPane, 'data-view-option') ); // Bind data-monitor-param elements to monitor.initParams. // This is a bit more difficult because initParams isnt a Backbone model. // Copy into a Backbone model, and bind to that. t.monitorParams = new Backbone.Model(t.monitor.get('initParams')); t.monitorParamBinder.bind( t.monitorParams, componentPane, Backbone.ModelBinder.createDefaultBindings(componentPane, 'data-monitor-param') ); t.monitorParams.on('change', function() { t.monitor.set('initParams', t.monitorParams.toJSON()); }); // Instantiate the source view t.sourceView = new UI.JsonView({ model: t.model.toJSON({trim:false}) }); t.sourceView.render(); t.$('.nm-cs-source-view').append(t.sourceView.$el); }
javascript
function(model, componentView, customView) { var t = this, componentPane = t.$('.nm-cs-component'); // Remember the model state on entry t.model = model; t.componentView = componentView; t.monitor = model.get('monitor'); t.originalModel = t.model.toJSON({trim:false}); // Remove any inner views if (t.sourceView) { t.sourceView.remove(); } if (t.customView) { t.customView.remove(); } // Clean up prior monitorParams if (t.monitorParams) { t.monitorParams.off('change'); } // Create the custom settings view if (customView) { t.customView = new customView({ model: t.model.get('viewOptions'), monitor: t.model.get('monitor'), pageView: UI.pageView, component: t.model, componentView: componentView }); t.$('.nm-cs-view-settings').append(t.customView.el); t.customView.render(); // Attach tooltips to anything with a title UI.tooltip(t.$('*[title]')); } // Normal data binding - name to model t.modelBinder.bind(t.model, t.$el, t.componentBindings); // Bind data-view-option elements to component.viewOptions t.viewOptionBinder.bind( t.model.get('viewOptions'), componentPane, Backbone.ModelBinder.createDefaultBindings(componentPane, 'data-view-option') ); // Bind data-monitor-param elements to monitor.initParams. // This is a bit more difficult because initParams isnt a Backbone model. // Copy into a Backbone model, and bind to that. t.monitorParams = new Backbone.Model(t.monitor.get('initParams')); t.monitorParamBinder.bind( t.monitorParams, componentPane, Backbone.ModelBinder.createDefaultBindings(componentPane, 'data-monitor-param') ); t.monitorParams.on('change', function() { t.monitor.set('initParams', t.monitorParams.toJSON()); }); // Instantiate the source view t.sourceView = new UI.JsonView({ model: t.model.toJSON({trim:false}) }); t.sourceView.render(); t.$('.nm-cs-source-view').append(t.sourceView.$el); }
[ "function", "(", "model", ",", "componentView", ",", "customView", ")", "{", "var", "t", "=", "this", ",", "componentPane", "=", "t", ".", "$", "(", "'.nm-cs-component'", ")", ";", "// Remember the model state on entry", "t", ".", "model", "=", "model", ";", "t", ".", "componentView", "=", "componentView", ";", "t", ".", "monitor", "=", "model", ".", "get", "(", "'monitor'", ")", ";", "t", ".", "originalModel", "=", "t", ".", "model", ".", "toJSON", "(", "{", "trim", ":", "false", "}", ")", ";", "// Remove any inner views", "if", "(", "t", ".", "sourceView", ")", "{", "t", ".", "sourceView", ".", "remove", "(", ")", ";", "}", "if", "(", "t", ".", "customView", ")", "{", "t", ".", "customView", ".", "remove", "(", ")", ";", "}", "// Clean up prior monitorParams", "if", "(", "t", ".", "monitorParams", ")", "{", "t", ".", "monitorParams", ".", "off", "(", "'change'", ")", ";", "}", "// Create the custom settings view", "if", "(", "customView", ")", "{", "t", ".", "customView", "=", "new", "customView", "(", "{", "model", ":", "t", ".", "model", ".", "get", "(", "'viewOptions'", ")", ",", "monitor", ":", "t", ".", "model", ".", "get", "(", "'monitor'", ")", ",", "pageView", ":", "UI", ".", "pageView", ",", "component", ":", "t", ".", "model", ",", "componentView", ":", "componentView", "}", ")", ";", "t", ".", "$", "(", "'.nm-cs-view-settings'", ")", ".", "append", "(", "t", ".", "customView", ".", "el", ")", ";", "t", ".", "customView", ".", "render", "(", ")", ";", "// Attach tooltips to anything with a title", "UI", ".", "tooltip", "(", "t", ".", "$", "(", "'*[title]'", ")", ")", ";", "}", "// Normal data binding - name to model", "t", ".", "modelBinder", ".", "bind", "(", "t", ".", "model", ",", "t", ".", "$el", ",", "t", ".", "componentBindings", ")", ";", "// Bind data-view-option elements to component.viewOptions", "t", ".", "viewOptionBinder", ".", "bind", "(", "t", ".", "model", ".", "get", "(", "'viewOptions'", ")", ",", "componentPane", ",", "Backbone", ".", "ModelBinder", ".", "createDefaultBindings", "(", "componentPane", ",", "'data-view-option'", ")", ")", ";", "// Bind data-monitor-param elements to monitor.initParams.", "// This is a bit more difficult because initParams isnt a Backbone model.", "// Copy into a Backbone model, and bind to that.", "t", ".", "monitorParams", "=", "new", "Backbone", ".", "Model", "(", "t", ".", "monitor", ".", "get", "(", "'initParams'", ")", ")", ";", "t", ".", "monitorParamBinder", ".", "bind", "(", "t", ".", "monitorParams", ",", "componentPane", ",", "Backbone", ".", "ModelBinder", ".", "createDefaultBindings", "(", "componentPane", ",", "'data-monitor-param'", ")", ")", ";", "t", ".", "monitorParams", ".", "on", "(", "'change'", ",", "function", "(", ")", "{", "t", ".", "monitor", ".", "set", "(", "'initParams'", ",", "t", ".", "monitorParams", ".", "toJSON", "(", ")", ")", ";", "}", ")", ";", "// Instantiate the source view", "t", ".", "sourceView", "=", "new", "UI", ".", "JsonView", "(", "{", "model", ":", "t", ".", "model", ".", "toJSON", "(", "{", "trim", ":", "false", "}", ")", "}", ")", ";", "t", ".", "sourceView", ".", "render", "(", ")", ";", "t", ".", "$", "(", "'.nm-cs-source-view'", ")", ".", "append", "(", "t", ".", "sourceView", ".", "$el", ")", ";", "}" ]
Set the specified data model into the component, specifying any custom component settings view
[ "Set", "the", "specified", "data", "model", "into", "the", "component", "specifying", "any", "custom", "component", "settings", "view" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/ComponentSettingsView.js#L71-L139
40,537
lorenwest/monitor-dashboard
lib/js/ComponentSettingsView.js
function(e) { var t = this; // Make view options changes immediately on keydown // Note: Don't be so aggressive with monitor initParams, because that // could result in backend round-trips for each keystroke. setTimeout(function(){ t.viewOptionBinder._onElChanged(e); },0); // Call the parent keydown t.onKeydown(e); }
javascript
function(e) { var t = this; // Make view options changes immediately on keydown // Note: Don't be so aggressive with monitor initParams, because that // could result in backend round-trips for each keystroke. setTimeout(function(){ t.viewOptionBinder._onElChanged(e); },0); // Call the parent keydown t.onKeydown(e); }
[ "function", "(", "e", ")", "{", "var", "t", "=", "this", ";", "// Make view options changes immediately on keydown", "// Note: Don't be so aggressive with monitor initParams, because that", "// could result in backend round-trips for each keystroke.", "setTimeout", "(", "function", "(", ")", "{", "t", ".", "viewOptionBinder", ".", "_onElChanged", "(", "e", ")", ";", "}", ",", "0", ")", ";", "// Call the parent keydown", "t", ".", "onKeydown", "(", "e", ")", ";", "}" ]
Detect changes on keydown - after the value has been set
[ "Detect", "changes", "on", "keydown", "-", "after", "the", "value", "has", "been", "set" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/ComponentSettingsView.js#L146-L158
40,538
lorenwest/monitor-dashboard
lib/js/ComponentSettingsView.js
function() { var t = this; // Add the component to the model, then to the page view var copy = t.model.toJSON(); delete copy.id; var component = t.pageView.model.addComponent(copy.viewClass); component.set(copy); // Position the component on top left var cv = t.pageView.getComponentView(component.get('id')); cv.raiseToTop(true); cv.moveToLeft(); t.pageView.leftJustify(); t.pageView.centerPage(); // Close the dialog box t.closeDialog(); }
javascript
function() { var t = this; // Add the component to the model, then to the page view var copy = t.model.toJSON(); delete copy.id; var component = t.pageView.model.addComponent(copy.viewClass); component.set(copy); // Position the component on top left var cv = t.pageView.getComponentView(component.get('id')); cv.raiseToTop(true); cv.moveToLeft(); t.pageView.leftJustify(); t.pageView.centerPage(); // Close the dialog box t.closeDialog(); }
[ "function", "(", ")", "{", "var", "t", "=", "this", ";", "// Add the component to the model, then to the page view", "var", "copy", "=", "t", ".", "model", ".", "toJSON", "(", ")", ";", "delete", "copy", ".", "id", ";", "var", "component", "=", "t", ".", "pageView", ".", "model", ".", "addComponent", "(", "copy", ".", "viewClass", ")", ";", "component", ".", "set", "(", "copy", ")", ";", "// Position the component on top left", "var", "cv", "=", "t", ".", "pageView", ".", "getComponentView", "(", "component", ".", "get", "(", "'id'", ")", ")", ";", "cv", ".", "raiseToTop", "(", "true", ")", ";", "cv", ".", "moveToLeft", "(", ")", ";", "t", ".", "pageView", ".", "leftJustify", "(", ")", ";", "t", ".", "pageView", ".", "centerPage", "(", ")", ";", "// Close the dialog box", "t", ".", "closeDialog", "(", ")", ";", "}" ]
Copy the component
[ "Copy", "the", "component" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/ComponentSettingsView.js#L161-L179
40,539
lorenwest/monitor-dashboard
lib/js/AppTemplate.js
function(dirpath, file) { var templateFile = Path.join(__dirname, '../template/app', dirpath, file), outputFile = Path.join(appPath, dirpath, file); try { var template = new Template({text: FS.readFileSync(templateFile).toString(), watchFile:false}); FS.writeFileSync(outputFile, template.apply(templateParams)); } catch(e) { logger.fatal('Template', 'Cannot process template file: ' + templateFile + '. reason: ', e.toString()); process.exit(1); } }
javascript
function(dirpath, file) { var templateFile = Path.join(__dirname, '../template/app', dirpath, file), outputFile = Path.join(appPath, dirpath, file); try { var template = new Template({text: FS.readFileSync(templateFile).toString(), watchFile:false}); FS.writeFileSync(outputFile, template.apply(templateParams)); } catch(e) { logger.fatal('Template', 'Cannot process template file: ' + templateFile + '. reason: ', e.toString()); process.exit(1); } }
[ "function", "(", "dirpath", ",", "file", ")", "{", "var", "templateFile", "=", "Path", ".", "join", "(", "__dirname", ",", "'../template/app'", ",", "dirpath", ",", "file", ")", ",", "outputFile", "=", "Path", ".", "join", "(", "appPath", ",", "dirpath", ",", "file", ")", ";", "try", "{", "var", "template", "=", "new", "Template", "(", "{", "text", ":", "FS", ".", "readFileSync", "(", "templateFile", ")", ".", "toString", "(", ")", ",", "watchFile", ":", "false", "}", ")", ";", "FS", ".", "writeFileSync", "(", "outputFile", ",", "template", ".", "apply", "(", "templateParams", ")", ")", ";", "}", "catch", "(", "e", ")", "{", "logger", ".", "fatal", "(", "'Template'", ",", "'Cannot process template file: '", "+", "templateFile", "+", "'. reason: '", ",", "e", ".", "toString", "(", ")", ")", ";", "process", ".", "exit", "(", "1", ")", ";", "}", "}" ]
Output the specified file from the template directory
[ "Output", "the", "specified", "file", "from", "the", "template", "directory" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/AppTemplate.js#L61-L71
40,540
lorenwest/monitor-dashboard
lib/js/AppTemplate.js
function(dirpath) { try { // Make the directory under the app if (dirpath !== '/') { FS.mkdirSync(Path.join('.', appPath, dirpath)); } // Read the template directory var templateDir = Path.join(__dirname, '../template/app', dirpath); var files = FS.readdirSync(templateDir); files.forEach(function(file) { var fullFile = Path.join(templateDir, file); var stat = FS.statSync(fullFile); if (stat.isDirectory()) { // Go into it outputDir(Path.join(dirpath, file)); } else { outputFile(dirpath, file); } }); } catch(e) { logger.fatal('Template', 'Cannot process template directory: ' + dirpath + '. reason: ', e.toString()); process.exit(1); } }
javascript
function(dirpath) { try { // Make the directory under the app if (dirpath !== '/') { FS.mkdirSync(Path.join('.', appPath, dirpath)); } // Read the template directory var templateDir = Path.join(__dirname, '../template/app', dirpath); var files = FS.readdirSync(templateDir); files.forEach(function(file) { var fullFile = Path.join(templateDir, file); var stat = FS.statSync(fullFile); if (stat.isDirectory()) { // Go into it outputDir(Path.join(dirpath, file)); } else { outputFile(dirpath, file); } }); } catch(e) { logger.fatal('Template', 'Cannot process template directory: ' + dirpath + '. reason: ', e.toString()); process.exit(1); } }
[ "function", "(", "dirpath", ")", "{", "try", "{", "// Make the directory under the app", "if", "(", "dirpath", "!==", "'/'", ")", "{", "FS", ".", "mkdirSync", "(", "Path", ".", "join", "(", "'.'", ",", "appPath", ",", "dirpath", ")", ")", ";", "}", "// Read the template directory", "var", "templateDir", "=", "Path", ".", "join", "(", "__dirname", ",", "'../template/app'", ",", "dirpath", ")", ";", "var", "files", "=", "FS", ".", "readdirSync", "(", "templateDir", ")", ";", "files", ".", "forEach", "(", "function", "(", "file", ")", "{", "var", "fullFile", "=", "Path", ".", "join", "(", "templateDir", ",", "file", ")", ";", "var", "stat", "=", "FS", ".", "statSync", "(", "fullFile", ")", ";", "if", "(", "stat", ".", "isDirectory", "(", ")", ")", "{", "// Go into it", "outputDir", "(", "Path", ".", "join", "(", "dirpath", ",", "file", ")", ")", ";", "}", "else", "{", "outputFile", "(", "dirpath", ",", "file", ")", ";", "}", "}", ")", ";", "}", "catch", "(", "e", ")", "{", "logger", ".", "fatal", "(", "'Template'", ",", "'Cannot process template directory: '", "+", "dirpath", "+", "'. reason: '", ",", "e", ".", "toString", "(", ")", ")", ";", "process", ".", "exit", "(", "1", ")", ";", "}", "}" ]
Traverse the app template directory, outputting all files
[ "Traverse", "the", "app", "template", "directory", "outputting", "all", "files" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/AppTemplate.js#L74-L101
40,541
nullobject/jsdoc-react
src/publish.js
buildClasses
function buildClasses (db) { const classes = data.findClasses(db).order('name') return classes.map(function (klass) { const fns = data .findChildFunctions(db, [klass]) .order('name') .map(copyFunction) return copyClass(klass, fns) }) }
javascript
function buildClasses (db) { const classes = data.findClasses(db).order('name') return classes.map(function (klass) { const fns = data .findChildFunctions(db, [klass]) .order('name') .map(copyFunction) return copyClass(klass, fns) }) }
[ "function", "buildClasses", "(", "db", ")", "{", "const", "classes", "=", "data", ".", "findClasses", "(", "db", ")", ".", "order", "(", "'name'", ")", "return", "classes", ".", "map", "(", "function", "(", "klass", ")", "{", "const", "fns", "=", "data", ".", "findChildFunctions", "(", "db", ",", "[", "klass", "]", ")", ".", "order", "(", "'name'", ")", ".", "map", "(", "copyFunction", ")", "return", "copyClass", "(", "klass", ",", "fns", ")", "}", ")", "}" ]
Builds the classes from the database object `db`.
[ "Builds", "the", "classes", "from", "the", "database", "object", "db", "." ]
4db6650a8f20c49c9ab1fe03bfaaeae65356c8f0
https://github.com/nullobject/jsdoc-react/blob/4db6650a8f20c49c9ab1fe03bfaaeae65356c8f0/src/publish.js#L62-L73
40,542
lorenwest/monitor-dashboard
lib/js/PagesProbe.js
function() { var t = this; if (t.dirWatcher) { t.dirWatcher.close(); t.dirWatcher = null; } for (var pageId in t.fileWatchers) { t.fileWatchers[pageId].close(); } t.fileWatchers = {}; }
javascript
function() { var t = this; if (t.dirWatcher) { t.dirWatcher.close(); t.dirWatcher = null; } for (var pageId in t.fileWatchers) { t.fileWatchers[pageId].close(); } t.fileWatchers = {}; }
[ "function", "(", ")", "{", "var", "t", "=", "this", ";", "if", "(", "t", ".", "dirWatcher", ")", "{", "t", ".", "dirWatcher", ".", "close", "(", ")", ";", "t", ".", "dirWatcher", "=", "null", ";", "}", "for", "(", "var", "pageId", "in", "t", ".", "fileWatchers", ")", "{", "t", ".", "fileWatchers", "[", "pageId", "]", ".", "close", "(", ")", ";", "}", "t", ".", "fileWatchers", "=", "{", "}", ";", "}" ]
Release probe resources
[ "Release", "probe", "resources" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/PagesProbe.js#L125-L135
40,543
lorenwest/monitor-dashboard
lib/js/PagesProbe.js
function(dirs, callback) { var t = this, numLeft = dirs.length, fileRegexp = /.json$/, trimmed = []; // Already trimmed if (numLeft === 0) { return callback(null, dirs); } // Process each directory dirs.forEach(function(dir) { t.hasContents(dir.path, fileRegexp, function(error, hasContents) { if (error) { numLeft = 0; return callback(error); } delete dir.path; if (hasContents) { trimmed.push(dir); } if (--numLeft === 0) { return callback(null, trimmed); } }); }); }
javascript
function(dirs, callback) { var t = this, numLeft = dirs.length, fileRegexp = /.json$/, trimmed = []; // Already trimmed if (numLeft === 0) { return callback(null, dirs); } // Process each directory dirs.forEach(function(dir) { t.hasContents(dir.path, fileRegexp, function(error, hasContents) { if (error) { numLeft = 0; return callback(error); } delete dir.path; if (hasContents) { trimmed.push(dir); } if (--numLeft === 0) { return callback(null, trimmed); } }); }); }
[ "function", "(", "dirs", ",", "callback", ")", "{", "var", "t", "=", "this", ",", "numLeft", "=", "dirs", ".", "length", ",", "fileRegexp", "=", "/", ".json$", "/", ",", "trimmed", "=", "[", "]", ";", "// Already trimmed", "if", "(", "numLeft", "===", "0", ")", "{", "return", "callback", "(", "null", ",", "dirs", ")", ";", "}", "// Process each directory", "dirs", ".", "forEach", "(", "function", "(", "dir", ")", "{", "t", ".", "hasContents", "(", "dir", ".", "path", ",", "fileRegexp", ",", "function", "(", "error", ",", "hasContents", ")", "{", "if", "(", "error", ")", "{", "numLeft", "=", "0", ";", "return", "callback", "(", "error", ")", ";", "}", "delete", "dir", ".", "path", ";", "if", "(", "hasContents", ")", "{", "trimmed", ".", "push", "(", "dir", ")", ";", "}", "if", "(", "--", "numLeft", "===", "0", ")", "{", "return", "callback", "(", "null", ",", "trimmed", ")", ";", "}", "}", ")", ";", "}", ")", ";", "}" ]
Trim directories that have no content This accepts an array of objects, where each object must have a 'path' element. If no content is at the path, the object will be trimmed from the array. The path element will be removed after checking. @method trimDirs @param dirs {Object} An object that contains a 'path' element @param callback {function(error, trimmed)} Called when complete (or error)
[ "Trim", "directories", "that", "have", "no", "content" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/PagesProbe.js#L273-L300
40,544
lorenwest/monitor-dashboard
lib/js/PagesProbe.js
function(dirname, fileRegexp, callback) { var t = this; // Get the directory at this level FS.readdir(dirname, function(error, fileNames) { // Process errors if (error) { console.error('Read dir error', error); return callback(error); } // Process sequentially until content is found. // If parallel, a deep scan would occur every time. var dirsToCheck = []; function checkNext() { // Done checking all filenames if (fileNames.length === 0) { // Check directories, and return true if any have content t.trimDirs(dirsToCheck, function(error, trimmed) { return callback(error, trimmed.length > 0); }); return; } // Stat the next entry var filename = fileNames[0]; fileNames.splice(0,1); var pathName = Path.join(dirname, filename); FS.stat(pathName, function(error, stat) { if (error) { return callback(error); } // Check for directory content or if a file should be included if (stat.isDirectory()) { dirsToCheck.push({path:pathName}); } else { // There is content if a file exists and it matches an optional regexp if (!fileRegexp || fileRegexp.test(filename)) { return callback(null, true); } } // Check the next filename checkNext(); }); } // Kick off the first check checkNext(); }); }
javascript
function(dirname, fileRegexp, callback) { var t = this; // Get the directory at this level FS.readdir(dirname, function(error, fileNames) { // Process errors if (error) { console.error('Read dir error', error); return callback(error); } // Process sequentially until content is found. // If parallel, a deep scan would occur every time. var dirsToCheck = []; function checkNext() { // Done checking all filenames if (fileNames.length === 0) { // Check directories, and return true if any have content t.trimDirs(dirsToCheck, function(error, trimmed) { return callback(error, trimmed.length > 0); }); return; } // Stat the next entry var filename = fileNames[0]; fileNames.splice(0,1); var pathName = Path.join(dirname, filename); FS.stat(pathName, function(error, stat) { if (error) { return callback(error); } // Check for directory content or if a file should be included if (stat.isDirectory()) { dirsToCheck.push({path:pathName}); } else { // There is content if a file exists and it matches an optional regexp if (!fileRegexp || fileRegexp.test(filename)) { return callback(null, true); } } // Check the next filename checkNext(); }); } // Kick off the first check checkNext(); }); }
[ "function", "(", "dirname", ",", "fileRegexp", ",", "callback", ")", "{", "var", "t", "=", "this", ";", "// Get the directory at this level", "FS", ".", "readdir", "(", "dirname", ",", "function", "(", "error", ",", "fileNames", ")", "{", "// Process errors", "if", "(", "error", ")", "{", "console", ".", "error", "(", "'Read dir error'", ",", "error", ")", ";", "return", "callback", "(", "error", ")", ";", "}", "// Process sequentially until content is found.", "// If parallel, a deep scan would occur every time.", "var", "dirsToCheck", "=", "[", "]", ";", "function", "checkNext", "(", ")", "{", "// Done checking all filenames", "if", "(", "fileNames", ".", "length", "===", "0", ")", "{", "// Check directories, and return true if any have content", "t", ".", "trimDirs", "(", "dirsToCheck", ",", "function", "(", "error", ",", "trimmed", ")", "{", "return", "callback", "(", "error", ",", "trimmed", ".", "length", ">", "0", ")", ";", "}", ")", ";", "return", ";", "}", "// Stat the next entry", "var", "filename", "=", "fileNames", "[", "0", "]", ";", "fileNames", ".", "splice", "(", "0", ",", "1", ")", ";", "var", "pathName", "=", "Path", ".", "join", "(", "dirname", ",", "filename", ")", ";", "FS", ".", "stat", "(", "pathName", ",", "function", "(", "error", ",", "stat", ")", "{", "if", "(", "error", ")", "{", "return", "callback", "(", "error", ")", ";", "}", "// Check for directory content or if a file should be included", "if", "(", "stat", ".", "isDirectory", "(", ")", ")", "{", "dirsToCheck", ".", "push", "(", "{", "path", ":", "pathName", "}", ")", ";", "}", "else", "{", "// There is content if a file exists and it matches an optional regexp", "if", "(", "!", "fileRegexp", "||", "fileRegexp", ".", "test", "(", "filename", ")", ")", "{", "return", "callback", "(", "null", ",", "true", ")", ";", "}", "}", "// Check the next filename", "checkNext", "(", ")", ";", "}", ")", ";", "}", "// Kick off the first check", "checkNext", "(", ")", ";", "}", ")", ";", "}" ]
Determine if a directory has any contents. This will return true if any sub-directories with contents exist, or if any files with the specified RegExp exist. @method hasContents @param dirname {Path} Full path to the directory @param fileRegexp {RegExp} Regular expression to test for files @param callback {function(error, hasContents}} Regular expression to test for files
[ "Determine", "if", "a", "directory", "has", "any", "contents", "." ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/PagesProbe.js#L314-L369
40,545
lorenwest/monitor-dashboard
lib/js/PagesProbe.js
function(fileNames, callback) { var t = this, stats = [], didError = false, numLeft = fileNames.length; // No files to process if (fileNames.length === 0) { return callback(null, stats); } // Call stat on each file fileNames.forEach(function(fileName, index) { var fullPath = Path.join(t.dirPath, fileName); FS.stat(fullPath, function(error, stat) { // Process a stat error if (error) { didError = true; return callback(error); } // Do nothing if a prior error callback happened if (didError) { return; } // Set this stat item stats[index] = stat; // Callback if all stats are complete if (--numLeft === 0) { callback(null, stats); } }); }); }
javascript
function(fileNames, callback) { var t = this, stats = [], didError = false, numLeft = fileNames.length; // No files to process if (fileNames.length === 0) { return callback(null, stats); } // Call stat on each file fileNames.forEach(function(fileName, index) { var fullPath = Path.join(t.dirPath, fileName); FS.stat(fullPath, function(error, stat) { // Process a stat error if (error) { didError = true; return callback(error); } // Do nothing if a prior error callback happened if (didError) { return; } // Set this stat item stats[index] = stat; // Callback if all stats are complete if (--numLeft === 0) { callback(null, stats); } }); }); }
[ "function", "(", "fileNames", ",", "callback", ")", "{", "var", "t", "=", "this", ",", "stats", "=", "[", "]", ",", "didError", "=", "false", ",", "numLeft", "=", "fileNames", ".", "length", ";", "// No files to process", "if", "(", "fileNames", ".", "length", "===", "0", ")", "{", "return", "callback", "(", "null", ",", "stats", ")", ";", "}", "// Call stat on each file", "fileNames", ".", "forEach", "(", "function", "(", "fileName", ",", "index", ")", "{", "var", "fullPath", "=", "Path", ".", "join", "(", "t", ".", "dirPath", ",", "fileName", ")", ";", "FS", ".", "stat", "(", "fullPath", ",", "function", "(", "error", ",", "stat", ")", "{", "// Process a stat error", "if", "(", "error", ")", "{", "didError", "=", "true", ";", "return", "callback", "(", "error", ")", ";", "}", "// Do nothing if a prior error callback happened", "if", "(", "didError", ")", "{", "return", ";", "}", "// Set this stat item", "stats", "[", "index", "]", "=", "stat", ";", "// Callback if all stats are complete", "if", "(", "--", "numLeft", "===", "0", ")", "{", "callback", "(", "null", ",", "stats", ")", ";", "}", "}", ")", ";", "}", ")", ";", "}" ]
Stat all the files, returning an array of file stats matching the array of input files. @method statFiles @param fileNames {Array} An array of filenames to stat (from this directory) @param callback {Function(error, stats)} @param callback.error {Mixed} Set if an error occured @param callback.stats {Array of Stat} An array of fs.stats objects
[ "Stat", "all", "the", "files", "returning", "an", "array", "of", "file", "stats", "matching", "the", "array", "of", "input", "files", "." ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/PagesProbe.js#L381-L418
40,546
lorenwest/monitor-dashboard
lib/js/TreeView.js
function() { var t = this, branches = t.model.get('branches'), leaves = t.model.get('leaves'), hash = ""; // The hash is the text of the branches & leaves branches && branches.forEach(function(node) { var label = node.get('label') || node.id, description = node.get('description'); hash += '|' + label; if (description) { hash += '|' + description; } }); // The hash is the text of the branches & leaves leaves && leaves.forEach(function(node) { var label = node.get('label') || node.id, description = node.get('description'); hash += '|' + label; if (description) { hash += '|' + description; } }); // Return the hash return hash; }
javascript
function() { var t = this, branches = t.model.get('branches'), leaves = t.model.get('leaves'), hash = ""; // The hash is the text of the branches & leaves branches && branches.forEach(function(node) { var label = node.get('label') || node.id, description = node.get('description'); hash += '|' + label; if (description) { hash += '|' + description; } }); // The hash is the text of the branches & leaves leaves && leaves.forEach(function(node) { var label = node.get('label') || node.id, description = node.get('description'); hash += '|' + label; if (description) { hash += '|' + description; } }); // Return the hash return hash; }
[ "function", "(", ")", "{", "var", "t", "=", "this", ",", "branches", "=", "t", ".", "model", ".", "get", "(", "'branches'", ")", ",", "leaves", "=", "t", ".", "model", ".", "get", "(", "'leaves'", ")", ",", "hash", "=", "\"\"", ";", "// The hash is the text of the branches & leaves", "branches", "&&", "branches", ".", "forEach", "(", "function", "(", "node", ")", "{", "var", "label", "=", "node", ".", "get", "(", "'label'", ")", "||", "node", ".", "id", ",", "description", "=", "node", ".", "get", "(", "'description'", ")", ";", "hash", "+=", "'|'", "+", "label", ";", "if", "(", "description", ")", "{", "hash", "+=", "'|'", "+", "description", ";", "}", "}", ")", ";", "// The hash is the text of the branches & leaves", "leaves", "&&", "leaves", ".", "forEach", "(", "function", "(", "node", ")", "{", "var", "label", "=", "node", ".", "get", "(", "'label'", ")", "||", "node", ".", "id", ",", "description", "=", "node", ".", "get", "(", "'description'", ")", ";", "hash", "+=", "'|'", "+", "label", ";", "if", "(", "description", ")", "{", "hash", "+=", "'|'", "+", "description", ";", "}", "}", ")", ";", "// Return the hash", "return", "hash", ";", "}" ]
Return a hash code representing the visual state of the underlying data model. This is compared with subsequent states to prevent too much re-rendering.
[ "Return", "a", "hash", "code", "representing", "the", "visual", "state", "of", "the", "underlying", "data", "model", ".", "This", "is", "compared", "with", "subsequent", "states", "to", "prevent", "too", "much", "re", "-", "rendering", "." ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/TreeView.js#L194-L222
40,547
lorenwest/monitor-dashboard
lib/js/TreeView.js
function() { var t = this, branches = t.model.get('branches'), leaves = t.model.get('leaves'); // Determine if we should connect a monitor to this node // // Connect a monitor if: // * There isn't one already connected, and // * There's a monitor definition available, and // * We're open, or // * preFetch is selected, and // * we have no parent or our parent is open // // ** Is there any way to make this logic simpler? var shouldConnect = !t.model.hasMonitor() && t.options.monitorParams && (t.model.get('isOpen') || (t.options.preFetch && (!t.options.parentView || t.options.parentView.model.get('isOpen')))); // Connect to the monitor if we've determined we should if (shouldConnect) { // If there isn't any model data to display, show Loading... if (!branches || !leaves) { t.loading = $('<li>Loading...</li>').appendTo(t.$el); } // Build and connect the Monitor var initParams = _.extend( {}, t.options.monitorParams.initParams || {}, {path:t.options.path} ); var monitorParams = _.extend( {}, t.options.monitorParams, {initParams: initParams} ); t.monitor = new Monitor(monitorParams); t.model.attachMonitor(t.monitor); // Call our handlers once connected t.monitor.on('connect', function(){ setTimeout(function(){ for (var i in t.connectHandlers) { var handler = t.connectHandlers[i]; handler(t.monitor); } },10); }); // Connect the monitor and process errors. Successes will change // the underlying data model (or not), causing a re-render. t.monitor.connect(function(error) { // Remove the Loading... message if (t.loading) { t.loading.remove(); t.loading = null; } // Handle errors if (error) { $('<li>(connection problem)</li>').appendTo(t.$el); console.error('TreeView monitor connection problem:', error, t.monitor); // Detach the problem monitor so it'll have another chance // if the user opens/closes the branch. t.model.detachMonitor(); } }); } }
javascript
function() { var t = this, branches = t.model.get('branches'), leaves = t.model.get('leaves'); // Determine if we should connect a monitor to this node // // Connect a monitor if: // * There isn't one already connected, and // * There's a monitor definition available, and // * We're open, or // * preFetch is selected, and // * we have no parent or our parent is open // // ** Is there any way to make this logic simpler? var shouldConnect = !t.model.hasMonitor() && t.options.monitorParams && (t.model.get('isOpen') || (t.options.preFetch && (!t.options.parentView || t.options.parentView.model.get('isOpen')))); // Connect to the monitor if we've determined we should if (shouldConnect) { // If there isn't any model data to display, show Loading... if (!branches || !leaves) { t.loading = $('<li>Loading...</li>').appendTo(t.$el); } // Build and connect the Monitor var initParams = _.extend( {}, t.options.monitorParams.initParams || {}, {path:t.options.path} ); var monitorParams = _.extend( {}, t.options.monitorParams, {initParams: initParams} ); t.monitor = new Monitor(monitorParams); t.model.attachMonitor(t.monitor); // Call our handlers once connected t.monitor.on('connect', function(){ setTimeout(function(){ for (var i in t.connectHandlers) { var handler = t.connectHandlers[i]; handler(t.monitor); } },10); }); // Connect the monitor and process errors. Successes will change // the underlying data model (or not), causing a re-render. t.monitor.connect(function(error) { // Remove the Loading... message if (t.loading) { t.loading.remove(); t.loading = null; } // Handle errors if (error) { $('<li>(connection problem)</li>').appendTo(t.$el); console.error('TreeView monitor connection problem:', error, t.monitor); // Detach the problem monitor so it'll have another chance // if the user opens/closes the branch. t.model.detachMonitor(); } }); } }
[ "function", "(", ")", "{", "var", "t", "=", "this", ",", "branches", "=", "t", ".", "model", ".", "get", "(", "'branches'", ")", ",", "leaves", "=", "t", ".", "model", ".", "get", "(", "'leaves'", ")", ";", "// Determine if we should connect a monitor to this node", "//", "// Connect a monitor if:", "// * There isn't one already connected, and", "// * There's a monitor definition available, and", "// * We're open, or", "// * preFetch is selected, and", "// * we have no parent or our parent is open", "//", "// ** Is there any way to make this logic simpler?", "var", "shouldConnect", "=", "!", "t", ".", "model", ".", "hasMonitor", "(", ")", "&&", "t", ".", "options", ".", "monitorParams", "&&", "(", "t", ".", "model", ".", "get", "(", "'isOpen'", ")", "||", "(", "t", ".", "options", ".", "preFetch", "&&", "(", "!", "t", ".", "options", ".", "parentView", "||", "t", ".", "options", ".", "parentView", ".", "model", ".", "get", "(", "'isOpen'", ")", ")", ")", ")", ";", "// Connect to the monitor if we've determined we should", "if", "(", "shouldConnect", ")", "{", "// If there isn't any model data to display, show Loading...", "if", "(", "!", "branches", "||", "!", "leaves", ")", "{", "t", ".", "loading", "=", "$", "(", "'<li>Loading...</li>'", ")", ".", "appendTo", "(", "t", ".", "$el", ")", ";", "}", "// Build and connect the Monitor", "var", "initParams", "=", "_", ".", "extend", "(", "{", "}", ",", "t", ".", "options", ".", "monitorParams", ".", "initParams", "||", "{", "}", ",", "{", "path", ":", "t", ".", "options", ".", "path", "}", ")", ";", "var", "monitorParams", "=", "_", ".", "extend", "(", "{", "}", ",", "t", ".", "options", ".", "monitorParams", ",", "{", "initParams", ":", "initParams", "}", ")", ";", "t", ".", "monitor", "=", "new", "Monitor", "(", "monitorParams", ")", ";", "t", ".", "model", ".", "attachMonitor", "(", "t", ".", "monitor", ")", ";", "// Call our handlers once connected", "t", ".", "monitor", ".", "on", "(", "'connect'", ",", "function", "(", ")", "{", "setTimeout", "(", "function", "(", ")", "{", "for", "(", "var", "i", "in", "t", ".", "connectHandlers", ")", "{", "var", "handler", "=", "t", ".", "connectHandlers", "[", "i", "]", ";", "handler", "(", "t", ".", "monitor", ")", ";", "}", "}", ",", "10", ")", ";", "}", ")", ";", "// Connect the monitor and process errors. Successes will change", "// the underlying data model (or not), causing a re-render.", "t", ".", "monitor", ".", "connect", "(", "function", "(", "error", ")", "{", "// Remove the Loading... message", "if", "(", "t", ".", "loading", ")", "{", "t", ".", "loading", ".", "remove", "(", ")", ";", "t", ".", "loading", "=", "null", ";", "}", "// Handle errors", "if", "(", "error", ")", "{", "$", "(", "'<li>(connection problem)</li>'", ")", ".", "appendTo", "(", "t", ".", "$el", ")", ";", "console", ".", "error", "(", "'TreeView monitor connection problem:'", ",", "error", ",", "t", ".", "monitor", ")", ";", "// Detach the problem monitor so it'll have another chance", "// if the user opens/closes the branch.", "t", ".", "model", ".", "detachMonitor", "(", ")", ";", "}", "}", ")", ";", "}", "}" ]
Determine if we should connect a monitor to the node, and connect if necessary.
[ "Determine", "if", "we", "should", "connect", "a", "monitor", "to", "the", "node", "and", "connect", "if", "necessary", "." ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/TreeView.js#L226-L302
40,548
lorenwest/monitor-dashboard
lib/js/SettingsView.js
function() { var t = this, json = t.model.toJSON({trim:false}); t.sourceView.model = json; t.sourceView.setData(); t.editor.val(JSON.stringify(json, null, 2)); }
javascript
function() { var t = this, json = t.model.toJSON({trim:false}); t.sourceView.model = json; t.sourceView.setData(); t.editor.val(JSON.stringify(json, null, 2)); }
[ "function", "(", ")", "{", "var", "t", "=", "this", ",", "json", "=", "t", ".", "model", ".", "toJSON", "(", "{", "trim", ":", "false", "}", ")", ";", "t", ".", "sourceView", ".", "model", "=", "json", ";", "t", ".", "sourceView", ".", "setData", "(", ")", ";", "t", ".", "editor", ".", "val", "(", "JSON", ".", "stringify", "(", "json", ",", "null", ",", "2", ")", ")", ";", "}" ]
Fill the view-source and edit-source editors
[ "Fill", "the", "view", "-", "source", "and", "edit", "-", "source", "editors" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/SettingsView.js#L123-L129
40,549
lorenwest/monitor-dashboard
lib/js/Server.js
function(params, options) { var t = this, port = t.get('port'), server = t.get('server'), templates = t.get('templates'), siteDbPath = t.get('siteDbPath'), parentPath = siteDbPath.indexOf('.') === 0 ? process.cwd() : ''; // Distribute the site path to probes that need it t.set('siteDbPath', Path.join(parentPath, siteDbPath)); // Initialize probes SyncProbe.Config.defaultProbe = 'FileSyncProbe'; SyncProbe.FileSyncProbe.setRootPath(siteDbPath); // Expose the current instance so probes running // in this process can communicate with the server UI.Server.currentServer = t; // Internal (non-model) attributes t.apps = {}; // Hash appName -> app data t.site = null; // Site model associated with the server // Create a connect server if no custom server was specified if (!server) { server = new Connect(); t.set({server: server}); } // Attach server components server.use(t.siteRoute.bind(t)); server.use(Connect['static'](Path.join(__dirname, '/../..'))); // Create a static server to the monitor distribution var monitorDistDir = require.resolve('monitor').replace(/lib[\\\/]index.js/, 'dist'); t.monitorDist = Connect['static'](monitorDistDir); // Initialize the template library var gruntModules = GruntConfig.MODULE_DEF; gruntModules.templates.sort().forEach(function(template){ var path = Path.normalize(__dirname + '/../../' + template); var id = Path.basename(path, '.html'); templates.add({id:id, path:path}); }); // Build the page parameters from the config file var styles = "", scripts=""; gruntModules.client_css.forEach(function(cssFile) { styles += CSS_TEMPLATE({cssFile: cssFile.replace('lib/','/static/')}); }); var clientScripts = gruntModules.client_ext.concat(gruntModules.shared_js.concat(gruntModules.client_js)); clientScripts.forEach(function(file) { scripts += JS_TEMPLATE({scriptFile: file.replace('lib/','/static/')}); }); _.extend(PAGE_PARAMS, { styles: styles, scripts: scripts, version: PACKAGE_JSON.version }); }
javascript
function(params, options) { var t = this, port = t.get('port'), server = t.get('server'), templates = t.get('templates'), siteDbPath = t.get('siteDbPath'), parentPath = siteDbPath.indexOf('.') === 0 ? process.cwd() : ''; // Distribute the site path to probes that need it t.set('siteDbPath', Path.join(parentPath, siteDbPath)); // Initialize probes SyncProbe.Config.defaultProbe = 'FileSyncProbe'; SyncProbe.FileSyncProbe.setRootPath(siteDbPath); // Expose the current instance so probes running // in this process can communicate with the server UI.Server.currentServer = t; // Internal (non-model) attributes t.apps = {}; // Hash appName -> app data t.site = null; // Site model associated with the server // Create a connect server if no custom server was specified if (!server) { server = new Connect(); t.set({server: server}); } // Attach server components server.use(t.siteRoute.bind(t)); server.use(Connect['static'](Path.join(__dirname, '/../..'))); // Create a static server to the monitor distribution var monitorDistDir = require.resolve('monitor').replace(/lib[\\\/]index.js/, 'dist'); t.monitorDist = Connect['static'](monitorDistDir); // Initialize the template library var gruntModules = GruntConfig.MODULE_DEF; gruntModules.templates.sort().forEach(function(template){ var path = Path.normalize(__dirname + '/../../' + template); var id = Path.basename(path, '.html'); templates.add({id:id, path:path}); }); // Build the page parameters from the config file var styles = "", scripts=""; gruntModules.client_css.forEach(function(cssFile) { styles += CSS_TEMPLATE({cssFile: cssFile.replace('lib/','/static/')}); }); var clientScripts = gruntModules.client_ext.concat(gruntModules.shared_js.concat(gruntModules.client_js)); clientScripts.forEach(function(file) { scripts += JS_TEMPLATE({scriptFile: file.replace('lib/','/static/')}); }); _.extend(PAGE_PARAMS, { styles: styles, scripts: scripts, version: PACKAGE_JSON.version }); }
[ "function", "(", "params", ",", "options", ")", "{", "var", "t", "=", "this", ",", "port", "=", "t", ".", "get", "(", "'port'", ")", ",", "server", "=", "t", ".", "get", "(", "'server'", ")", ",", "templates", "=", "t", ".", "get", "(", "'templates'", ")", ",", "siteDbPath", "=", "t", ".", "get", "(", "'siteDbPath'", ")", ",", "parentPath", "=", "siteDbPath", ".", "indexOf", "(", "'.'", ")", "===", "0", "?", "process", ".", "cwd", "(", ")", ":", "''", ";", "// Distribute the site path to probes that need it", "t", ".", "set", "(", "'siteDbPath'", ",", "Path", ".", "join", "(", "parentPath", ",", "siteDbPath", ")", ")", ";", "// Initialize probes", "SyncProbe", ".", "Config", ".", "defaultProbe", "=", "'FileSyncProbe'", ";", "SyncProbe", ".", "FileSyncProbe", ".", "setRootPath", "(", "siteDbPath", ")", ";", "// Expose the current instance so probes running", "// in this process can communicate with the server", "UI", ".", "Server", ".", "currentServer", "=", "t", ";", "// Internal (non-model) attributes", "t", ".", "apps", "=", "{", "}", ";", "// Hash appName -> app data", "t", ".", "site", "=", "null", ";", "// Site model associated with the server", "// Create a connect server if no custom server was specified", "if", "(", "!", "server", ")", "{", "server", "=", "new", "Connect", "(", ")", ";", "t", ".", "set", "(", "{", "server", ":", "server", "}", ")", ";", "}", "// Attach server components", "server", ".", "use", "(", "t", ".", "siteRoute", ".", "bind", "(", "t", ")", ")", ";", "server", ".", "use", "(", "Connect", "[", "'static'", "]", "(", "Path", ".", "join", "(", "__dirname", ",", "'/../..'", ")", ")", ")", ";", "// Create a static server to the monitor distribution", "var", "monitorDistDir", "=", "require", ".", "resolve", "(", "'monitor'", ")", ".", "replace", "(", "/", "lib[\\\\\\/]index.js", "/", ",", "'dist'", ")", ";", "t", ".", "monitorDist", "=", "Connect", "[", "'static'", "]", "(", "monitorDistDir", ")", ";", "// Initialize the template library", "var", "gruntModules", "=", "GruntConfig", ".", "MODULE_DEF", ";", "gruntModules", ".", "templates", ".", "sort", "(", ")", ".", "forEach", "(", "function", "(", "template", ")", "{", "var", "path", "=", "Path", ".", "normalize", "(", "__dirname", "+", "'/../../'", "+", "template", ")", ";", "var", "id", "=", "Path", ".", "basename", "(", "path", ",", "'.html'", ")", ";", "templates", ".", "add", "(", "{", "id", ":", "id", ",", "path", ":", "path", "}", ")", ";", "}", ")", ";", "// Build the page parameters from the config file", "var", "styles", "=", "\"\"", ",", "scripts", "=", "\"\"", ";", "gruntModules", ".", "client_css", ".", "forEach", "(", "function", "(", "cssFile", ")", "{", "styles", "+=", "CSS_TEMPLATE", "(", "{", "cssFile", ":", "cssFile", ".", "replace", "(", "'lib/'", ",", "'/static/'", ")", "}", ")", ";", "}", ")", ";", "var", "clientScripts", "=", "gruntModules", ".", "client_ext", ".", "concat", "(", "gruntModules", ".", "shared_js", ".", "concat", "(", "gruntModules", ".", "client_js", ")", ")", ";", "clientScripts", ".", "forEach", "(", "function", "(", "file", ")", "{", "scripts", "+=", "JS_TEMPLATE", "(", "{", "scriptFile", ":", "file", ".", "replace", "(", "'lib/'", ",", "'/static/'", ")", "}", ")", ";", "}", ")", ";", "_", ".", "extend", "(", "PAGE_PARAMS", ",", "{", "styles", ":", "styles", ",", "scripts", ":", "scripts", ",", "version", ":", "PACKAGE_JSON", ".", "version", "}", ")", ";", "}" ]
Initialize the server
[ "Initialize", "the", "server" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/Server.js#L70-L127
40,550
lorenwest/monitor-dashboard
lib/js/Server.js
function(request, response, next) { var t = this; // URL rewrites var url = URL.resolve('', request.url); if (url === '/favicon.ico') { var faviconUrl = t.site.get('favicon'); url = request.url = faviconUrl || request.url; } // Remove the leading slash for page manipulation url = url.substr(1); // Rewrite the url and forward if it points to static content var urlParts = url.split('/'); if (urlParts[0] === 'static') { // Replace static with lib, and put the leading slash back in request.url = url.replace('static/', '/lib/'); // Forward to the monitor distribution if (request.url.indexOf('monitor-all.js') > 0) { request.url = '/monitor-all.js'; return t.monitorDist(request, response, next); } // Next is the static server return next(); } // If it's an URL to an app, route to the app if (urlParts[0] === 'app') { var appName = urlParts[1], app = t.apps[appName]; // Route to a monitor page if the app doesn't handle the request var appNext = function() { t._monitorPageRoute(request, response, next); }; // Continue if the app isn't defined if (!app) { return appNext(); } // Make the app request relative to the app var appUrl = '/' + url.split('/').slice(2).join('/'), appRequest = _.extend({}, request, {url: appUrl}); // Forward the request to the app server var server = typeof app.server === 'function' ? app.server : app.staticServer; return server(appRequest, response, appNext); } // Forward to a monitor page t._monitorPageRoute(request, response, next); }
javascript
function(request, response, next) { var t = this; // URL rewrites var url = URL.resolve('', request.url); if (url === '/favicon.ico') { var faviconUrl = t.site.get('favicon'); url = request.url = faviconUrl || request.url; } // Remove the leading slash for page manipulation url = url.substr(1); // Rewrite the url and forward if it points to static content var urlParts = url.split('/'); if (urlParts[0] === 'static') { // Replace static with lib, and put the leading slash back in request.url = url.replace('static/', '/lib/'); // Forward to the monitor distribution if (request.url.indexOf('monitor-all.js') > 0) { request.url = '/monitor-all.js'; return t.monitorDist(request, response, next); } // Next is the static server return next(); } // If it's an URL to an app, route to the app if (urlParts[0] === 'app') { var appName = urlParts[1], app = t.apps[appName]; // Route to a monitor page if the app doesn't handle the request var appNext = function() { t._monitorPageRoute(request, response, next); }; // Continue if the app isn't defined if (!app) { return appNext(); } // Make the app request relative to the app var appUrl = '/' + url.split('/').slice(2).join('/'), appRequest = _.extend({}, request, {url: appUrl}); // Forward the request to the app server var server = typeof app.server === 'function' ? app.server : app.staticServer; return server(appRequest, response, appNext); } // Forward to a monitor page t._monitorPageRoute(request, response, next); }
[ "function", "(", "request", ",", "response", ",", "next", ")", "{", "var", "t", "=", "this", ";", "// URL rewrites", "var", "url", "=", "URL", ".", "resolve", "(", "''", ",", "request", ".", "url", ")", ";", "if", "(", "url", "===", "'/favicon.ico'", ")", "{", "var", "faviconUrl", "=", "t", ".", "site", ".", "get", "(", "'favicon'", ")", ";", "url", "=", "request", ".", "url", "=", "faviconUrl", "||", "request", ".", "url", ";", "}", "// Remove the leading slash for page manipulation", "url", "=", "url", ".", "substr", "(", "1", ")", ";", "// Rewrite the url and forward if it points to static content", "var", "urlParts", "=", "url", ".", "split", "(", "'/'", ")", ";", "if", "(", "urlParts", "[", "0", "]", "===", "'static'", ")", "{", "// Replace static with lib, and put the leading slash back in", "request", ".", "url", "=", "url", ".", "replace", "(", "'static/'", ",", "'/lib/'", ")", ";", "// Forward to the monitor distribution", "if", "(", "request", ".", "url", ".", "indexOf", "(", "'monitor-all.js'", ")", ">", "0", ")", "{", "request", ".", "url", "=", "'/monitor-all.js'", ";", "return", "t", ".", "monitorDist", "(", "request", ",", "response", ",", "next", ")", ";", "}", "// Next is the static server", "return", "next", "(", ")", ";", "}", "// If it's an URL to an app, route to the app", "if", "(", "urlParts", "[", "0", "]", "===", "'app'", ")", "{", "var", "appName", "=", "urlParts", "[", "1", "]", ",", "app", "=", "t", ".", "apps", "[", "appName", "]", ";", "// Route to a monitor page if the app doesn't handle the request", "var", "appNext", "=", "function", "(", ")", "{", "t", ".", "_monitorPageRoute", "(", "request", ",", "response", ",", "next", ")", ";", "}", ";", "// Continue if the app isn't defined", "if", "(", "!", "app", ")", "{", "return", "appNext", "(", ")", ";", "}", "// Make the app request relative to the app", "var", "appUrl", "=", "'/'", "+", "url", ".", "split", "(", "'/'", ")", ".", "slice", "(", "2", ")", ".", "join", "(", "'/'", ")", ",", "appRequest", "=", "_", ".", "extend", "(", "{", "}", ",", "request", ",", "{", "url", ":", "appUrl", "}", ")", ";", "// Forward the request to the app server", "var", "server", "=", "typeof", "app", ".", "server", "===", "'function'", "?", "app", ".", "server", ":", "app", ".", "staticServer", ";", "return", "server", "(", "appRequest", ",", "response", ",", "appNext", ")", ";", "}", "// Forward to a monitor page", "t", ".", "_monitorPageRoute", "(", "request", ",", "response", ",", "next", ")", ";", "}" ]
Internal route for all non-static site endpoints @method siteRoute @param request {Connect.Request} The http request object @param response {Connect.Response} The http response object @param next {Function()} Function to pass control if this doesn't handle the url.
[ "Internal", "route", "for", "all", "non", "-", "static", "site", "endpoints" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/Server.js#L137-L193
40,551
lorenwest/monitor-dashboard
lib/js/Server.js
function(request, response, next) { var t = this, url = request.url, searchStart = url.indexOf('?'), templates = t.get('templates'); // Remove any URL params if (searchStart > 0) { url = url.substr(0, searchStart); } // Get the page model t._getPage(url, function(error, pageModel) { if (error) { return response.end('page error: ' + JSON.stringify(error)); } // Build the object to put into the page template var page = _.extend({templates:''}, PAGE_PARAMS, t.site.toJSON(), pageModel.toJSON()); page.pageParams = Template.indent(JSON.stringify(pageModel.toJSON({deep:true,trim:true}), null, 2), 8); // Add all watched templates except the main page templates.each(function(template) { if (template.id !== 'UI') { page.templates += TMPL_TEMPLATE({ id:template.id, text:Template.indent(template.get('text'),8) }); } }); // Output the page response.writeHead(200, {'Content-Type': 'text/html'}); var pageTemplate = templates.get('UI'); return response.end(pageTemplate.apply(page)); }); }
javascript
function(request, response, next) { var t = this, url = request.url, searchStart = url.indexOf('?'), templates = t.get('templates'); // Remove any URL params if (searchStart > 0) { url = url.substr(0, searchStart); } // Get the page model t._getPage(url, function(error, pageModel) { if (error) { return response.end('page error: ' + JSON.stringify(error)); } // Build the object to put into the page template var page = _.extend({templates:''}, PAGE_PARAMS, t.site.toJSON(), pageModel.toJSON()); page.pageParams = Template.indent(JSON.stringify(pageModel.toJSON({deep:true,trim:true}), null, 2), 8); // Add all watched templates except the main page templates.each(function(template) { if (template.id !== 'UI') { page.templates += TMPL_TEMPLATE({ id:template.id, text:Template.indent(template.get('text'),8) }); } }); // Output the page response.writeHead(200, {'Content-Type': 'text/html'}); var pageTemplate = templates.get('UI'); return response.end(pageTemplate.apply(page)); }); }
[ "function", "(", "request", ",", "response", ",", "next", ")", "{", "var", "t", "=", "this", ",", "url", "=", "request", ".", "url", ",", "searchStart", "=", "url", ".", "indexOf", "(", "'?'", ")", ",", "templates", "=", "t", ".", "get", "(", "'templates'", ")", ";", "// Remove any URL params", "if", "(", "searchStart", ">", "0", ")", "{", "url", "=", "url", ".", "substr", "(", "0", ",", "searchStart", ")", ";", "}", "// Get the page model", "t", ".", "_getPage", "(", "url", ",", "function", "(", "error", ",", "pageModel", ")", "{", "if", "(", "error", ")", "{", "return", "response", ".", "end", "(", "'page error: '", "+", "JSON", ".", "stringify", "(", "error", ")", ")", ";", "}", "// Build the object to put into the page template", "var", "page", "=", "_", ".", "extend", "(", "{", "templates", ":", "''", "}", ",", "PAGE_PARAMS", ",", "t", ".", "site", ".", "toJSON", "(", ")", ",", "pageModel", ".", "toJSON", "(", ")", ")", ";", "page", ".", "pageParams", "=", "Template", ".", "indent", "(", "JSON", ".", "stringify", "(", "pageModel", ".", "toJSON", "(", "{", "deep", ":", "true", ",", "trim", ":", "true", "}", ")", ",", "null", ",", "2", ")", ",", "8", ")", ";", "// Add all watched templates except the main page", "templates", ".", "each", "(", "function", "(", "template", ")", "{", "if", "(", "template", ".", "id", "!==", "'UI'", ")", "{", "page", ".", "templates", "+=", "TMPL_TEMPLATE", "(", "{", "id", ":", "template", ".", "id", ",", "text", ":", "Template", ".", "indent", "(", "template", ".", "get", "(", "'text'", ")", ",", "8", ")", "}", ")", ";", "}", "}", ")", ";", "// Output the page", "response", ".", "writeHead", "(", "200", ",", "{", "'Content-Type'", ":", "'text/html'", "}", ")", ";", "var", "pageTemplate", "=", "templates", ".", "get", "(", "'UI'", ")", ";", "return", "response", ".", "end", "(", "pageTemplate", ".", "apply", "(", "page", ")", ")", ";", "}", ")", ";", "}" ]
Route to a monitor page. @protected @method _monitorPageRoute @param request {Connect.Request} The http request object @param response {Connect.Response} The http response object @param next {Function()} Function to pass control if this doesn't handle the url.
[ "Route", "to", "a", "monitor", "page", "." ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/Server.js#L204-L241
40,552
lorenwest/monitor-dashboard
lib/js/Server.js
function(url, callback) { var t = this, originalUrl = url, page = null; // Change urls that end in / to /index if (url.substr(-1) === '/') { url = url + 'index'; } // Return if it's in cache page = pageCache.get(url); if (page) { return callback(null, page); } // Read from storage page = new Page({id: url}); page.fetch({liveSync: true, silenceErrors: true}, function(error) { // Process a 404. This returns a transient page copied from // the default 404 page, with the id replaced by the specified url. if (error && error.code === 'NOTFOUND' && url !== '/app/core/404') { // Default the home page if notfound if (originalUrl === '/') { return t._getPage('/app/core/index', callback); } // Default the 404 page if notfound if (originalUrl === '/404') { return t._getPage('/app/core/404', callback); } // Otherwise it's a new page. Create it. t._getPage('/404', function(error, page404) { if (error) { console.error("Error loading the 404 page", error); return callback('404 page load error'); } // Copy the 404 page into a new page var newPage = new Page(JSON.parse(JSON.stringify(page404))); // Build a sane starting title. TitleCase the last url element, separate words, replace underscores var title = $.titleCase(url.split('/').pop(), true).replace(/([A-Z])/g," $1").replace(/^ /,'').replace(/_/g,' '); var title = url.split('/').pop().replace(/([A-Z])/g," $1").replace(/^ /,'').replace(/_/g,' '); newPage.set({id:url, title:title, is404page:true}); callback(null, newPage); }); return; } // Process other errors if (error) { return callback(error); } // Assure the page model ID is correct on disk if (url !== page.get('id')) { page.set('id', url); } // Put the page into cache and return it pageCache.add(page); return callback(null, page); }); }
javascript
function(url, callback) { var t = this, originalUrl = url, page = null; // Change urls that end in / to /index if (url.substr(-1) === '/') { url = url + 'index'; } // Return if it's in cache page = pageCache.get(url); if (page) { return callback(null, page); } // Read from storage page = new Page({id: url}); page.fetch({liveSync: true, silenceErrors: true}, function(error) { // Process a 404. This returns a transient page copied from // the default 404 page, with the id replaced by the specified url. if (error && error.code === 'NOTFOUND' && url !== '/app/core/404') { // Default the home page if notfound if (originalUrl === '/') { return t._getPage('/app/core/index', callback); } // Default the 404 page if notfound if (originalUrl === '/404') { return t._getPage('/app/core/404', callback); } // Otherwise it's a new page. Create it. t._getPage('/404', function(error, page404) { if (error) { console.error("Error loading the 404 page", error); return callback('404 page load error'); } // Copy the 404 page into a new page var newPage = new Page(JSON.parse(JSON.stringify(page404))); // Build a sane starting title. TitleCase the last url element, separate words, replace underscores var title = $.titleCase(url.split('/').pop(), true).replace(/([A-Z])/g," $1").replace(/^ /,'').replace(/_/g,' '); var title = url.split('/').pop().replace(/([A-Z])/g," $1").replace(/^ /,'').replace(/_/g,' '); newPage.set({id:url, title:title, is404page:true}); callback(null, newPage); }); return; } // Process other errors if (error) { return callback(error); } // Assure the page model ID is correct on disk if (url !== page.get('id')) { page.set('id', url); } // Put the page into cache and return it pageCache.add(page); return callback(null, page); }); }
[ "function", "(", "url", ",", "callback", ")", "{", "var", "t", "=", "this", ",", "originalUrl", "=", "url", ",", "page", "=", "null", ";", "// Change urls that end in / to /index", "if", "(", "url", ".", "substr", "(", "-", "1", ")", "===", "'/'", ")", "{", "url", "=", "url", "+", "'index'", ";", "}", "// Return if it's in cache", "page", "=", "pageCache", ".", "get", "(", "url", ")", ";", "if", "(", "page", ")", "{", "return", "callback", "(", "null", ",", "page", ")", ";", "}", "// Read from storage", "page", "=", "new", "Page", "(", "{", "id", ":", "url", "}", ")", ";", "page", ".", "fetch", "(", "{", "liveSync", ":", "true", ",", "silenceErrors", ":", "true", "}", ",", "function", "(", "error", ")", "{", "// Process a 404. This returns a transient page copied from", "// the default 404 page, with the id replaced by the specified url.", "if", "(", "error", "&&", "error", ".", "code", "===", "'NOTFOUND'", "&&", "url", "!==", "'/app/core/404'", ")", "{", "// Default the home page if notfound", "if", "(", "originalUrl", "===", "'/'", ")", "{", "return", "t", ".", "_getPage", "(", "'/app/core/index'", ",", "callback", ")", ";", "}", "// Default the 404 page if notfound", "if", "(", "originalUrl", "===", "'/404'", ")", "{", "return", "t", ".", "_getPage", "(", "'/app/core/404'", ",", "callback", ")", ";", "}", "// Otherwise it's a new page. Create it.", "t", ".", "_getPage", "(", "'/404'", ",", "function", "(", "error", ",", "page404", ")", "{", "if", "(", "error", ")", "{", "console", ".", "error", "(", "\"Error loading the 404 page\"", ",", "error", ")", ";", "return", "callback", "(", "'404 page load error'", ")", ";", "}", "// Copy the 404 page into a new page", "var", "newPage", "=", "new", "Page", "(", "JSON", ".", "parse", "(", "JSON", ".", "stringify", "(", "page404", ")", ")", ")", ";", "// Build a sane starting title. TitleCase the last url element, separate words, replace underscores", "var", "title", "=", "$", ".", "titleCase", "(", "url", ".", "split", "(", "'/'", ")", ".", "pop", "(", ")", ",", "true", ")", ".", "replace", "(", "/", "([A-Z])", "/", "g", ",", "\" $1\"", ")", ".", "replace", "(", "/", "^ ", "/", ",", "''", ")", ".", "replace", "(", "/", "_", "/", "g", ",", "' '", ")", ";", "var", "title", "=", "url", ".", "split", "(", "'/'", ")", ".", "pop", "(", ")", ".", "replace", "(", "/", "([A-Z])", "/", "g", ",", "\" $1\"", ")", ".", "replace", "(", "/", "^ ", "/", ",", "''", ")", ".", "replace", "(", "/", "_", "/", "g", ",", "' '", ")", ";", "newPage", ".", "set", "(", "{", "id", ":", "url", ",", "title", ":", "title", ",", "is404page", ":", "true", "}", ")", ";", "callback", "(", "null", ",", "newPage", ")", ";", "}", ")", ";", "return", ";", "}", "// Process other errors", "if", "(", "error", ")", "{", "return", "callback", "(", "error", ")", ";", "}", "// Assure the page model ID is correct on disk", "if", "(", "url", "!==", "page", ".", "get", "(", "'id'", ")", ")", "{", "page", ".", "set", "(", "'id'", ",", "url", ")", ";", "}", "// Put the page into cache and return it", "pageCache", ".", "add", "(", "page", ")", ";", "return", "callback", "(", "null", ",", "page", ")", ";", "}", ")", ";", "}" ]
Get the specified page from cache This retrieves the page from cache, or puts it there. @method _getPage @param url {url} URL to the page @param callback {function(error, pageModel)} Called when complete
[ "Get", "the", "specified", "page", "from", "cache" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/Server.js#L252-L319
40,553
lorenwest/monitor-dashboard
lib/js/Server.js
function(callback) { callback = callback || function(){}; var t = this, server = t.get('server'), port = t.get('port'), allowExternalConnections = t.get('allowExternalConnections'); // Allow connections from INADDR_ANY or LOCALHOST only var host = allowExternalConnections ? '0.0.0.0' : '127.0.0.1'; // Start listening server.listen(port, host, function(){ // Allow the UI server to be a Monitor gateway server t.monitorServer = new Monitor.Server({server:server, gateway: true}); t.monitorServer.start(function(){ // Called after the site object is loaded var onSiteLoad = function(error) { if (error) { return callback(error); } // Discover and initialize application modules t.loadApps(); // Bind server events t._bindEvents(callback); }; // Load and keep the web site object updated t.site = new Site(); t.site.fetch({liveSync: true, silenceErrors:true}, function(error) { // Initialize the site if it's not found if (error && error.code === 'NOTFOUND') { t.site = new Site(); t.site.id = null; // This causes a create vs. update on save return t.site.save({}, {liveSync: true}, onSiteLoad); } else if (error) { return onSiteLoad(error); } // Bind server events once connected onSiteLoad(); }); }); }); }
javascript
function(callback) { callback = callback || function(){}; var t = this, server = t.get('server'), port = t.get('port'), allowExternalConnections = t.get('allowExternalConnections'); // Allow connections from INADDR_ANY or LOCALHOST only var host = allowExternalConnections ? '0.0.0.0' : '127.0.0.1'; // Start listening server.listen(port, host, function(){ // Allow the UI server to be a Monitor gateway server t.monitorServer = new Monitor.Server({server:server, gateway: true}); t.monitorServer.start(function(){ // Called after the site object is loaded var onSiteLoad = function(error) { if (error) { return callback(error); } // Discover and initialize application modules t.loadApps(); // Bind server events t._bindEvents(callback); }; // Load and keep the web site object updated t.site = new Site(); t.site.fetch({liveSync: true, silenceErrors:true}, function(error) { // Initialize the site if it's not found if (error && error.code === 'NOTFOUND') { t.site = new Site(); t.site.id = null; // This causes a create vs. update on save return t.site.save({}, {liveSync: true}, onSiteLoad); } else if (error) { return onSiteLoad(error); } // Bind server events once connected onSiteLoad(); }); }); }); }
[ "function", "(", "callback", ")", "{", "callback", "=", "callback", "||", "function", "(", ")", "{", "}", ";", "var", "t", "=", "this", ",", "server", "=", "t", ".", "get", "(", "'server'", ")", ",", "port", "=", "t", ".", "get", "(", "'port'", ")", ",", "allowExternalConnections", "=", "t", ".", "get", "(", "'allowExternalConnections'", ")", ";", "// Allow connections from INADDR_ANY or LOCALHOST only", "var", "host", "=", "allowExternalConnections", "?", "'0.0.0.0'", ":", "'127.0.0.1'", ";", "// Start listening", "server", ".", "listen", "(", "port", ",", "host", ",", "function", "(", ")", "{", "// Allow the UI server to be a Monitor gateway server", "t", ".", "monitorServer", "=", "new", "Monitor", ".", "Server", "(", "{", "server", ":", "server", ",", "gateway", ":", "true", "}", ")", ";", "t", ".", "monitorServer", ".", "start", "(", "function", "(", ")", "{", "// Called after the site object is loaded", "var", "onSiteLoad", "=", "function", "(", "error", ")", "{", "if", "(", "error", ")", "{", "return", "callback", "(", "error", ")", ";", "}", "// Discover and initialize application modules", "t", ".", "loadApps", "(", ")", ";", "// Bind server events", "t", ".", "_bindEvents", "(", "callback", ")", ";", "}", ";", "// Load and keep the web site object updated", "t", ".", "site", "=", "new", "Site", "(", ")", ";", "t", ".", "site", ".", "fetch", "(", "{", "liveSync", ":", "true", ",", "silenceErrors", ":", "true", "}", ",", "function", "(", "error", ")", "{", "// Initialize the site if it's not found", "if", "(", "error", "&&", "error", ".", "code", "===", "'NOTFOUND'", ")", "{", "t", ".", "site", "=", "new", "Site", "(", ")", ";", "t", ".", "site", ".", "id", "=", "null", ";", "// This causes a create vs. update on save", "return", "t", ".", "site", ".", "save", "(", "{", "}", ",", "{", "liveSync", ":", "true", "}", ",", "onSiteLoad", ")", ";", "}", "else", "if", "(", "error", ")", "{", "return", "onSiteLoad", "(", "error", ")", ";", "}", "// Bind server events once connected", "onSiteLoad", "(", ")", ";", "}", ")", ";", "}", ")", ";", "}", ")", ";", "}" ]
Start the UI server This method starts listening for incoming UI requests. @method start @param [callback] {Function(error)} - Called when the server has started The server has started This event is fired when the server has begun listening for incoming web requests. @event start A client error has been detected This event is fired if an error has been detected in the underlying transport. It may indicate message loss. @event error
[ "Start", "the", "UI", "server" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/Server.js#L345-L393
40,554
lorenwest/monitor-dashboard
lib/js/Server.js
function() { var t = this; // Test an app directory to see if it's a monitor app var testAppDir = function(dir) { // Load the package.json if it exists (and remove relative refs) var pkg; dir = Path.resolve(dir); try { pkg = JSON.parse(FS.readFileSync(dir + '/package.json', 'utf-8')); } catch (e) { // Report an error if the package.json has a parse problem. This is // good during app development to show why we didn't discover the app. if (e.code !== "ENOENT") { console.error("Problem parsing " + dir + "/package.json"); } return false; } // Is this a monitor-dashboard app? var isMonitorApp = pkg.dependencies && _.find(_.keys(pkg.dependencies), function(keyword){ return keyword === 'monitor-dashboard'; }); if (!isMonitorApp) { return false; } // This is a monitor-dashboard app. return t.loadApp(dir, pkg); }; // Process all apps under a node_modules directory var loadNodeModulesDir = function(dir) { // Return if the node_modules directory doesn't exist. try { FS.statSync(dir); } catch (e) {return;} // Check each direcory for a monitor-dashboard app FS.readdirSync(dir).forEach(function(moduleName) { // See if this is a monitor app, and load if it is // then load sub-modules var moduleDir = dir + '/' + moduleName; if (testAppDir(moduleDir) || moduleName === 'monitor') { // If it is a monitor-app, process any sub node_modules loadNodeModulesDir(moduleDir + '/node_modules'); } }); }; // Test this app as a monitor app t.thisAppName = testAppDir('.'); // Process all possible node_module directories in the require path. process.mainModule.paths.forEach(loadNodeModulesDir); }
javascript
function() { var t = this; // Test an app directory to see if it's a monitor app var testAppDir = function(dir) { // Load the package.json if it exists (and remove relative refs) var pkg; dir = Path.resolve(dir); try { pkg = JSON.parse(FS.readFileSync(dir + '/package.json', 'utf-8')); } catch (e) { // Report an error if the package.json has a parse problem. This is // good during app development to show why we didn't discover the app. if (e.code !== "ENOENT") { console.error("Problem parsing " + dir + "/package.json"); } return false; } // Is this a monitor-dashboard app? var isMonitorApp = pkg.dependencies && _.find(_.keys(pkg.dependencies), function(keyword){ return keyword === 'monitor-dashboard'; }); if (!isMonitorApp) { return false; } // This is a monitor-dashboard app. return t.loadApp(dir, pkg); }; // Process all apps under a node_modules directory var loadNodeModulesDir = function(dir) { // Return if the node_modules directory doesn't exist. try { FS.statSync(dir); } catch (e) {return;} // Check each direcory for a monitor-dashboard app FS.readdirSync(dir).forEach(function(moduleName) { // See if this is a monitor app, and load if it is // then load sub-modules var moduleDir = dir + '/' + moduleName; if (testAppDir(moduleDir) || moduleName === 'monitor') { // If it is a monitor-app, process any sub node_modules loadNodeModulesDir(moduleDir + '/node_modules'); } }); }; // Test this app as a monitor app t.thisAppName = testAppDir('.'); // Process all possible node_module directories in the require path. process.mainModule.paths.forEach(loadNodeModulesDir); }
[ "function", "(", ")", "{", "var", "t", "=", "this", ";", "// Test an app directory to see if it's a monitor app", "var", "testAppDir", "=", "function", "(", "dir", ")", "{", "// Load the package.json if it exists (and remove relative refs)", "var", "pkg", ";", "dir", "=", "Path", ".", "resolve", "(", "dir", ")", ";", "try", "{", "pkg", "=", "JSON", ".", "parse", "(", "FS", ".", "readFileSync", "(", "dir", "+", "'/package.json'", ",", "'utf-8'", ")", ")", ";", "}", "catch", "(", "e", ")", "{", "// Report an error if the package.json has a parse problem. This is", "// good during app development to show why we didn't discover the app.", "if", "(", "e", ".", "code", "!==", "\"ENOENT\"", ")", "{", "console", ".", "error", "(", "\"Problem parsing \"", "+", "dir", "+", "\"/package.json\"", ")", ";", "}", "return", "false", ";", "}", "// Is this a monitor-dashboard app?", "var", "isMonitorApp", "=", "pkg", ".", "dependencies", "&&", "_", ".", "find", "(", "_", ".", "keys", "(", "pkg", ".", "dependencies", ")", ",", "function", "(", "keyword", ")", "{", "return", "keyword", "===", "'monitor-dashboard'", ";", "}", ")", ";", "if", "(", "!", "isMonitorApp", ")", "{", "return", "false", ";", "}", "// This is a monitor-dashboard app.", "return", "t", ".", "loadApp", "(", "dir", ",", "pkg", ")", ";", "}", ";", "// Process all apps under a node_modules directory", "var", "loadNodeModulesDir", "=", "function", "(", "dir", ")", "{", "// Return if the node_modules directory doesn't exist.", "try", "{", "FS", ".", "statSync", "(", "dir", ")", ";", "}", "catch", "(", "e", ")", "{", "return", ";", "}", "// Check each direcory for a monitor-dashboard app", "FS", ".", "readdirSync", "(", "dir", ")", ".", "forEach", "(", "function", "(", "moduleName", ")", "{", "// See if this is a monitor app, and load if it is", "// then load sub-modules", "var", "moduleDir", "=", "dir", "+", "'/'", "+", "moduleName", ";", "if", "(", "testAppDir", "(", "moduleDir", ")", "||", "moduleName", "===", "'monitor'", ")", "{", "// If it is a monitor-app, process any sub node_modules", "loadNodeModulesDir", "(", "moduleDir", "+", "'/node_modules'", ")", ";", "}", "}", ")", ";", "}", ";", "// Test this app as a monitor app", "t", ".", "thisAppName", "=", "testAppDir", "(", "'.'", ")", ";", "// Process all possible node_module directories in the require path.", "process", ".", "mainModule", ".", "paths", ".", "forEach", "(", "loadNodeModulesDir", ")", ";", "}" ]
Discover and load all node_monitor application modules This is designed to run during server initialization, and is synchronous. @method loadApps
[ "Discover", "and", "load", "all", "node_monitor", "application", "modules" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/Server.js#L430-L488
40,555
lorenwest/monitor-dashboard
lib/js/Server.js
function(dir) { // Load the package.json if it exists (and remove relative refs) var pkg; dir = Path.resolve(dir); try { pkg = JSON.parse(FS.readFileSync(dir + '/package.json', 'utf-8')); } catch (e) { // Report an error if the package.json has a parse problem. This is // good during app development to show why we didn't discover the app. if (e.code !== "ENOENT") { console.error("Problem parsing " + dir + "/package.json"); } return false; } // Is this a monitor-dashboard app? var isMonitorApp = pkg.dependencies && _.find(_.keys(pkg.dependencies), function(keyword){ return keyword === 'monitor-dashboard'; }); if (!isMonitorApp) { return false; } // This is a monitor-dashboard app. return t.loadApp(dir, pkg); }
javascript
function(dir) { // Load the package.json if it exists (and remove relative refs) var pkg; dir = Path.resolve(dir); try { pkg = JSON.parse(FS.readFileSync(dir + '/package.json', 'utf-8')); } catch (e) { // Report an error if the package.json has a parse problem. This is // good during app development to show why we didn't discover the app. if (e.code !== "ENOENT") { console.error("Problem parsing " + dir + "/package.json"); } return false; } // Is this a monitor-dashboard app? var isMonitorApp = pkg.dependencies && _.find(_.keys(pkg.dependencies), function(keyword){ return keyword === 'monitor-dashboard'; }); if (!isMonitorApp) { return false; } // This is a monitor-dashboard app. return t.loadApp(dir, pkg); }
[ "function", "(", "dir", ")", "{", "// Load the package.json if it exists (and remove relative refs)", "var", "pkg", ";", "dir", "=", "Path", ".", "resolve", "(", "dir", ")", ";", "try", "{", "pkg", "=", "JSON", ".", "parse", "(", "FS", ".", "readFileSync", "(", "dir", "+", "'/package.json'", ",", "'utf-8'", ")", ")", ";", "}", "catch", "(", "e", ")", "{", "// Report an error if the package.json has a parse problem. This is", "// good during app development to show why we didn't discover the app.", "if", "(", "e", ".", "code", "!==", "\"ENOENT\"", ")", "{", "console", ".", "error", "(", "\"Problem parsing \"", "+", "dir", "+", "\"/package.json\"", ")", ";", "}", "return", "false", ";", "}", "// Is this a monitor-dashboard app?", "var", "isMonitorApp", "=", "pkg", ".", "dependencies", "&&", "_", ".", "find", "(", "_", ".", "keys", "(", "pkg", ".", "dependencies", ")", ",", "function", "(", "keyword", ")", "{", "return", "keyword", "===", "'monitor-dashboard'", ";", "}", ")", ";", "if", "(", "!", "isMonitorApp", ")", "{", "return", "false", ";", "}", "// This is a monitor-dashboard app.", "return", "t", ".", "loadApp", "(", "dir", ",", "pkg", ")", ";", "}" ]
Test an app directory to see if it's a monitor app
[ "Test", "an", "app", "directory", "to", "see", "if", "it", "s", "a", "monitor", "app" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/Server.js#L434-L458
40,556
lorenwest/monitor-dashboard
lib/js/Server.js
function(dir) { // Return if the node_modules directory doesn't exist. try { FS.statSync(dir); } catch (e) {return;} // Check each direcory for a monitor-dashboard app FS.readdirSync(dir).forEach(function(moduleName) { // See if this is a monitor app, and load if it is // then load sub-modules var moduleDir = dir + '/' + moduleName; if (testAppDir(moduleDir) || moduleName === 'monitor') { // If it is a monitor-app, process any sub node_modules loadNodeModulesDir(moduleDir + '/node_modules'); } }); }
javascript
function(dir) { // Return if the node_modules directory doesn't exist. try { FS.statSync(dir); } catch (e) {return;} // Check each direcory for a monitor-dashboard app FS.readdirSync(dir).forEach(function(moduleName) { // See if this is a monitor app, and load if it is // then load sub-modules var moduleDir = dir + '/' + moduleName; if (testAppDir(moduleDir) || moduleName === 'monitor') { // If it is a monitor-app, process any sub node_modules loadNodeModulesDir(moduleDir + '/node_modules'); } }); }
[ "function", "(", "dir", ")", "{", "// Return if the node_modules directory doesn't exist.", "try", "{", "FS", ".", "statSync", "(", "dir", ")", ";", "}", "catch", "(", "e", ")", "{", "return", ";", "}", "// Check each direcory for a monitor-dashboard app", "FS", ".", "readdirSync", "(", "dir", ")", ".", "forEach", "(", "function", "(", "moduleName", ")", "{", "// See if this is a monitor app, and load if it is", "// then load sub-modules", "var", "moduleDir", "=", "dir", "+", "'/'", "+", "moduleName", ";", "if", "(", "testAppDir", "(", "moduleDir", ")", "||", "moduleName", "===", "'monitor'", ")", "{", "// If it is a monitor-app, process any sub node_modules", "loadNodeModulesDir", "(", "moduleDir", "+", "'/node_modules'", ")", ";", "}", "}", ")", ";", "}" ]
Process all apps under a node_modules directory
[ "Process", "all", "apps", "under", "a", "node_modules", "directory" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/Server.js#L461-L480
40,557
lorenwest/monitor-dashboard
lib/js/Server.js
function(callback) { var t = this, server = t.get('server'); callback = callback || function(){}; // Unwatch all template files t.get('templates').forEach(function(template) { template.unWatchFile(); }); // Don't stop more than once. if (!t.isListening) { return callback(); } // Shut down the server t.isListening = false; t.monitorServer.stop(function(error) { if (!error) { // Disregard close exception try { server.close(); } catch (e) {} t.trigger('stop'); } return callback(error); }); }
javascript
function(callback) { var t = this, server = t.get('server'); callback = callback || function(){}; // Unwatch all template files t.get('templates').forEach(function(template) { template.unWatchFile(); }); // Don't stop more than once. if (!t.isListening) { return callback(); } // Shut down the server t.isListening = false; t.monitorServer.stop(function(error) { if (!error) { // Disregard close exception try { server.close(); } catch (e) {} t.trigger('stop'); } return callback(error); }); }
[ "function", "(", "callback", ")", "{", "var", "t", "=", "this", ",", "server", "=", "t", ".", "get", "(", "'server'", ")", ";", "callback", "=", "callback", "||", "function", "(", ")", "{", "}", ";", "// Unwatch all template files", "t", ".", "get", "(", "'templates'", ")", ".", "forEach", "(", "function", "(", "template", ")", "{", "template", ".", "unWatchFile", "(", ")", ";", "}", ")", ";", "// Don't stop more than once.", "if", "(", "!", "t", ".", "isListening", ")", "{", "return", "callback", "(", ")", ";", "}", "// Shut down the server", "t", ".", "isListening", "=", "false", ";", "t", ".", "monitorServer", ".", "stop", "(", "function", "(", "error", ")", "{", "if", "(", "!", "error", ")", "{", "// Disregard close exception", "try", "{", "server", ".", "close", "(", ")", ";", "}", "catch", "(", "e", ")", "{", "}", "t", ".", "trigger", "(", "'stop'", ")", ";", "}", "return", "callback", "(", "error", ")", ";", "}", ")", ";", "}" ]
Stop processing inbound web and monitor traffic This method stops accepting new inbound monitor connections, and closes all existing monitor connections associated with the server. @method stop @param callback {Function(error)} - Called when the server has stopped The server has stopped This event is fired after the server has stopped accepting inbound connections, and has closed all existing connections and released associated resources. @event stop
[ "Stop", "processing", "inbound", "web", "and", "monitor", "traffic" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/Server.js#L653-L679
40,558
lorenwest/monitor-dashboard
lib/js/TourSettingsView.js
function() { var t = this; t.$el.append(template.apply({})); t.dialog = t.$('.modal'); // Build the tour tree view t.tv = new UI.TreeView({ preFetch: true, monitorParams: {probeClass: 'ToursProbe'} }); t.tv.render().appendTo(t.$('.nm-tsv-tree')); // Select the first tour once the tree is loaded t.tv.whenConnected(function(tree) { t.firstTour(); }); // Instantiate the new tour page view t.newTourPage = new UI.NewTourPage({tourSettings:t}); t.newTourPage.render(); UI.pageView.$el.append(t.newTourPage.$el); }
javascript
function() { var t = this; t.$el.append(template.apply({})); t.dialog = t.$('.modal'); // Build the tour tree view t.tv = new UI.TreeView({ preFetch: true, monitorParams: {probeClass: 'ToursProbe'} }); t.tv.render().appendTo(t.$('.nm-tsv-tree')); // Select the first tour once the tree is loaded t.tv.whenConnected(function(tree) { t.firstTour(); }); // Instantiate the new tour page view t.newTourPage = new UI.NewTourPage({tourSettings:t}); t.newTourPage.render(); UI.pageView.$el.append(t.newTourPage.$el); }
[ "function", "(", ")", "{", "var", "t", "=", "this", ";", "t", ".", "$el", ".", "append", "(", "template", ".", "apply", "(", "{", "}", ")", ")", ";", "t", ".", "dialog", "=", "t", ".", "$", "(", "'.modal'", ")", ";", "// Build the tour tree view", "t", ".", "tv", "=", "new", "UI", ".", "TreeView", "(", "{", "preFetch", ":", "true", ",", "monitorParams", ":", "{", "probeClass", ":", "'ToursProbe'", "}", "}", ")", ";", "t", ".", "tv", ".", "render", "(", ")", ".", "appendTo", "(", "t", ".", "$", "(", "'.nm-tsv-tree'", ")", ")", ";", "// Select the first tour once the tree is loaded", "t", ".", "tv", ".", "whenConnected", "(", "function", "(", "tree", ")", "{", "t", ".", "firstTour", "(", ")", ";", "}", ")", ";", "// Instantiate the new tour page view", "t", ".", "newTourPage", "=", "new", "UI", ".", "NewTourPage", "(", "{", "tourSettings", ":", "t", "}", ")", ";", "t", ".", "newTourPage", ".", "render", "(", ")", ";", "UI", ".", "pageView", ".", "$el", ".", "append", "(", "t", ".", "newTourPage", ".", "$el", ")", ";", "}" ]
This is called once after construction to render the components onto the screen.
[ "This", "is", "called", "once", "after", "construction", "to", "render", "the", "components", "onto", "the", "screen", "." ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/TourSettingsView.js#L52-L73
40,559
lorenwest/monitor-dashboard
lib/js/TourSettingsView.js
function(e) { var t = this, item = $(e.currentTarget), path = item.attr('data-path'); t.showTour(path); }
javascript
function(e) { var t = this, item = $(e.currentTarget), path = item.attr('data-path'); t.showTour(path); }
[ "function", "(", "e", ")", "{", "var", "t", "=", "this", ",", "item", "=", "$", "(", "e", ".", "currentTarget", ")", ",", "path", "=", "item", ".", "attr", "(", "'data-path'", ")", ";", "t", ".", "showTour", "(", "path", ")", ";", "}" ]
Process a tour selection
[ "Process", "a", "tour", "selection" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/TourSettingsView.js#L76-L81
40,560
lorenwest/monitor-dashboard
lib/js/TourSettingsView.js
function() { var t = this; // Set the current tour pages t.pages = t.tour.get('pages'); // Tour fields t.$('.nm-tsv-id').val(t.tour.get('id')); t.$('.nm-tsv-title').val(t.tour.get('title')); t.$('.nm-tsv-description').val(t.tour.get('description')); t.$('.nm-tsv-auto-next-sec').val(t.tour.get('autoNextSec')); var pageList = t.$('.nm-tsv-page-list').html(''); // Tour pages var table = $('<table></table>').appendTo(pageList); for (var i = 0; i < t.pages.length; i++) { var page = t.pages[i]; $('<tr><td>' + page['title'] + '</td><td class="nm-tsv-up" title="move up"><i class="icon-caret-up"></i></td><td class="nm-tsv-down" title="move down"><i class="icon-caret-down"></i></td><td class="nm-tsv-remove" title="remove page"><i class="icon-minus"></i></td></tr>').appendTo(table); } // Connect all tooltips UI.tooltip(t.$('*[title]'),{placement:'bottom'}); }
javascript
function() { var t = this; // Set the current tour pages t.pages = t.tour.get('pages'); // Tour fields t.$('.nm-tsv-id').val(t.tour.get('id')); t.$('.nm-tsv-title').val(t.tour.get('title')); t.$('.nm-tsv-description').val(t.tour.get('description')); t.$('.nm-tsv-auto-next-sec').val(t.tour.get('autoNextSec')); var pageList = t.$('.nm-tsv-page-list').html(''); // Tour pages var table = $('<table></table>').appendTo(pageList); for (var i = 0; i < t.pages.length; i++) { var page = t.pages[i]; $('<tr><td>' + page['title'] + '</td><td class="nm-tsv-up" title="move up"><i class="icon-caret-up"></i></td><td class="nm-tsv-down" title="move down"><i class="icon-caret-down"></i></td><td class="nm-tsv-remove" title="remove page"><i class="icon-minus"></i></td></tr>').appendTo(table); } // Connect all tooltips UI.tooltip(t.$('*[title]'),{placement:'bottom'}); }
[ "function", "(", ")", "{", "var", "t", "=", "this", ";", "// Set the current tour pages", "t", ".", "pages", "=", "t", ".", "tour", ".", "get", "(", "'pages'", ")", ";", "// Tour fields", "t", ".", "$", "(", "'.nm-tsv-id'", ")", ".", "val", "(", "t", ".", "tour", ".", "get", "(", "'id'", ")", ")", ";", "t", ".", "$", "(", "'.nm-tsv-title'", ")", ".", "val", "(", "t", ".", "tour", ".", "get", "(", "'title'", ")", ")", ";", "t", ".", "$", "(", "'.nm-tsv-description'", ")", ".", "val", "(", "t", ".", "tour", ".", "get", "(", "'description'", ")", ")", ";", "t", ".", "$", "(", "'.nm-tsv-auto-next-sec'", ")", ".", "val", "(", "t", ".", "tour", ".", "get", "(", "'autoNextSec'", ")", ")", ";", "var", "pageList", "=", "t", ".", "$", "(", "'.nm-tsv-page-list'", ")", ".", "html", "(", "''", ")", ";", "// Tour pages", "var", "table", "=", "$", "(", "'<table></table>'", ")", ".", "appendTo", "(", "pageList", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "t", ".", "pages", ".", "length", ";", "i", "++", ")", "{", "var", "page", "=", "t", ".", "pages", "[", "i", "]", ";", "$", "(", "'<tr><td>'", "+", "page", "[", "'title'", "]", "+", "'</td><td class=\"nm-tsv-up\" title=\"move up\"><i class=\"icon-caret-up\"></i></td><td class=\"nm-tsv-down\" title=\"move down\"><i class=\"icon-caret-down\"></i></td><td class=\"nm-tsv-remove\" title=\"remove page\"><i class=\"icon-minus\"></i></td></tr>'", ")", ".", "appendTo", "(", "table", ")", ";", "}", "// Connect all tooltips", "UI", ".", "tooltip", "(", "t", ".", "$", "(", "'*[title]'", ")", ",", "{", "placement", ":", "'bottom'", "}", ")", ";", "}" ]
Send data to the form
[ "Send", "data", "to", "the", "form" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/TourSettingsView.js#L113-L137
40,561
lorenwest/monitor-dashboard
lib/js/TourSettingsView.js
function() { var t = this; // Show the modal dialog t.dialog.centerBox().css({top:40}).modal('show'); // Set the cursor when the dialog fades in setTimeout(function(){ t.$('.nm-tsv-title').focus(); }, 500); }
javascript
function() { var t = this; // Show the modal dialog t.dialog.centerBox().css({top:40}).modal('show'); // Set the cursor when the dialog fades in setTimeout(function(){ t.$('.nm-tsv-title').focus(); }, 500); }
[ "function", "(", ")", "{", "var", "t", "=", "this", ";", "// Show the modal dialog", "t", ".", "dialog", ".", "centerBox", "(", ")", ".", "css", "(", "{", "top", ":", "40", "}", ")", ".", "modal", "(", "'show'", ")", ";", "// Set the cursor when the dialog fades in", "setTimeout", "(", "function", "(", ")", "{", "t", ".", "$", "(", "'.nm-tsv-title'", ")", ".", "focus", "(", ")", ";", "}", ",", "500", ")", ";", "}" ]
Called when the dialog is opened
[ "Called", "when", "the", "dialog", "is", "opened" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/TourSettingsView.js#L140-L150
40,562
lorenwest/monitor-dashboard
lib/js/TourSettingsView.js
function() { var t = this; for (var i in t.tv.orderedNodes) { var node = t.tv.orderedNodes[i]; if (node.type === 'leaf') { var tour = node.node; t.showTour('/' + tour.get('id')); break; } } }
javascript
function() { var t = this; for (var i in t.tv.orderedNodes) { var node = t.tv.orderedNodes[i]; if (node.type === 'leaf') { var tour = node.node; t.showTour('/' + tour.get('id')); break; } } }
[ "function", "(", ")", "{", "var", "t", "=", "this", ";", "for", "(", "var", "i", "in", "t", ".", "tv", ".", "orderedNodes", ")", "{", "var", "node", "=", "t", ".", "tv", ".", "orderedNodes", "[", "i", "]", ";", "if", "(", "node", ".", "type", "===", "'leaf'", ")", "{", "var", "tour", "=", "node", ".", "node", ";", "t", ".", "showTour", "(", "'/'", "+", "tour", ".", "get", "(", "'id'", ")", ")", ";", "break", ";", "}", "}", "}" ]
Show the first tour in the tree
[ "Show", "the", "first", "tour", "in", "the", "tree" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/TourSettingsView.js#L153-L163
40,563
lorenwest/monitor-dashboard
lib/js/TourSettingsView.js
function(e) { var t = this; // Scrape the form var params = { title: t.$('.nm-tsv-title').val(), description: t.$('.nm-tsv-description').val(), autoNextSec: t.$('.nm-tsv-auto-next-sec').val() }; if (!parseInt(params.autoNextSec)) { // Assure blank, NaN, undefined, 0, etc translates to 0 (no auto-next) params.autoNextSec = 0; } t.tour.set(params); t.tour.isDirty = true; t.setDirty(true); t.loadForm(); // Change the title/description in the tree view var tvNode = t.tv.model.getByPath(t.tour.get('id')); tvNode.set({ label: params.title ? params.title : ' ', description: params.description }); // If the tour is deleted, go to the first one if (!params.title) { t.firstTour(); } }
javascript
function(e) { var t = this; // Scrape the form var params = { title: t.$('.nm-tsv-title').val(), description: t.$('.nm-tsv-description').val(), autoNextSec: t.$('.nm-tsv-auto-next-sec').val() }; if (!parseInt(params.autoNextSec)) { // Assure blank, NaN, undefined, 0, etc translates to 0 (no auto-next) params.autoNextSec = 0; } t.tour.set(params); t.tour.isDirty = true; t.setDirty(true); t.loadForm(); // Change the title/description in the tree view var tvNode = t.tv.model.getByPath(t.tour.get('id')); tvNode.set({ label: params.title ? params.title : ' ', description: params.description }); // If the tour is deleted, go to the first one if (!params.title) { t.firstTour(); } }
[ "function", "(", "e", ")", "{", "var", "t", "=", "this", ";", "// Scrape the form", "var", "params", "=", "{", "title", ":", "t", ".", "$", "(", "'.nm-tsv-title'", ")", ".", "val", "(", ")", ",", "description", ":", "t", ".", "$", "(", "'.nm-tsv-description'", ")", ".", "val", "(", ")", ",", "autoNextSec", ":", "t", ".", "$", "(", "'.nm-tsv-auto-next-sec'", ")", ".", "val", "(", ")", "}", ";", "if", "(", "!", "parseInt", "(", "params", ".", "autoNextSec", ")", ")", "{", "// Assure blank, NaN, undefined, 0, etc translates to 0 (no auto-next)", "params", ".", "autoNextSec", "=", "0", ";", "}", "t", ".", "tour", ".", "set", "(", "params", ")", ";", "t", ".", "tour", ".", "isDirty", "=", "true", ";", "t", ".", "setDirty", "(", "true", ")", ";", "t", ".", "loadForm", "(", ")", ";", "// Change the title/description in the tree view", "var", "tvNode", "=", "t", ".", "tv", ".", "model", ".", "getByPath", "(", "t", ".", "tour", ".", "get", "(", "'id'", ")", ")", ";", "tvNode", ".", "set", "(", "{", "label", ":", "params", ".", "title", "?", "params", ".", "title", ":", "' '", ",", "description", ":", "params", ".", "description", "}", ")", ";", "// If the tour is deleted, go to the first one", "if", "(", "!", "params", ".", "title", ")", "{", "t", ".", "firstTour", "(", ")", ";", "}", "}" ]
Called when a form input element changes
[ "Called", "when", "a", "form", "input", "element", "changes" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/TourSettingsView.js#L166-L196
40,564
lorenwest/monitor-dashboard
lib/js/TourSettingsView.js
function() { var t = this, modal = t.newTourPage.$('.modal'); UI.hideToolTips(); modal.centerBox().css({top:20, left:modal.css('left').replace(/px/,'') - 40}).modal('show'); $('.modal-backdrop:last-child').css({zIndex:1140}); }
javascript
function() { var t = this, modal = t.newTourPage.$('.modal'); UI.hideToolTips(); modal.centerBox().css({top:20, left:modal.css('left').replace(/px/,'') - 40}).modal('show'); $('.modal-backdrop:last-child').css({zIndex:1140}); }
[ "function", "(", ")", "{", "var", "t", "=", "this", ",", "modal", "=", "t", ".", "newTourPage", ".", "$", "(", "'.modal'", ")", ";", "UI", ".", "hideToolTips", "(", ")", ";", "modal", ".", "centerBox", "(", ")", ".", "css", "(", "{", "top", ":", "20", ",", "left", ":", "modal", ".", "css", "(", "'left'", ")", ".", "replace", "(", "/", "px", "/", ",", "''", ")", "-", "40", "}", ")", ".", "modal", "(", "'show'", ")", ";", "$", "(", "'.modal-backdrop:last-child'", ")", ".", "css", "(", "{", "zIndex", ":", "1140", "}", ")", ";", "}" ]
Open the addPage dialog
[ "Open", "the", "addPage", "dialog" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/TourSettingsView.js#L319-L325
40,565
lorenwest/monitor-dashboard
lib/js/TourSettingsView.js
function(page) { var t = this, newPages = t.pages.slice(0); newPages.push(page); t.tour.set('pages', newPages); t.tour.isDirty = true; t.setDirty(true); t.loadForm(); }
javascript
function(page) { var t = this, newPages = t.pages.slice(0); newPages.push(page); t.tour.set('pages', newPages); t.tour.isDirty = true; t.setDirty(true); t.loadForm(); }
[ "function", "(", "page", ")", "{", "var", "t", "=", "this", ",", "newPages", "=", "t", ".", "pages", ".", "slice", "(", "0", ")", ";", "newPages", ".", "push", "(", "page", ")", ";", "t", ".", "tour", ".", "set", "(", "'pages'", ",", "newPages", ")", ";", "t", ".", "tour", ".", "isDirty", "=", "true", ";", "t", ".", "setDirty", "(", "true", ")", ";", "t", ".", "loadForm", "(", ")", ";", "}" ]
Add a page to the current tour
[ "Add", "a", "page", "to", "the", "current", "tour" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/TourSettingsView.js#L328-L336
40,566
lorenwest/monitor-dashboard
lib/js/UI.js
setAttr
function setAttr(setModel, newValue, setOptions) { var oldValue = model._containedModels[attrName]; // Pass through if removing if (newValue === undefined || newValue === null) { model._containedModels[attrName] = newValue; return; } // Is the new value the correct type? if (newValue instanceof Ctor) { // Directly set if no old value if (!oldValue instanceof Ctor) { model._containedModels[attrName] = newValue; return; } // They're both models. Disregard if they're the same. var oldJSON = oldValue.toJSON({deep:true}); var newJSON = newValue.toJSON({deep:true}); if (_.isEqual(oldJSON, newJSON)) { return; } // Merge the raw JSON if they're both models newValue = newJSON; } // Keep the previous model and merge new data into it // For collections this relies on the Collection.set() method if (oldValue instanceof Ctor) { model.attributes[attrName] = oldValue; model._currentAttributes[attrName] = oldValue; model.changed[attrName] = oldValue; oldValue.set(newValue, setOptions); return; } // Create a new model or collection, passing the value newValue = model._containedModels[attrName] = model.attributes[attrName] = model._currentAttributes[attrName] = new Ctor(newValue, setOptions); // Watch for changes to the underlying model or collection // (collection add/remove), forwarding changes to this model newValue.on('change add remove reset', UI.onSubModelChange, { parent:model, attrName: attrName }); }
javascript
function setAttr(setModel, newValue, setOptions) { var oldValue = model._containedModels[attrName]; // Pass through if removing if (newValue === undefined || newValue === null) { model._containedModels[attrName] = newValue; return; } // Is the new value the correct type? if (newValue instanceof Ctor) { // Directly set if no old value if (!oldValue instanceof Ctor) { model._containedModels[attrName] = newValue; return; } // They're both models. Disregard if they're the same. var oldJSON = oldValue.toJSON({deep:true}); var newJSON = newValue.toJSON({deep:true}); if (_.isEqual(oldJSON, newJSON)) { return; } // Merge the raw JSON if they're both models newValue = newJSON; } // Keep the previous model and merge new data into it // For collections this relies on the Collection.set() method if (oldValue instanceof Ctor) { model.attributes[attrName] = oldValue; model._currentAttributes[attrName] = oldValue; model.changed[attrName] = oldValue; oldValue.set(newValue, setOptions); return; } // Create a new model or collection, passing the value newValue = model._containedModels[attrName] = model.attributes[attrName] = model._currentAttributes[attrName] = new Ctor(newValue, setOptions); // Watch for changes to the underlying model or collection // (collection add/remove), forwarding changes to this model newValue.on('change add remove reset', UI.onSubModelChange, { parent:model, attrName: attrName }); }
[ "function", "setAttr", "(", "setModel", ",", "newValue", ",", "setOptions", ")", "{", "var", "oldValue", "=", "model", ".", "_containedModels", "[", "attrName", "]", ";", "// Pass through if removing", "if", "(", "newValue", "===", "undefined", "||", "newValue", "===", "null", ")", "{", "model", ".", "_containedModels", "[", "attrName", "]", "=", "newValue", ";", "return", ";", "}", "// Is the new value the correct type?", "if", "(", "newValue", "instanceof", "Ctor", ")", "{", "// Directly set if no old value", "if", "(", "!", "oldValue", "instanceof", "Ctor", ")", "{", "model", ".", "_containedModels", "[", "attrName", "]", "=", "newValue", ";", "return", ";", "}", "// They're both models. Disregard if they're the same.", "var", "oldJSON", "=", "oldValue", ".", "toJSON", "(", "{", "deep", ":", "true", "}", ")", ";", "var", "newJSON", "=", "newValue", ".", "toJSON", "(", "{", "deep", ":", "true", "}", ")", ";", "if", "(", "_", ".", "isEqual", "(", "oldJSON", ",", "newJSON", ")", ")", "{", "return", ";", "}", "// Merge the raw JSON if they're both models", "newValue", "=", "newJSON", ";", "}", "// Keep the previous model and merge new data into it", "// For collections this relies on the Collection.set() method", "if", "(", "oldValue", "instanceof", "Ctor", ")", "{", "model", ".", "attributes", "[", "attrName", "]", "=", "oldValue", ";", "model", ".", "_currentAttributes", "[", "attrName", "]", "=", "oldValue", ";", "model", ".", "changed", "[", "attrName", "]", "=", "oldValue", ";", "oldValue", ".", "set", "(", "newValue", ",", "setOptions", ")", ";", "return", ";", "}", "// Create a new model or collection, passing the value", "newValue", "=", "model", ".", "_containedModels", "[", "attrName", "]", "=", "model", ".", "attributes", "[", "attrName", "]", "=", "model", ".", "_currentAttributes", "[", "attrName", "]", "=", "new", "Ctor", "(", "newValue", ",", "setOptions", ")", ";", "// Watch for changes to the underlying model or collection", "// (collection add/remove), forwarding changes to this model", "newValue", ".", "on", "(", "'change add remove reset'", ",", "UI", ".", "onSubModelChange", ",", "{", "parent", ":", "model", ",", "attrName", ":", "attrName", "}", ")", ";", "}" ]
Build the function for setting model data
[ "Build", "the", "function", "for", "setting", "model", "data" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/UI.js#L254-L306
40,567
lorenwest/monitor-dashboard
lib/js/Template.js
function(params, options) { var t = this; // If raw text was sent to the template, compile and return if (t.get('text')) { t.compile(); return; } // Watch for changes in the text element t.on('change:text', t.compile, t); // Process a file template var path = t.get('path'); if (path) { // Load the file if (t.asyncLoad) { FS.readFile(path, function(err, text) { if (err) { return console.error('Error reading file: ' + path, err); } t.set({text: text.toString()}); }); } else { t.set({text: FS.readFileSync(path).toString()}); } // Watch the file for changes if (t.get('watchFile')) { t._watchFile(); } } }
javascript
function(params, options) { var t = this; // If raw text was sent to the template, compile and return if (t.get('text')) { t.compile(); return; } // Watch for changes in the text element t.on('change:text', t.compile, t); // Process a file template var path = t.get('path'); if (path) { // Load the file if (t.asyncLoad) { FS.readFile(path, function(err, text) { if (err) { return console.error('Error reading file: ' + path, err); } t.set({text: text.toString()}); }); } else { t.set({text: FS.readFileSync(path).toString()}); } // Watch the file for changes if (t.get('watchFile')) { t._watchFile(); } } }
[ "function", "(", "params", ",", "options", ")", "{", "var", "t", "=", "this", ";", "// If raw text was sent to the template, compile and return", "if", "(", "t", ".", "get", "(", "'text'", ")", ")", "{", "t", ".", "compile", "(", ")", ";", "return", ";", "}", "// Watch for changes in the text element", "t", ".", "on", "(", "'change:text'", ",", "t", ".", "compile", ",", "t", ")", ";", "// Process a file template", "var", "path", "=", "t", ".", "get", "(", "'path'", ")", ";", "if", "(", "path", ")", "{", "// Load the file", "if", "(", "t", ".", "asyncLoad", ")", "{", "FS", ".", "readFile", "(", "path", ",", "function", "(", "err", ",", "text", ")", "{", "if", "(", "err", ")", "{", "return", "console", ".", "error", "(", "'Error reading file: '", "+", "path", ",", "err", ")", ";", "}", "t", ".", "set", "(", "{", "text", ":", "text", ".", "toString", "(", ")", "}", ")", ";", "}", ")", ";", "}", "else", "{", "t", ".", "set", "(", "{", "text", ":", "FS", ".", "readFileSync", "(", "path", ")", ".", "toString", "(", ")", "}", ")", ";", "}", "// Watch the file for changes", "if", "(", "t", ".", "get", "(", "'watchFile'", ")", ")", "{", "t", ".", "_watchFile", "(", ")", ";", "}", "}", "}" ]
Initialize the template
[ "Initialize", "the", "template" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/Template.js#L66-L98
40,568
lorenwest/monitor-dashboard
lib/js/Template.js
function() { var t = this, path = t.get('path'); t.watcher = FileProbe.watchLoad(path, {persistent: true}, function(error, content) { if (!error) { t.set('text', content); } }); }
javascript
function() { var t = this, path = t.get('path'); t.watcher = FileProbe.watchLoad(path, {persistent: true}, function(error, content) { if (!error) { t.set('text', content); } }); }
[ "function", "(", ")", "{", "var", "t", "=", "this", ",", "path", "=", "t", ".", "get", "(", "'path'", ")", ";", "t", ".", "watcher", "=", "FileProbe", ".", "watchLoad", "(", "path", ",", "{", "persistent", ":", "true", "}", ",", "function", "(", "error", ",", "content", ")", "{", "if", "(", "!", "error", ")", "{", "t", ".", "set", "(", "'text'", ",", "content", ")", ";", "}", "}", ")", ";", "}" ]
Watch the file for changes This sets up a watcher for the file specified in the ```path``` element. It is called by the constructor if the ```watchFile``` data element is true. @private @method _watchFile
[ "Watch", "the", "file", "for", "changes" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/Template.js#L109-L116
40,569
lorenwest/monitor-dashboard
lib/js/Template.js
function(params) { var t = this, text = t.get('text'), compiled = t.get('compiled'); // Convert parameters to JS object if they're a backbone model if (params instanceof Backbone.Model) { params = params.toJSON(); } // Compile the template if necessary if (!compiled) { compiled = t.compile(); } // Apply the template return compiled(params); }
javascript
function(params) { var t = this, text = t.get('text'), compiled = t.get('compiled'); // Convert parameters to JS object if they're a backbone model if (params instanceof Backbone.Model) { params = params.toJSON(); } // Compile the template if necessary if (!compiled) { compiled = t.compile(); } // Apply the template return compiled(params); }
[ "function", "(", "params", ")", "{", "var", "t", "=", "this", ",", "text", "=", "t", ".", "get", "(", "'text'", ")", ",", "compiled", "=", "t", ".", "get", "(", "'compiled'", ")", ";", "// Convert parameters to JS object if they're a backbone model", "if", "(", "params", "instanceof", "Backbone", ".", "Model", ")", "{", "params", "=", "params", ".", "toJSON", "(", ")", ";", "}", "// Compile the template if necessary", "if", "(", "!", "compiled", ")", "{", "compiled", "=", "t", ".", "compile", "(", ")", ";", "}", "// Apply the template", "return", "compiled", "(", "params", ")", ";", "}" ]
Apply the parameters to the template This accepts an object and returns the template with the parameters applied. @method apply @param params {Object or Backbone.Model} Parameters to apply to the template @return {String} The template text with parameters applied
[ "Apply", "the", "parameters", "to", "the", "template" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/Template.js#L141-L156
40,570
lorenwest/monitor-dashboard
lib/js/Template.js
function() { var t = this, text = t.get('text'); var compiled = Mustache.compile(text); t.set({compiled: compiled}); return compiled; }
javascript
function() { var t = this, text = t.get('text'); var compiled = Mustache.compile(text); t.set({compiled: compiled}); return compiled; }
[ "function", "(", ")", "{", "var", "t", "=", "this", ",", "text", "=", "t", ".", "get", "(", "'text'", ")", ";", "var", "compiled", "=", "Mustache", ".", "compile", "(", "text", ")", ";", "t", ".", "set", "(", "{", "compiled", ":", "compiled", "}", ")", ";", "return", "compiled", ";", "}" ]
Compile the text element into the compiled element @protected @method compile @return {Function} Compiled function ready to call
[ "Compile", "the", "text", "element", "into", "the", "compiled", "element" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/Template.js#L165-L170
40,571
lorenwest/monitor-dashboard
lib/js/ComponentView.js
function() { var styles = {}, viewOptions = component.get('viewOptions'), title = viewOptions.get('title') || '', background = viewOptions.get('background'), css = component.get('css'); for (var selector in css) { styles['#' + component.id + ' ' + selector] = css[selector]; } $.styleSheet(styles, 'nm-cv-css-' + component.id); t.$('.nm-cv') .toggleClass('background', background === true) .toggleClass('title', title.length > 0); t.$('.nm-cv-title span').text(title); }
javascript
function() { var styles = {}, viewOptions = component.get('viewOptions'), title = viewOptions.get('title') || '', background = viewOptions.get('background'), css = component.get('css'); for (var selector in css) { styles['#' + component.id + ' ' + selector] = css[selector]; } $.styleSheet(styles, 'nm-cv-css-' + component.id); t.$('.nm-cv') .toggleClass('background', background === true) .toggleClass('title', title.length > 0); t.$('.nm-cv-title span').text(title); }
[ "function", "(", ")", "{", "var", "styles", "=", "{", "}", ",", "viewOptions", "=", "component", ".", "get", "(", "'viewOptions'", ")", ",", "title", "=", "viewOptions", ".", "get", "(", "'title'", ")", "||", "''", ",", "background", "=", "viewOptions", ".", "get", "(", "'background'", ")", ",", "css", "=", "component", ".", "get", "(", "'css'", ")", ";", "for", "(", "var", "selector", "in", "css", ")", "{", "styles", "[", "'#'", "+", "component", ".", "id", "+", "' '", "+", "selector", "]", "=", "css", "[", "selector", "]", ";", "}", "$", ".", "styleSheet", "(", "styles", ",", "'nm-cv-css-'", "+", "component", ".", "id", ")", ";", "t", ".", "$", "(", "'.nm-cv'", ")", ".", "toggleClass", "(", "'background'", ",", "background", "===", "true", ")", ".", "toggleClass", "(", "'title'", ",", "title", ".", "length", ">", "0", ")", ";", "t", ".", "$", "(", "'.nm-cv-title span'", ")", ".", "text", "(", "title", ")", ";", "}" ]
Apply styles for this component ID
[ "Apply", "styles", "for", "this", "component", "ID" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/ComponentView.js#L115-L129
40,572
lorenwest/monitor-dashboard
lib/js/ComponentView.js
function() { // Don't continue if the probe portion was what changed. var thisMonitor = JSON.stringify(monitor.toMonitorJSON()); if (thisMonitor === t.priorMonitor) { return; } // Remove the component listeners log.info('render.monitorChange', t.logCtxt); component.off('change:css change:viewOptions', applyStyles); component.off('change:monitor', onMonitorChange, t); // Disconnect, then build a fresh component t.connectMonitor(false, function(){ UI.pageView.removeComponent(t.model); UI.pageView.addComponent(t.model); }); }
javascript
function() { // Don't continue if the probe portion was what changed. var thisMonitor = JSON.stringify(monitor.toMonitorJSON()); if (thisMonitor === t.priorMonitor) { return; } // Remove the component listeners log.info('render.monitorChange', t.logCtxt); component.off('change:css change:viewOptions', applyStyles); component.off('change:monitor', onMonitorChange, t); // Disconnect, then build a fresh component t.connectMonitor(false, function(){ UI.pageView.removeComponent(t.model); UI.pageView.addComponent(t.model); }); }
[ "function", "(", ")", "{", "// Don't continue if the probe portion was what changed.", "var", "thisMonitor", "=", "JSON", ".", "stringify", "(", "monitor", ".", "toMonitorJSON", "(", ")", ")", ";", "if", "(", "thisMonitor", "===", "t", ".", "priorMonitor", ")", "{", "return", ";", "}", "// Remove the component listeners", "log", ".", "info", "(", "'render.monitorChange'", ",", "t", ".", "logCtxt", ")", ";", "component", ".", "off", "(", "'change:css change:viewOptions'", ",", "applyStyles", ")", ";", "component", ".", "off", "(", "'change:monitor'", ",", "onMonitorChange", ",", "t", ")", ";", "// Disconnect, then build a fresh component", "t", ".", "connectMonitor", "(", "false", ",", "function", "(", ")", "{", "UI", ".", "pageView", ".", "removeComponent", "(", "t", ".", "model", ")", ";", "UI", ".", "pageView", ".", "addComponent", "(", "t", ".", "model", ")", ";", "}", ")", ";", "}" ]
Destroy this component, and render a new component if the underlying monitor definition changes.
[ "Destroy", "this", "component", "and", "render", "a", "new", "component", "if", "the", "underlying", "monitor", "definition", "changes", "." ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/ComponentView.js#L135-L153
40,573
lorenwest/monitor-dashboard
lib/js/ComponentView.js
function() { var t = this; UI.hideToolTips(); UI.pageView.model.get('components').remove(t.model); t.connectMonitor(false); t.view.remove(); }
javascript
function() { var t = this; UI.hideToolTips(); UI.pageView.model.get('components').remove(t.model); t.connectMonitor(false); t.view.remove(); }
[ "function", "(", ")", "{", "var", "t", "=", "this", ";", "UI", ".", "hideToolTips", "(", ")", ";", "UI", ".", "pageView", ".", "model", ".", "get", "(", "'components'", ")", ".", "remove", "(", "t", ".", "model", ")", ";", "t", ".", "connectMonitor", "(", "false", ")", ";", "t", ".", "view", ".", "remove", "(", ")", ";", "}" ]
Close the component view This removes the component from the model, closing the view and leaving the form in a dirty state. @method close
[ "Close", "the", "component", "view" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/ComponentView.js#L216-L222
40,574
lorenwest/monitor-dashboard
lib/js/ComponentView.js
function(connect, callback) { callback = callback || function(){}; var t = this, needsConnecting = false, logMethod = (connect ? 'connectMonitor' : 'disconnectMonitor'), originalParams = null, monitor = t.model.get('monitor'), isConnected = monitor.isConnected(); // Determine if we need to connect/disconnect if ( (connect && !isConnected && monitor.get('probeClass')) || (!connect && isConnected)) { needsConnecting = true; } // If no need to connect, callback on next tick. This makes the // call stack consistent regardless of the presence of monitors. if (!needsConnecting) { log.info(logMethod + '.alreadyConnected', t.logCtxt); setTimeout(function(){ callback(null); },0); return; } // If connecting, override the init params with url params if (connect) { originalParams = monitor.get('initParams'); monitor.set( {initParams: _.extend({}, originalParams, initOverrides)}, {silent: true} ); } else { // If disconnecting, remove all change listeners monitor.off('change'); } // Connect or disconnect, calling the callback when done var connectFn = connect ? 'connect' : 'disconnect'; log.info(logMethod, t.logCtxt); monitor[connectFn](function(error) { // Replace original initParams (so the page isn't dirty) // Acutal init params will become attributes of the monitor object if (originalParams) { monitor.set( {initParams: originalParams}, {silent: true} ); } // If disconnecting, clear the probe data if (!connect) { var probeElems = monitor.toProbeJSON(); delete probeElems.id; monitor.set(probeElems, {unset:true}); } // Callback passing error if set return callback(error); }); }
javascript
function(connect, callback) { callback = callback || function(){}; var t = this, needsConnecting = false, logMethod = (connect ? 'connectMonitor' : 'disconnectMonitor'), originalParams = null, monitor = t.model.get('monitor'), isConnected = monitor.isConnected(); // Determine if we need to connect/disconnect if ( (connect && !isConnected && monitor.get('probeClass')) || (!connect && isConnected)) { needsConnecting = true; } // If no need to connect, callback on next tick. This makes the // call stack consistent regardless of the presence of monitors. if (!needsConnecting) { log.info(logMethod + '.alreadyConnected', t.logCtxt); setTimeout(function(){ callback(null); },0); return; } // If connecting, override the init params with url params if (connect) { originalParams = monitor.get('initParams'); monitor.set( {initParams: _.extend({}, originalParams, initOverrides)}, {silent: true} ); } else { // If disconnecting, remove all change listeners monitor.off('change'); } // Connect or disconnect, calling the callback when done var connectFn = connect ? 'connect' : 'disconnect'; log.info(logMethod, t.logCtxt); monitor[connectFn](function(error) { // Replace original initParams (so the page isn't dirty) // Acutal init params will become attributes of the monitor object if (originalParams) { monitor.set( {initParams: originalParams}, {silent: true} ); } // If disconnecting, clear the probe data if (!connect) { var probeElems = monitor.toProbeJSON(); delete probeElems.id; monitor.set(probeElems, {unset:true}); } // Callback passing error if set return callback(error); }); }
[ "function", "(", "connect", ",", "callback", ")", "{", "callback", "=", "callback", "||", "function", "(", ")", "{", "}", ";", "var", "t", "=", "this", ",", "needsConnecting", "=", "false", ",", "logMethod", "=", "(", "connect", "?", "'connectMonitor'", ":", "'disconnectMonitor'", ")", ",", "originalParams", "=", "null", ",", "monitor", "=", "t", ".", "model", ".", "get", "(", "'monitor'", ")", ",", "isConnected", "=", "monitor", ".", "isConnected", "(", ")", ";", "// Determine if we need to connect/disconnect", "if", "(", "(", "connect", "&&", "!", "isConnected", "&&", "monitor", ".", "get", "(", "'probeClass'", ")", ")", "||", "(", "!", "connect", "&&", "isConnected", ")", ")", "{", "needsConnecting", "=", "true", ";", "}", "// If no need to connect, callback on next tick. This makes the", "// call stack consistent regardless of the presence of monitors.", "if", "(", "!", "needsConnecting", ")", "{", "log", ".", "info", "(", "logMethod", "+", "'.alreadyConnected'", ",", "t", ".", "logCtxt", ")", ";", "setTimeout", "(", "function", "(", ")", "{", "callback", "(", "null", ")", ";", "}", ",", "0", ")", ";", "return", ";", "}", "// If connecting, override the init params with url params", "if", "(", "connect", ")", "{", "originalParams", "=", "monitor", ".", "get", "(", "'initParams'", ")", ";", "monitor", ".", "set", "(", "{", "initParams", ":", "_", ".", "extend", "(", "{", "}", ",", "originalParams", ",", "initOverrides", ")", "}", ",", "{", "silent", ":", "true", "}", ")", ";", "}", "else", "{", "// If disconnecting, remove all change listeners", "monitor", ".", "off", "(", "'change'", ")", ";", "}", "// Connect or disconnect, calling the callback when done", "var", "connectFn", "=", "connect", "?", "'connect'", ":", "'disconnect'", ";", "log", ".", "info", "(", "logMethod", ",", "t", ".", "logCtxt", ")", ";", "monitor", "[", "connectFn", "]", "(", "function", "(", "error", ")", "{", "// Replace original initParams (so the page isn't dirty)", "// Acutal init params will become attributes of the monitor object", "if", "(", "originalParams", ")", "{", "monitor", ".", "set", "(", "{", "initParams", ":", "originalParams", "}", ",", "{", "silent", ":", "true", "}", ")", ";", "}", "// If disconnecting, clear the probe data", "if", "(", "!", "connect", ")", "{", "var", "probeElems", "=", "monitor", ".", "toProbeJSON", "(", ")", ";", "delete", "probeElems", ".", "id", ";", "monitor", ".", "set", "(", "probeElems", ",", "{", "unset", ":", "true", "}", ")", ";", "}", "// Callback passing error if set", "return", "callback", "(", "error", ")", ";", "}", ")", ";", "}" ]
Connect or disconnect the monitor, calling the callback when done. @method connectMonitor @param connect {boolean} Connect if true, disconnect if false @param callback(error)
[ "Connect", "or", "disconnect", "the", "monitor", "calling", "the", "callback", "when", "done", "." ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/ComponentView.js#L231-L294
40,575
lorenwest/monitor-dashboard
lib/js/ComponentView.js
function(e) { var t = this; UI.pauseTour(); // Set the component model into the settings view settingsView.setModel(t.model, t, t.viewClass['SettingsView']); // Center and show the settings $('#nm-cv-settings').centerBox().css({top:40}).modal('show'); e.stopPropagation(); // Place the cursor into the first field once the form fades in setTimeout(function(){ settingsView.$('#nm-cv-settings input').first().focus(); }, 500); }
javascript
function(e) { var t = this; UI.pauseTour(); // Set the component model into the settings view settingsView.setModel(t.model, t, t.viewClass['SettingsView']); // Center and show the settings $('#nm-cv-settings').centerBox().css({top:40}).modal('show'); e.stopPropagation(); // Place the cursor into the first field once the form fades in setTimeout(function(){ settingsView.$('#nm-cv-settings input').first().focus(); }, 500); }
[ "function", "(", "e", ")", "{", "var", "t", "=", "this", ";", "UI", ".", "pauseTour", "(", ")", ";", "// Set the component model into the settings view", "settingsView", ".", "setModel", "(", "t", ".", "model", ",", "t", ",", "t", ".", "viewClass", "[", "'SettingsView'", "]", ")", ";", "// Center and show the settings", "$", "(", "'#nm-cv-settings'", ")", ".", "centerBox", "(", ")", ".", "css", "(", "{", "top", ":", "40", "}", ")", ".", "modal", "(", "'show'", ")", ";", "e", ".", "stopPropagation", "(", ")", ";", "// Place the cursor into the first field once the form fades in", "setTimeout", "(", "function", "(", ")", "{", "settingsView", ".", "$", "(", "'#nm-cv-settings input'", ")", ".", "first", "(", ")", ".", "focus", "(", ")", ";", "}", ",", "500", ")", ";", "}" ]
Open the component settings dialog
[ "Open", "the", "component", "settings", "dialog" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/ComponentView.js#L320-L335
40,576
lorenwest/monitor-dashboard
lib/js/ComponentView.js
function() { var t = this, pageView = UI.pageView, pageModel = pageView.model, view = t.view, getMonitor = function(id) {return pageView.getMonitor(id);}, monitor = t.model.get('monitor'); // Execute the onInit try { eval(t.model.get('onInit')); } catch (e) { log.error('onInitException', t.logCtxt, e); alert("Component onInit exception. See error log for more information."); } }
javascript
function() { var t = this, pageView = UI.pageView, pageModel = pageView.model, view = t.view, getMonitor = function(id) {return pageView.getMonitor(id);}, monitor = t.model.get('monitor'); // Execute the onInit try { eval(t.model.get('onInit')); } catch (e) { log.error('onInitException', t.logCtxt, e); alert("Component onInit exception. See error log for more information."); } }
[ "function", "(", ")", "{", "var", "t", "=", "this", ",", "pageView", "=", "UI", ".", "pageView", ",", "pageModel", "=", "pageView", ".", "model", ",", "view", "=", "t", ".", "view", ",", "getMonitor", "=", "function", "(", "id", ")", "{", "return", "pageView", ".", "getMonitor", "(", "id", ")", ";", "}", ",", "monitor", "=", "t", ".", "model", ".", "get", "(", "'monitor'", ")", ";", "// Execute the onInit", "try", "{", "eval", "(", "t", ".", "model", ".", "get", "(", "'onInit'", ")", ")", ";", "}", "catch", "(", "e", ")", "{", "log", ".", "error", "(", "'onInitException'", ",", "t", ".", "logCtxt", ",", "e", ")", ";", "alert", "(", "\"Component onInit exception. See error log for more information.\"", ")", ";", "}", "}" ]
This executes the onInit code contained in the component model
[ "This", "executes", "the", "onInit", "code", "contained", "in", "the", "component", "model" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/ComponentView.js#L338-L354
40,577
lorenwest/monitor-dashboard
lib/js/ComponentView.js
function(persist) { var t = this, viewElem = t.$('.nm-cv'), thisZIndex = (viewElem.css('zIndex') === 'auto' ? 0 : +viewElem.css('zIndex')), components = UI.pageView.model.get('components'), maxZIndex = 0; // Get the maximum z-index (disregarding this) components.forEach(function(component) { var id = component.get('id'), elem = $('#' + id + ' .nm-cv'), zIndex = elem.css('zIndex') === 'auto' ? 0 : +elem.css('zIndex'); if (id === t.model.get('id')) {return;} if (zIndex > maxZIndex) { maxZIndex = zIndex; } }); // Set this z-index to the max + 1 (unless already there) if (maxZIndex >= thisZIndex) { thisZIndex = maxZIndex + 1; if (persist) { // Change the model CSS. var css = _.clone(t.model.get('css')), parsedCss = $.parseStyleString(css['.nm-cv'] || ''); parsedCss['z-index'] = thisZIndex; css['.nm-cv'] = $.makeStyleString(parsedCss); t.model.set({css: css}); } else { t.$('.nm-cv').css({zIndex: thisZIndex}); } } // Return this zIndex return thisZIndex; }
javascript
function(persist) { var t = this, viewElem = t.$('.nm-cv'), thisZIndex = (viewElem.css('zIndex') === 'auto' ? 0 : +viewElem.css('zIndex')), components = UI.pageView.model.get('components'), maxZIndex = 0; // Get the maximum z-index (disregarding this) components.forEach(function(component) { var id = component.get('id'), elem = $('#' + id + ' .nm-cv'), zIndex = elem.css('zIndex') === 'auto' ? 0 : +elem.css('zIndex'); if (id === t.model.get('id')) {return;} if (zIndex > maxZIndex) { maxZIndex = zIndex; } }); // Set this z-index to the max + 1 (unless already there) if (maxZIndex >= thisZIndex) { thisZIndex = maxZIndex + 1; if (persist) { // Change the model CSS. var css = _.clone(t.model.get('css')), parsedCss = $.parseStyleString(css['.nm-cv'] || ''); parsedCss['z-index'] = thisZIndex; css['.nm-cv'] = $.makeStyleString(parsedCss); t.model.set({css: css}); } else { t.$('.nm-cv').css({zIndex: thisZIndex}); } } // Return this zIndex return thisZIndex; }
[ "function", "(", "persist", ")", "{", "var", "t", "=", "this", ",", "viewElem", "=", "t", ".", "$", "(", "'.nm-cv'", ")", ",", "thisZIndex", "=", "(", "viewElem", ".", "css", "(", "'zIndex'", ")", "===", "'auto'", "?", "0", ":", "+", "viewElem", ".", "css", "(", "'zIndex'", ")", ")", ",", "components", "=", "UI", ".", "pageView", ".", "model", ".", "get", "(", "'components'", ")", ",", "maxZIndex", "=", "0", ";", "// Get the maximum z-index (disregarding this)", "components", ".", "forEach", "(", "function", "(", "component", ")", "{", "var", "id", "=", "component", ".", "get", "(", "'id'", ")", ",", "elem", "=", "$", "(", "'#'", "+", "id", "+", "' .nm-cv'", ")", ",", "zIndex", "=", "elem", ".", "css", "(", "'zIndex'", ")", "===", "'auto'", "?", "0", ":", "+", "elem", ".", "css", "(", "'zIndex'", ")", ";", "if", "(", "id", "===", "t", ".", "model", ".", "get", "(", "'id'", ")", ")", "{", "return", ";", "}", "if", "(", "zIndex", ">", "maxZIndex", ")", "{", "maxZIndex", "=", "zIndex", ";", "}", "}", ")", ";", "// Set this z-index to the max + 1 (unless already there)", "if", "(", "maxZIndex", ">=", "thisZIndex", ")", "{", "thisZIndex", "=", "maxZIndex", "+", "1", ";", "if", "(", "persist", ")", "{", "// Change the model CSS.", "var", "css", "=", "_", ".", "clone", "(", "t", ".", "model", ".", "get", "(", "'css'", ")", ")", ",", "parsedCss", "=", "$", ".", "parseStyleString", "(", "css", "[", "'.nm-cv'", "]", "||", "''", ")", ";", "parsedCss", "[", "'z-index'", "]", "=", "thisZIndex", ";", "css", "[", "'.nm-cv'", "]", "=", "$", ".", "makeStyleString", "(", "parsedCss", ")", ";", "t", ".", "model", ".", "set", "(", "{", "css", ":", "css", "}", ")", ";", "}", "else", "{", "t", ".", "$", "(", "'.nm-cv'", ")", ".", "css", "(", "{", "zIndex", ":", "thisZIndex", "}", ")", ";", "}", "}", "// Return this zIndex", "return", "thisZIndex", ";", "}" ]
Raise this component to the top of the stack If persist is true, persist any new zIndex into the CSS of the data model Returns the component zIndex
[ "Raise", "this", "component", "to", "the", "top", "of", "the", "stack", "If", "persist", "is", "true", "persist", "any", "new", "zIndex", "into", "the", "CSS", "of", "the", "data", "model", "Returns", "the", "component", "zIndex" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/ComponentView.js#L359-L396
40,578
lorenwest/monitor-dashboard
lib/js/ComponentView.js
function() { var t = this, viewElem = t.$('.nm-cv'), width = viewElem.outerWidth() + 10; // Change the model CSS. var css = _.clone(t.model.get('css')), parsedCss = $.parseStyleString(css['.nm-cv'] || ''); parsedCss['left'] = '-' + width + 'px'; css['.nm-cv'] = $.makeStyleString(parsedCss); t.model.set({css: css}); }
javascript
function() { var t = this, viewElem = t.$('.nm-cv'), width = viewElem.outerWidth() + 10; // Change the model CSS. var css = _.clone(t.model.get('css')), parsedCss = $.parseStyleString(css['.nm-cv'] || ''); parsedCss['left'] = '-' + width + 'px'; css['.nm-cv'] = $.makeStyleString(parsedCss); t.model.set({css: css}); }
[ "function", "(", ")", "{", "var", "t", "=", "this", ",", "viewElem", "=", "t", ".", "$", "(", "'.nm-cv'", ")", ",", "width", "=", "viewElem", ".", "outerWidth", "(", ")", "+", "10", ";", "// Change the model CSS.", "var", "css", "=", "_", ".", "clone", "(", "t", ".", "model", ".", "get", "(", "'css'", ")", ")", ",", "parsedCss", "=", "$", ".", "parseStyleString", "(", "css", "[", "'.nm-cv'", "]", "||", "''", ")", ";", "parsedCss", "[", "'left'", "]", "=", "'-'", "+", "width", "+", "'px'", ";", "css", "[", "'.nm-cv'", "]", "=", "$", ".", "makeStyleString", "(", "parsedCss", ")", ";", "t", ".", "model", ".", "set", "(", "{", "css", ":", "css", "}", ")", ";", "}" ]
Move the component to the left of others by the width + 10
[ "Move", "the", "component", "to", "the", "left", "of", "others", "by", "the", "width", "+", "10" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/ComponentView.js#L399-L410
40,579
lorenwest/monitor-dashboard
lib/js/PageSettingsView.js
function() { var t = this; t.saveChanges(); // Open the new component dialog if no components exist if (t.model.get('components').length === 0) { t.pageView.newComponent(); } }
javascript
function() { var t = this; t.saveChanges(); // Open the new component dialog if no components exist if (t.model.get('components').length === 0) { t.pageView.newComponent(); } }
[ "function", "(", ")", "{", "var", "t", "=", "this", ";", "t", ".", "saveChanges", "(", ")", ";", "// Open the new component dialog if no components exist", "if", "(", "t", ".", "model", ".", "get", "(", "'components'", ")", ".", "length", "===", "0", ")", "{", "t", ".", "pageView", ".", "newComponent", "(", ")", ";", "}", "}" ]
Local override for page save
[ "Local", "override", "for", "page", "save" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/PageSettingsView.js#L98-L106
40,580
lorenwest/monitor-dashboard
lib/js/PageSettingsView.js
function() { var t = this; if (window.confirm('Are you sure you want to permanently delete this page?')) { t.pageView.exiting = true; t.model.destroy(function(){ UI.pageView.navigateTo('/'); }); return true; } return false; }
javascript
function() { var t = this; if (window.confirm('Are you sure you want to permanently delete this page?')) { t.pageView.exiting = true; t.model.destroy(function(){ UI.pageView.navigateTo('/'); }); return true; } return false; }
[ "function", "(", ")", "{", "var", "t", "=", "this", ";", "if", "(", "window", ".", "confirm", "(", "'Are you sure you want to permanently delete this page?'", ")", ")", "{", "t", ".", "pageView", ".", "exiting", "=", "true", ";", "t", ".", "model", ".", "destroy", "(", "function", "(", ")", "{", "UI", ".", "pageView", ".", "navigateTo", "(", "'/'", ")", ";", "}", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Delete the page?
[ "Delete", "the", "page?" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/PageSettingsView.js#L120-L130
40,581
lorenwest/monitor-dashboard
lib/js/SidebarView.js
function(e) { var t = this, item = $(e.currentTarget), id = item.attr('data-id'), path = item.attr('data-path'); // Process a tour selection if ($(e.currentTarget).parents('.nm-sb-tours').length) { UI.pageView.runTour(path); return; } // Process a page selection UI.pageView.navigateTo(path); }
javascript
function(e) { var t = this, item = $(e.currentTarget), id = item.attr('data-id'), path = item.attr('data-path'); // Process a tour selection if ($(e.currentTarget).parents('.nm-sb-tours').length) { UI.pageView.runTour(path); return; } // Process a page selection UI.pageView.navigateTo(path); }
[ "function", "(", "e", ")", "{", "var", "t", "=", "this", ",", "item", "=", "$", "(", "e", ".", "currentTarget", ")", ",", "id", "=", "item", ".", "attr", "(", "'data-id'", ")", ",", "path", "=", "item", ".", "attr", "(", "'data-path'", ")", ";", "// Process a tour selection", "if", "(", "$", "(", "e", ".", "currentTarget", ")", ".", "parents", "(", "'.nm-sb-tours'", ")", ".", "length", ")", "{", "UI", ".", "pageView", ".", "runTour", "(", "path", ")", ";", "return", ";", "}", "// Process a page selection", "UI", ".", "pageView", ".", "navigateTo", "(", "path", ")", ";", "}" ]
Process an item selection
[ "Process", "an", "item", "selection" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/SidebarView.js#L118-L132
40,582
lorenwest/monitor-dashboard
lib/js/SidebarView.js
function(e) { var t = this; UI.hideToolTips(); UI.pauseTour(); // Tell the settings it's about to be shown UI.pageView.$('#nm-pv-new').centerBox().css({top:100}).modal('show'); setTimeout(function(){ $('.nm-np-address').focus(); }, 500); // Don't propagate the click to the heading e.stopPropagation(); }
javascript
function(e) { var t = this; UI.hideToolTips(); UI.pauseTour(); // Tell the settings it's about to be shown UI.pageView.$('#nm-pv-new').centerBox().css({top:100}).modal('show'); setTimeout(function(){ $('.nm-np-address').focus(); }, 500); // Don't propagate the click to the heading e.stopPropagation(); }
[ "function", "(", "e", ")", "{", "var", "t", "=", "this", ";", "UI", ".", "hideToolTips", "(", ")", ";", "UI", ".", "pauseTour", "(", ")", ";", "// Tell the settings it's about to be shown", "UI", ".", "pageView", ".", "$", "(", "'#nm-pv-new'", ")", ".", "centerBox", "(", ")", ".", "css", "(", "{", "top", ":", "100", "}", ")", ".", "modal", "(", "'show'", ")", ";", "setTimeout", "(", "function", "(", ")", "{", "$", "(", "'.nm-np-address'", ")", ".", "focus", "(", ")", ";", "}", ",", "500", ")", ";", "// Don't propagate the click to the heading", "e", ".", "stopPropagation", "(", ")", ";", "}" ]
Open the new page dialog
[ "Open", "the", "new", "page", "dialog" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/SidebarView.js#L163-L176
40,583
lorenwest/monitor-dashboard
lib/js/SidebarView.js
function(e) { var t = this; UI.hideToolTips(); UI.pauseTour(); // Tell the settings it's about to be shown t.tourSettingsView.show(); // Don't propagate the click to the heading e.stopPropagation(); }
javascript
function(e) { var t = this; UI.hideToolTips(); UI.pauseTour(); // Tell the settings it's about to be shown t.tourSettingsView.show(); // Don't propagate the click to the heading e.stopPropagation(); }
[ "function", "(", "e", ")", "{", "var", "t", "=", "this", ";", "UI", ".", "hideToolTips", "(", ")", ";", "UI", ".", "pauseTour", "(", ")", ";", "// Tell the settings it's about to be shown", "t", ".", "tourSettingsView", ".", "show", "(", ")", ";", "// Don't propagate the click to the heading", "e", ".", "stopPropagation", "(", ")", ";", "}" ]
Open the tour settings dialog
[ "Open", "the", "tour", "settings", "dialog" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/SidebarView.js#L179-L189
40,584
lorenwest/monitor-dashboard
lib/js/SidebarView.js
function(e) { var t = this, sidebar = $('.nm-sb'), newWidth = startWidth = sidebar.width(), startX = e.pageX; function drag(e) { newWidth = startWidth + (e.pageX - startX); sidebar.css({width:newWidth}); t.tour.css({left: newWidth + t.handleWidth}); UI.pageView.centerPage(); } function drop(e) { t.handle.removeClass('drag'); $(document).unbind("mousemove", drag).unbind("mouseup", drop); // Simulate click? if (newWidth === startWidth) { newWidth = startWidth === 0 ? Sidebar.prototype.defaults.width : 0; } // Auto-close? else if (newWidth < 30) { newWidth = 0; } // Set the width, center the page, and persist t.sidebar.set('width', newWidth); sidebar.css({width: newWidth}); t.tour.css({left: newWidth + t.handleWidth}); UI.pageView.centerPage(); } $(document).bind("mousemove", drag).bind("mouseup", drop); t.handle.addClass('drag'); drag(e); e.preventDefault(); }
javascript
function(e) { var t = this, sidebar = $('.nm-sb'), newWidth = startWidth = sidebar.width(), startX = e.pageX; function drag(e) { newWidth = startWidth + (e.pageX - startX); sidebar.css({width:newWidth}); t.tour.css({left: newWidth + t.handleWidth}); UI.pageView.centerPage(); } function drop(e) { t.handle.removeClass('drag'); $(document).unbind("mousemove", drag).unbind("mouseup", drop); // Simulate click? if (newWidth === startWidth) { newWidth = startWidth === 0 ? Sidebar.prototype.defaults.width : 0; } // Auto-close? else if (newWidth < 30) { newWidth = 0; } // Set the width, center the page, and persist t.sidebar.set('width', newWidth); sidebar.css({width: newWidth}); t.tour.css({left: newWidth + t.handleWidth}); UI.pageView.centerPage(); } $(document).bind("mousemove", drag).bind("mouseup", drop); t.handle.addClass('drag'); drag(e); e.preventDefault(); }
[ "function", "(", "e", ")", "{", "var", "t", "=", "this", ",", "sidebar", "=", "$", "(", "'.nm-sb'", ")", ",", "newWidth", "=", "startWidth", "=", "sidebar", ".", "width", "(", ")", ",", "startX", "=", "e", ".", "pageX", ";", "function", "drag", "(", "e", ")", "{", "newWidth", "=", "startWidth", "+", "(", "e", ".", "pageX", "-", "startX", ")", ";", "sidebar", ".", "css", "(", "{", "width", ":", "newWidth", "}", ")", ";", "t", ".", "tour", ".", "css", "(", "{", "left", ":", "newWidth", "+", "t", ".", "handleWidth", "}", ")", ";", "UI", ".", "pageView", ".", "centerPage", "(", ")", ";", "}", "function", "drop", "(", "e", ")", "{", "t", ".", "handle", ".", "removeClass", "(", "'drag'", ")", ";", "$", "(", "document", ")", ".", "unbind", "(", "\"mousemove\"", ",", "drag", ")", ".", "unbind", "(", "\"mouseup\"", ",", "drop", ")", ";", "// Simulate click?", "if", "(", "newWidth", "===", "startWidth", ")", "{", "newWidth", "=", "startWidth", "===", "0", "?", "Sidebar", ".", "prototype", ".", "defaults", ".", "width", ":", "0", ";", "}", "// Auto-close?", "else", "if", "(", "newWidth", "<", "30", ")", "{", "newWidth", "=", "0", ";", "}", "// Set the width, center the page, and persist", "t", ".", "sidebar", ".", "set", "(", "'width'", ",", "newWidth", ")", ";", "sidebar", ".", "css", "(", "{", "width", ":", "newWidth", "}", ")", ";", "t", ".", "tour", ".", "css", "(", "{", "left", ":", "newWidth", "+", "t", ".", "handleWidth", "}", ")", ";", "UI", ".", "pageView", ".", "centerPage", "(", ")", ";", "}", "$", "(", "document", ")", ".", "bind", "(", "\"mousemove\"", ",", "drag", ")", ".", "bind", "(", "\"mouseup\"", ",", "drop", ")", ";", "t", ".", "handle", ".", "addClass", "(", "'drag'", ")", ";", "drag", "(", "e", ")", ";", "e", ".", "preventDefault", "(", ")", ";", "}" ]
Resize the sidebar
[ "Resize", "the", "sidebar" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/SidebarView.js#L192-L224
40,585
lorenwest/monitor-dashboard
lib/js/SidebarView.js
function() { var t = this, sbJSON = t.sidebar.toJSON({deep:true, trim:true}); // Function to trim closed sub-branches from a tree var trimSubBranch = function(tree) { var branches = tree.branches; for (var i in branches) { var subTree = branches[i]; if (subTree.isOpen && !subTree.isLoading) { branches[i] = trimSubBranch(subTree); } else { branches[i] = { id: subTree.id, }; if (subTree.label) { branches[i].label = subTree.label; } } } return tree; }; // Trim sub-tree elements in pages, and save for (var i = 0; i < sbJSON.tree.branches.length; i++) { sbJSON.tree.branches[i] = trimSubBranch(sbJSON.tree.branches[i]); } localStorage.sidebar = JSON.stringify(sbJSON); }
javascript
function() { var t = this, sbJSON = t.sidebar.toJSON({deep:true, trim:true}); // Function to trim closed sub-branches from a tree var trimSubBranch = function(tree) { var branches = tree.branches; for (var i in branches) { var subTree = branches[i]; if (subTree.isOpen && !subTree.isLoading) { branches[i] = trimSubBranch(subTree); } else { branches[i] = { id: subTree.id, }; if (subTree.label) { branches[i].label = subTree.label; } } } return tree; }; // Trim sub-tree elements in pages, and save for (var i = 0; i < sbJSON.tree.branches.length; i++) { sbJSON.tree.branches[i] = trimSubBranch(sbJSON.tree.branches[i]); } localStorage.sidebar = JSON.stringify(sbJSON); }
[ "function", "(", ")", "{", "var", "t", "=", "this", ",", "sbJSON", "=", "t", ".", "sidebar", ".", "toJSON", "(", "{", "deep", ":", "true", ",", "trim", ":", "true", "}", ")", ";", "// Function to trim closed sub-branches from a tree", "var", "trimSubBranch", "=", "function", "(", "tree", ")", "{", "var", "branches", "=", "tree", ".", "branches", ";", "for", "(", "var", "i", "in", "branches", ")", "{", "var", "subTree", "=", "branches", "[", "i", "]", ";", "if", "(", "subTree", ".", "isOpen", "&&", "!", "subTree", ".", "isLoading", ")", "{", "branches", "[", "i", "]", "=", "trimSubBranch", "(", "subTree", ")", ";", "}", "else", "{", "branches", "[", "i", "]", "=", "{", "id", ":", "subTree", ".", "id", ",", "}", ";", "if", "(", "subTree", ".", "label", ")", "{", "branches", "[", "i", "]", ".", "label", "=", "subTree", ".", "label", ";", "}", "}", "}", "return", "tree", ";", "}", ";", "// Trim sub-tree elements in pages, and save", "for", "(", "var", "i", "=", "0", ";", "i", "<", "sbJSON", ".", "tree", ".", "branches", ".", "length", ";", "i", "++", ")", "{", "sbJSON", ".", "tree", ".", "branches", "[", "i", "]", "=", "trimSubBranch", "(", "sbJSON", ".", "tree", ".", "branches", "[", "i", "]", ")", ";", "}", "localStorage", ".", "sidebar", "=", "JSON", ".", "stringify", "(", "sbJSON", ")", ";", "}" ]
Save the sidebar to localStorage
[ "Save", "the", "sidebar", "to", "localStorage" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/SidebarView.js#L227-L255
40,586
lorenwest/monitor-dashboard
lib/js/SidebarView.js
function(tree) { var branches = tree.branches; for (var i in branches) { var subTree = branches[i]; if (subTree.isOpen && !subTree.isLoading) { branches[i] = trimSubBranch(subTree); } else { branches[i] = { id: subTree.id, }; if (subTree.label) { branches[i].label = subTree.label; } } } return tree; }
javascript
function(tree) { var branches = tree.branches; for (var i in branches) { var subTree = branches[i]; if (subTree.isOpen && !subTree.isLoading) { branches[i] = trimSubBranch(subTree); } else { branches[i] = { id: subTree.id, }; if (subTree.label) { branches[i].label = subTree.label; } } } return tree; }
[ "function", "(", "tree", ")", "{", "var", "branches", "=", "tree", ".", "branches", ";", "for", "(", "var", "i", "in", "branches", ")", "{", "var", "subTree", "=", "branches", "[", "i", "]", ";", "if", "(", "subTree", ".", "isOpen", "&&", "!", "subTree", ".", "isLoading", ")", "{", "branches", "[", "i", "]", "=", "trimSubBranch", "(", "subTree", ")", ";", "}", "else", "{", "branches", "[", "i", "]", "=", "{", "id", ":", "subTree", ".", "id", ",", "}", ";", "if", "(", "subTree", ".", "label", ")", "{", "branches", "[", "i", "]", ".", "label", "=", "subTree", ".", "label", ";", "}", "}", "}", "return", "tree", ";", "}" ]
Function to trim closed sub-branches from a tree
[ "Function", "to", "trim", "closed", "sub", "-", "branches", "from", "a", "tree" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/SidebarView.js#L232-L248
40,587
lorenwest/monitor-dashboard
lib/js/Component.js
function(size) { var t = this, css = _.clone(t.get('css')), parsedCss = $.parseStyleString(css['.nm-cv-viewport'] || ''); if (!parsedCss.height && !parsedCss.width) { parsedCss.height = size.height + 'px'; parsedCss.width = size.width + 'px'; css['.nm-cv-viewport'] = $.makeStyleString(parsedCss); t.set({css: css}); } }
javascript
function(size) { var t = this, css = _.clone(t.get('css')), parsedCss = $.parseStyleString(css['.nm-cv-viewport'] || ''); if (!parsedCss.height && !parsedCss.width) { parsedCss.height = size.height + 'px'; parsedCss.width = size.width + 'px'; css['.nm-cv-viewport'] = $.makeStyleString(parsedCss); t.set({css: css}); } }
[ "function", "(", "size", ")", "{", "var", "t", "=", "this", ",", "css", "=", "_", ".", "clone", "(", "t", ".", "get", "(", "'css'", ")", ")", ",", "parsedCss", "=", "$", ".", "parseStyleString", "(", "css", "[", "'.nm-cv-viewport'", "]", "||", "''", ")", ";", "if", "(", "!", "parsedCss", ".", "height", "&&", "!", "parsedCss", ".", "width", ")", "{", "parsedCss", ".", "height", "=", "size", ".", "height", "+", "'px'", ";", "parsedCss", ".", "width", "=", "size", ".", "width", "+", "'px'", ";", "css", "[", "'.nm-cv-viewport'", "]", "=", "$", ".", "makeStyleString", "(", "parsedCss", ")", ";", "t", ".", "set", "(", "{", "css", ":", "css", "}", ")", ";", "}", "}" ]
Set the default component size This will add CSS to set the component size if it hasn't already been set. @method setDefaultSize @param size {Object} @param size.height {Integer} Default height @param size.width {Integer} Default width
[ "Set", "the", "default", "component", "size" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/Component.js#L74-L84
40,588
lorenwest/monitor-dashboard
lib/js/Component.js
function(options) { var t = this, opts = _.extend({trim:true, deep:true, monitorOnly:true}, options), raw = Backbone.Model.prototype.toJSON.call(t, opts); // Keep only the monitor portion (strip the probe portion)? if (opts.monitorOnly) { raw.monitor = t.get('monitor').toMonitorJSON(opts); } return raw; }
javascript
function(options) { var t = this, opts = _.extend({trim:true, deep:true, monitorOnly:true}, options), raw = Backbone.Model.prototype.toJSON.call(t, opts); // Keep only the monitor portion (strip the probe portion)? if (opts.monitorOnly) { raw.monitor = t.get('monitor').toMonitorJSON(opts); } return raw; }
[ "function", "(", "options", ")", "{", "var", "t", "=", "this", ",", "opts", "=", "_", ".", "extend", "(", "{", "trim", ":", "true", ",", "deep", ":", "true", ",", "monitorOnly", ":", "true", "}", ",", "options", ")", ",", "raw", "=", "Backbone", ".", "Model", ".", "prototype", ".", "toJSON", ".", "call", "(", "t", ",", "opts", ")", ";", "// Keep only the monitor portion (strip the probe portion)?", "if", "(", "opts", ".", "monitorOnly", ")", "{", "raw", ".", "monitor", "=", "t", ".", "get", "(", "'monitor'", ")", ".", "toMonitorJSON", "(", "opts", ")", ";", "}", "return", "raw", ";", "}" ]
Overridden to produce only the persistent portion of the page
[ "Overridden", "to", "produce", "only", "the", "persistent", "portion", "of", "the", "page" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/Component.js#L87-L97
40,589
lorenwest/monitor-dashboard
lib/js/PageView.js
function(e) { var code = e.keyCode; // Hotkeys while a tour is present if (UI.pageView.tourView) { // 1-9 direct page navigation var target; if (code >= 49 && code <=57) { target = $('.nm-tv-page[data-index="' + (code - 49) + '"]'); } // Pause / Run if (code == 32) { UI.pageView.tourView[UI.pageView.tourView.timer ? 'pause' : 'play'](); } // Left / Up if (code == 37 || code == 38) { UI.pageView.tourView.prev(); } // Right / Down if (code == 39 || code == 40) { UI.pageView.tourView.prev(); } // Programmatically click the target if (target && target.length) { target.click(); } } }
javascript
function(e) { var code = e.keyCode; // Hotkeys while a tour is present if (UI.pageView.tourView) { // 1-9 direct page navigation var target; if (code >= 49 && code <=57) { target = $('.nm-tv-page[data-index="' + (code - 49) + '"]'); } // Pause / Run if (code == 32) { UI.pageView.tourView[UI.pageView.tourView.timer ? 'pause' : 'play'](); } // Left / Up if (code == 37 || code == 38) { UI.pageView.tourView.prev(); } // Right / Down if (code == 39 || code == 40) { UI.pageView.tourView.prev(); } // Programmatically click the target if (target && target.length) { target.click(); } } }
[ "function", "(", "e", ")", "{", "var", "code", "=", "e", ".", "keyCode", ";", "// Hotkeys while a tour is present", "if", "(", "UI", ".", "pageView", ".", "tourView", ")", "{", "// 1-9 direct page navigation", "var", "target", ";", "if", "(", "code", ">=", "49", "&&", "code", "<=", "57", ")", "{", "target", "=", "$", "(", "'.nm-tv-page[data-index=\"'", "+", "(", "code", "-", "49", ")", "+", "'\"]'", ")", ";", "}", "// Pause / Run", "if", "(", "code", "==", "32", ")", "{", "UI", ".", "pageView", ".", "tourView", "[", "UI", ".", "pageView", ".", "tourView", ".", "timer", "?", "'pause'", ":", "'play'", "]", "(", ")", ";", "}", "// Left / Up", "if", "(", "code", "==", "37", "||", "code", "==", "38", ")", "{", "UI", ".", "pageView", ".", "tourView", ".", "prev", "(", ")", ";", "}", "// Right / Down", "if", "(", "code", "==", "39", "||", "code", "==", "40", ")", "{", "UI", ".", "pageView", ".", "tourView", ".", "prev", "(", ")", ";", "}", "// Programmatically click the target", "if", "(", "target", "&&", "target", ".", "length", ")", "{", "target", ".", "click", "(", ")", ";", "}", "}", "}" ]
Process hot keys
[ "Process", "hot", "keys" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/PageView.js#L210-L242
40,590
lorenwest/monitor-dashboard
lib/js/PageView.js
function(e) { var t = this, box = t.getComponentArea(), sidebarWidth = t.sidebar.width(), canvasWidth = t.$el.width() - sidebarWidth, canvasCenter = canvasWidth / 2; // No components if (!box.width) {return;} // Obtain the center point, and offset the canvas by the difference // Keep the left margin at multiples of 10 to match components var componentCenter = box.left + (box.width / 2); var newLeft = sidebarWidth + Math.max(0, canvasCenter - componentCenter); newLeft = newLeft - newLeft % 10; t.canvas.css({marginLeft: newLeft}); }
javascript
function(e) { var t = this, box = t.getComponentArea(), sidebarWidth = t.sidebar.width(), canvasWidth = t.$el.width() - sidebarWidth, canvasCenter = canvasWidth / 2; // No components if (!box.width) {return;} // Obtain the center point, and offset the canvas by the difference // Keep the left margin at multiples of 10 to match components var componentCenter = box.left + (box.width / 2); var newLeft = sidebarWidth + Math.max(0, canvasCenter - componentCenter); newLeft = newLeft - newLeft % 10; t.canvas.css({marginLeft: newLeft}); }
[ "function", "(", "e", ")", "{", "var", "t", "=", "this", ",", "box", "=", "t", ".", "getComponentArea", "(", ")", ",", "sidebarWidth", "=", "t", ".", "sidebar", ".", "width", "(", ")", ",", "canvasWidth", "=", "t", ".", "$el", ".", "width", "(", ")", "-", "sidebarWidth", ",", "canvasCenter", "=", "canvasWidth", "/", "2", ";", "// No components", "if", "(", "!", "box", ".", "width", ")", "{", "return", ";", "}", "// Obtain the center point, and offset the canvas by the difference", "// Keep the left margin at multiples of 10 to match components", "var", "componentCenter", "=", "box", ".", "left", "+", "(", "box", ".", "width", "/", "2", ")", ";", "var", "newLeft", "=", "sidebarWidth", "+", "Math", ".", "max", "(", "0", ",", "canvasCenter", "-", "componentCenter", ")", ";", "newLeft", "=", "newLeft", "-", "newLeft", "%", "10", ";", "t", ".", "canvas", ".", "css", "(", "{", "marginLeft", ":", "newLeft", "}", ")", ";", "}" ]
Center the page by adding left margin to the canvas
[ "Center", "the", "page", "by", "adding", "left", "margin", "to", "the", "canvas" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/PageView.js#L289-L305
40,591
lorenwest/monitor-dashboard
lib/js/PageView.js
function() { var t = this, box = t.getComponentArea(); // Shift all components by the furthest left if (box.left) { t.$('.nm-pv-component').each(function() { var elem = $(this).find('.nm-cv'), left = (parseInt(elem.css('left'), 10)), model = t.componentViews[($(this).attr('id'))].model, css = _.clone(model.get('css')), parsedCss = $.parseStyleString(css['.nm-cv'] || ''); // Set the left into the model & remove from the element style parsedCss.left = (left - box.left) + 'px'; css['.nm-cv'] = $.makeStyleString(parsedCss); model.set({css: css}); elem.css({left:''}); }); } }
javascript
function() { var t = this, box = t.getComponentArea(); // Shift all components by the furthest left if (box.left) { t.$('.nm-pv-component').each(function() { var elem = $(this).find('.nm-cv'), left = (parseInt(elem.css('left'), 10)), model = t.componentViews[($(this).attr('id'))].model, css = _.clone(model.get('css')), parsedCss = $.parseStyleString(css['.nm-cv'] || ''); // Set the left into the model & remove from the element style parsedCss.left = (left - box.left) + 'px'; css['.nm-cv'] = $.makeStyleString(parsedCss); model.set({css: css}); elem.css({left:''}); }); } }
[ "function", "(", ")", "{", "var", "t", "=", "this", ",", "box", "=", "t", ".", "getComponentArea", "(", ")", ";", "// Shift all components by the furthest left", "if", "(", "box", ".", "left", ")", "{", "t", ".", "$", "(", "'.nm-pv-component'", ")", ".", "each", "(", "function", "(", ")", "{", "var", "elem", "=", "$", "(", "this", ")", ".", "find", "(", "'.nm-cv'", ")", ",", "left", "=", "(", "parseInt", "(", "elem", ".", "css", "(", "'left'", ")", ",", "10", ")", ")", ",", "model", "=", "t", ".", "componentViews", "[", "(", "$", "(", "this", ")", ".", "attr", "(", "'id'", ")", ")", "]", ".", "model", ",", "css", "=", "_", ".", "clone", "(", "model", ".", "get", "(", "'css'", ")", ")", ",", "parsedCss", "=", "$", ".", "parseStyleString", "(", "css", "[", "'.nm-cv'", "]", "||", "''", ")", ";", "// Set the left into the model & remove from the element style", "parsedCss", ".", "left", "=", "(", "left", "-", "box", ".", "left", ")", "+", "'px'", ";", "css", "[", "'.nm-cv'", "]", "=", "$", ".", "makeStyleString", "(", "parsedCss", ")", ";", "model", ".", "set", "(", "{", "css", ":", "css", "}", ")", ";", "elem", ".", "css", "(", "{", "left", ":", "''", "}", ")", ";", "}", ")", ";", "}", "}" ]
Move all components so the furthest left is on the left of the canvas. This makes the scrollbars make sense.
[ "Move", "all", "components", "so", "the", "furthest", "left", "is", "on", "the", "left", "of", "the", "canvas", ".", "This", "makes", "the", "scrollbars", "make", "sense", "." ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/PageView.js#L309-L329
40,592
lorenwest/monitor-dashboard
lib/js/PageView.js
function(model) { var t = this, componentView = new ComponentView({model: model}); componentView.$el .addClass('nm-pv-component') .data('view', componentView); componentView.render(); t.canvas.append(componentView.$el); t.componentViews[model.get('id')] = componentView; }
javascript
function(model) { var t = this, componentView = new ComponentView({model: model}); componentView.$el .addClass('nm-pv-component') .data('view', componentView); componentView.render(); t.canvas.append(componentView.$el); t.componentViews[model.get('id')] = componentView; }
[ "function", "(", "model", ")", "{", "var", "t", "=", "this", ",", "componentView", "=", "new", "ComponentView", "(", "{", "model", ":", "model", "}", ")", ";", "componentView", ".", "$el", ".", "addClass", "(", "'nm-pv-component'", ")", ".", "data", "(", "'view'", ",", "componentView", ")", ";", "componentView", ".", "render", "(", ")", ";", "t", ".", "canvas", ".", "append", "(", "componentView", ".", "$el", ")", ";", "t", ".", "componentViews", "[", "model", ".", "get", "(", "'id'", ")", "]", "=", "componentView", ";", "}" ]
Add a component to the canvas
[ "Add", "a", "component", "to", "the", "canvas" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/PageView.js#L332-L341
40,593
lorenwest/monitor-dashboard
lib/js/PageView.js
function() { var t = this, components = t.model.get('components'), canvas = t.$('.nm-pv-canvas'); // Remove components not in the data model canvas.find('.nm-pv-component').each(function() { var component = $(this); if (!components.get(component.attr('id'))) { component.remove(); } }); // Add new components components.forEach(function(component) { var onScreen = t.$('#' + component.get('id')); if (!onScreen.length) { t.addComponent(component); } }); // Center components onto the screen t.leftJustify(); t.centerPage(); }
javascript
function() { var t = this, components = t.model.get('components'), canvas = t.$('.nm-pv-canvas'); // Remove components not in the data model canvas.find('.nm-pv-component').each(function() { var component = $(this); if (!components.get(component.attr('id'))) { component.remove(); } }); // Add new components components.forEach(function(component) { var onScreen = t.$('#' + component.get('id')); if (!onScreen.length) { t.addComponent(component); } }); // Center components onto the screen t.leftJustify(); t.centerPage(); }
[ "function", "(", ")", "{", "var", "t", "=", "this", ",", "components", "=", "t", ".", "model", ".", "get", "(", "'components'", ")", ",", "canvas", "=", "t", ".", "$", "(", "'.nm-pv-canvas'", ")", ";", "// Remove components not in the data model", "canvas", ".", "find", "(", "'.nm-pv-component'", ")", ".", "each", "(", "function", "(", ")", "{", "var", "component", "=", "$", "(", "this", ")", ";", "if", "(", "!", "components", ".", "get", "(", "component", ".", "attr", "(", "'id'", ")", ")", ")", "{", "component", ".", "remove", "(", ")", ";", "}", "}", ")", ";", "// Add new components", "components", ".", "forEach", "(", "function", "(", "component", ")", "{", "var", "onScreen", "=", "t", ".", "$", "(", "'#'", "+", "component", ".", "get", "(", "'id'", ")", ")", ";", "if", "(", "!", "onScreen", ".", "length", ")", "{", "t", ".", "addComponent", "(", "component", ")", ";", "}", "}", ")", ";", "// Center components onto the screen", "t", ".", "leftJustify", "(", ")", ";", "t", ".", "centerPage", "(", ")", ";", "}" ]
This adds and removes components from the page, updating component data models if necessary.
[ "This", "adds", "and", "removes", "components", "from", "the", "page", "updating", "component", "data", "models", "if", "necessary", "." ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/PageView.js#L357-L381
40,594
lorenwest/monitor-dashboard
lib/js/PageView.js
function() { var t = this, pageView = t, getMonitor = function(id){return t.getMonitor(id);}; pageModel = t.model; // Execute the onInit try { eval(t.model.get('onInit')); } catch (e) { console.error('PageView onInit threw exception: ', e); alert("Page onInit exception. See console log for more information."); } }
javascript
function() { var t = this, pageView = t, getMonitor = function(id){return t.getMonitor(id);}; pageModel = t.model; // Execute the onInit try { eval(t.model.get('onInit')); } catch (e) { console.error('PageView onInit threw exception: ', e); alert("Page onInit exception. See console log for more information."); } }
[ "function", "(", ")", "{", "var", "t", "=", "this", ",", "pageView", "=", "t", ",", "getMonitor", "=", "function", "(", "id", ")", "{", "return", "t", ".", "getMonitor", "(", "id", ")", ";", "}", ";", "pageModel", "=", "t", ".", "model", ";", "// Execute the onInit", "try", "{", "eval", "(", "t", ".", "model", ".", "get", "(", "'onInit'", ")", ")", ";", "}", "catch", "(", "e", ")", "{", "console", ".", "error", "(", "'PageView onInit threw exception: '", ",", "e", ")", ";", "alert", "(", "\"Page onInit exception. See console log for more information.\"", ")", ";", "}", "}" ]
This executes the onInit code contained in the page model
[ "This", "executes", "the", "onInit", "code", "contained", "in", "the", "page", "model" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/PageView.js#L384-L398
40,595
lorenwest/monitor-dashboard
lib/js/PageView.js
function() { var t = this, raw = t.model.toJSON({trim:false}); return !(_.isEqual(t.originalPage, raw)); }
javascript
function() { var t = this, raw = t.model.toJSON({trim:false}); return !(_.isEqual(t.originalPage, raw)); }
[ "function", "(", ")", "{", "var", "t", "=", "this", ",", "raw", "=", "t", ".", "model", ".", "toJSON", "(", "{", "trim", ":", "false", "}", ")", ";", "return", "!", "(", "_", ".", "isEqual", "(", "t", ".", "originalPage", ",", "raw", ")", ")", ";", "}" ]
Is the page model different from the persisted state?
[ "Is", "the", "page", "model", "different", "from", "the", "persisted", "state?" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/PageView.js#L401-L405
40,596
lorenwest/monitor-dashboard
lib/js/PageView.js
function(isDirty) { var t = this; // Pause a tour if the page turns dirty if (isDirty) { UI.pauseTour(); } // Change the view elements t.$el.toggleClass('dirty', isDirty); if (!isDirty) { t.originalPage = t.model.toJSON({trim:false}); } }
javascript
function(isDirty) { var t = this; // Pause a tour if the page turns dirty if (isDirty) { UI.pauseTour(); } // Change the view elements t.$el.toggleClass('dirty', isDirty); if (!isDirty) { t.originalPage = t.model.toJSON({trim:false}); } }
[ "function", "(", "isDirty", ")", "{", "var", "t", "=", "this", ";", "// Pause a tour if the page turns dirty", "if", "(", "isDirty", ")", "{", "UI", ".", "pauseTour", "(", ")", ";", "}", "// Change the view elements", "t", ".", "$el", ".", "toggleClass", "(", "'dirty'", ",", "isDirty", ")", ";", "if", "(", "!", "isDirty", ")", "{", "t", ".", "originalPage", "=", "t", ".", "model", ".", "toJSON", "(", "{", "trim", ":", "false", "}", ")", ";", "}", "}" ]
Set the page as dirty or not
[ "Set", "the", "page", "as", "dirty", "or", "not" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/PageView.js#L408-L421
40,597
lorenwest/monitor-dashboard
lib/js/PageView.js
function() { // Remember the current page state var t = this; t.pageSettingsView.originalModel = t.model.toJSON({trim:false}); // Load & show the dialog t.showDialog('#nm-pv-settings'); }
javascript
function() { // Remember the current page state var t = this; t.pageSettingsView.originalModel = t.model.toJSON({trim:false}); // Load & show the dialog t.showDialog('#nm-pv-settings'); }
[ "function", "(", ")", "{", "// Remember the current page state", "var", "t", "=", "this", ";", "t", ".", "pageSettingsView", ".", "originalModel", "=", "t", ".", "model", ".", "toJSON", "(", "{", "trim", ":", "false", "}", ")", ";", "// Load & show the dialog", "t", ".", "showDialog", "(", "'#nm-pv-settings'", ")", ";", "}" ]
This shows the page settings modal dialog
[ "This", "shows", "the", "page", "settings", "modal", "dialog" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/PageView.js#L462-L469
40,598
lorenwest/monitor-dashboard
lib/js/PageView.js
function() { var t = this, components = t.model.get('components'); components.remove(components.models); t.showSettings(); }
javascript
function() { var t = this, components = t.model.get('components'); components.remove(components.models); t.showSettings(); }
[ "function", "(", ")", "{", "var", "t", "=", "this", ",", "components", "=", "t", ".", "model", ".", "get", "(", "'components'", ")", ";", "components", ".", "remove", "(", "components", ".", "models", ")", ";", "t", ".", "showSettings", "(", ")", ";", "}" ]
This clears all page components and opens the settings dialog
[ "This", "clears", "all", "page", "components", "and", "opens", "the", "settings", "dialog" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/PageView.js#L472-L477
40,599
lorenwest/monitor-dashboard
lib/js/PageView.js
function(id) { var t = this, components = t.model.get('components'); return components.get(id).get('monitor'); }
javascript
function(id) { var t = this, components = t.model.get('components'); return components.get(id).get('monitor'); }
[ "function", "(", "id", ")", "{", "var", "t", "=", "this", ",", "components", "=", "t", ".", "model", ".", "get", "(", "'components'", ")", ";", "return", "components", ".", "get", "(", "id", ")", ".", "get", "(", "'monitor'", ")", ";", "}" ]
Get the monitor for the specified component ID
[ "Get", "the", "monitor", "for", "the", "specified", "component", "ID" ]
a990e03d07096515744332ae0761441f8534369c
https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/PageView.js#L480-L484