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
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
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",
")",
"{",
"if",
"(",
"messages",
".",
"errors",
".",
"length",
">",
"1",
")",
"{",
"messages",
".",
"errors",
".",
"length",
"=",
"1",
";",
"}",
"return",
"reject",
"(",
"new",
"Error",
"(",
"messages",
".",
"errors",
".",
"join",
"(",
"'\\n\\n'",
")",
")",
")",
";",
"}",
"\\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'",
"+",
"\\n",
")",
")",
";",
"\\n",
"}",
"'Most CI servers set it automatically.\\n'",
";",
"}"
]
| 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 | train |
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",
"]",
")",
")",
"{",
"return",
"attribLength",
"!==",
"data",
".",
"length",
"*",
"itemSize",
"}",
"else",
"{",
"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 | train |
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 | train |
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",
")",
"{",
"layer",
".",
"save",
"(",
")",
";",
"var",
"innerRadius",
"=",
"options",
".",
"series",
".",
"pie",
".",
"innerRadius",
">",
"1",
"?",
"options",
".",
"series",
".",
"pie",
".",
"innerRadius",
":",
"maxRadius",
"*",
"options",
".",
"series",
".",
"pie",
".",
"innerRadius",
";",
"layer",
".",
"globalCompositeOperation",
"=",
"\"destination-out\"",
";",
"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",
"(",
")",
";",
"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",
"(",
")",
";",
"}",
"}"
]
| 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 | train |
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",
"}",
";",
"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 | train |
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",
"(",
")",
";",
"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 | train |
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 | train |
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",
";",
"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",
")",
";",
"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 | train |
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 | train |
|
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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",
";",
"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 | train |
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",
"]",
";",
"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 | train |
|
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 | train |
|
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'",
")",
";",
"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 | train |
|
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'",
")",
";",
"t",
".",
"model",
"=",
"model",
";",
"t",
".",
"componentView",
"=",
"componentView",
";",
"t",
".",
"monitor",
"=",
"model",
".",
"get",
"(",
"'monitor'",
")",
";",
"t",
".",
"originalModel",
"=",
"t",
".",
"model",
".",
"toJSON",
"(",
"{",
"trim",
":",
"false",
"}",
")",
";",
"if",
"(",
"t",
".",
"sourceView",
")",
"{",
"t",
".",
"sourceView",
".",
"remove",
"(",
")",
";",
"}",
"if",
"(",
"t",
".",
"customView",
")",
"{",
"t",
".",
"customView",
".",
"remove",
"(",
")",
";",
"}",
"if",
"(",
"t",
".",
"monitorParams",
")",
"{",
"t",
".",
"monitorParams",
".",
"off",
"(",
"'change'",
")",
";",
"}",
"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",
"(",
")",
";",
"UI",
".",
"tooltip",
"(",
"t",
".",
"$",
"(",
"'*[title]'",
")",
")",
";",
"}",
"t",
".",
"modelBinder",
".",
"bind",
"(",
"t",
".",
"model",
",",
"t",
".",
"$el",
",",
"t",
".",
"componentBindings",
")",
";",
"t",
".",
"viewOptionBinder",
".",
"bind",
"(",
"t",
".",
"model",
".",
"get",
"(",
"'viewOptions'",
")",
",",
"componentPane",
",",
"Backbone",
".",
"ModelBinder",
".",
"createDefaultBindings",
"(",
"componentPane",
",",
"'data-view-option'",
")",
")",
";",
"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",
"(",
")",
")",
";",
"}",
")",
";",
"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 | train |
|
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",
";",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"t",
".",
"viewOptionBinder",
".",
"_onElChanged",
"(",
"e",
")",
";",
"}",
",",
"0",
")",
";",
"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 | train |
|
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",
";",
"var",
"copy",
"=",
"t",
".",
"model",
".",
"toJSON",
"(",
")",
";",
"delete",
"copy",
".",
"id",
";",
"var",
"component",
"=",
"t",
".",
"pageView",
".",
"model",
".",
"addComponent",
"(",
"copy",
".",
"viewClass",
")",
";",
"component",
".",
"set",
"(",
"copy",
")",
";",
"var",
"cv",
"=",
"t",
".",
"pageView",
".",
"getComponentView",
"(",
"component",
".",
"get",
"(",
"'id'",
")",
")",
";",
"cv",
".",
"raiseToTop",
"(",
"true",
")",
";",
"cv",
".",
"moveToLeft",
"(",
")",
";",
"t",
".",
"pageView",
".",
"leftJustify",
"(",
")",
";",
"t",
".",
"pageView",
".",
"centerPage",
"(",
")",
";",
"t",
".",
"closeDialog",
"(",
")",
";",
"}"
]
| Copy the component | [
"Copy",
"the",
"component"
]
| a990e03d07096515744332ae0761441f8534369c | https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/ComponentSettingsView.js#L161-L179 | train |
|
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 | train |
|
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",
"{",
"if",
"(",
"dirpath",
"!==",
"'/'",
")",
"{",
"FS",
".",
"mkdirSync",
"(",
"Path",
".",
"join",
"(",
"'.'",
",",
"appPath",
",",
"dirpath",
")",
")",
";",
"}",
"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",
"(",
")",
")",
"{",
"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 | train |
|
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 | train |
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 | train |
|
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",
"=",
"[",
"]",
";",
"if",
"(",
"numLeft",
"===",
"0",
")",
"{",
"return",
"callback",
"(",
"null",
",",
"dirs",
")",
";",
"}",
"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 | train |
|
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",
";",
"FS",
".",
"readdir",
"(",
"dirname",
",",
"function",
"(",
"error",
",",
"fileNames",
")",
"{",
"if",
"(",
"error",
")",
"{",
"console",
".",
"error",
"(",
"'Read dir error'",
",",
"error",
")",
";",
"return",
"callback",
"(",
"error",
")",
";",
"}",
"var",
"dirsToCheck",
"=",
"[",
"]",
";",
"function",
"checkNext",
"(",
")",
"{",
"if",
"(",
"fileNames",
".",
"length",
"===",
"0",
")",
"{",
"t",
".",
"trimDirs",
"(",
"dirsToCheck",
",",
"function",
"(",
"error",
",",
"trimmed",
")",
"{",
"return",
"callback",
"(",
"error",
",",
"trimmed",
".",
"length",
">",
"0",
")",
";",
"}",
")",
";",
"return",
";",
"}",
"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",
")",
";",
"}",
"if",
"(",
"stat",
".",
"isDirectory",
"(",
")",
")",
"{",
"dirsToCheck",
".",
"push",
"(",
"{",
"path",
":",
"pathName",
"}",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"fileRegexp",
"||",
"fileRegexp",
".",
"test",
"(",
"filename",
")",
")",
"{",
"return",
"callback",
"(",
"null",
",",
"true",
")",
";",
"}",
"}",
"checkNext",
"(",
")",
";",
"}",
")",
";",
"}",
"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 | train |
|
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",
";",
"if",
"(",
"fileNames",
".",
"length",
"===",
"0",
")",
"{",
"return",
"callback",
"(",
"null",
",",
"stats",
")",
";",
"}",
"fileNames",
".",
"forEach",
"(",
"function",
"(",
"fileName",
",",
"index",
")",
"{",
"var",
"fullPath",
"=",
"Path",
".",
"join",
"(",
"t",
".",
"dirPath",
",",
"fileName",
")",
";",
"FS",
".",
"stat",
"(",
"fullPath",
",",
"function",
"(",
"error",
",",
"stat",
")",
"{",
"if",
"(",
"error",
")",
"{",
"didError",
"=",
"true",
";",
"return",
"callback",
"(",
"error",
")",
";",
"}",
"if",
"(",
"didError",
")",
"{",
"return",
";",
"}",
"stats",
"[",
"index",
"]",
"=",
"stat",
";",
"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 | train |
|
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",
"=",
"\"\"",
";",
"branches",
"&&",
"branches",
".",
"forEach",
"(",
"function",
"(",
"node",
")",
"{",
"var",
"label",
"=",
"node",
".",
"get",
"(",
"'label'",
")",
"||",
"node",
".",
"id",
",",
"description",
"=",
"node",
".",
"get",
"(",
"'description'",
")",
";",
"hash",
"+=",
"'|'",
"+",
"label",
";",
"if",
"(",
"description",
")",
"{",
"hash",
"+=",
"'|'",
"+",
"description",
";",
"}",
"}",
")",
";",
"leaves",
"&&",
"leaves",
".",
"forEach",
"(",
"function",
"(",
"node",
")",
"{",
"var",
"label",
"=",
"node",
".",
"get",
"(",
"'label'",
")",
"||",
"node",
".",
"id",
",",
"description",
"=",
"node",
".",
"get",
"(",
"'description'",
")",
";",
"hash",
"+=",
"'|'",
"+",
"label",
";",
"if",
"(",
"description",
")",
"{",
"hash",
"+=",
"'|'",
"+",
"description",
";",
"}",
"}",
")",
";",
"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 | train |
|
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'",
")",
";",
"var",
"shouldConnect",
"=",
"!",
"t",
".",
"model",
".",
"hasMonitor",
"(",
")",
"&&",
"t",
".",
"options",
".",
"monitorParams",
"&&",
"(",
"t",
".",
"model",
".",
"get",
"(",
"'isOpen'",
")",
"||",
"(",
"t",
".",
"options",
".",
"preFetch",
"&&",
"(",
"!",
"t",
".",
"options",
".",
"parentView",
"||",
"t",
".",
"options",
".",
"parentView",
".",
"model",
".",
"get",
"(",
"'isOpen'",
")",
")",
")",
")",
";",
"if",
"(",
"shouldConnect",
")",
"{",
"if",
"(",
"!",
"branches",
"||",
"!",
"leaves",
")",
"{",
"t",
".",
"loading",
"=",
"$",
"(",
"'<li>Loading...</li>'",
")",
".",
"appendTo",
"(",
"t",
".",
"$el",
")",
";",
"}",
"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",
")",
";",
"t",
".",
"monitor",
".",
"on",
"(",
"'connect'",
",",
"function",
"(",
")",
"{",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"for",
"(",
"var",
"i",
"in",
"t",
".",
"connectHandlers",
")",
"{",
"var",
"handler",
"=",
"t",
".",
"connectHandlers",
"[",
"i",
"]",
";",
"handler",
"(",
"t",
".",
"monitor",
")",
";",
"}",
"}",
",",
"10",
")",
";",
"}",
")",
";",
"t",
".",
"monitor",
".",
"connect",
"(",
"function",
"(",
"error",
")",
"{",
"if",
"(",
"t",
".",
"loading",
")",
"{",
"t",
".",
"loading",
".",
"remove",
"(",
")",
";",
"t",
".",
"loading",
"=",
"null",
";",
"}",
"if",
"(",
"error",
")",
"{",
"$",
"(",
"'<li>(connection problem)</li>'",
")",
".",
"appendTo",
"(",
"t",
".",
"$el",
")",
";",
"console",
".",
"error",
"(",
"'TreeView monitor connection problem:'",
",",
"error",
",",
"t",
".",
"monitor",
")",
";",
"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 | train |
|
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 | train |
|
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",
"(",
")",
":",
"''",
";",
"t",
".",
"set",
"(",
"'siteDbPath'",
",",
"Path",
".",
"join",
"(",
"parentPath",
",",
"siteDbPath",
")",
")",
";",
"SyncProbe",
".",
"Config",
".",
"defaultProbe",
"=",
"'FileSyncProbe'",
";",
"SyncProbe",
".",
"FileSyncProbe",
".",
"setRootPath",
"(",
"siteDbPath",
")",
";",
"UI",
".",
"Server",
".",
"currentServer",
"=",
"t",
";",
"t",
".",
"apps",
"=",
"{",
"}",
";",
"t",
".",
"site",
"=",
"null",
";",
"if",
"(",
"!",
"server",
")",
"{",
"server",
"=",
"new",
"Connect",
"(",
")",
";",
"t",
".",
"set",
"(",
"{",
"server",
":",
"server",
"}",
")",
";",
"}",
"server",
".",
"use",
"(",
"t",
".",
"siteRoute",
".",
"bind",
"(",
"t",
")",
")",
";",
"server",
".",
"use",
"(",
"Connect",
"[",
"'static'",
"]",
"(",
"Path",
".",
"join",
"(",
"__dirname",
",",
"'/../..'",
")",
")",
")",
";",
"var",
"monitorDistDir",
"=",
"require",
".",
"resolve",
"(",
"'monitor'",
")",
".",
"replace",
"(",
"/",
"lib[\\\\\\/]index.js",
"/",
",",
"'dist'",
")",
";",
"t",
".",
"monitorDist",
"=",
"Connect",
"[",
"'static'",
"]",
"(",
"monitorDistDir",
")",
";",
"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",
"}",
")",
";",
"}",
")",
";",
"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 | train |
|
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",
";",
"var",
"url",
"=",
"URL",
".",
"resolve",
"(",
"''",
",",
"request",
".",
"url",
")",
";",
"if",
"(",
"url",
"===",
"'/favicon.ico'",
")",
"{",
"var",
"faviconUrl",
"=",
"t",
".",
"site",
".",
"get",
"(",
"'favicon'",
")",
";",
"url",
"=",
"request",
".",
"url",
"=",
"faviconUrl",
"||",
"request",
".",
"url",
";",
"}",
"url",
"=",
"url",
".",
"substr",
"(",
"1",
")",
";",
"var",
"urlParts",
"=",
"url",
".",
"split",
"(",
"'/'",
")",
";",
"if",
"(",
"urlParts",
"[",
"0",
"]",
"===",
"'static'",
")",
"{",
"request",
".",
"url",
"=",
"url",
".",
"replace",
"(",
"'static/'",
",",
"'/lib/'",
")",
";",
"if",
"(",
"request",
".",
"url",
".",
"indexOf",
"(",
"'monitor-all.js'",
")",
">",
"0",
")",
"{",
"request",
".",
"url",
"=",
"'/monitor-all.js'",
";",
"return",
"t",
".",
"monitorDist",
"(",
"request",
",",
"response",
",",
"next",
")",
";",
"}",
"return",
"next",
"(",
")",
";",
"}",
"if",
"(",
"urlParts",
"[",
"0",
"]",
"===",
"'app'",
")",
"{",
"var",
"appName",
"=",
"urlParts",
"[",
"1",
"]",
",",
"app",
"=",
"t",
".",
"apps",
"[",
"appName",
"]",
";",
"var",
"appNext",
"=",
"function",
"(",
")",
"{",
"t",
".",
"_monitorPageRoute",
"(",
"request",
",",
"response",
",",
"next",
")",
";",
"}",
";",
"if",
"(",
"!",
"app",
")",
"{",
"return",
"appNext",
"(",
")",
";",
"}",
"var",
"appUrl",
"=",
"'/'",
"+",
"url",
".",
"split",
"(",
"'/'",
")",
".",
"slice",
"(",
"2",
")",
".",
"join",
"(",
"'/'",
")",
",",
"appRequest",
"=",
"_",
".",
"extend",
"(",
"{",
"}",
",",
"request",
",",
"{",
"url",
":",
"appUrl",
"}",
")",
";",
"var",
"server",
"=",
"typeof",
"app",
".",
"server",
"===",
"'function'",
"?",
"app",
".",
"server",
":",
"app",
".",
"staticServer",
";",
"return",
"server",
"(",
"appRequest",
",",
"response",
",",
"appNext",
")",
";",
"}",
"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 | train |
|
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'",
")",
";",
"if",
"(",
"searchStart",
">",
"0",
")",
"{",
"url",
"=",
"url",
".",
"substr",
"(",
"0",
",",
"searchStart",
")",
";",
"}",
"t",
".",
"_getPage",
"(",
"url",
",",
"function",
"(",
"error",
",",
"pageModel",
")",
"{",
"if",
"(",
"error",
")",
"{",
"return",
"response",
".",
"end",
"(",
"'page error: '",
"+",
"JSON",
".",
"stringify",
"(",
"error",
")",
")",
";",
"}",
"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",
")",
";",
"templates",
".",
"each",
"(",
"function",
"(",
"template",
")",
"{",
"if",
"(",
"template",
".",
"id",
"!==",
"'UI'",
")",
"{",
"page",
".",
"templates",
"+=",
"TMPL_TEMPLATE",
"(",
"{",
"id",
":",
"template",
".",
"id",
",",
"text",
":",
"Template",
".",
"indent",
"(",
"template",
".",
"get",
"(",
"'text'",
")",
",",
"8",
")",
"}",
")",
";",
"}",
"}",
")",
";",
"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 | train |
|
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",
";",
"if",
"(",
"url",
".",
"substr",
"(",
"-",
"1",
")",
"===",
"'/'",
")",
"{",
"url",
"=",
"url",
"+",
"'index'",
";",
"}",
"page",
"=",
"pageCache",
".",
"get",
"(",
"url",
")",
";",
"if",
"(",
"page",
")",
"{",
"return",
"callback",
"(",
"null",
",",
"page",
")",
";",
"}",
"page",
"=",
"new",
"Page",
"(",
"{",
"id",
":",
"url",
"}",
")",
";",
"page",
".",
"fetch",
"(",
"{",
"liveSync",
":",
"true",
",",
"silenceErrors",
":",
"true",
"}",
",",
"function",
"(",
"error",
")",
"{",
"if",
"(",
"error",
"&&",
"error",
".",
"code",
"===",
"'NOTFOUND'",
"&&",
"url",
"!==",
"'/app/core/404'",
")",
"{",
"if",
"(",
"originalUrl",
"===",
"'/'",
")",
"{",
"return",
"t",
".",
"_getPage",
"(",
"'/app/core/index'",
",",
"callback",
")",
";",
"}",
"if",
"(",
"originalUrl",
"===",
"'/404'",
")",
"{",
"return",
"t",
".",
"_getPage",
"(",
"'/app/core/404'",
",",
"callback",
")",
";",
"}",
"t",
".",
"_getPage",
"(",
"'/404'",
",",
"function",
"(",
"error",
",",
"page404",
")",
"{",
"if",
"(",
"error",
")",
"{",
"console",
".",
"error",
"(",
"\"Error loading the 404 page\"",
",",
"error",
")",
";",
"return",
"callback",
"(",
"'404 page load error'",
")",
";",
"}",
"var",
"newPage",
"=",
"new",
"Page",
"(",
"JSON",
".",
"parse",
"(",
"JSON",
".",
"stringify",
"(",
"page404",
")",
")",
")",
";",
"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",
";",
"}",
"if",
"(",
"error",
")",
"{",
"return",
"callback",
"(",
"error",
")",
";",
"}",
"if",
"(",
"url",
"!==",
"page",
".",
"get",
"(",
"'id'",
")",
")",
"{",
"page",
".",
"set",
"(",
"'id'",
",",
"url",
")",
";",
"}",
"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 | train |
|
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'",
")",
";",
"var",
"host",
"=",
"allowExternalConnections",
"?",
"'0.0.0.0'",
":",
"'127.0.0.1'",
";",
"server",
".",
"listen",
"(",
"port",
",",
"host",
",",
"function",
"(",
")",
"{",
"t",
".",
"monitorServer",
"=",
"new",
"Monitor",
".",
"Server",
"(",
"{",
"server",
":",
"server",
",",
"gateway",
":",
"true",
"}",
")",
";",
"t",
".",
"monitorServer",
".",
"start",
"(",
"function",
"(",
")",
"{",
"var",
"onSiteLoad",
"=",
"function",
"(",
"error",
")",
"{",
"if",
"(",
"error",
")",
"{",
"return",
"callback",
"(",
"error",
")",
";",
"}",
"t",
".",
"loadApps",
"(",
")",
";",
"t",
".",
"_bindEvents",
"(",
"callback",
")",
";",
"}",
";",
"t",
".",
"site",
"=",
"new",
"Site",
"(",
")",
";",
"t",
".",
"site",
".",
"fetch",
"(",
"{",
"liveSync",
":",
"true",
",",
"silenceErrors",
":",
"true",
"}",
",",
"function",
"(",
"error",
")",
"{",
"if",
"(",
"error",
"&&",
"error",
".",
"code",
"===",
"'NOTFOUND'",
")",
"{",
"t",
".",
"site",
"=",
"new",
"Site",
"(",
")",
";",
"t",
".",
"site",
".",
"id",
"=",
"null",
";",
"return",
"t",
".",
"site",
".",
"save",
"(",
"{",
"}",
",",
"{",
"liveSync",
":",
"true",
"}",
",",
"onSiteLoad",
")",
";",
"}",
"else",
"if",
"(",
"error",
")",
"{",
"return",
"onSiteLoad",
"(",
"error",
")",
";",
"}",
"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 | train |
|
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",
";",
"var",
"testAppDir",
"=",
"function",
"(",
"dir",
")",
"{",
"var",
"pkg",
";",
"dir",
"=",
"Path",
".",
"resolve",
"(",
"dir",
")",
";",
"try",
"{",
"pkg",
"=",
"JSON",
".",
"parse",
"(",
"FS",
".",
"readFileSync",
"(",
"dir",
"+",
"'/package.json'",
",",
"'utf-8'",
")",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"if",
"(",
"e",
".",
"code",
"!==",
"\"ENOENT\"",
")",
"{",
"console",
".",
"error",
"(",
"\"Problem parsing \"",
"+",
"dir",
"+",
"\"/package.json\"",
")",
";",
"}",
"return",
"false",
";",
"}",
"var",
"isMonitorApp",
"=",
"pkg",
".",
"dependencies",
"&&",
"_",
".",
"find",
"(",
"_",
".",
"keys",
"(",
"pkg",
".",
"dependencies",
")",
",",
"function",
"(",
"keyword",
")",
"{",
"return",
"keyword",
"===",
"'monitor-dashboard'",
";",
"}",
")",
";",
"if",
"(",
"!",
"isMonitorApp",
")",
"{",
"return",
"false",
";",
"}",
"return",
"t",
".",
"loadApp",
"(",
"dir",
",",
"pkg",
")",
";",
"}",
";",
"var",
"loadNodeModulesDir",
"=",
"function",
"(",
"dir",
")",
"{",
"try",
"{",
"FS",
".",
"statSync",
"(",
"dir",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
";",
"}",
"FS",
".",
"readdirSync",
"(",
"dir",
")",
".",
"forEach",
"(",
"function",
"(",
"moduleName",
")",
"{",
"var",
"moduleDir",
"=",
"dir",
"+",
"'/'",
"+",
"moduleName",
";",
"if",
"(",
"testAppDir",
"(",
"moduleDir",
")",
"||",
"moduleName",
"===",
"'monitor'",
")",
"{",
"loadNodeModulesDir",
"(",
"moduleDir",
"+",
"'/node_modules'",
")",
";",
"}",
"}",
")",
";",
"}",
";",
"t",
".",
"thisAppName",
"=",
"testAppDir",
"(",
"'.'",
")",
";",
"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 | train |
|
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",
")",
"{",
"var",
"pkg",
";",
"dir",
"=",
"Path",
".",
"resolve",
"(",
"dir",
")",
";",
"try",
"{",
"pkg",
"=",
"JSON",
".",
"parse",
"(",
"FS",
".",
"readFileSync",
"(",
"dir",
"+",
"'/package.json'",
",",
"'utf-8'",
")",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"if",
"(",
"e",
".",
"code",
"!==",
"\"ENOENT\"",
")",
"{",
"console",
".",
"error",
"(",
"\"Problem parsing \"",
"+",
"dir",
"+",
"\"/package.json\"",
")",
";",
"}",
"return",
"false",
";",
"}",
"var",
"isMonitorApp",
"=",
"pkg",
".",
"dependencies",
"&&",
"_",
".",
"find",
"(",
"_",
".",
"keys",
"(",
"pkg",
".",
"dependencies",
")",
",",
"function",
"(",
"keyword",
")",
"{",
"return",
"keyword",
"===",
"'monitor-dashboard'",
";",
"}",
")",
";",
"if",
"(",
"!",
"isMonitorApp",
")",
"{",
"return",
"false",
";",
"}",
"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 | train |
|
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",
")",
"{",
"try",
"{",
"FS",
".",
"statSync",
"(",
"dir",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
";",
"}",
"FS",
".",
"readdirSync",
"(",
"dir",
")",
".",
"forEach",
"(",
"function",
"(",
"moduleName",
")",
"{",
"var",
"moduleDir",
"=",
"dir",
"+",
"'/'",
"+",
"moduleName",
";",
"if",
"(",
"testAppDir",
"(",
"moduleDir",
")",
"||",
"moduleName",
"===",
"'monitor'",
")",
"{",
"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 | train |
|
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",
"(",
")",
"{",
"}",
";",
"t",
".",
"get",
"(",
"'templates'",
")",
".",
"forEach",
"(",
"function",
"(",
"template",
")",
"{",
"template",
".",
"unWatchFile",
"(",
")",
";",
"}",
")",
";",
"if",
"(",
"!",
"t",
".",
"isListening",
")",
"{",
"return",
"callback",
"(",
")",
";",
"}",
"t",
".",
"isListening",
"=",
"false",
";",
"t",
".",
"monitorServer",
".",
"stop",
"(",
"function",
"(",
"error",
")",
"{",
"if",
"(",
"!",
"error",
")",
"{",
"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 | train |
|
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'",
")",
";",
"t",
".",
"tv",
"=",
"new",
"UI",
".",
"TreeView",
"(",
"{",
"preFetch",
":",
"true",
",",
"monitorParams",
":",
"{",
"probeClass",
":",
"'ToursProbe'",
"}",
"}",
")",
";",
"t",
".",
"tv",
".",
"render",
"(",
")",
".",
"appendTo",
"(",
"t",
".",
"$",
"(",
"'.nm-tsv-tree'",
")",
")",
";",
"t",
".",
"tv",
".",
"whenConnected",
"(",
"function",
"(",
"tree",
")",
"{",
"t",
".",
"firstTour",
"(",
")",
";",
"}",
")",
";",
"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 | train |
|
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 | train |
|
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",
";",
"t",
".",
"pages",
"=",
"t",
".",
"tour",
".",
"get",
"(",
"'pages'",
")",
";",
"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",
"(",
"''",
")",
";",
"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",
")",
";",
"}",
"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 | train |
|
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",
";",
"t",
".",
"dialog",
".",
"centerBox",
"(",
")",
".",
"css",
"(",
"{",
"top",
":",
"40",
"}",
")",
".",
"modal",
"(",
"'show'",
")",
";",
"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 | train |
|
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 | train |
|
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",
";",
"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",
")",
")",
"{",
"params",
".",
"autoNextSec",
"=",
"0",
";",
"}",
"t",
".",
"tour",
".",
"set",
"(",
"params",
")",
";",
"t",
".",
"tour",
".",
"isDirty",
"=",
"true",
";",
"t",
".",
"setDirty",
"(",
"true",
")",
";",
"t",
".",
"loadForm",
"(",
")",
";",
"var",
"tvNode",
"=",
"t",
".",
"tv",
".",
"model",
".",
"getByPath",
"(",
"t",
".",
"tour",
".",
"get",
"(",
"'id'",
")",
")",
";",
"tvNode",
".",
"set",
"(",
"{",
"label",
":",
"params",
".",
"title",
"?",
"params",
".",
"title",
":",
"' '",
",",
"description",
":",
"params",
".",
"description",
"}",
")",
";",
"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 | train |
|
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 | train |
|
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 | train |
|
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",
"]",
";",
"if",
"(",
"newValue",
"===",
"undefined",
"||",
"newValue",
"===",
"null",
")",
"{",
"model",
".",
"_containedModels",
"[",
"attrName",
"]",
"=",
"newValue",
";",
"return",
";",
"}",
"if",
"(",
"newValue",
"instanceof",
"Ctor",
")",
"{",
"if",
"(",
"!",
"oldValue",
"instanceof",
"Ctor",
")",
"{",
"model",
".",
"_containedModels",
"[",
"attrName",
"]",
"=",
"newValue",
";",
"return",
";",
"}",
"var",
"oldJSON",
"=",
"oldValue",
".",
"toJSON",
"(",
"{",
"deep",
":",
"true",
"}",
")",
";",
"var",
"newJSON",
"=",
"newValue",
".",
"toJSON",
"(",
"{",
"deep",
":",
"true",
"}",
")",
";",
"if",
"(",
"_",
".",
"isEqual",
"(",
"oldJSON",
",",
"newJSON",
")",
")",
"{",
"return",
";",
"}",
"newValue",
"=",
"newJSON",
";",
"}",
"if",
"(",
"oldValue",
"instanceof",
"Ctor",
")",
"{",
"model",
".",
"attributes",
"[",
"attrName",
"]",
"=",
"oldValue",
";",
"model",
".",
"_currentAttributes",
"[",
"attrName",
"]",
"=",
"oldValue",
";",
"model",
".",
"changed",
"[",
"attrName",
"]",
"=",
"oldValue",
";",
"oldValue",
".",
"set",
"(",
"newValue",
",",
"setOptions",
")",
";",
"return",
";",
"}",
"newValue",
"=",
"model",
".",
"_containedModels",
"[",
"attrName",
"]",
"=",
"model",
".",
"attributes",
"[",
"attrName",
"]",
"=",
"model",
".",
"_currentAttributes",
"[",
"attrName",
"]",
"=",
"new",
"Ctor",
"(",
"newValue",
",",
"setOptions",
")",
";",
"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 | train |
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",
"(",
"t",
".",
"get",
"(",
"'text'",
")",
")",
"{",
"t",
".",
"compile",
"(",
")",
";",
"return",
";",
"}",
"t",
".",
"on",
"(",
"'change:text'",
",",
"t",
".",
"compile",
",",
"t",
")",
";",
"var",
"path",
"=",
"t",
".",
"get",
"(",
"'path'",
")",
";",
"if",
"(",
"path",
")",
"{",
"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",
"(",
")",
"}",
")",
";",
"}",
"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 | train |
|
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 | train |
|
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'",
")",
";",
"if",
"(",
"params",
"instanceof",
"Backbone",
".",
"Model",
")",
"{",
"params",
"=",
"params",
".",
"toJSON",
"(",
")",
";",
"}",
"if",
"(",
"!",
"compiled",
")",
"{",
"compiled",
"=",
"t",
".",
"compile",
"(",
")",
";",
"}",
"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 | train |
|
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 | train |
|
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 | train |
|
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",
"(",
")",
"{",
"var",
"thisMonitor",
"=",
"JSON",
".",
"stringify",
"(",
"monitor",
".",
"toMonitorJSON",
"(",
")",
")",
";",
"if",
"(",
"thisMonitor",
"===",
"t",
".",
"priorMonitor",
")",
"{",
"return",
";",
"}",
"log",
".",
"info",
"(",
"'render.monitorChange'",
",",
"t",
".",
"logCtxt",
")",
";",
"component",
".",
"off",
"(",
"'change:css change:viewOptions'",
",",
"applyStyles",
")",
";",
"component",
".",
"off",
"(",
"'change:monitor'",
",",
"onMonitorChange",
",",
"t",
")",
";",
"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 | train |
|
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 | train |
|
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",
"(",
")",
";",
"if",
"(",
"(",
"connect",
"&&",
"!",
"isConnected",
"&&",
"monitor",
".",
"get",
"(",
"'probeClass'",
")",
")",
"||",
"(",
"!",
"connect",
"&&",
"isConnected",
")",
")",
"{",
"needsConnecting",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"needsConnecting",
")",
"{",
"log",
".",
"info",
"(",
"logMethod",
"+",
"'.alreadyConnected'",
",",
"t",
".",
"logCtxt",
")",
";",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"callback",
"(",
"null",
")",
";",
"}",
",",
"0",
")",
";",
"return",
";",
"}",
"if",
"(",
"connect",
")",
"{",
"originalParams",
"=",
"monitor",
".",
"get",
"(",
"'initParams'",
")",
";",
"monitor",
".",
"set",
"(",
"{",
"initParams",
":",
"_",
".",
"extend",
"(",
"{",
"}",
",",
"originalParams",
",",
"initOverrides",
")",
"}",
",",
"{",
"silent",
":",
"true",
"}",
")",
";",
"}",
"else",
"{",
"monitor",
".",
"off",
"(",
"'change'",
")",
";",
"}",
"var",
"connectFn",
"=",
"connect",
"?",
"'connect'",
":",
"'disconnect'",
";",
"log",
".",
"info",
"(",
"logMethod",
",",
"t",
".",
"logCtxt",
")",
";",
"monitor",
"[",
"connectFn",
"]",
"(",
"function",
"(",
"error",
")",
"{",
"if",
"(",
"originalParams",
")",
"{",
"monitor",
".",
"set",
"(",
"{",
"initParams",
":",
"originalParams",
"}",
",",
"{",
"silent",
":",
"true",
"}",
")",
";",
"}",
"if",
"(",
"!",
"connect",
")",
"{",
"var",
"probeElems",
"=",
"monitor",
".",
"toProbeJSON",
"(",
")",
";",
"delete",
"probeElems",
".",
"id",
";",
"monitor",
".",
"set",
"(",
"probeElems",
",",
"{",
"unset",
":",
"true",
"}",
")",
";",
"}",
"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 | train |
|
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",
"(",
")",
";",
"settingsView",
".",
"setModel",
"(",
"t",
".",
"model",
",",
"t",
",",
"t",
".",
"viewClass",
"[",
"'SettingsView'",
"]",
")",
";",
"$",
"(",
"'#nm-cv-settings'",
")",
".",
"centerBox",
"(",
")",
".",
"css",
"(",
"{",
"top",
":",
"40",
"}",
")",
".",
"modal",
"(",
"'show'",
")",
";",
"e",
".",
"stopPropagation",
"(",
")",
";",
"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 | train |
|
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'",
")",
";",
"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 | train |
|
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",
";",
"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",
";",
"}",
"}",
")",
";",
"if",
"(",
"maxZIndex",
">=",
"thisZIndex",
")",
"{",
"thisZIndex",
"=",
"maxZIndex",
"+",
"1",
";",
"if",
"(",
"persist",
")",
"{",
"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",
"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 | train |
|
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",
";",
"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 | train |
|
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",
"(",
")",
";",
"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 | train |
|
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 | train |
|
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'",
")",
";",
"if",
"(",
"$",
"(",
"e",
".",
"currentTarget",
")",
".",
"parents",
"(",
"'.nm-sb-tours'",
")",
".",
"length",
")",
"{",
"UI",
".",
"pageView",
".",
"runTour",
"(",
"path",
")",
";",
"return",
";",
"}",
"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 | train |
|
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",
"(",
")",
";",
"UI",
".",
"pageView",
".",
"$",
"(",
"'#nm-pv-new'",
")",
".",
"centerBox",
"(",
")",
".",
"css",
"(",
"{",
"top",
":",
"100",
"}",
")",
".",
"modal",
"(",
"'show'",
")",
";",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"$",
"(",
"'.nm-np-address'",
")",
".",
"focus",
"(",
")",
";",
"}",
",",
"500",
")",
";",
"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 | train |
|
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",
"(",
")",
";",
"t",
".",
"tourSettingsView",
".",
"show",
"(",
")",
";",
"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 | train |
|
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",
")",
";",
"if",
"(",
"newWidth",
"===",
"startWidth",
")",
"{",
"newWidth",
"=",
"startWidth",
"===",
"0",
"?",
"Sidebar",
".",
"prototype",
".",
"defaults",
".",
"width",
":",
"0",
";",
"}",
"else",
"if",
"(",
"newWidth",
"<",
"30",
")",
"{",
"newWidth",
"=",
"0",
";",
"}",
"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 | train |
|
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",
"}",
")",
";",
"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",
";",
"}",
";",
"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 | train |
|
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 | train |
|
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 | train |
|
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",
")",
";",
"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 | train |
|
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",
";",
"if",
"(",
"UI",
".",
"pageView",
".",
"tourView",
")",
"{",
"var",
"target",
";",
"if",
"(",
"code",
">=",
"49",
"&&",
"code",
"<=",
"57",
")",
"{",
"target",
"=",
"$",
"(",
"'.nm-tv-page[data-index=\"'",
"+",
"(",
"code",
"-",
"49",
")",
"+",
"'\"]'",
")",
";",
"}",
"if",
"(",
"code",
"==",
"32",
")",
"{",
"UI",
".",
"pageView",
".",
"tourView",
"[",
"UI",
".",
"pageView",
".",
"tourView",
".",
"timer",
"?",
"'pause'",
":",
"'play'",
"]",
"(",
")",
";",
"}",
"if",
"(",
"code",
"==",
"37",
"||",
"code",
"==",
"38",
")",
"{",
"UI",
".",
"pageView",
".",
"tourView",
".",
"prev",
"(",
")",
";",
"}",
"if",
"(",
"code",
"==",
"39",
"||",
"code",
"==",
"40",
")",
"{",
"UI",
".",
"pageView",
".",
"tourView",
".",
"prev",
"(",
")",
";",
"}",
"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 | train |
|
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",
";",
"if",
"(",
"!",
"box",
".",
"width",
")",
"{",
"return",
";",
"}",
"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 | train |
|
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",
"(",
")",
";",
"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'",
"]",
"||",
"''",
")",
";",
"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 | train |
|
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 | train |
|
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'",
")",
";",
"canvas",
".",
"find",
"(",
"'.nm-pv-component'",
")",
".",
"each",
"(",
"function",
"(",
")",
"{",
"var",
"component",
"=",
"$",
"(",
"this",
")",
";",
"if",
"(",
"!",
"components",
".",
"get",
"(",
"component",
".",
"attr",
"(",
"'id'",
")",
")",
")",
"{",
"component",
".",
"remove",
"(",
")",
";",
"}",
"}",
")",
";",
"components",
".",
"forEach",
"(",
"function",
"(",
"component",
")",
"{",
"var",
"onScreen",
"=",
"t",
".",
"$",
"(",
"'#'",
"+",
"component",
".",
"get",
"(",
"'id'",
")",
")",
";",
"if",
"(",
"!",
"onScreen",
".",
"length",
")",
"{",
"t",
".",
"addComponent",
"(",
"component",
")",
";",
"}",
"}",
")",
";",
"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 | train |
|
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",
";",
"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 | train |
|
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 | train |
|
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",
";",
"if",
"(",
"isDirty",
")",
"{",
"UI",
".",
"pauseTour",
"(",
")",
";",
"}",
"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 | train |
|
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",
"(",
")",
"{",
"var",
"t",
"=",
"this",
";",
"t",
".",
"pageSettingsView",
".",
"originalModel",
"=",
"t",
".",
"model",
".",
"toJSON",
"(",
"{",
"trim",
":",
"false",
"}",
")",
";",
"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 | train |
|
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 | train |
|
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 | train |
|
lorenwest/monitor-dashboard | lib/js/PageView.js | function(id) {
var t = this;
// Is there a tour running already?
if (t.tourView) {
t.tourView.stop();
}
// Load the Tour and start it
var tour = new UI.Tour({id:id});
tour.fetch(function(err){
if (err) {
alert("Error: Cannot open tour id: " + id);
console.error(e);
return;
}
// Go to the first page
var pages = tour.get('pages');
if (!pages.length) {
alert('No pages in tour: ' + tour.get('title'));
return;
}
// Save the current tour, and navigate to it
localStorage.currentTour = JSON.stringify(tour);
t.navigateTo(pages[0].url);
});
} | javascript | function(id) {
var t = this;
// Is there a tour running already?
if (t.tourView) {
t.tourView.stop();
}
// Load the Tour and start it
var tour = new UI.Tour({id:id});
tour.fetch(function(err){
if (err) {
alert("Error: Cannot open tour id: " + id);
console.error(e);
return;
}
// Go to the first page
var pages = tour.get('pages');
if (!pages.length) {
alert('No pages in tour: ' + tour.get('title'));
return;
}
// Save the current tour, and navigate to it
localStorage.currentTour = JSON.stringify(tour);
t.navigateTo(pages[0].url);
});
} | [
"function",
"(",
"id",
")",
"{",
"var",
"t",
"=",
"this",
";",
"if",
"(",
"t",
".",
"tourView",
")",
"{",
"t",
".",
"tourView",
".",
"stop",
"(",
")",
";",
"}",
"var",
"tour",
"=",
"new",
"UI",
".",
"Tour",
"(",
"{",
"id",
":",
"id",
"}",
")",
";",
"tour",
".",
"fetch",
"(",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"alert",
"(",
"\"Error: Cannot open tour id: \"",
"+",
"id",
")",
";",
"console",
".",
"error",
"(",
"e",
")",
";",
"return",
";",
"}",
"var",
"pages",
"=",
"tour",
".",
"get",
"(",
"'pages'",
")",
";",
"if",
"(",
"!",
"pages",
".",
"length",
")",
"{",
"alert",
"(",
"'No pages in tour: '",
"+",
"tour",
".",
"get",
"(",
"'title'",
")",
")",
";",
"return",
";",
"}",
"localStorage",
".",
"currentTour",
"=",
"JSON",
".",
"stringify",
"(",
"tour",
")",
";",
"t",
".",
"navigateTo",
"(",
"pages",
"[",
"0",
"]",
".",
"url",
")",
";",
"}",
")",
";",
"}"
]
| Run the tour specified by id | [
"Run",
"the",
"tour",
"specified",
"by",
"id"
]
| a990e03d07096515744332ae0761441f8534369c | https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/PageView.js#L505-L533 | train |
|
lorenwest/monitor-dashboard | lib/js/PageView.js | function() {
var t = this,
isEditMode = t.$el.hasClass('edit-mode'),
text = isEditMode ? 'Lock Components' : 'Edit Components',
icon = isEditMode ? 'lock' : 'edit';
t.$('.nm-pvm-lock').text(text);
t.$('.nm-pvm-edit i').attr('class', 'icon-' + icon);
} | javascript | function() {
var t = this,
isEditMode = t.$el.hasClass('edit-mode'),
text = isEditMode ? 'Lock Components' : 'Edit Components',
icon = isEditMode ? 'lock' : 'edit';
t.$('.nm-pvm-lock').text(text);
t.$('.nm-pvm-edit i').attr('class', 'icon-' + icon);
} | [
"function",
"(",
")",
"{",
"var",
"t",
"=",
"this",
",",
"isEditMode",
"=",
"t",
".",
"$el",
".",
"hasClass",
"(",
"'edit-mode'",
")",
",",
"text",
"=",
"isEditMode",
"?",
"'Lock Components'",
":",
"'Edit Components'",
",",
"icon",
"=",
"isEditMode",
"?",
"'lock'",
":",
"'edit'",
";",
"t",
".",
"$",
"(",
"'.nm-pvm-lock'",
")",
".",
"text",
"(",
"text",
")",
";",
"t",
".",
"$",
"(",
"'.nm-pvm-edit i'",
")",
".",
"attr",
"(",
"'class'",
",",
"'icon-'",
"+",
"icon",
")",
";",
"}"
]
| This sets the edit menu text and icon | [
"This",
"sets",
"the",
"edit",
"menu",
"text",
"and",
"icon"
]
| a990e03d07096515744332ae0761441f8534369c | https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/PageView.js#L542-L549 | train |
|
lorenwest/monitor-dashboard | lib/js/PageView.js | function() {
var t = this;
// Show if loaded
if (aboutTemplate) {
return t.showDialog('#nm-pv-about');
}
UI.loadTemplate('', 'About', function(error, template) {
if (error) {return;}
t.$el.append(template.apply(t));
t.$('.modal a').attr({target: '_blank'});
t.$('.colorPicker').miniColors({opacity: true});
t.showDialog('#nm-pv-about');
});
} | javascript | function() {
var t = this;
// Show if loaded
if (aboutTemplate) {
return t.showDialog('#nm-pv-about');
}
UI.loadTemplate('', 'About', function(error, template) {
if (error) {return;}
t.$el.append(template.apply(t));
t.$('.modal a').attr({target: '_blank'});
t.$('.colorPicker').miniColors({opacity: true});
t.showDialog('#nm-pv-about');
});
} | [
"function",
"(",
")",
"{",
"var",
"t",
"=",
"this",
";",
"if",
"(",
"aboutTemplate",
")",
"{",
"return",
"t",
".",
"showDialog",
"(",
"'#nm-pv-about'",
")",
";",
"}",
"UI",
".",
"loadTemplate",
"(",
"''",
",",
"'About'",
",",
"function",
"(",
"error",
",",
"template",
")",
"{",
"if",
"(",
"error",
")",
"{",
"return",
";",
"}",
"t",
".",
"$el",
".",
"append",
"(",
"template",
".",
"apply",
"(",
"t",
")",
")",
";",
"t",
".",
"$",
"(",
"'.modal a'",
")",
".",
"attr",
"(",
"{",
"target",
":",
"'_blank'",
"}",
")",
";",
"t",
".",
"$",
"(",
"'.colorPicker'",
")",
".",
"miniColors",
"(",
"{",
"opacity",
":",
"true",
"}",
")",
";",
"t",
".",
"showDialog",
"(",
"'#nm-pv-about'",
")",
";",
"}",
")",
";",
"}"
]
| This shows the about page | [
"This",
"shows",
"the",
"about",
"page"
]
| a990e03d07096515744332ae0761441f8534369c | https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/PageView.js#L552-L568 | train |
|
lorenwest/monitor-dashboard | lib/js/PageView.js | function() {
var t = this;
UI.hideToolTips();
t.leftJustify();
t.centerPage();
t.model.save(function(error){
if (error) {
console.error("Page save error:", error);
}
});
t.unlockPage();
t.setDirty(false);
} | javascript | function() {
var t = this;
UI.hideToolTips();
t.leftJustify();
t.centerPage();
t.model.save(function(error){
if (error) {
console.error("Page save error:", error);
}
});
t.unlockPage();
t.setDirty(false);
} | [
"function",
"(",
")",
"{",
"var",
"t",
"=",
"this",
";",
"UI",
".",
"hideToolTips",
"(",
")",
";",
"t",
".",
"leftJustify",
"(",
")",
";",
"t",
".",
"centerPage",
"(",
")",
";",
"t",
".",
"model",
".",
"save",
"(",
"function",
"(",
"error",
")",
"{",
"if",
"(",
"error",
")",
"{",
"console",
".",
"error",
"(",
"\"Page save error:\"",
",",
"error",
")",
";",
"}",
"}",
")",
";",
"t",
".",
"unlockPage",
"(",
")",
";",
"t",
".",
"setDirty",
"(",
"false",
")",
";",
"}"
]
| Persist the page to the backend | [
"Persist",
"the",
"page",
"to",
"the",
"backend"
]
| a990e03d07096515744332ae0761441f8534369c | https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/PageView.js#L571-L583 | train |
|
lorenwest/monitor-dashboard | lib/js/JsonView.js | function() {
var t = this;
t.$el.html('');
// Output the heading if specified
if (t.options.heading) {
$(t.template.heading({value:t.options.heading})).appendTo(t.$el);
}
// If a non-object, just print it
t.json = t.isBackbone ? t.model.toJSON() : t.model;
if (typeof t.json !== 'object') {
$(t.template.line({name:'value', value:t.json})).appendTo(t.$el);
return;
}
t.keys = _.keys(t.json);
// Info about each element, keyed by element name
// div - The jQuery selector of the element outer div
// span - The jQuery selector of the data value span
// value - The element raw value
// isBackbone - Is the element an instance of a Backbone model?
// strValue - The currently displayed value
// isArray - True of the element is an array (or collection)
// innerDiv - The container for the inner view for objects
// innerView - The inner view if the element is an object
t.elems = {};
// Layout the tree (without element data)
for (var elemName in t.json) {
var elem = t.elems[elemName] = {};
elem.value = t.getElemValue(elemName);
elem.isBackbone = elem.value instanceof Backbone.Model || elem.value instanceof Backbone.Collection;
elem.div = $(t.template.line({name:elemName, value: ' '})).appendTo(t.$el);
elem.span = $('.data', elem.div);
// Render a sub-element as another JsonView
if (elem.value !== null && typeof elem.value === 'object') {
elem.div.addClass('open-close').data({elemName:elemName});
$('i', elem.div).html('');
elem.innerDiv = $(t.template.inner()).appendTo(t.$el);
elem.innerView = new JsonView({
model: elem.value,
closedOnInit: t.closedOnInit
});
elem.innerView.render();
elem.innerView.$el.appendTo(elem.innerDiv);
elem.isArray = _.isArray(elem.value);
$(t.template.endInner({symbol:elem.isArray ? "]" : "}"})).appendTo(elem.innerDiv);
}
}
// Bind the change handler
if (t.isBackbone) {
t.model.bind('change', t.setData, t);
}
// Add element data to the tree
t.setData();
// Reset for future renders
t.closedOnInit = false;
} | javascript | function() {
var t = this;
t.$el.html('');
// Output the heading if specified
if (t.options.heading) {
$(t.template.heading({value:t.options.heading})).appendTo(t.$el);
}
// If a non-object, just print it
t.json = t.isBackbone ? t.model.toJSON() : t.model;
if (typeof t.json !== 'object') {
$(t.template.line({name:'value', value:t.json})).appendTo(t.$el);
return;
}
t.keys = _.keys(t.json);
// Info about each element, keyed by element name
// div - The jQuery selector of the element outer div
// span - The jQuery selector of the data value span
// value - The element raw value
// isBackbone - Is the element an instance of a Backbone model?
// strValue - The currently displayed value
// isArray - True of the element is an array (or collection)
// innerDiv - The container for the inner view for objects
// innerView - The inner view if the element is an object
t.elems = {};
// Layout the tree (without element data)
for (var elemName in t.json) {
var elem = t.elems[elemName] = {};
elem.value = t.getElemValue(elemName);
elem.isBackbone = elem.value instanceof Backbone.Model || elem.value instanceof Backbone.Collection;
elem.div = $(t.template.line({name:elemName, value: ' '})).appendTo(t.$el);
elem.span = $('.data', elem.div);
// Render a sub-element as another JsonView
if (elem.value !== null && typeof elem.value === 'object') {
elem.div.addClass('open-close').data({elemName:elemName});
$('i', elem.div).html('');
elem.innerDiv = $(t.template.inner()).appendTo(t.$el);
elem.innerView = new JsonView({
model: elem.value,
closedOnInit: t.closedOnInit
});
elem.innerView.render();
elem.innerView.$el.appendTo(elem.innerDiv);
elem.isArray = _.isArray(elem.value);
$(t.template.endInner({symbol:elem.isArray ? "]" : "}"})).appendTo(elem.innerDiv);
}
}
// Bind the change handler
if (t.isBackbone) {
t.model.bind('change', t.setData, t);
}
// Add element data to the tree
t.setData();
// Reset for future renders
t.closedOnInit = false;
} | [
"function",
"(",
")",
"{",
"var",
"t",
"=",
"this",
";",
"t",
".",
"$el",
".",
"html",
"(",
"''",
")",
";",
"if",
"(",
"t",
".",
"options",
".",
"heading",
")",
"{",
"$",
"(",
"t",
".",
"template",
".",
"heading",
"(",
"{",
"value",
":",
"t",
".",
"options",
".",
"heading",
"}",
")",
")",
".",
"appendTo",
"(",
"t",
".",
"$el",
")",
";",
"}",
"t",
".",
"json",
"=",
"t",
".",
"isBackbone",
"?",
"t",
".",
"model",
".",
"toJSON",
"(",
")",
":",
"t",
".",
"model",
";",
"if",
"(",
"typeof",
"t",
".",
"json",
"!==",
"'object'",
")",
"{",
"$",
"(",
"t",
".",
"template",
".",
"line",
"(",
"{",
"name",
":",
"'value'",
",",
"value",
":",
"t",
".",
"json",
"}",
")",
")",
".",
"appendTo",
"(",
"t",
".",
"$el",
")",
";",
"return",
";",
"}",
"t",
".",
"keys",
"=",
"_",
".",
"keys",
"(",
"t",
".",
"json",
")",
";",
"t",
".",
"elems",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"elemName",
"in",
"t",
".",
"json",
")",
"{",
"var",
"elem",
"=",
"t",
".",
"elems",
"[",
"elemName",
"]",
"=",
"{",
"}",
";",
"elem",
".",
"value",
"=",
"t",
".",
"getElemValue",
"(",
"elemName",
")",
";",
"elem",
".",
"isBackbone",
"=",
"elem",
".",
"value",
"instanceof",
"Backbone",
".",
"Model",
"||",
"elem",
".",
"value",
"instanceof",
"Backbone",
".",
"Collection",
";",
"elem",
".",
"div",
"=",
"$",
"(",
"t",
".",
"template",
".",
"line",
"(",
"{",
"name",
":",
"elemName",
",",
"value",
":",
"' '",
"}",
")",
")",
".",
"appendTo",
"(",
"t",
".",
"$el",
")",
";",
"elem",
".",
"span",
"=",
"$",
"(",
"'.data'",
",",
"elem",
".",
"div",
")",
";",
"if",
"(",
"elem",
".",
"value",
"!==",
"null",
"&&",
"typeof",
"elem",
".",
"value",
"===",
"'object'",
")",
"{",
"elem",
".",
"div",
".",
"addClass",
"(",
"'open-close'",
")",
".",
"data",
"(",
"{",
"elemName",
":",
"elemName",
"}",
")",
";",
"$",
"(",
"'i'",
",",
"elem",
".",
"div",
")",
".",
"html",
"(",
"''",
")",
";",
"elem",
".",
"innerDiv",
"=",
"$",
"(",
"t",
".",
"template",
".",
"inner",
"(",
")",
")",
".",
"appendTo",
"(",
"t",
".",
"$el",
")",
";",
"elem",
".",
"innerView",
"=",
"new",
"JsonView",
"(",
"{",
"model",
":",
"elem",
".",
"value",
",",
"closedOnInit",
":",
"t",
".",
"closedOnInit",
"}",
")",
";",
"elem",
".",
"innerView",
".",
"render",
"(",
")",
";",
"elem",
".",
"innerView",
".",
"$el",
".",
"appendTo",
"(",
"elem",
".",
"innerDiv",
")",
";",
"elem",
".",
"isArray",
"=",
"_",
".",
"isArray",
"(",
"elem",
".",
"value",
")",
";",
"$",
"(",
"t",
".",
"template",
".",
"endInner",
"(",
"{",
"symbol",
":",
"elem",
".",
"isArray",
"?",
"\"]\"",
":",
"\"}\"",
"}",
")",
")",
".",
"appendTo",
"(",
"elem",
".",
"innerDiv",
")",
";",
"}",
"}",
"if",
"(",
"t",
".",
"isBackbone",
")",
"{",
"t",
".",
"model",
".",
"bind",
"(",
"'change'",
",",
"t",
".",
"setData",
",",
"t",
")",
";",
"}",
"t",
".",
"setData",
"(",
")",
";",
"t",
".",
"closedOnInit",
"=",
"false",
";",
"}"
]
| Render new HTML | [
"Render",
"new",
"HTML"
]
| a990e03d07096515744332ae0761441f8534369c | https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/JsonView.js#L56-L118 | train |
|
lorenwest/monitor-dashboard | lib/js/JsonView.js | function(elemName) {
var t = this;
if (t.isBackbone) {
return t.model instanceof Backbone.Collection ? t.model.at(elemName) : t.model.get(elemName);
}
return t.model[elemName];
} | javascript | function(elemName) {
var t = this;
if (t.isBackbone) {
return t.model instanceof Backbone.Collection ? t.model.at(elemName) : t.model.get(elemName);
}
return t.model[elemName];
} | [
"function",
"(",
"elemName",
")",
"{",
"var",
"t",
"=",
"this",
";",
"if",
"(",
"t",
".",
"isBackbone",
")",
"{",
"return",
"t",
".",
"model",
"instanceof",
"Backbone",
".",
"Collection",
"?",
"t",
".",
"model",
".",
"at",
"(",
"elemName",
")",
":",
"t",
".",
"model",
".",
"get",
"(",
"elemName",
")",
";",
"}",
"return",
"t",
".",
"model",
"[",
"elemName",
"]",
";",
"}"
]
| Get the value of the element with the specified name | [
"Get",
"the",
"value",
"of",
"the",
"element",
"with",
"the",
"specified",
"name"
]
| a990e03d07096515744332ae0761441f8534369c | https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/JsonView.js#L152-L158 | train |
|
lorenwest/monitor-dashboard | lib/js/JsonView.js | function(elem) {
var t = this,
strValue;
// Catch recursive stringify
try {strValue = JSON.stringify(elem.value);}
catch (e) {strValue = "{object}";}
// Set if the value changed
if (strValue !== elem.strValue) {
var priorStrValue = elem.strValue;
elem.strValue = strValue;
// Set the value of this element or the inner element
elem.span.text(strValue);
if (elem.innerView) {
elem.innerView.model = elem.value;
elem.innerView.setData();
// Set the inner element open or closed
var isClosed = false;
if (priorStrValue) {
isClosed = elem.innerView.isClosed;
} else {
isClosed = t.closedOnInit ? true : strValue.length < AUTO_CLOSE_CHARS;
}
t.toggleClosed(elem, isClosed);
}
}
} | javascript | function(elem) {
var t = this,
strValue;
// Catch recursive stringify
try {strValue = JSON.stringify(elem.value);}
catch (e) {strValue = "{object}";}
// Set if the value changed
if (strValue !== elem.strValue) {
var priorStrValue = elem.strValue;
elem.strValue = strValue;
// Set the value of this element or the inner element
elem.span.text(strValue);
if (elem.innerView) {
elem.innerView.model = elem.value;
elem.innerView.setData();
// Set the inner element open or closed
var isClosed = false;
if (priorStrValue) {
isClosed = elem.innerView.isClosed;
} else {
isClosed = t.closedOnInit ? true : strValue.length < AUTO_CLOSE_CHARS;
}
t.toggleClosed(elem, isClosed);
}
}
} | [
"function",
"(",
"elem",
")",
"{",
"var",
"t",
"=",
"this",
",",
"strValue",
";",
"try",
"{",
"strValue",
"=",
"JSON",
".",
"stringify",
"(",
"elem",
".",
"value",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"strValue",
"=",
"\"{object}\"",
";",
"}",
"if",
"(",
"strValue",
"!==",
"elem",
".",
"strValue",
")",
"{",
"var",
"priorStrValue",
"=",
"elem",
".",
"strValue",
";",
"elem",
".",
"strValue",
"=",
"strValue",
";",
"elem",
".",
"span",
".",
"text",
"(",
"strValue",
")",
";",
"if",
"(",
"elem",
".",
"innerView",
")",
"{",
"elem",
".",
"innerView",
".",
"model",
"=",
"elem",
".",
"value",
";",
"elem",
".",
"innerView",
".",
"setData",
"(",
")",
";",
"var",
"isClosed",
"=",
"false",
";",
"if",
"(",
"priorStrValue",
")",
"{",
"isClosed",
"=",
"elem",
".",
"innerView",
".",
"isClosed",
";",
"}",
"else",
"{",
"isClosed",
"=",
"t",
".",
"closedOnInit",
"?",
"true",
":",
"strValue",
".",
"length",
"<",
"AUTO_CLOSE_CHARS",
";",
"}",
"t",
".",
"toggleClosed",
"(",
"elem",
",",
"isClosed",
")",
";",
"}",
"}",
"}"
]
| Set the DOM element value to the JSON.stringify format | [
"Set",
"the",
"DOM",
"element",
"value",
"to",
"the",
"JSON",
".",
"stringify",
"format"
]
| a990e03d07096515744332ae0761441f8534369c | https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/JsonView.js#L161-L190 | train |
|
lorenwest/monitor-dashboard | lib/js/TourView.js | function() {
// Compute the amount of play left to go
t.playLeft = t.playEnd - Date.now();
// Done playing
if (t.playLeft <= 0) {
clearInterval(t.timer);
t.next();
}
// Set the progress bar width
t.setProgress();
} | javascript | function() {
// Compute the amount of play left to go
t.playLeft = t.playEnd - Date.now();
// Done playing
if (t.playLeft <= 0) {
clearInterval(t.timer);
t.next();
}
// Set the progress bar width
t.setProgress();
} | [
"function",
"(",
")",
"{",
"t",
".",
"playLeft",
"=",
"t",
".",
"playEnd",
"-",
"Date",
".",
"now",
"(",
")",
";",
"if",
"(",
"t",
".",
"playLeft",
"<=",
"0",
")",
"{",
"clearInterval",
"(",
"t",
".",
"timer",
")",
";",
"t",
".",
"next",
"(",
")",
";",
"}",
"t",
".",
"setProgress",
"(",
")",
";",
"}"
]
| Run at each animation interval | [
"Run",
"at",
"each",
"animation",
"interval"
]
| a990e03d07096515744332ae0761441f8534369c | https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/TourView.js#L157-L169 | train |
|
lorenwest/monitor-dashboard | lib/js/TourView.js | function(e) {
var t = this,
target = $(e.currentTarget),
index = target.attr('data-index');
// Save the index. If a tour has many instances of the
// same page, it needs to know which instance.
localStorage.tourPageIndex = index;
// Navigate to the page
UI.pageView.navigateTo(target.attr('href'));
} | javascript | function(e) {
var t = this,
target = $(e.currentTarget),
index = target.attr('data-index');
// Save the index. If a tour has many instances of the
// same page, it needs to know which instance.
localStorage.tourPageIndex = index;
// Navigate to the page
UI.pageView.navigateTo(target.attr('href'));
} | [
"function",
"(",
"e",
")",
"{",
"var",
"t",
"=",
"this",
",",
"target",
"=",
"$",
"(",
"e",
".",
"currentTarget",
")",
",",
"index",
"=",
"target",
".",
"attr",
"(",
"'data-index'",
")",
";",
"localStorage",
".",
"tourPageIndex",
"=",
"index",
";",
"UI",
".",
"pageView",
".",
"navigateTo",
"(",
"target",
".",
"attr",
"(",
"'href'",
")",
")",
";",
"}"
]
| Select a page | [
"Select",
"a",
"page"
]
| a990e03d07096515744332ae0761441f8534369c | https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/TourView.js#L213-L224 | train |
|
lorenwest/monitor-dashboard | lib/template/app/lib/view/SampleView.js | function(options) {
var t = this;
t.options = options;
t.monitor = options.monitor;
// Call this to set the initial height/width to something
// other than the size of the inner view elements.
options.component.setDefaultSize({
width: 400,
height: 300
});
// Set monitor defaults. If your view is for a specific probe,
// then set the probeClass and any default probe initialization
// parameters.
if (!t.monitor.get('probeClass')) {
t.monitor.set({
probeClass: '{{shortAppName}}SampleProbe'
});
}
// Update the view on monitor change. The monitor isn't in
// a connected state, so this will be called when connected.
if (t.monitor != null) {
t.monitor.on('change', t.onchange, t);
}
} | javascript | function(options) {
var t = this;
t.options = options;
t.monitor = options.monitor;
// Call this to set the initial height/width to something
// other than the size of the inner view elements.
options.component.setDefaultSize({
width: 400,
height: 300
});
// Set monitor defaults. If your view is for a specific probe,
// then set the probeClass and any default probe initialization
// parameters.
if (!t.monitor.get('probeClass')) {
t.monitor.set({
probeClass: '{{shortAppName}}SampleProbe'
});
}
// Update the view on monitor change. The monitor isn't in
// a connected state, so this will be called when connected.
if (t.monitor != null) {
t.monitor.on('change', t.onchange, t);
}
} | [
"function",
"(",
"options",
")",
"{",
"var",
"t",
"=",
"this",
";",
"t",
".",
"options",
"=",
"options",
";",
"t",
".",
"monitor",
"=",
"options",
".",
"monitor",
";",
"options",
".",
"component",
".",
"setDefaultSize",
"(",
"{",
"width",
":",
"400",
",",
"height",
":",
"300",
"}",
")",
";",
"if",
"(",
"!",
"t",
".",
"monitor",
".",
"get",
"(",
"'probeClass'",
")",
")",
"{",
"t",
".",
"monitor",
".",
"set",
"(",
"{",
"probeClass",
":",
"'{{shortAppName}}SampleProbe'",
"}",
")",
";",
"}",
"if",
"(",
"t",
".",
"monitor",
"!=",
"null",
")",
"{",
"t",
".",
"monitor",
".",
"on",
"(",
"'change'",
",",
"t",
".",
"onchange",
",",
"t",
")",
";",
"}",
"}"
]
| Add your view to the categories listed in these tags Called by the Backbone.View constructor | [
"Add",
"your",
"view",
"to",
"the",
"categories",
"listed",
"in",
"these",
"tags",
"Called",
"by",
"the",
"Backbone",
".",
"View",
"constructor"
]
| a990e03d07096515744332ae0761441f8534369c | https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/template/app/lib/view/SampleView.js#L37-L63 | train |
|
lorenwest/monitor-dashboard | lib/template/app/lib/view/SampleView.js | function() {
var t = this;
// Append a monitor picker
t.monitorPicker = new UI.MonitorPicker({
el: t.$el,
hideProbe: true, // Set false for the user to select the probe class
model: t.options.monitor
});
t.monitorPicker.render();
} | javascript | function() {
var t = this;
// Append a monitor picker
t.monitorPicker = new UI.MonitorPicker({
el: t.$el,
hideProbe: true, // Set false for the user to select the probe class
model: t.options.monitor
});
t.monitorPicker.render();
} | [
"function",
"(",
")",
"{",
"var",
"t",
"=",
"this",
";",
"t",
".",
"monitorPicker",
"=",
"new",
"UI",
".",
"MonitorPicker",
"(",
"{",
"el",
":",
"t",
".",
"$el",
",",
"hideProbe",
":",
"true",
",",
"model",
":",
"t",
".",
"options",
".",
"monitor",
"}",
")",
";",
"t",
".",
"monitorPicker",
".",
"render",
"(",
")",
";",
"}"
]
| This is called when the settings page is opened. The options element of this view is set to the above options prior to calling render, so it doesn't have to be set in an initialize method. | [
"This",
"is",
"called",
"when",
"the",
"settings",
"page",
"is",
"opened",
".",
"The",
"options",
"element",
"of",
"this",
"view",
"is",
"set",
"to",
"the",
"above",
"options",
"prior",
"to",
"calling",
"render",
"so",
"it",
"doesn",
"t",
"have",
"to",
"be",
"set",
"in",
"an",
"initialize",
"method",
"."
]
| a990e03d07096515744332ae0761441f8534369c | https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/template/app/lib/view/SampleView.js#L107-L117 | train |
|
lorenwest/monitor-dashboard | lib/js/NetworkMap.js | function() {
var t = this,
map = {},
router = Monitor.getRouter(),
hostName = Monitor.getRouter().getHostName(),
appName = Monitor.Config.Monitor.appName,
appInstance = process.env.NODE_APP_INSTANCE;
// Add this process to the map
map[hostName] = {};
map[hostName][appName] = {
instances: [appInstance],
probeClasses: _.keys(Probe.classes)
};
// Process all known connections
var connections = router.findConnections();
connections.forEach(function(connection) {
hostName = connection.get('hostName') || connection.get('remoteHostName');
appName = connection.get('remoteAppName') || '';
appInstance = connection.get('remoteAppInstance') || '';
// Don't add to the map not yet connected
if (connection.connecting || !connection.connected) {
return;
}
// Add the hostname to the map
var host = map[hostName];
if (!host) {
host = map[hostName] = {};
}
// Add the app to the map
var app = host[appName];
if (!app) {
app = host[appName] = {
instances: [appInstance],
probeClasses: connection.get('remoteProbeClasses')
};
} else {
app.instances.push(appInstance);
}
});
log.info('buildMap', map);
// Set the map if it's changed. This method is called whenever
// connections come and go - including firewalled connections which
// aren't visible in the map. Only update if the map has changed.
if (!_.isEqual(map, t.get('map'))) {
log.info('mapChanged');
t.set({
map: map,
updateSequence: t.updateSequence++
});
} else {
log.info('mapNotChanged');
}
} | javascript | function() {
var t = this,
map = {},
router = Monitor.getRouter(),
hostName = Monitor.getRouter().getHostName(),
appName = Monitor.Config.Monitor.appName,
appInstance = process.env.NODE_APP_INSTANCE;
// Add this process to the map
map[hostName] = {};
map[hostName][appName] = {
instances: [appInstance],
probeClasses: _.keys(Probe.classes)
};
// Process all known connections
var connections = router.findConnections();
connections.forEach(function(connection) {
hostName = connection.get('hostName') || connection.get('remoteHostName');
appName = connection.get('remoteAppName') || '';
appInstance = connection.get('remoteAppInstance') || '';
// Don't add to the map not yet connected
if (connection.connecting || !connection.connected) {
return;
}
// Add the hostname to the map
var host = map[hostName];
if (!host) {
host = map[hostName] = {};
}
// Add the app to the map
var app = host[appName];
if (!app) {
app = host[appName] = {
instances: [appInstance],
probeClasses: connection.get('remoteProbeClasses')
};
} else {
app.instances.push(appInstance);
}
});
log.info('buildMap', map);
// Set the map if it's changed. This method is called whenever
// connections come and go - including firewalled connections which
// aren't visible in the map. Only update if the map has changed.
if (!_.isEqual(map, t.get('map'))) {
log.info('mapChanged');
t.set({
map: map,
updateSequence: t.updateSequence++
});
} else {
log.info('mapNotChanged');
}
} | [
"function",
"(",
")",
"{",
"var",
"t",
"=",
"this",
",",
"map",
"=",
"{",
"}",
",",
"router",
"=",
"Monitor",
".",
"getRouter",
"(",
")",
",",
"hostName",
"=",
"Monitor",
".",
"getRouter",
"(",
")",
".",
"getHostName",
"(",
")",
",",
"appName",
"=",
"Monitor",
".",
"Config",
".",
"Monitor",
".",
"appName",
",",
"appInstance",
"=",
"process",
".",
"env",
".",
"NODE_APP_INSTANCE",
";",
"map",
"[",
"hostName",
"]",
"=",
"{",
"}",
";",
"map",
"[",
"hostName",
"]",
"[",
"appName",
"]",
"=",
"{",
"instances",
":",
"[",
"appInstance",
"]",
",",
"probeClasses",
":",
"_",
".",
"keys",
"(",
"Probe",
".",
"classes",
")",
"}",
";",
"var",
"connections",
"=",
"router",
".",
"findConnections",
"(",
")",
";",
"connections",
".",
"forEach",
"(",
"function",
"(",
"connection",
")",
"{",
"hostName",
"=",
"connection",
".",
"get",
"(",
"'hostName'",
")",
"||",
"connection",
".",
"get",
"(",
"'remoteHostName'",
")",
";",
"appName",
"=",
"connection",
".",
"get",
"(",
"'remoteAppName'",
")",
"||",
"''",
";",
"appInstance",
"=",
"connection",
".",
"get",
"(",
"'remoteAppInstance'",
")",
"||",
"''",
";",
"if",
"(",
"connection",
".",
"connecting",
"||",
"!",
"connection",
".",
"connected",
")",
"{",
"return",
";",
"}",
"var",
"host",
"=",
"map",
"[",
"hostName",
"]",
";",
"if",
"(",
"!",
"host",
")",
"{",
"host",
"=",
"map",
"[",
"hostName",
"]",
"=",
"{",
"}",
";",
"}",
"var",
"app",
"=",
"host",
"[",
"appName",
"]",
";",
"if",
"(",
"!",
"app",
")",
"{",
"app",
"=",
"host",
"[",
"appName",
"]",
"=",
"{",
"instances",
":",
"[",
"appInstance",
"]",
",",
"probeClasses",
":",
"connection",
".",
"get",
"(",
"'remoteProbeClasses'",
")",
"}",
";",
"}",
"else",
"{",
"app",
".",
"instances",
".",
"push",
"(",
"appInstance",
")",
";",
"}",
"}",
")",
";",
"log",
".",
"info",
"(",
"'buildMap'",
",",
"map",
")",
";",
"if",
"(",
"!",
"_",
".",
"isEqual",
"(",
"map",
",",
"t",
".",
"get",
"(",
"'map'",
")",
")",
")",
"{",
"log",
".",
"info",
"(",
"'mapChanged'",
")",
";",
"t",
".",
"set",
"(",
"{",
"map",
":",
"map",
",",
"updateSequence",
":",
"t",
".",
"updateSequence",
"++",
"}",
")",
";",
"}",
"else",
"{",
"log",
".",
"info",
"(",
"'mapNotChanged'",
")",
";",
"}",
"}"
]
| This builds a new site map, and sets it into the map property if it is different from the current map. | [
"This",
"builds",
"a",
"new",
"site",
"map",
"and",
"sets",
"it",
"into",
"the",
"map",
"property",
"if",
"it",
"is",
"different",
"from",
"the",
"current",
"map",
"."
]
| a990e03d07096515744332ae0761441f8534369c | https://github.com/lorenwest/monitor-dashboard/blob/a990e03d07096515744332ae0761441f8534369c/lib/js/NetworkMap.js#L77-L135 | train |
|
flint-bot/flint | lib/flint.js | Flint | function Flint(options) {
EventEmitter.call(this);
this.id = options.id || u.genUUID64();
/**
* Options Object
*
* @memberof Flint
* @instance
* @namespace options
* @property {string} token - Spark Token.
* @property {string} webhookUrl - URL that is used for SPark API to send callbacks.
* @property {string} [webhookSecret] - If specified, inbound webhooks are authorized before being processed.
* @property {string} [messageFormat=text] - Default Spark message format to use with bot.say().
* @property {number} [maxPageItems=50] - Max results that the paginator uses.
* @property {number} [maxConcurrent=3] - Max concurrent sessions to the Spark API
* @property {number} [minTime=600] - Min time between consecutive request starts.
* @property {number} [requeueMinTime=minTime*10] - Min time between consecutive request starts of requests that have been re-queued.
* @property {number} [requeueMaxRetry=3] - Msx number of atteempts to make for failed request.
* @property {array} [requeueCodes=[429,500,503]] - Array of http result codes that should be retried.
* @property {number} [requestTimeout=20000] - Timeout for an individual request recieving a response.
* @property {number} [queueSize=10000] - Size of the buffer that holds outbound requests.
* @property {number} [requeueSize=10000] - Size of the buffer that holds outbound re-queue requests.
* @property {string} [id=random] - The id this instance of flint uses.
* @property {string} [webhookRequestJSONLocation=body] - The property under the Request to find the JSON contents.
* @property {Boolean} [removeWebhooksOnStart=true] - If you wish to have the bot remove all account webhooks when starting.
*/
this.options = options;
this.active = false;
this.initialized = false;
this.storageActive = false;
this.isBotAccount = false;
this.isUserAccount = false;
this.person = {};
this.email;
// define location in webhook request to find json values of incoming webhook.
// note: this is typically 'request.body' but depending on express/restify configuration, it may be 'request.params'
this.options.webhookRequestJSONLocation = this.options.webhookRequestJSONLocation || 'body';
// define if flint remove all webhooks attached to token on start (if not defined, defaults to true)
this.options.removeWebhooksOnStart = typeof this.options.removeWebhooksOnStart === 'boolean' ? this.options.removeWebhooksOnStart : true;
// define default messageFormat used with bot.say (if not defined, defaults to 'text')
if(typeof this.options.messageFormat === 'string' && _.includes(['text', 'markdown', 'html'], _.toLower(this.options.messageFormat))) {
this.messageFormat = _.toLower(this.options.messageFormat);
} else {
this.messageFormat = 'text';
}
this.batchDelay = options.minTime * 2;
this.auditInterval;
this.auditDelay = 300;
this.auditCounter = 0;
this.logs = [];
this.logMax = 1000;
this.lexicon = [];
this.bots = [];
this.spark = {};
this.webhook = {};
// register internal events
this.on('error', err => {
if(err) {
console.err(err.stack);
}
});
this.on('start', () => {
require('./logs')(this);
this.initialize();
});
} | javascript | function Flint(options) {
EventEmitter.call(this);
this.id = options.id || u.genUUID64();
/**
* Options Object
*
* @memberof Flint
* @instance
* @namespace options
* @property {string} token - Spark Token.
* @property {string} webhookUrl - URL that is used for SPark API to send callbacks.
* @property {string} [webhookSecret] - If specified, inbound webhooks are authorized before being processed.
* @property {string} [messageFormat=text] - Default Spark message format to use with bot.say().
* @property {number} [maxPageItems=50] - Max results that the paginator uses.
* @property {number} [maxConcurrent=3] - Max concurrent sessions to the Spark API
* @property {number} [minTime=600] - Min time between consecutive request starts.
* @property {number} [requeueMinTime=minTime*10] - Min time between consecutive request starts of requests that have been re-queued.
* @property {number} [requeueMaxRetry=3] - Msx number of atteempts to make for failed request.
* @property {array} [requeueCodes=[429,500,503]] - Array of http result codes that should be retried.
* @property {number} [requestTimeout=20000] - Timeout for an individual request recieving a response.
* @property {number} [queueSize=10000] - Size of the buffer that holds outbound requests.
* @property {number} [requeueSize=10000] - Size of the buffer that holds outbound re-queue requests.
* @property {string} [id=random] - The id this instance of flint uses.
* @property {string} [webhookRequestJSONLocation=body] - The property under the Request to find the JSON contents.
* @property {Boolean} [removeWebhooksOnStart=true] - If you wish to have the bot remove all account webhooks when starting.
*/
this.options = options;
this.active = false;
this.initialized = false;
this.storageActive = false;
this.isBotAccount = false;
this.isUserAccount = false;
this.person = {};
this.email;
// define location in webhook request to find json values of incoming webhook.
// note: this is typically 'request.body' but depending on express/restify configuration, it may be 'request.params'
this.options.webhookRequestJSONLocation = this.options.webhookRequestJSONLocation || 'body';
// define if flint remove all webhooks attached to token on start (if not defined, defaults to true)
this.options.removeWebhooksOnStart = typeof this.options.removeWebhooksOnStart === 'boolean' ? this.options.removeWebhooksOnStart : true;
// define default messageFormat used with bot.say (if not defined, defaults to 'text')
if(typeof this.options.messageFormat === 'string' && _.includes(['text', 'markdown', 'html'], _.toLower(this.options.messageFormat))) {
this.messageFormat = _.toLower(this.options.messageFormat);
} else {
this.messageFormat = 'text';
}
this.batchDelay = options.minTime * 2;
this.auditInterval;
this.auditDelay = 300;
this.auditCounter = 0;
this.logs = [];
this.logMax = 1000;
this.lexicon = [];
this.bots = [];
this.spark = {};
this.webhook = {};
// register internal events
this.on('error', err => {
if(err) {
console.err(err.stack);
}
});
this.on('start', () => {
require('./logs')(this);
this.initialize();
});
} | [
"function",
"Flint",
"(",
"options",
")",
"{",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"id",
"=",
"options",
".",
"id",
"||",
"u",
".",
"genUUID64",
"(",
")",
";",
"this",
".",
"options",
"=",
"options",
";",
"this",
".",
"active",
"=",
"false",
";",
"this",
".",
"initialized",
"=",
"false",
";",
"this",
".",
"storageActive",
"=",
"false",
";",
"this",
".",
"isBotAccount",
"=",
"false",
";",
"this",
".",
"isUserAccount",
"=",
"false",
";",
"this",
".",
"person",
"=",
"{",
"}",
";",
"this",
".",
"email",
";",
"this",
".",
"options",
".",
"webhookRequestJSONLocation",
"=",
"this",
".",
"options",
".",
"webhookRequestJSONLocation",
"||",
"'body'",
";",
"this",
".",
"options",
".",
"removeWebhooksOnStart",
"=",
"typeof",
"this",
".",
"options",
".",
"removeWebhooksOnStart",
"===",
"'boolean'",
"?",
"this",
".",
"options",
".",
"removeWebhooksOnStart",
":",
"true",
";",
"if",
"(",
"typeof",
"this",
".",
"options",
".",
"messageFormat",
"===",
"'string'",
"&&",
"_",
".",
"includes",
"(",
"[",
"'text'",
",",
"'markdown'",
",",
"'html'",
"]",
",",
"_",
".",
"toLower",
"(",
"this",
".",
"options",
".",
"messageFormat",
")",
")",
")",
"{",
"this",
".",
"messageFormat",
"=",
"_",
".",
"toLower",
"(",
"this",
".",
"options",
".",
"messageFormat",
")",
";",
"}",
"else",
"{",
"this",
".",
"messageFormat",
"=",
"'text'",
";",
"}",
"this",
".",
"batchDelay",
"=",
"options",
".",
"minTime",
"*",
"2",
";",
"this",
".",
"auditInterval",
";",
"this",
".",
"auditDelay",
"=",
"300",
";",
"this",
".",
"auditCounter",
"=",
"0",
";",
"this",
".",
"logs",
"=",
"[",
"]",
";",
"this",
".",
"logMax",
"=",
"1000",
";",
"this",
".",
"lexicon",
"=",
"[",
"]",
";",
"this",
".",
"bots",
"=",
"[",
"]",
";",
"this",
".",
"spark",
"=",
"{",
"}",
";",
"this",
".",
"webhook",
"=",
"{",
"}",
";",
"this",
".",
"on",
"(",
"'error'",
",",
"err",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"err",
"(",
"err",
".",
"stack",
")",
";",
"}",
"}",
")",
";",
"this",
".",
"on",
"(",
"'start'",
",",
"(",
")",
"=>",
"{",
"require",
"(",
"'./logs'",
")",
"(",
"this",
")",
";",
"this",
".",
"initialize",
"(",
")",
";",
"}",
")",
";",
"}"
]
| Creates an instance of Flint.
@constructor Flint
@param {Object} options - Configuration object containing Flint settings.
@property {string} id - Flint UUID
@property {boolean} active - Flint active state
@property {boolean} intialized - Flint fully initialized
@property {boolean} isBotAccount - Is Flint attached to Spark using a bot account?
@property {boolean} isUserAccount - Is Flint attached to Spark using a user account?
@property {object} person - Flint person object
@property {string} email - Flint email
@property {object} spark - The Spark instance used by flint
@example
var options = {
webhookUrl: 'http://myserver.com/flint',
token: 'Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u'
};
var flint = new Flint(options); | [
"Creates",
"an",
"instance",
"of",
"Flint",
"."
]
| 718923a17e794e28328aed1a2b24d75748b81fbc | https://github.com/flint-bot/flint/blob/718923a17e794e28328aed1a2b24d75748b81fbc/lib/flint.js#L40-L113 | train |
flint-bot/flint | lib/flint.js | runActions | function runActions(matched, bot, trigger, id) {
// process preference logic
if(matched.length > 1) {
matched = _.sortBy(matched, match => match.preference);
var prefLow = matched[0].preference;
var prefHigh = matched[matched.length - 1].preference;
if(prefLow !== prefHigh) {
matched = _.filter(matched, match => (match.preference === prefLow));
}
}
_.forEach(matched, lex => {
// for regex
if(lex.phrase instanceof RegExp && typeof lex.action === 'function') {
// define trigger.args, trigger.phrase
trigger.args = trigger.text.split(' ');
trigger.phrase = lex.phrase;
// run action
lex.action(bot, trigger, id);
return true;
}
// for string
else if (typeof lex.phrase === 'string' && typeof lex.action === 'function') {
// find index of match
var args = _.toLower(trigger.text).split(' ');
var indexOfMatch = args.indexOf(lex.phrase) !== -1 ? args.indexOf(lex.phrase) : 0;
// define trigger.args, trigger.phrase
trigger.args = trigger.text.split(' ');
trigger.args = trigger.args.slice(indexOfMatch, trigger.args.length);
trigger.phrase = lex.phrase;
// run action
lex.action(bot, trigger, id);
return true;
}
// for nothing...
else {
return false;
}
});
} | javascript | function runActions(matched, bot, trigger, id) {
// process preference logic
if(matched.length > 1) {
matched = _.sortBy(matched, match => match.preference);
var prefLow = matched[0].preference;
var prefHigh = matched[matched.length - 1].preference;
if(prefLow !== prefHigh) {
matched = _.filter(matched, match => (match.preference === prefLow));
}
}
_.forEach(matched, lex => {
// for regex
if(lex.phrase instanceof RegExp && typeof lex.action === 'function') {
// define trigger.args, trigger.phrase
trigger.args = trigger.text.split(' ');
trigger.phrase = lex.phrase;
// run action
lex.action(bot, trigger, id);
return true;
}
// for string
else if (typeof lex.phrase === 'string' && typeof lex.action === 'function') {
// find index of match
var args = _.toLower(trigger.text).split(' ');
var indexOfMatch = args.indexOf(lex.phrase) !== -1 ? args.indexOf(lex.phrase) : 0;
// define trigger.args, trigger.phrase
trigger.args = trigger.text.split(' ');
trigger.args = trigger.args.slice(indexOfMatch, trigger.args.length);
trigger.phrase = lex.phrase;
// run action
lex.action(bot, trigger, id);
return true;
}
// for nothing...
else {
return false;
}
});
} | [
"function",
"runActions",
"(",
"matched",
",",
"bot",
",",
"trigger",
",",
"id",
")",
"{",
"if",
"(",
"matched",
".",
"length",
">",
"1",
")",
"{",
"matched",
"=",
"_",
".",
"sortBy",
"(",
"matched",
",",
"match",
"=>",
"match",
".",
"preference",
")",
";",
"var",
"prefLow",
"=",
"matched",
"[",
"0",
"]",
".",
"preference",
";",
"var",
"prefHigh",
"=",
"matched",
"[",
"matched",
".",
"length",
"-",
"1",
"]",
".",
"preference",
";",
"if",
"(",
"prefLow",
"!==",
"prefHigh",
")",
"{",
"matched",
"=",
"_",
".",
"filter",
"(",
"matched",
",",
"match",
"=>",
"(",
"match",
".",
"preference",
"===",
"prefLow",
")",
")",
";",
"}",
"}",
"_",
".",
"forEach",
"(",
"matched",
",",
"lex",
"=>",
"{",
"if",
"(",
"lex",
".",
"phrase",
"instanceof",
"RegExp",
"&&",
"typeof",
"lex",
".",
"action",
"===",
"'function'",
")",
"{",
"trigger",
".",
"args",
"=",
"trigger",
".",
"text",
".",
"split",
"(",
"' '",
")",
";",
"trigger",
".",
"phrase",
"=",
"lex",
".",
"phrase",
";",
"lex",
".",
"action",
"(",
"bot",
",",
"trigger",
",",
"id",
")",
";",
"return",
"true",
";",
"}",
"else",
"if",
"(",
"typeof",
"lex",
".",
"phrase",
"===",
"'string'",
"&&",
"typeof",
"lex",
".",
"action",
"===",
"'function'",
")",
"{",
"var",
"args",
"=",
"_",
".",
"toLower",
"(",
"trigger",
".",
"text",
")",
".",
"split",
"(",
"' '",
")",
";",
"var",
"indexOfMatch",
"=",
"args",
".",
"indexOf",
"(",
"lex",
".",
"phrase",
")",
"!==",
"-",
"1",
"?",
"args",
".",
"indexOf",
"(",
"lex",
".",
"phrase",
")",
":",
"0",
";",
"trigger",
".",
"args",
"=",
"trigger",
".",
"text",
".",
"split",
"(",
"' '",
")",
";",
"trigger",
".",
"args",
"=",
"trigger",
".",
"args",
".",
"slice",
"(",
"indexOfMatch",
",",
"trigger",
".",
"args",
".",
"length",
")",
";",
"trigger",
".",
"phrase",
"=",
"lex",
".",
"phrase",
";",
"lex",
".",
"action",
"(",
"bot",
",",
"trigger",
",",
"id",
")",
";",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
")",
";",
"}"
]
| function to run the action | [
"function",
"to",
"run",
"the",
"action"
]
| 718923a17e794e28328aed1a2b24d75748b81fbc | https://github.com/flint-bot/flint/blob/718923a17e794e28328aed1a2b24d75748b81fbc/lib/flint.js#L1432-L1477 | train |
flint-bot/flint | lib/bot.js | markdownFormat | function markdownFormat(str) {
// if string...
if(str && typeof str === 'string') {
// process characters that do not render visibly in markdown
str = str.replace(/\<(?!@)/g, '<');
str = str.split('').reverse().join('').replace(/\>(?!.*@\<)/g, ';tg&').split('').reverse().join('');
return str;
}
// else return empty
else {
return '';
}
} | javascript | function markdownFormat(str) {
// if string...
if(str && typeof str === 'string') {
// process characters that do not render visibly in markdown
str = str.replace(/\<(?!@)/g, '<');
str = str.split('').reverse().join('').replace(/\>(?!.*@\<)/g, ';tg&').split('').reverse().join('');
return str;
}
// else return empty
else {
return '';
}
} | [
"function",
"markdownFormat",
"(",
"str",
")",
"{",
"if",
"(",
"str",
"&&",
"typeof",
"str",
"===",
"'string'",
")",
"{",
"str",
"=",
"str",
".",
"replace",
"(",
"/",
"\\<(?!@)",
"/",
"g",
",",
"'<'",
")",
";",
"str",
"=",
"str",
".",
"split",
"(",
"''",
")",
".",
"reverse",
"(",
")",
".",
"join",
"(",
"''",
")",
".",
"replace",
"(",
"/",
"\\>(?!.*@\\<)",
"/",
"g",
",",
"';tg&'",
")",
".",
"split",
"(",
"''",
")",
".",
"reverse",
"(",
")",
".",
"join",
"(",
"''",
")",
";",
"return",
"str",
";",
"}",
"else",
"{",
"return",
"''",
";",
"}",
"}"
]
| format makrdown type | [
"format",
"makrdown",
"type"
]
| 718923a17e794e28328aed1a2b24d75748b81fbc | https://github.com/flint-bot/flint/blob/718923a17e794e28328aed1a2b24d75748b81fbc/lib/bot.js#L17-L32 | train |
flint-bot/flint | lib/bot.js | Bot | function Bot(flint) {
EventEmitter.call(this);
this.id = u.genUUID64();
this.flint = flint;
this.options = flint.options;
this.debug = function(message) {
message = util.format.apply(null, Array.prototype.slice.call(arguments));
if(typeof flint.debugger === 'function') {
flint.debugger(message, this.id);
} else {
_debug(message);
}
};
//randomize distribution of when audit event should take place for this bot instance...
this.auditTrigger = Math.floor((Math.random() * this.flint.auditDelay)) + 1;
this.spark = this.flint.spark;
this.batchDelay = this.flint.batchDelay;
this.active = false;
this.room = {};
this.team = {};
this.person = this.flint.person;
this.membership = {};
this.memberships = [];
this.email = this.flint.email;
this.isLocked = false;
this.isModerator = false;
this.isGroup = false;
this.isDirect = false;
this.isTeam = false;
this.lastActivity = moment().utc().toDate();
this.on('error', err => {
if(err) {
this.debug(err.stack);
}
});
} | javascript | function Bot(flint) {
EventEmitter.call(this);
this.id = u.genUUID64();
this.flint = flint;
this.options = flint.options;
this.debug = function(message) {
message = util.format.apply(null, Array.prototype.slice.call(arguments));
if(typeof flint.debugger === 'function') {
flint.debugger(message, this.id);
} else {
_debug(message);
}
};
//randomize distribution of when audit event should take place for this bot instance...
this.auditTrigger = Math.floor((Math.random() * this.flint.auditDelay)) + 1;
this.spark = this.flint.spark;
this.batchDelay = this.flint.batchDelay;
this.active = false;
this.room = {};
this.team = {};
this.person = this.flint.person;
this.membership = {};
this.memberships = [];
this.email = this.flint.email;
this.isLocked = false;
this.isModerator = false;
this.isGroup = false;
this.isDirect = false;
this.isTeam = false;
this.lastActivity = moment().utc().toDate();
this.on('error', err => {
if(err) {
this.debug(err.stack);
}
});
} | [
"function",
"Bot",
"(",
"flint",
")",
"{",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"id",
"=",
"u",
".",
"genUUID64",
"(",
")",
";",
"this",
".",
"flint",
"=",
"flint",
";",
"this",
".",
"options",
"=",
"flint",
".",
"options",
";",
"this",
".",
"debug",
"=",
"function",
"(",
"message",
")",
"{",
"message",
"=",
"util",
".",
"format",
".",
"apply",
"(",
"null",
",",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
")",
";",
"if",
"(",
"typeof",
"flint",
".",
"debugger",
"===",
"'function'",
")",
"{",
"flint",
".",
"debugger",
"(",
"message",
",",
"this",
".",
"id",
")",
";",
"}",
"else",
"{",
"_debug",
"(",
"message",
")",
";",
"}",
"}",
";",
"this",
".",
"auditTrigger",
"=",
"Math",
".",
"floor",
"(",
"(",
"Math",
".",
"random",
"(",
")",
"*",
"this",
".",
"flint",
".",
"auditDelay",
")",
")",
"+",
"1",
";",
"this",
".",
"spark",
"=",
"this",
".",
"flint",
".",
"spark",
";",
"this",
".",
"batchDelay",
"=",
"this",
".",
"flint",
".",
"batchDelay",
";",
"this",
".",
"active",
"=",
"false",
";",
"this",
".",
"room",
"=",
"{",
"}",
";",
"this",
".",
"team",
"=",
"{",
"}",
";",
"this",
".",
"person",
"=",
"this",
".",
"flint",
".",
"person",
";",
"this",
".",
"membership",
"=",
"{",
"}",
";",
"this",
".",
"memberships",
"=",
"[",
"]",
";",
"this",
".",
"email",
"=",
"this",
".",
"flint",
".",
"email",
";",
"this",
".",
"isLocked",
"=",
"false",
";",
"this",
".",
"isModerator",
"=",
"false",
";",
"this",
".",
"isGroup",
"=",
"false",
";",
"this",
".",
"isDirect",
"=",
"false",
";",
"this",
".",
"isTeam",
"=",
"false",
";",
"this",
".",
"lastActivity",
"=",
"moment",
"(",
")",
".",
"utc",
"(",
")",
".",
"toDate",
"(",
")",
";",
"this",
".",
"on",
"(",
"'error'",
",",
"err",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"this",
".",
"debug",
"(",
"err",
".",
"stack",
")",
";",
"}",
"}",
")",
";",
"}"
]
| Creates a Bot instance that is then attached to a Spark Room.
@constructor
@param {Object} flint - The flint object this Bot spawns under.
@property {string} id - Bot UUID
@property {boolean} active - Bot active state
@property {object} person - Bot Person Object
@property {string} email - Bot email
@property {object} team - Bot team object
@property {object} room - Bot room object
@property {object} membership - Bot membership object
@property {boolean} isLocked - If bot is locked
@property {boolean} isModerator - If bot is a moderator
@property {boolean} isGroup - If bot is in Group Room
@property {boolean} isDirect - If bot is in 1:1/Direct Room
@property {string} isDirectTo - Recipient Email if bot is in 1:1/Direct Room
@property {boolean} isTeam - If bot is in Team Room
@property {date} lastActivity - Last bot activity | [
"Creates",
"a",
"Bot",
"instance",
"that",
"is",
"then",
"attached",
"to",
"a",
"Spark",
"Room",
"."
]
| 718923a17e794e28328aed1a2b24d75748b81fbc | https://github.com/flint-bot/flint/blob/718923a17e794e28328aed1a2b24d75748b81fbc/lib/bot.js#L59-L101 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.