_id stringlengths 2 6 | title stringlengths 0 58 | partition stringclasses 3 values | text stringlengths 52 373k | language stringclasses 1 value | meta_information dict |
|---|---|---|---|---|---|
q28700 | Toolbar | train | function Toolbar() {
var buttons = {};
/*jslint unparam: true*//* allow the unused param title until Toolbar rewrite*/
function add(id, text, title, fn) {
if (!buttons[id]) {
var button = renderer.text(
text,
0,
0
)
.css(options.toolbar.itemStyle)
.align({
align: 'right',
x: -marginRight - 20,
y: plotTop + 30
})
.on('click', fn)
/*.on('touchstart', function(e) {
e.stopPropagation(); // don't fire the container event
fn();
})*/
.attr({
align: 'right',
zIndex: 20
})
.add();
buttons[id] = button;
}
}
/*jslint unparam: false*/
function remove(id) {
discardElement(buttons[id].element);
buttons[id] = null;
}
// public
return {
add: add,
remove: remove
};
} | javascript | {
"resource": ""
} |
q28701 | defaultFormatter | train | function defaultFormatter() {
var pThis = this,
items = pThis.points || splat(pThis),
xAxis = items[0].series.xAxis,
x = pThis.x,
isDateTime = xAxis && xAxis.options.type === 'datetime',
useHeader = isString(x) || isDateTime,
s;
// build the header
s = useHeader ?
['<span style="font-size: 10px">' +
(isDateTime ? dateFormat('%A, %b %e, %Y', x) : x) +
'</span>'] : [];
// build the values
each(items, function (item) {
s.push(item.point.tooltipFormatter(useHeader));
});
return s.join('<br/>');
} | javascript | {
"resource": ""
} |
q28702 | onmousemove | train | function onmousemove(e) {
var point,
points,
hoverPoint = chart.hoverPoint,
hoverSeries = chart.hoverSeries,
i,
j,
distance = chartWidth,
index = inverted ? e.chartY : e.chartX - plotLeft; // wtf?
// shared tooltip
if (tooltip && options.shared) {
points = [];
// loop over all series and find the ones with points closest to the mouse
i = series.length;
for (j = 0; j < i; j++) {
if (series[j].visible && series[j].tooltipPoints.length) {
point = series[j].tooltipPoints[index];
point._dist = mathAbs(index - point.plotX);
distance = mathMin(distance, point._dist);
points.push(point);
}
}
// remove furthest points
i = points.length;
while (i--) {
if (points[i]._dist > distance) {
points.splice(i, 1);
}
}
// refresh the tooltip if necessary
if (points.length && (points[0].plotX !== hoverX)) {
tooltip.refresh(points);
hoverX = points[0].plotX;
}
}
// separate tooltip and general mouse events
if (hoverSeries && hoverSeries.tracker) { // only use for line-type series with common tracker
// get the point
point = hoverSeries.tooltipPoints[index];
// a new point is hovered, refresh the tooltip
if (point && point !== hoverPoint) {
// trigger the events
point.onMouseOver();
}
}
} | javascript | {
"resource": ""
} |
q28703 | drop | train | function drop() {
if (selectionMarker) {
var selectionData = {
xAxis: [],
yAxis: []
},
selectionBox = selectionMarker.getBBox(),
selectionLeft = selectionBox.x - plotLeft,
selectionTop = selectionBox.y - plotTop;
// a selection has been made
if (hasDragged) {
// record each axis' min and max
each(axes, function (axis) {
var translate = axis.translate,
isXAxis = axis.isXAxis,
isHorizontal = inverted ? !isXAxis : isXAxis,
selectionMin = translate(
isHorizontal ?
selectionLeft :
plotHeight - selectionTop - selectionBox.height,
true,
0,
0,
1
),
selectionMax = translate(
isHorizontal ?
selectionLeft + selectionBox.width :
plotHeight - selectionTop,
true,
0,
0,
1
);
selectionData[isXAxis ? 'xAxis' : 'yAxis'].push({
axis: axis,
min: mathMin(selectionMin, selectionMax), // for reversed axes,
max: mathMax(selectionMin, selectionMax)
});
});
fireEvent(chart, 'selection', selectionData, zoom);
}
selectionMarker = selectionMarker.destroy();
}
chart.mouseIsDown = mouseIsDown = hasDragged = false;
removeEvent(doc, hasTouch ? 'touchend' : 'mouseup', drop);
} | javascript | {
"resource": ""
} |
q28704 | hideTooltipOnMouseMove | train | function hideTooltipOnMouseMove(e) {
var pageX = defined(e.pageX) ? e.pageX : e.page.x, // In mootools the event is wrapped and the page x/y position is named e.page.x
pageY = defined(e.pageX) ? e.pageY : e.page.y; // Ref: http://mootools.net/docs/core/Types/DOMEvent
if (chartPosition &&
!isInsidePlot(pageX - chartPosition.left - plotLeft,
pageY - chartPosition.top - plotTop)) {
resetTracker();
}
} | javascript | {
"resource": ""
} |
q28705 | destroy | train | function destroy() {
// Destroy the tracker group element
if (chart.trackerGroup) {
chart.trackerGroup = trackerGroup = chart.trackerGroup.destroy();
}
removeEvent(doc, 'mousemove', hideTooltipOnMouseMove);
container.onclick = container.onmousedown = container.onmousemove = container.ontouchstart = container.ontouchend = container.ontouchmove = null;
} | javascript | {
"resource": ""
} |
q28706 | destroyItem | train | function destroyItem(item) {
var checkbox = item.checkbox;
// pull out from the array
//erase(allItems, item);
// destroy SVG elements
each(['legendItem', 'legendLine', 'legendSymbol'], function (key) {
if (item[key]) {
item[key].destroy();
}
});
if (checkbox) {
discardElement(item.checkbox);
}
} | javascript | {
"resource": ""
} |
q28707 | train | function () {
if (!this.hasImportedEvents) {
var point = this,
options = merge(point.series.options.point, point.options),
events = options.events,
eventType;
point.events = events;
for (eventType in events) {
addEvent(point, eventType, events[eventType]);
}
this.hasImportedEvents = true;
}
} | javascript | {
"resource": ""
} | |
q28708 | train | function () {
var series = this,
options = series.options,
xIncrement = series.xIncrement;
xIncrement = pick(xIncrement, options.pointStart, 0);
series.pointInterval = pick(series.pointInterval, options.pointInterval, 1);
series.xIncrement = xIncrement + series.pointInterval;
return xIncrement;
} | javascript | {
"resource": ""
} | |
q28709 | train | function () {
var series = this,
chart = series.chart,
data = series.data,
closestPoints,
smallestInterval,
chartSmallestInterval = chart.smallestInterval,
interval,
i;
// sort the data points
stableSort(data, function (a, b) {
return (a.x - b.x);
});
// remove points with equal x values
// record the closest distance for calculation of column widths
/*for (i = data.length - 1; i >= 0; i--) {
if (data[i - 1]) {
if (data[i - 1].x == data[i].x) {
data[i - 1].destroy();
data.splice(i - 1, 1); // remove the duplicate
}
}
}*/
// connect nulls
if (series.options.connectNulls) {
for (i = data.length - 1; i >= 0; i--) {
if (data[i].y === null && data[i - 1] && data[i + 1]) {
data.splice(i, 1);
}
}
}
// find the closes pair of points
for (i = data.length - 1; i >= 0; i--) {
if (data[i - 1]) {
interval = data[i].x - data[i - 1].x;
if (interval > 0 && (smallestInterval === UNDEFINED || interval < smallestInterval)) {
smallestInterval = interval;
closestPoints = i;
}
}
}
if (chartSmallestInterval === UNDEFINED || smallestInterval < chartSmallestInterval) {
chart.smallestInterval = smallestInterval;
}
series.closestPoints = closestPoints;
} | javascript | {
"resource": ""
} | |
q28710 | train | function () {
// trigger the event only if listeners exist
var series = this,
options = series.options,
chart = series.chart,
tooltip = chart.tooltip,
hoverPoint = chart.hoverPoint;
// trigger mouse out on the point, which must be in this series
if (hoverPoint) {
hoverPoint.onMouseOut();
}
// fire the mouse out event
if (series && options.events.mouseOut) {
fireEvent(series, 'mouseOut');
}
// hide the tooltip
if (tooltip && !options.stickyTracking) {
tooltip.hide();
}
// set normal state
series.setState();
chart.hoverSeries = null;
} | javascript | {
"resource": ""
} | |
q28711 | train | function (options, base1, base2, base3) {
var conversion = this.pointAttrToOptions,
attr,
option,
obj = {};
options = options || {};
base1 = base1 || {};
base2 = base2 || {};
base3 = base3 || {};
for (attr in conversion) {
option = conversion[attr];
obj[attr] = pick(options[option], base1[attr], base2[attr], base3[attr]);
}
return obj;
} | javascript | {
"resource": ""
} | |
q28712 | train | function (state) {
var series = this,
options = series.options,
graph = series.graph,
stateOptions = options.states,
lineWidth = options.lineWidth;
state = state || NORMAL_STATE;
if (series.state !== state) {
series.state = state;
if (stateOptions[state] && stateOptions[state].enabled === false) {
return;
}
if (state) {
lineWidth = stateOptions[state].lineWidth || lineWidth + 1;
}
if (graph && !graph.dashstyle) { // hover is turned off for dashed lines in VML
graph.attr({ // use attr because animate will cause any other animation on the graph to stop
'stroke-width': lineWidth
}, state ? 0 : 500);
}
}
} | javascript | {
"resource": ""
} | |
q28713 | train | function (selected) {
var series = this;
// if called without an argument, toggle
series.selected = selected = (selected === UNDEFINED) ? !series.selected : selected;
if (series.checkbox) {
series.checkbox.checked = selected;
}
fireEvent(series, selected ? 'select' : 'unselect');
} | javascript | {
"resource": ""
} | |
q28714 | train | function () {
var series = this,
chart = series.chart,
renderer = chart.renderer,
shapeArgs,
tracker,
trackerLabel = +new Date(),
options = series.options,
cursor = options.cursor,
css = cursor && { cursor: cursor },
rel;
each(series.data, function (point) {
tracker = point.tracker;
shapeArgs = point.trackerArgs || point.shapeArgs;
delete shapeArgs.strokeWidth;
if (point.y !== null) {
if (tracker) {// update
tracker.attr(shapeArgs);
} else {
point.tracker =
renderer[point.shapeType](shapeArgs)
.attr({
isTracker: trackerLabel,
fill: TRACKER_FILL,
visibility: series.visible ? VISIBLE : HIDDEN,
zIndex: options.zIndex || 1
})
.on(hasTouch ? 'touchstart' : 'mouseover', function (event) {
rel = event.relatedTarget || event.fromElement;
if (chart.hoverSeries !== series && attr(rel, 'isTracker') !== trackerLabel) {
series.onMouseOver();
}
point.onMouseOver();
})
.on('mouseout', function (event) {
if (!options.stickyTracking) {
rel = event.relatedTarget || event.toElement;
if (attr(rel, 'isTracker') !== trackerLabel) {
series.onMouseOut();
}
}
})
.css(css)
.add(point.group || chart.trackerGroup); // pies have point group - see issue #118
}
}
});
} | javascript | {
"resource": ""
} | |
q28715 | train | function () {
var series = this;
Series.prototype.translate.apply(series);
each(series.data, function (point) {
point.shapeType = 'circle';
point.shapeArgs = {
x: point.plotX,
y: point.plotY,
r: series.chart.options.tooltip.snap
};
});
} | javascript | {
"resource": ""
} | |
q28716 | train | function () {
var series = this;
// cache attributes for shapes
//series.getAttribs();
this.drawPoints();
// draw the mouse tracking area
if (series.options.enableMouseTracking !== false) {
series.drawTracker();
}
// PATCH by Simon Fishel
//
// execute beforeLabelRender hook to allow re-formatting of data labels
//
// + if(series.options.hooks && series.options.hooks.beforeLabelRender) {
// + series.options.hooks.beforeLabelRender(series)
// + }
if(series.options.hooks && series.options.hooks.beforeLabelRender) {
series.options.hooks.beforeLabelRender(series)
}
this.drawDataLabels();
if (series.options.animation && series.animate) {
series.animate();
}
series.isDirty = false; // means data is in accordance with what you see
} | javascript | {
"resource": ""
} | |
q28717 | Argument | train | function Argument(argumentConfig) {
if (!argumentConfig) {
argumentConfig = {};
}
this.name = utils.isUndefined(argumentConfig.name) ? "" : argumentConfig.name;
this.description = utils.isUndefined(argumentConfig.description) ? null : argumentConfig.description;
this.validation = utils.isUndefined(argumentConfig.validation) ? null : argumentConfig.validation;
this.dataType = utils.isUndefined(argumentConfig.dataType) ? Argument.dataTypeString : argumentConfig.dataType;
this.requiredOnEdit = utils.isUndefined(argumentConfig.requiredOnEdit) ? false : argumentConfig.requiredOnEdit;
this.requiredOnCreate = utils.isUndefined(argumentConfig.requiredOnCreate) ? false : argumentConfig.requiredOnCreate;
} | javascript | {
"resource": ""
} |
q28718 | Event | train | function Event(eventConfig) {
eventConfig = utils.isUndefined(eventConfig) ? {} : eventConfig;
this.data = utils.isUndefined(eventConfig.data) ? null : eventConfig.data;
this.done = utils.isUndefined(eventConfig.done) ? true : eventConfig.done;
this.host = utils.isUndefined(eventConfig.host) ? null : eventConfig.host;
this.index = utils.isUndefined(eventConfig.index) ? null : eventConfig.index;
this.source = utils.isUndefined(eventConfig.source) ? null : eventConfig.source;
this.sourcetype = utils.isUndefined(eventConfig.sourcetype) ? null : eventConfig.sourcetype;
this.stanza = utils.isUndefined(eventConfig.stanza) ? null : eventConfig.stanza;
this.unbroken = utils.isUndefined(eventConfig.unbroken) ? true : eventConfig.unbroken;
// eventConfig.time can be of type Date, Number, or String.
this.time = utils.isUndefined(eventConfig.time) ? null : eventConfig.time;
} | javascript | {
"resource": ""
} |
q28719 | train | function(results, job, done) {
// Print out the statics
console.log("Job Statistics: ");
console.log(" Event Count: " + job.properties().eventCount);
console.log(" Disk Usage: " + job.properties().diskUsage + " bytes");
console.log(" Priority: " + job.properties().priority);
// Find the index of the fields we want
var rawIndex = results.fields.indexOf("_raw");
var sourcetypeIndex = results.fields.indexOf("sourcetype");
var userIndex = results.fields.indexOf("user");
// Print out each result and the key-value pairs we want
console.log("Results: ");
for(var i = 0; i < results.rows.length; i++) {
console.log(" Result " + i + ": ");
console.log(" sourcetype: " + results.rows[i][sourcetypeIndex]);
console.log(" user: " + results.rows[i][userIndex]);
console.log(" _raw: " + results.rows[i][rawIndex]);
}
// Once we're done, cancel the job.
job.cancel(done);
} | javascript | {
"resource": ""
} | |
q28720 | train | function (path, callback) {
var mkdir = child_process.spawn('mkdir', ['-p', path]);
mkdir.on('error', function (err) {
callback(err);
callback = function(){};
});
mkdir.on('exit', function (code) {
if (code === 0) callback();
else callback(new Error('mkdir exited with code: ' + code));
});
} | javascript | {
"resource": ""
} | |
q28721 | train | function(http, params) {
if (!(http instanceof Http) && !params) {
// Move over the params
params = http;
http = null;
}
params = params || {};
this.scheme = params.scheme || "https";
this.host = params.host || "localhost";
this.port = params.port || 8089;
this.username = params.username || null;
this.password = params.password || null;
this.owner = params.owner;
this.app = params.app;
this.sessionKey = params.sessionKey || "";
this.authorization = params.authorization || "Splunk";
this.paths = params.paths || Paths;
this.version = params.version || "default";
this.timeout = params.timeout || 0;
this.autologin = true;
// Initialize autologin
// The reason we explicitly check to see if 'autologin'
// is actually set is because we need to distinguish the
// case of it being set to 'false', and it not being set.
// Unfortunately, in JavaScript, these are both false-y
if (params.hasOwnProperty("autologin")) {
this.autologin = params.autologin;
}
if (!http) {
// If there is no HTTP implementation set, we check what platform
// we're running on. If we're running in the browser, then complain,
// else, we instantiate NodeHttp.
if (typeof(window) !== 'undefined') {
throw new Error("Http instance required when creating a Context within a browser.");
}
else {
var NodeHttp = require('./platform/node/node_http').NodeHttp;
http = new NodeHttp();
}
}
// Store the HTTP implementation
this.http = http;
this.http._setSplunkVersion(this.version);
// Store our full prefix, which is just combining together
// the scheme with the host
var versionPrefix = utils.getWithVersion(this.version, prefixMap);
this.prefix = this.scheme + "://" + this.host + ":" + this.port + versionPrefix;
// We perform the bindings so that every function works
// properly when it is passed as a callback.
this._headers = utils.bind(this, this._headers);
this.fullpath = utils.bind(this, this.fullpath);
this.urlify = utils.bind(this, this.urlify);
this.get = utils.bind(this, this.get);
this.del = utils.bind(this, this.del);
this.post = utils.bind(this, this.post);
this.login = utils.bind(this, this.login);
this._shouldAutoLogin = utils.bind(this, this._shouldAutoLogin);
this._requestWrapper = utils.bind(this, this._requestWrapper);
} | javascript | {
"resource": ""
} | |
q28722 | train | function(path, namespace) {
namespace = namespace || {};
if (utils.startsWith(path, "/")) {
return path;
}
// If we don't have an app name (explicitly or implicitly), we default to /services/
if (!namespace.app && !this.app && namespace.sharing !== root.Sharing.SYSTEM) {
return "/services/" + path;
}
// Get the app and owner, first from the passed in namespace, then the service,
// finally defaulting to wild cards
var owner = namespace.owner || this.owner || "-";
var app = namespace.app || this.app || "-";
namespace.sharing = (namespace.sharing || "").toLowerCase();
// Modify the owner and app appropriately based on the sharing parameter
if (namespace.sharing === root.Sharing.APP || namespace.sharing === root.Sharing.GLOBAL) {
owner = "nobody";
}
else if (namespace.sharing === root.Sharing.SYSTEM) {
owner = "nobody";
app = "system";
}
return utils.trim("/servicesNS/" + encodeURIComponent(owner) + "/" + encodeURIComponent(app) + "/" + path);
} | javascript | {
"resource": ""
} | |
q28723 | train | function(callback) {
var that = this;
var url = this.paths.login;
var params = {
username: this.username,
password: this.password,
cookie : '1'
};
callback = callback || function() {};
var wrappedCallback = function(err, response) {
// Let's make sure that not only did the request succeed, but
// we actually got a non-empty session key back.
var hasSessionKey = !!(!err && response.data && response.data.sessionKey);
if (err || !hasSessionKey) {
callback(err || "No session key available", false);
}
else {
that.sessionKey = response.data.sessionKey;
callback(null, true);
}
};
return this.http.post(
this.urlify(url),
this._headers(),
params,
this.timeout,
wrappedCallback
);
} | javascript | {
"resource": ""
} | |
q28724 | train | function(path, params, callback) {
var that = this;
var request = function(callback) {
return that.http.del(
that.urlify(path),
that._headers(),
params,
that.timeout,
callback
);
};
return this._requestWrapper(request, callback);
} | javascript | {
"resource": ""
} | |
q28725 | train | function(path, method, query, post, body, headers, callback) {
var that = this;
var request = function(callback) {
return that.http.request(
that.urlify(path),
{
method: method,
headers: that._headers(headers),
query: query,
post: post,
body: body,
timeout: that.timeout
},
callback
);
};
return this._requestWrapper(request, callback);
} | javascript | {
"resource": ""
} | |
q28726 | train | function() {
this._super.apply(this, arguments);
// We perform the bindings so that every function works
// properly when it is passed as a callback.
this.specialize = utils.bind(this, this.specialize);
this.apps = utils.bind(this, this.apps);
this.configurations = utils.bind(this, this.configurations);
this.indexes = utils.bind(this, this.indexes);
this.savedSearches = utils.bind(this, this.savedSearches);
this.jobs = utils.bind(this, this.jobs);
this.users = utils.bind(this, this.users);
this.currentUser = utils.bind(this, this.currentUser);
this.views = utils.bind(this, this.views);
this.firedAlertGroups = utils.bind(this, this.firedAlertGroups);
this.dataModels = utils.bind(this, this.dataModels);
} | javascript | {
"resource": ""
} | |
q28727 | train | function(owner, app) {
return new Service(this.http, {
scheme: this.scheme,
host: this.host,
port: this.port,
username: this.username,
password: this.password,
owner: owner,
app: app,
sessionKey: this.sessionKey,
version: this.version
});
} | javascript | {
"resource": ""
} | |
q28728 | train | function(sid, namespace, callback) {
if (!callback && utils.isFunction(namespace)) {
callback = namespace;
namespace = null;
}
var job = new root.Job(this, sid, namespace);
return job.fetch({}, callback);
} | javascript | {
"resource": ""
} | |
q28729 | train | function(callback) {
callback = callback || function() {};
var that = this;
var req = this.get(Paths.currentUser, {}, function(err, response) {
if (err) {
callback(err);
}
else {
var username = response.data.entry[0].content.username;
var user = new root.User(that, username);
user.fetch(function() {
if (req.wasAborted) {
return; // aborted, so ignore
}
else {
callback.apply(null, arguments);
}
});
}
});
return req;
} | javascript | {
"resource": ""
} | |
q28730 | train | function(query, params, callback) {
if (!callback && utils.isFunction(params)) {
callback = params;
params = {};
}
callback = callback || function() {};
params = params || {};
params.q = query;
return this.get(Paths.parser, params, function(err, response) {
if (err) {
callback(err);
}
else {
callback(null, response.data);
}
});
} | javascript | {
"resource": ""
} | |
q28731 | train | function(prefix, count, callback) {
if (!callback && utils.isFunction(count)) {
callback = count;
count = 10;
}
callback = callback || function() {};
var params = {
count: count || 10,
prefix: prefix
};
return this.get(Paths.typeahead, params, function(err, response) {
if (err) {
callback(err);
}
else {
var results = (response.data || {}).results;
callback(null, results || []);
}
});
} | javascript | {
"resource": ""
} | |
q28732 | train | function(event, params, callback) {
if (!callback && utils.isFunction(params)) {
callback = params;
params = {};
}
callback = callback || function() {};
params = params || {};
// If the event is a JSON object, convert it to a string.
if (utils.isObject(event)) {
event = JSON.stringify(event);
}
var path = this.paths.submitEvent;
var method = "POST";
var headers = {"Content-Type": "text/plain"};
var body = event;
var get = params;
var post = {};
var req = this.request(
path,
method,
get,
post,
body,
headers,
function(err, response) {
if (err) {
callback(err);
}
else {
callback(null, response.data);
}
}
);
return req;
} | javascript | {
"resource": ""
} | |
q28733 | train | function(service, qualifiedPath) {
if (!service) {
throw new Error("Passed in a null Service.");
}
if (!qualifiedPath) {
throw new Error("Passed in an empty path.");
}
this.service = service;
this.qualifiedPath = qualifiedPath;
// We perform the bindings so that every function works
// properly when it is passed as a callback.
this.get = utils.bind(this, this.get);
this.post = utils.bind(this, this.post);
this.del = utils.bind(this, this.del);
} | javascript | {
"resource": ""
} | |
q28734 | train | function(relpath, params, callback) {
var url = this.qualifiedPath;
// If we have a relative path, we will append it with a preceding
// slash.
if (relpath) {
url = url + "/" + relpath;
}
return this.service.get(
url,
params,
callback
);
} | javascript | {
"resource": ""
} | |
q28735 | train | function(relpath, params, callback) {
var url = this.qualifiedPath;
// If we have a relative path, we will append it with a preceding
// slash.
if (relpath) {
url = url + "/" + relpath;
}
return this.service.post(
url,
params,
callback
);
} | javascript | {
"resource": ""
} | |
q28736 | train | function(relpath, params, callback) {
var url = this.qualifiedPath;
// If we have a relative path, we will append it with a preceding
// slash.
if (relpath) {
url = url + "/" + relpath;
}
return this.service.del(
url,
params,
callback
);
} | javascript | {
"resource": ""
} | |
q28737 | train | function(service, path, namespace) {
var fullpath = service.fullpath(path, namespace);
this._super(service, fullpath);
this.namespace = namespace;
this._properties = {};
this._state = {};
// We perform the bindings so that every function works
// properly when it is passed as a callback.
this._load = utils.bind(this, this._load);
this.fetch = utils.bind(this, this.fetch);
this.properties = utils.bind(this, this.properties);
this.state = utils.bind(this, this.state);
this.path = utils.bind(this, this.path);
} | javascript | {
"resource": ""
} | |
q28738 | train | function(service, path, namespace) {
this._super(service, path, namespace);
// We perform the bindings so that every function works
// properly when it is passed as a callback.
this._load = utils.bind(this, this._load);
this.fetch = utils.bind(this, this.fetch);
this.remove = utils.bind(this, this.remove);
this.update = utils.bind(this, this.update);
this.fields = utils.bind(this, this.fields);
this.links = utils.bind(this, this.links);
this.acl = utils.bind(this, this.acl);
this.author = utils.bind(this, this.author);
this.updated = utils.bind(this, this.updated);
this.published = utils.bind(this, this.published);
this.enable = utils.bind(this, this.enable);
this.disable = utils.bind(this, this.disable);
this.reload = utils.bind(this, this.reload);
// Initial values
this._properties = {};
this._fields = {};
this._acl = {};
this._links = {};
} | javascript | {
"resource": ""
} | |
q28739 | train | function(properties) {
properties = utils.isArray(properties) ? properties[0] : properties;
// Initialize the properties to
// empty values
properties = properties || {
content: {},
fields: {},
acl: {},
links: {}
};
this._super(properties);
// Take out the entity-specific content
this._properties = properties.content || {};
this._fields = properties.fields || this._fields || {};
this._acl = properties.acl || {};
this._links = properties.links || {};
this._author = properties.author || null;
this._updated = properties.updated || null;
this._published = properties.published || null;
} | javascript | {
"resource": ""
} | |
q28740 | train | function(options, callback) {
if (!callback && utils.isFunction(options)) {
callback = options;
options = {};
}
callback = callback || function() {};
options = options || {};
var that = this;
return this.get("", options, function(err, response) {
if (err) {
callback(err);
}
else {
that._load(response.data ? response.data.entry : null);
callback(null, that);
}
});
} | javascript | {
"resource": ""
} | |
q28741 | train | function(props, callback) {
callback = callback || function() {};
if (props.hasOwnProperty("name")) {
throw new Error("Cannot set 'name' field in 'update'");
}
var that = this;
var req = this.post("", props, function(err, response) {
if (!err && !that.fetchOnUpdate) {
that._load(response.data.entry);
callback(err, that);
}
else if (!err && that.fetchOnUpdate) {
that.fetch(function() {
if (req.wasAborted) {
return; // aborted, so ignore
}
else {
callback.apply(null, arguments);
}
});
}
else {
callback(err, that);
}
});
return req;
} | javascript | {
"resource": ""
} | |
q28742 | train | function(callback) {
callback = callback || function() {};
var that = this;
this.post("disable", {}, function(err, response) {
if (err) {
callback(err);
}
else {
callback(null, that);
}
});
} | javascript | {
"resource": ""
} | |
q28743 | train | function(service, path, namespace) {
this._super(service, path, namespace);
// We perform the bindings so that every function works
// properly when it is passed as a callback.
this._load = utils.bind(this, this._load);
this.fetch = utils.bind(this, this.fetch);
this.create = utils.bind(this, this.create);
this.list = utils.bind(this, this.list);
this.item = utils.bind(this, this.item);
this.instantiateEntity = utils.bind(this, this.instantiateEntity);
// Initial values
this._entities = [];
this._entitiesByName = {};
this._properties = {};
this._paging = {};
this._links = {};
} | javascript | {
"resource": ""
} | |
q28744 | train | function(options, callback) {
if (!callback && utils.isFunction(options)) {
callback = options;
options = {};
}
callback = callback || function() {};
options = options || {};
if (!options.count) {
options.count = 0;
}
var that = this;
var req = that.get("", options, function(err, response) {
if (err) {
callback(err);
}
else {
that._load(response.data);
callback(null, that);
}
});
return req;
} | javascript | {
"resource": ""
} | |
q28745 | train | function(id, namespace) {
if (utils.isEmpty(namespace)) {
namespace = null;
}
if (!id) {
throw new Error("Must suply a non-empty name.");
}
if (namespace && (namespace.app === '-' || namespace.owner === '-')) {
throw new Error("When searching for an entity, wildcards are not allowed in the namespace. Please refine your search.");
}
var fullPath = null;
if (this._entitiesByName.hasOwnProperty(id)) {
var entities = this._entitiesByName[id];
if (entities.length === 1 && !namespace) {
// If there is only one entity with the
// specified name and the user did not
// specify a namespace, then we just
// return it
return entities[0];
}
else if (entities.length === 1 && namespace) {
// If we specified a namespace, then we
// only return the entity if it matches
// the full path
fullPath = this.service.fullpath(entities[0].path(), namespace);
if (entities[0].qualifiedPath === fullPath) {
return entities[0];
}
else {
return null;
}
}
else if (entities.length > 1 && !namespace) {
// If there is more than one entity and we didn't
// specify a namespace, then we return an error
// saying the match is ambiguous
throw new Error("Ambiguous match for name '" + id + "'");
}
else {
// There is more than one entity, and we do have
// a namespace, so we try and find it
for(var i = 0; i < entities.length; i++) {
var entity = entities[i];
fullPath = this.service.fullpath(entities[i].path(), namespace);
if (entity.qualifiedPath === fullPath) {
return entity;
}
}
}
}
else {
return null;
}
} | javascript | {
"resource": ""
} | |
q28746 | train | function(params, callback) {
callback = callback || function() {};
var that = this;
var req = this.post("", params, function(err, response) {
if (err) {
callback(err);
}
else {
var props = response.data.entry;
if (utils.isArray(props)) {
props = props[0];
}
var entity = that.instantiateEntity(props);
entity._load(props);
if (that.fetchOnEntityCreation) {
entity.fetch(function() {
if (req.wasAborted) {
return; // aborted, so ignore
}
else {
callback.apply(null, arguments);
}
});
}
else {
callback(null, entity);
}
}
});
return req;
} | javascript | {
"resource": ""
} | |
q28747 | train | function(service, name, namespace) {
this.name = name;
this._super(service, this.path(), namespace);
this.acknowledge = utils.bind(this, this.acknowledge);
this.dispatch = utils.bind(this, this.dispatch);
this.history = utils.bind(this, this.history);
this.suppressInfo = utils.bind(this, this.suppressInfo);
} | javascript | {
"resource": ""
} | |
q28748 | train | function(options, callback) {
if (!callback && utils.isFunction(options)) {
callback = options;
options = {};
}
callback = callback || function() {};
options = options || {};
var that = this;
var req = this.post("dispatch", options, function(err, response) {
if (err) {
callback(err);
return;
}
var sid = response.data.sid;
var job = new root.Job(that.service, sid, that.namespace);
callback(null, job, that);
});
return req;
} | javascript | {
"resource": ""
} | |
q28749 | train | function(params, callback) {
params = params || {};
if (!params.search) {
var update = this._super;
var req = this.fetch(function(err, search) {
if (err) {
callback(err);
}
else {
params.search = search.properties().search;
update.call(search, params, function() {
if (req.wasAborted) {
return; // aborted, so ignore
}
else {
callback.apply(null, arguments);
}
});
}
});
return req;
}
else {
return this._super(params, callback);
}
} | javascript | {
"resource": ""
} | |
q28750 | train | function(props) {
var entityNamespace = utils.namespaceFromProperties(props);
return new root.SavedSearch(this.service, props.name, entityNamespace);
} | javascript | {
"resource": ""
} | |
q28751 | train | function(props) {
var entityNamespace = utils.namespaceFromProperties(props);
return new root.StoragePassword(this.service, props.name, entityNamespace);
} | javascript | {
"resource": ""
} | |
q28752 | train | function(service, name, namespace) {
this.name = name;
this._super(service, this.path(), namespace);
this.list = utils.bind(this, this.list);
} | javascript | {
"resource": ""
} | |
q28753 | train | function(props) {
var entityNamespace = utils.namespaceFromProperties(props);
return new root.FiredAlertGroup(this.service, props.name, entityNamespace);
} | javascript | {
"resource": ""
} | |
q28754 | train | function(service, namespace) {
this._super(service, this.path(), namespace);
this.instantiateEntity = utils.bind(this, this.instantiateEntity);
this.remove = utils.bind(this, this.remove);
} | javascript | {
"resource": ""
} | |
q28755 | train | function(service, name) {
this.name = name;
this._super(service, this.path(), {});
this.setupInfo = utils.bind(this, this.setupInfo);
this.updateInfo = utils.bind(this, this.updateInfo);
} | javascript | {
"resource": ""
} | |
q28756 | train | function(callback) {
callback = callback || function() {};
var that = this;
return this.get("setup", {}, function(err, response) {
if (err) {
callback(err);
}
else {
callback(null, response.data.entry.content, that);
}
});
} | javascript | {
"resource": ""
} | |
q28757 | train | function(props) {
var entityNamespace = utils.namespaceFromProperties(props);
return new root.View(this.service, props.name, entityNamespace);
} | javascript | {
"resource": ""
} | |
q28758 | train | function(service, name, namespace) {
this.name = name;
this._super(service, this.path(), namespace);
this.submitEvent = utils.bind(this, this.submitEvent);
} | javascript | {
"resource": ""
} | |
q28759 | train | function(event, params, callback) {
if (!callback && utils.isFunction(params)) {
callback = params;
params = {};
}
callback = callback || function() {};
params = params || {};
// Add the index name
params["index"] = this.name;
var that = this;
return this.service.log(event, params, function(err, result) {
callback(err, result, that);
});
} | javascript | {
"resource": ""
} | |
q28760 | train | function(props) {
var entityNamespace = utils.namespaceFromProperties(props);
return new root.Index(this.service, props.name, entityNamespace);
} | javascript | {
"resource": ""
} | |
q28761 | train | function(name, params, callback) {
// If someone called us with the default style of (params, callback),
// lets make it work
if (utils.isObject(name) && utils.isFunction(params) && !callback) {
callback = params;
params = name;
name = params.name;
}
params = params || {};
params["name"] = name;
return this._super(params, callback);
} | javascript | {
"resource": ""
} | |
q28762 | train | function(service, file, name, namespace) {
this.name = name;
this.file = file;
this._super(service, this.path(), namespace);
} | javascript | {
"resource": ""
} | |
q28763 | train | function(props) {
var entityNamespace = utils.namespaceFromProperties(props);
return new root.ConfigurationStanza(this.service, this.name, props.name, entityNamespace);
} | javascript | {
"resource": ""
} | |
q28764 | train | function(stanzaName, values, callback) {
// If someone called us with the default style of (params, callback),
// lets make it work
if (utils.isObject(stanzaName) && utils.isFunction(values) && !callback) {
callback = values;
values = stanzaName;
stanzaName = values.name;
}
if (utils.isFunction(values) && !callback) {
callback = values;
values = {};
}
values = values || {};
values["name"] = stanzaName;
return this._super(values, callback);
} | javascript | {
"resource": ""
} | |
q28765 | train | function(service, namespace) {
if (!namespace || namespace.owner === "-" || namespace.app === "-") {
throw new Error("Configurations requires a non-wildcard owner/app");
}
this._super(service, this.path(), namespace);
} | javascript | {
"resource": ""
} | |
q28766 | train | function(filename, callback) {
// If someone called us with the default style of (params, callback),
// lets make it work
if (utils.isObject(filename)) {
filename = filename["__conf"];
}
callback = callback || function() {};
var that = this;
var req = this.post("", {__conf: filename}, function(err, response) {
if (err) {
callback(err);
}
else {
var entity = new root.ConfigurationFile(that.service, filename);
entity.fetch(function() {
if (req.wasAborted) {
return; // aborted, so ignore
}
else {
callback.apply(null, arguments);
}
});
}
});
return req;
} | javascript | {
"resource": ""
} | |
q28767 | train | function(service, sid, namespace) {
this.name = sid;
this._super(service, this.path(), namespace);
this.sid = sid;
// We perform the bindings so that every function works
// properly when it is passed as a callback.
this.cancel = utils.bind(this, this.cancel);
this.disablePreview = utils.bind(this, this.disablePreview);
this.enablePreview = utils.bind(this, this.enablePreview);
this.events = utils.bind(this, this.events);
this.finalize = utils.bind(this, this.finalize);
this.pause = utils.bind(this, this.pause);
this.preview = utils.bind(this, this.preview);
this.results = utils.bind(this, this.results);
this.searchlog = utils.bind(this, this.searchlog);
this.setPriority = utils.bind(this, this.setPriority);
this.setTTL = utils.bind(this, this.setTTL);
this.summary = utils.bind(this, this.summary);
this.timeline = utils.bind(this, this.timeline);
this.touch = utils.bind(this, this.touch);
this.unpause = utils.bind(this, this.unpause);
} | javascript | {
"resource": ""
} | |
q28768 | train | function(callback) {
callback = callback || function() {};
var that = this;
var req = this.post("control", {action: "enablepreview"}, function(err) {
callback(err, that);
});
return req;
} | javascript | {
"resource": ""
} | |
q28769 | train | function(params, callback) {
callback = callback || function() {};
params = params || {};
params.output_mode = params.output_mode || "json_rows";
var that = this;
return this.get("events", params, function(err, response) {
if (err) {
callback(err);
}
else {
callback(null, response.data, that);
}
});
} | javascript | {
"resource": ""
} | |
q28770 | train | function(value, callback) {
callback = callback || function() {};
var that = this;
var req = this.post("control", {action: "setpriority", priority: value}, function(err) {
callback(err, that);
});
return req;
} | javascript | {
"resource": ""
} | |
q28771 | train | function(options, callbacks) {
var period = options.period || 500; // ms
if (utils.isFunction(callbacks)) {
callbacks = {
done: callbacks
};
}
var noCallbacksAfterReady = (
!callbacks.progress &&
!callbacks.done &&
!callbacks.failed &&
!callbacks.error
);
callbacks.ready = callbacks.ready || function() {};
callbacks.progress = callbacks.progress || function() {};
callbacks.done = callbacks.done || function() {};
callbacks.failed = callbacks.failed || function() {};
callbacks.error = callbacks.error || function() {};
// For use by tests only
callbacks._preready = callbacks._preready || function() {};
callbacks._stoppedAfterReady = callbacks._stoppedAfterReady || function() {};
var that = this;
var emittedReady = false;
var doneLooping = false;
Async.whilst(
function() { return !doneLooping; },
function(nextIteration) {
that.fetch(function(err, job) {
if (err) {
nextIteration(err);
return;
}
var dispatchState = job.properties().dispatchState;
var notReady = dispatchState === "QUEUED" || dispatchState === "PARSING";
if (notReady) {
callbacks._preready(job);
}
else {
if (!emittedReady) {
callbacks.ready(job);
emittedReady = true;
// Optimization: Don't keep polling the job if the
// caller only cares about the `ready` event.
if (noCallbacksAfterReady) {
callbacks._stoppedAfterReady(job);
doneLooping = true;
nextIteration();
return;
}
}
callbacks.progress(job);
var props = job.properties();
if (dispatchState === "DONE" && props.isDone) {
callbacks.done(job);
doneLooping = true;
nextIteration();
return;
}
else if (dispatchState === "FAILED" && props.isFailed) {
callbacks.failed(job);
doneLooping = true;
nextIteration();
return;
}
}
Async.sleep(period, nextIteration);
});
},
function(err) {
if (err) {
callbacks.error(err);
}
}
);
} | javascript | {
"resource": ""
} | |
q28772 | train | function(props) {
var sid = props.content.sid;
var entityNamespace = utils.namespaceFromProperties(props);
return new root.Job(this.service, sid, entityNamespace);
} | javascript | {
"resource": ""
} | |
q28773 | train | function(query, params, callback) {
// If someone called us with the default style of (params, callback),
// lets make it work
if (utils.isObject(query) && utils.isFunction(params) && !callback) {
callback = params;
params = query;
query = params.search;
}
callback = callback || function() {};
params = params || {};
params.search = query;
params.exec_mode = "oneshot";
if (!params.search) {
callback("Must provide a query to create a search job");
}
var outputMode = params.output_mode || "json_rows";
var path = this.qualifiedPath;
var method = "POST";
var headers = {};
var post = params;
var get = {output_mode: outputMode};
var body = null;
var req = this.service.request(
path,
method,
get,
post,
body,
headers,
function(err, response) {
if (err) {
callback(err);
}
else {
callback(null, response.data);
}
}
);
return req;
} | javascript | {
"resource": ""
} | |
q28774 | train | function(props) {
props = props || {};
props.owner = props.owner || "";
this.name = props.fieldName;
this.displayName = props.displayName;
this.type = props.type;
this.multivalued = props.multivalue;
this.required = props.required;
this.hidden = props.hidden;
this.editable = props.editable;
this.comment = props.comment || null;
this.fieldSearch = props.fieldSearch;
this.lineage = props.owner.split(".");
this.owner = this.lineage[this.lineage.length - 1];
} | javascript | {
"resource": ""
} | |
q28775 | train | function(props) {
props = props || {};
props.owner = props.owner || "";
this.query = props.search;
this.lineage = props.owner.split(".");
this.owner = this.lineage[this.lineage.length - 1];
} | javascript | {
"resource": ""
} | |
q28776 | train | function(props) {
props = props || {};
props.owner = props.owner || "";
this.id = props.calculationID;
this.type = props.calculationType;
this.comment = props.comment || null;
this.editable = props.editable;
this.lineage = props.owner.split(".");
this.owner = this.lineage[this.lineage.length - 1];
this.outputFields = [];
for (var i = 0; i < props.outputFields.length; i++) {
this.outputFields[props.outputFields[i].fieldName] = new root.DataModelField(props.outputFields[i]);
}
if ("Eval" === this.type || "Rex" === this.type) {
this.expression = props.expression;
}
if ("GeoIP" === this.type || "Rex" === this.type) {
this.inputField = props.inputField;
}
if ("Lookup" === this.type) {
this.lookupName = props.lookupName;
this.inputFieldMappings = props.lookupInputs[0];
}
} | javascript | {
"resource": ""
} | |
q28777 | train | function(service, props) {
this.service = service;
this.search = props.search;
this.drilldownSearch = props.drilldown_search;
this.prettyQuery = this.openInSearch = props.open_in_search;
this.pivotSearch = props.pivot_search;
this.tstatsSearch = props.tstats_search || null;
this.run = utils.bind(this, this.run);
} | javascript | {
"resource": ""
} | |
q28778 | train | function(args, callback) {
if (utils.isUndefined(callback)) {
callback = args;
args = {};
}
if (!args || Object.keys(args).length === 0) {
args = {};
}
// If tstats is undefined, use pivotSearch (try to run an accelerated search if possible)
this.service.search(this.tstatsSearch || this.pivotSearch, args, callback);
} | javascript | {
"resource": ""
} | |
q28779 | train | function(dataModelObject) {
this.dataModelObject = dataModelObject;
this.columns = [];
this.rows = [];
this.filters = [];
this.cells = [];
this.accelerationNamespace = dataModelObject.dataModel.isAccelerated() ?
dataModelObject.dataModel.name : null;
this.run = utils.bind(this, this.run);
this.pivot = utils.bind(this, this.pivot);
} | javascript | {
"resource": ""
} | |
q28780 | train | function(sid) {
// If a search object is passed in, get its sid
if (sid && sid instanceof Service.Job) {
sid = sid.sid;
}
if (!sid) {
throw new Error("Sid to use for acceleration must not be null.");
}
this.accelerationNamespace = "sid=" + sid;
return this;
} | javascript | {
"resource": ""
} | |
q28781 | train | function(fieldName, sortAttribute, sortDirection, limit, statsFunction) {
if (!this.dataModelObject.hasField(fieldName)) {
throw new Error("Cannot add limit filter on a nonexistent field.");
}
var f = this.dataModelObject.fieldByName(fieldName);
if (!utils.contains(["string", "number", "objectCount"], f.type)) {
throw new Error("Cannot add limit filter on " + fieldName + " because it is of type " + f.type);
}
if ("string" === f.type && !utils.contains(["count", "dc"], statsFunction)) {
throw new Error("Stats function for fields of type string must be COUNT or DISTINCT_COUNT; found " +
statsFunction);
}
if ("number" === f.type && !utils.contains(["count", "dc", "average", "sum"], statsFunction)) {
throw new Error("Stats function for fields of type number must be one of COUNT, DISTINCT_COUNT, SUM, or AVERAGE; found " +
statsFunction);
}
if ("objectCount" === f.type && !utils.contains(["count"], statsFunction)) {
throw new Error("Stats function for fields of type object count must be COUNT; found " + statsFunction);
}
var filter = {
fieldName: fieldName,
owner: f.lineage.join("."),
type: f.type,
attributeName: sortAttribute,
attributeOwner: this.dataModelObject.fieldByName(sortAttribute).lineage.join("."),
sortDirection: sortDirection,
limitAmount: limit,
statsFn: statsFunction
};
// Assumed "highest" is preferred for when sortDirection is "DEFAULT"
filter.limitType = "ASCENDING" === sortDirection ? "lowest" : "highest";
this.filters.push(filter);
return this;
} | javascript | {
"resource": ""
} | |
q28782 | train | function(fieldName, label) {
if (!this.dataModelObject.hasField(fieldName)) {
throw new Error("Did not find field " + fieldName);
}
var f = this.dataModelObject.fieldByName(fieldName);
if (!utils.contains(["number", "string"], f.type)) {
throw new Error("Field was of type " + f.type + ", expected number or string.");
}
var row = {
fieldName: fieldName,
owner: f.owner,
type: f.type,
label: label
};
if ("number" === f.type) {
row.display = "all";
}
this.rows.push(row);
return this;
} | javascript | {
"resource": ""
} | |
q28783 | train | function(field, label, ranges) {
if (!this.dataModelObject.hasField(field)) {
throw new Error("Did not find field " + field);
}
var f = this.dataModelObject.fieldByName(field);
if ("number" !== f.type) {
throw new Error("Field was of type " + f.type + ", expected number.");
}
var updateRanges = {};
if (!utils.isUndefined(ranges.start) && ranges.start !== null) {
updateRanges.start = ranges.start;
}
if (!utils.isUndefined(ranges.end) && ranges.end !== null) {
updateRanges.end = ranges.end;
}
if (!utils.isUndefined(ranges.step) && ranges.step !== null) {
updateRanges.size = ranges.step;
}
if (!utils.isUndefined(ranges.limit) && ranges.limit !== null) {
updateRanges.maxNumberOf = ranges.limit;
}
this.rows.push({
fieldName: field,
owner: f.owner,
type: f.type,
label: label,
display: "ranges",
ranges: updateRanges
});
return this;
} | javascript | {
"resource": ""
} | |
q28784 | train | function(field, label, trueDisplayValue, falseDisplayValue) {
if (!this.dataModelObject.fieldByName(field)) {
throw new Error("Did not find field " + field);
}
var f = this.dataModelObject.fieldByName(field);
if ("boolean" !== f.type) {
throw new Error("Field was of type " + f.type + ", expected boolean.");
}
this.rows.push({
fieldName: field,
owner: f.owner,
type: f.type,
label: label,
trueLabel: trueDisplayValue,
falseLabel: falseDisplayValue
});
return this;
} | javascript | {
"resource": ""
} | |
q28785 | train | function(fieldName) {
if (!this.dataModelObject.hasField(fieldName)) {
throw new Error("Did not find field " + fieldName);
}
var f = this.dataModelObject.fieldByName(fieldName);
if (!utils.contains(["number", "string"], f.type)) {
throw new Error("Field was of type " + f.type + ", expected number or string.");
}
var col = {
fieldName: fieldName,
owner: f.owner,
type: f.type
};
if ("number" === f.type) {
col.display = "all";
}
this.columns.push(col);
return this;
} | javascript | {
"resource": ""
} | |
q28786 | train | function(fieldName, ranges) {
if (!this.dataModelObject.hasField(fieldName)) {
throw new Error("Did not find field " + fieldName);
}
var f = this.dataModelObject.fieldByName(fieldName);
if ("number" !== f.type) {
throw new Error("Field was of type " + f.type + ", expected number.");
}
// In Splunk 6.0.1.1, data models incorrectly expect strings for these fields
// instead of numbers. In 6.1, this is fixed and both are accepted.
var updatedRanges = {};
if (!utils.isUndefined(ranges.start) && ranges.start !== null) {
updatedRanges.start = ranges.start;
}
if (!utils.isUndefined(ranges.end) && ranges.end !== null) {
updatedRanges.end = ranges.end;
}
if (!utils.isUndefined(ranges.step) && ranges.step !== null) {
updatedRanges.size = ranges.step;
}
if (!utils.isUndefined(ranges.limit) && ranges.limit !== null) {
updatedRanges.maxNumberOf = ranges.limit;
}
this.columns.push({
fieldName: fieldName,
owner: f.owner,
type: f.type,
display: "ranges",
ranges: updatedRanges
});
return this;
} | javascript | {
"resource": ""
} | |
q28787 | train | function(fieldName, trueDisplayValue, falseDisplayValue) {
if (!this.dataModelObject.fieldByName(fieldName)) {
throw new Error("Did not find field " + fieldName);
}
var f = this.dataModelObject.fieldByName(fieldName);
if ("boolean" !== f.type) {
throw new Error("Field was of type " + f.type + ", expected boolean.");
}
this.columns.push({
fieldName: fieldName,
owner: f.owner,
type: f.type,
trueLabel: trueDisplayValue,
falseLabel: falseDisplayValue
});
return this;
} | javascript | {
"resource": ""
} | |
q28788 | train | function(field, binning) {
if (!this.dataModelObject.hasField(field)) {
throw new Error("Did not find field " + field);
}
var f = this.dataModelObject.fieldByName(field);
if ("timestamp" !== f.type) {
throw new Error("Field was of type " + f.type + ", expected timestamp.");
}
if (!utils.contains(this._binning, binning)) {
throw new Error("Invalid binning " + binning + " found. Valid values are: " + this._binning.join(", "));
}
this.columns.push({
fieldName: field,
owner: f.owner,
type: f.type,
period: binning
});
return this;
} | javascript | {
"resource": ""
} | |
q28789 | train | function(fieldName, label, statsFunction) {
if (!this.dataModelObject.hasField(fieldName)) {
throw new Error("Did not find field " + fieldName);
}
var f = this.dataModelObject.fieldByName(fieldName);
if (utils.contains(["string", "ipv4"], f.type) &&
!utils.contains([
"list",
"values",
"first",
"last",
"count",
"dc"], statsFunction)
) {
throw new Error("Stats function on string and IPv4 fields must be one of:" +
" list, distinct_values, first, last, count, or distinct_count; found " +
statsFunction);
}
else if ("number" === f.type &&
!utils.contains([
"sum",
"count",
"average",
"min",
"max",
"stdev",
"list",
"values"
], statsFunction)
) {
throw new Error("Stats function on number field must be must be one of:" +
" sum, count, average, max, min, stdev, list, or distinct_values; found " +
statsFunction
);
}
else if ("timestamp" === f.type &&
!utils.contains([
"duration",
"earliest",
"latest",
"list",
"values"
], statsFunction)
) {
throw new Error("Stats function on timestamp field must be one of:" +
" duration, earliest, latest, list, or distinct values; found " +
statsFunction
);
}
else if (utils.contains(["objectCount", "childCount"], f.type) &&
"count" !== statsFunction
) {
throw new Error("Stats function on childcount and objectcount fields must be count; " +
"found " + statsFunction);
}
else if ("boolean" === f.type) {
throw new Error("Cannot use boolean valued fields as cell values.");
}
this.cells.push({
fieldName: fieldName,
owner: f.lineage.join("."),
type: f.type,
label: label,
sparkline: false, // Not properly implemented in core yet.
value: statsFunction
});
return this;
} | javascript | {
"resource": ""
} | |
q28790 | train | function() {
return {
dataModel: this.dataModelObject.dataModel.name,
baseClass: this.dataModelObject.name,
rows: this.rows,
columns: this.columns,
cells: this.cells,
filters: this.filters
};
} | javascript | {
"resource": ""
} | |
q28791 | train | function(callback) {
var svc = this.dataModelObject.dataModel.service;
var args = {
pivot_json: JSON.stringify(this.toJsonObject())
};
if (!utils.isUndefined(this.accelerationNamespace)) {
args.namespace = this.accelerationNamespace;
}
return svc.get(Paths.pivot + "/" + encodeURIComponent(this.dataModelObject.dataModel.name), args, function(err, response) {
if (err) {
callback(new Error(err.data.messages[0].text), response);
return;
}
if (response.data.entry && response.data.entry[0]) {
callback(null, new root.Pivot(svc, response.data.entry[0].content));
}
else {
callback(new Error("Didn't get a Pivot report back from Splunk"), response);
}
});
} | javascript | {
"resource": ""
} | |
q28792 | train | function(props, parentDataModel) {
props = props || {};
props.owner = props.owner || "";
this.dataModel = parentDataModel;
this.name = props.objectName;
this.displayName = props.displayName;
this.parentName = props.parentName;
this.lineage = props.lineage.split(".");
// Properties exclusive to BaseTransaction
if (props.hasOwnProperty("groupByFields")) {
this.groupByFields = props.groupByFields;
}
if (props.hasOwnProperty("objectsToGroup")) {
this.objectsToGroup = props.objectsToGroup;
}
if (props.hasOwnProperty("transactionMaxTimeSpan")) {
this.maxSpan = props.transactionMaxTimeSpan;
}
if (props.hasOwnProperty("transactionMaxPause")) {
this.maxPause = props.transactionMaxPause;
}
// Property exclusive to BaseSearch
if (props.hasOwnProperty("baseSearch")) {
this.baseSearch = props.baseSearch;
}
// Parse fields
this.fields = {};
for (var i = 0; i < props.fields.length; i++) {
this.fields[props.fields[i].fieldName] = new root.DataModelField(props.fields[i]);
}
// Parse constraints
this.constraints = [];
for (var j = 0; j < props.constraints.length; j++) {
this.constraints.push(new root.DataModelConstraint(props.constraints[j]));
}
// Parse calculations
this.calculations = [];
for (var k = 0; k < props.calculations.length; k++) {
this.calculations[props.calculations[k].calculationID] = new root.DataModelCalculation(props.calculations[k]);
}
} | javascript | {
"resource": ""
} | |
q28793 | train | function() {
// merge fields and calculatedFields()
var combinedFields = [];
for (var f in this.fields) {
if (this.fields.hasOwnProperty(f)) {
combinedFields[f] = this.fields[f];
}
}
var calculatedFields = this.calculatedFields();
for (var cf in calculatedFields) {
if (calculatedFields.hasOwnProperty(cf)) {
combinedFields[cf] = calculatedFields[cf];
}
}
return combinedFields;
} | javascript | {
"resource": ""
} | |
q28794 | train | function(){
var fields = {};
// Iterate over the calculations, get their fields
var keys = this.calculationIDs();
var calculations = this.calculations;
for (var i = 0; i < keys.length; i++) {
var calculation = calculations[keys[i]];
for (var f = 0; f < calculation.outputFieldNames().length; f++) {
fields[calculation.outputFieldNames()[f]] = calculation.outputFields[calculation.outputFieldNames()[f]];
}
}
return fields;
} | javascript | {
"resource": ""
} | |
q28795 | train | function(earliestTime, callback) {
// If earliestTime parameter is not specified, then set callback to its value
if (!callback && utils.isFunction(earliestTime)) {
callback = earliestTime;
earliestTime = undefined;
}
var query = "| datamodel \"" + this.dataModel.name + "\" " + this.name + " search | tscollect";
var args = earliestTime ? {earliest_time: earliestTime} : {};
this.dataModel.service.search(query, args, callback);
} | javascript | {
"resource": ""
} | |
q28796 | train | function(params, querySuffix, callback) {
var query = "| datamodel " + this.dataModel.name + " " + this.name + " search";
// Prepend a space to the querySuffix, or set it to an empty string if null or undefined
querySuffix = (querySuffix) ? (" " + querySuffix) : ("");
this.dataModel.service.search(query + querySuffix, params, callback);
} | javascript | {
"resource": ""
} | |
q28797 | train | function(name) {
for (var i = 0; i < this.objects.length; i++) {
if (this.objects[i].name === name) {
return this.objects[i];
}
}
return null;
} | javascript | {
"resource": ""
} | |
q28798 | train | function(props, callback) {
if (utils.isUndefined(callback)) {
callback = props;
props = {};
}
callback = callback || function() {};
if (!props) {
callback(new Error("Must specify a props argument to update a data model."));
return; // Exit if props isn't set, to avoid calling the callback twice.
}
if (props.hasOwnProperty("name")) {
callback(new Error("Cannot set 'name' field in 'update'"), this);
return; // Exit if the name is set, to avoid calling the callback twice.
}
var updatedProps = {
acceleration: JSON.stringify({
enabled: props.accceleration && props.acceleration.enabled || this.acceleration.enabled,
earliest_time: props.accceleration && props.acceleration.earliestTime || this.acceleration.earliestTime,
cron_schedule: props.accceleration && props.acceleration.cronSchedule || this.acceleration.cronSchedule
})
};
var that = this;
return this.post("", updatedProps, function(err, response) {
if (err) {
callback(err, that);
}
else {
var dataModelNamespace = utils.namespaceFromProperties(response.data.entry[0]);
callback(null, new root.DataModel(that.service, response.data.entry[0].name, dataModelNamespace, response.data.entry[0]));
}
});
} | javascript | {
"resource": ""
} | |
q28799 | train | function(service, namespace) {
namespace = namespace || {};
this._super(service, this.path(), namespace);
this.create = utils.bind(this, this.create);
} | javascript | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.