Client library should now cover all APIs
TODO: Testing & Debugging
This commit is contained in:
parent
5f8c3d967c
commit
1678951d84
17 changed files with 867 additions and 176 deletions
22
src/octoprint/static/js/app/client/browser.js
Normal file
22
src/octoprint/static/js/app/client/browser.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
OctoPrint.browser = (function($, _) {
|
||||
var exports = {};
|
||||
|
||||
exports.login = function(username, password, remember, opts) {
|
||||
var data = {
|
||||
user: username,
|
||||
pass: password,
|
||||
remember: !!remember
|
||||
};
|
||||
return OctoPrint.postJson("api/login", data, opts);
|
||||
};
|
||||
|
||||
exports.passiveLogin = function(opts) {
|
||||
return OctoPrint.postJson("api/login", {passive: true}, opts);
|
||||
};
|
||||
|
||||
exports.logout = function(opts) {
|
||||
return OctoPrint.postJson("api/logout", {}, opts);
|
||||
};
|
||||
|
||||
return exports;
|
||||
})($, _);
|
||||
|
|
@ -1,41 +1,25 @@
|
|||
OctoPrint.connection = (function() {
|
||||
var self = {};
|
||||
var exports = {};
|
||||
|
||||
self.getSettings = function(opts) {
|
||||
opts = opts || {};
|
||||
|
||||
var params = $.extend({}, opts);
|
||||
params.url = "api/connection";
|
||||
|
||||
return OctoPrint.getJson(params);
|
||||
exports.getSettings = function(opts) {
|
||||
return OctoPrint.get("api/connection", opts);
|
||||
};
|
||||
|
||||
self.connect = function(data, opts) {
|
||||
data = data || {};
|
||||
|
||||
return self.issueCommand("connect", data, opts);
|
||||
exports.connect = function(data, opts) {
|
||||
return exports.issueCommand("connect", data || {}, opts);
|
||||
};
|
||||
|
||||
self.disconnect = function(opts) {
|
||||
return self.issueCommand("disconnect", {}, opts);
|
||||
exports.disconnect = function(opts) {
|
||||
return exports.issueCommand("disconnect", {}, opts);
|
||||
};
|
||||
|
||||
self.fakeAck = function(opts) {
|
||||
return self.issueCommand("fake_ack", {}, opts);
|
||||
exports.fakeAck = function(opts) {
|
||||
return exports.issueCommand("fake_ack", {}, opts);
|
||||
};
|
||||
|
||||
self.issueCommand = function(command, data, opts) {
|
||||
opts = opts || {};
|
||||
data = data || {};
|
||||
|
||||
var payload = $.extend({}, data);
|
||||
payload.command = command;
|
||||
|
||||
var params = $.extend({}, opts);
|
||||
params.url = "api/connection";
|
||||
|
||||
return OctoPrint.postJson(payload, params);
|
||||
exports.issueCommand = function(command, data, opts) {
|
||||
return OctoPrint.issueCommand("api/connection", command, data, opts);
|
||||
};
|
||||
|
||||
return self;
|
||||
return exports;
|
||||
})($, _);
|
||||
|
|
|
|||
44
src/octoprint/static/js/app/client/control.js
Normal file
44
src/octoprint/static/js/app/client/control.js
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
OctoPrint.control = (function($, _) {
|
||||
var exports = {};
|
||||
|
||||
var customUrl = "api/printer/command/custom";
|
||||
var commandUrl = "api/printer/command";
|
||||
|
||||
exports.getCustomControls = function(opts) {
|
||||
return OctoPrint.get(customUrl, opts);
|
||||
};
|
||||
|
||||
exports.sendGcode = function(commands, opts) {
|
||||
commands = commands || [];
|
||||
|
||||
if (typeof commands === "string") {
|
||||
commands = [commands];
|
||||
}
|
||||
|
||||
return OctoPrint.postJson(commandUrl, {commands: commands}, opts);
|
||||
};
|
||||
|
||||
exports.sendGcodeWithParameters = function(commands, parameters, opts) {
|
||||
commands = commands || [];
|
||||
parameters = parameters || {};
|
||||
|
||||
if (typeof commands === "string") {
|
||||
commands = [commands];
|
||||
}
|
||||
|
||||
return OctoPrint.postJson(commandUrl, {commands: commands, parameters: parameters}, opts);
|
||||
};
|
||||
|
||||
exports.sendGcodeScript = function(script, context, opts) {
|
||||
script = script || "";
|
||||
context = context || {};
|
||||
|
||||
return OctoPrint.postJson(commandUrl, {script: script, context: context}, opts);
|
||||
};
|
||||
|
||||
exports.executeSystemCommand = function(action, opts) {
|
||||
return OctoPrint.postJson("api/system", {action: action}, opts);
|
||||
};
|
||||
|
||||
return exports;
|
||||
})($, _);
|
||||
|
|
@ -1,88 +1,69 @@
|
|||
OctoPrint.files = (function($, _) {
|
||||
var exports = {};
|
||||
|
||||
exports.get = function(opts) {
|
||||
opts = opts || {};
|
||||
|
||||
var path = "api/files";
|
||||
var location = opts.location || "";
|
||||
|
||||
if (location && _.contains(["local", "sdcard"], location)) {
|
||||
path += "/" + location;
|
||||
}
|
||||
|
||||
var params = _.extend({}, opts);
|
||||
params.url = path;
|
||||
|
||||
return OctoPrint.getJson(params);
|
||||
var resourceForFile = function(location, filename) {
|
||||
return "api/files/" + location + "/" + filename;
|
||||
};
|
||||
|
||||
exports.listAll = function(opts) {
|
||||
opts = opts || {};
|
||||
|
||||
if (opts.location) {
|
||||
opts.location = undefined;
|
||||
}
|
||||
|
||||
return exports.get(opts);
|
||||
var issueFileCommand = function(location, filename, command, data, opts) {
|
||||
var url = resourceForFile(location, filename);
|
||||
return OctoPrint.issueCommand(url, command, data, opts);
|
||||
};
|
||||
|
||||
exports.listAllForLocation = function(location, opts) {
|
||||
opts = opts || {};
|
||||
opts.location = location;
|
||||
|
||||
return exports.get(opts);
|
||||
exports.list = function(opts) {
|
||||
return OctoPrint.get("api/files", opts);
|
||||
};
|
||||
|
||||
exports.getInfoForFile = function(location, filename, opts) {
|
||||
opts = opts || {};
|
||||
|
||||
var params = $.extend({}, opts);
|
||||
params.url = exports.resourceForFile(location, filename);
|
||||
|
||||
return OctoPrint.getJson(params);
|
||||
exports.listForLocation = function(location, opts) {
|
||||
return OctoPrint.get("api/files/" + location, opts);
|
||||
};
|
||||
|
||||
exports.selectFile = function(location, filename, print, opts) {
|
||||
exports.get = function(location, filename, opts) {
|
||||
return OctoPrint.get(resourceForFile(location, filename), opts);
|
||||
};
|
||||
|
||||
exports.select = function(location, filename, print, opts) {
|
||||
print = print || false;
|
||||
|
||||
var data = {
|
||||
print: print
|
||||
};
|
||||
|
||||
return exports.issueFileCommand(location, filename, "select", data, opts);
|
||||
return issueFileCommand(location, filename, "select", data, opts);
|
||||
};
|
||||
|
||||
exports.sliceFile = function(location, filename, parameters, opts) {
|
||||
parameters = parameters || {};
|
||||
|
||||
return exports.issueFileCommand(location, filename, "slice", parameters, opts);
|
||||
exports.slice = function(location, filename, parameters, opts) {
|
||||
return issueFileCommand(location, filename, "slice",
|
||||
parameters || {}, opts);
|
||||
};
|
||||
|
||||
exports.issueFileCommand = function(location, filename, command, data, opts) {
|
||||
opts = opts || {};
|
||||
exports.delete = function(location, filename, opts) {
|
||||
return OctoPrint.delete(resourceForFile(location, filename), opts);
|
||||
};
|
||||
|
||||
exports.upload = function(location, file, data) {
|
||||
data = data || {};
|
||||
|
||||
var payload = $.extend({}, data);
|
||||
payload.command = command;
|
||||
|
||||
var params = $.extend({}, opts);
|
||||
params.url = exports.resourceForFile(location, filename);
|
||||
|
||||
return OctoPrint.postJson(payload, params);
|
||||
var filename = data.filename || undefined;
|
||||
return OctoPrint.upload("api/files/" + location, file, filename, data);
|
||||
};
|
||||
|
||||
exports.deleteFile = function(location, filename, opts) {
|
||||
opts = opts || {};
|
||||
|
||||
var params = $.extend({}, opts);
|
||||
params.url = exports.resourceForFile(location, filename);
|
||||
|
||||
return OctoPrint.delete(opts);
|
||||
};
|
||||
|
||||
exports.resourceForFile = function(location, filename) {
|
||||
return "api/files/" + location + "/" + filename;
|
||||
exports.download = function(location, filename, opts) {
|
||||
var deferred = $.Deferred();
|
||||
exports.get(location, filename, opts)
|
||||
.done(function(response) {
|
||||
OctoPrint.download(response.refs.download, opts)
|
||||
.done(function() {
|
||||
deferred.resolve.apply(null, arguments);
|
||||
})
|
||||
.fail(function() {
|
||||
deferred.reject.apply(null, arguments);
|
||||
});
|
||||
})
|
||||
.fail(function() {
|
||||
deferred.reject.apply(null, arguments);
|
||||
});
|
||||
return deferred.promise();
|
||||
};
|
||||
|
||||
return exports;
|
||||
|
|
|
|||
31
src/octoprint/static/js/app/client/job.js
Normal file
31
src/octoprint/static/js/app/client/job.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
OctoPrint.job = (function($, _) {
|
||||
var exports = {};
|
||||
|
||||
var url = "api/job";
|
||||
|
||||
var issueCommand = function(command, data, opts) {
|
||||
return OctoPrint.issueCommand(url, command, data, opts);
|
||||
};
|
||||
|
||||
exports.get = function(opts) {
|
||||
return OctoPrint.get(url, opts);
|
||||
};
|
||||
|
||||
exports.start = function(opts) {
|
||||
return issueCommand("start", {}, opts);
|
||||
};
|
||||
|
||||
exports.restart = function(opts) {
|
||||
return issueCommand("restart", {}, opts);
|
||||
};
|
||||
|
||||
exports.pause = function(opts) {
|
||||
return issueCommand("pause", {}, opts);
|
||||
};
|
||||
|
||||
exports.cancel = function(opts) {
|
||||
return issueCommand("cancel", {}, opts);
|
||||
};
|
||||
|
||||
return exports;
|
||||
})($, _);
|
||||
20
src/octoprint/static/js/app/client/languages.js
Normal file
20
src/octoprint/static/js/app/client/languages.js
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
OctoPrint.languages = (function($, _) {
|
||||
var exports = {};
|
||||
|
||||
var url = "api/languages";
|
||||
|
||||
exports.list = function(opt) {
|
||||
return OctoPrint.get(url, opt);
|
||||
};
|
||||
|
||||
exports.upload = function(file) {
|
||||
return OctoPrint.upload(url, file);
|
||||
};
|
||||
|
||||
exports.delete = function(locale, pack, opts) {
|
||||
var packUrl = url + "/" + locale + "/" + pack;
|
||||
return OctoPrint.delete(packUrl, opts);
|
||||
};
|
||||
|
||||
return exports;
|
||||
})($, _);
|
||||
21
src/octoprint/static/js/app/client/logs.js
Normal file
21
src/octoprint/static/js/app/client/logs.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
OctoPrint.logs = (function($, _) {
|
||||
var exports = {};
|
||||
|
||||
var url = "api/logs";
|
||||
|
||||
exports.list = function(opts) {
|
||||
return OctoPrint.get(url, opts);
|
||||
};
|
||||
|
||||
exports.delete = function(file, opts) {
|
||||
var fileUrl = url + "/" + file;
|
||||
return OctoPrint.delete(fileUrl, opts);
|
||||
};
|
||||
|
||||
exports.download = function(file, opts) {
|
||||
var fileUrl = url + "/" + file;
|
||||
return OctoPrint.download(fileUrl, opts);
|
||||
};
|
||||
|
||||
return exports;
|
||||
})($, _);
|
||||
|
|
@ -1,80 +1,243 @@
|
|||
var OctoPrint = (function($, _) {
|
||||
var exports = {};
|
||||
|
||||
var noCache = function(opts) {
|
||||
opts = opts || {};
|
||||
|
||||
var params = $.extend({}, opts);
|
||||
params.headers = $.extend({}, params.headers || {});
|
||||
params.headers["Cache-Control"] = "no-cache";
|
||||
|
||||
return params;
|
||||
};
|
||||
|
||||
var contentTypeJson = function(opts) {
|
||||
opts = opts || {};
|
||||
|
||||
var params = $.extend({}, opts);
|
||||
params.contentType = "application/json; charset=UTF-8";
|
||||
|
||||
return params;
|
||||
};
|
||||
|
||||
exports.options = {
|
||||
"baseurl": undefined,
|
||||
"apikey": undefined
|
||||
};
|
||||
|
||||
exports.ajax = function(opts) {
|
||||
opts = opts || {};
|
||||
exports.plugins = {};
|
||||
|
||||
exports.getBaseUrl = function() {
|
||||
var url = exports.options.baseurl;
|
||||
if (!_.endsWith(url, "/")) {
|
||||
url = url + "/";
|
||||
}
|
||||
url += opts.url;
|
||||
return url;
|
||||
};
|
||||
|
||||
var headers = $.extend({}, opts.headers || {});
|
||||
exports.getRequestHeaders = function(additional) {
|
||||
additional = additional || {};
|
||||
|
||||
var headers = $.extend({}, additional);
|
||||
headers["X-Api-Key"] = exports.options.apikey;
|
||||
|
||||
return headers;
|
||||
};
|
||||
|
||||
exports.ajax = function(method, url, opts) {
|
||||
opts = opts || {};
|
||||
|
||||
method = opts.method || method || "GET";
|
||||
url = opts.url || url || "";
|
||||
|
||||
var urlToCall = url;
|
||||
if (!_.startsWith(url, "http://") && !_.startsWith(url, "https://")) {
|
||||
urlToCall = exports.getBaseUrl() + url;
|
||||
}
|
||||
|
||||
var headers = exports.getRequestHeaders(opts.headers);
|
||||
|
||||
var params = $.extend({}, opts);
|
||||
params.url = url;
|
||||
params.type = method;
|
||||
params.headers = headers;
|
||||
params.dataType = params.dataType || "json";
|
||||
|
||||
return $.ajax(params);
|
||||
return $.ajax(urlToCall, params);
|
||||
};
|
||||
|
||||
exports.get = function(opts) {
|
||||
exports.ajaxWithData = function(method, url, data, opts) {
|
||||
opts = opts || {};
|
||||
|
||||
var params = $.extend({}, opts);
|
||||
params.type = "GET";
|
||||
|
||||
return exports.ajax(params);
|
||||
};
|
||||
|
||||
exports.post = function(data, opts) {
|
||||
opts = opts || {};
|
||||
|
||||
var headers = $.extend({}, opts.headers || {});
|
||||
headers["Cache-Control"] = "no-cache";
|
||||
|
||||
var params = $.extend({}, opts);
|
||||
params.type = "POST";
|
||||
params.data = data;
|
||||
params.headers = headers;
|
||||
|
||||
return exports.ajax(params);
|
||||
return exports.ajax(method, url, params);
|
||||
};
|
||||
|
||||
exports.delete = function(opts) {
|
||||
opts = opts || {};
|
||||
|
||||
var params = $.extend({}, opts);
|
||||
params.type = "DELETE";
|
||||
|
||||
return exports.ajax(params);
|
||||
exports.get = function(url, opts) {
|
||||
return exports.ajax("GET", url, opts);
|
||||
};
|
||||
|
||||
exports.getJson = function(opts) {
|
||||
opts = opts || {};
|
||||
|
||||
var params = $.extend({}, opts);
|
||||
params.dataType = "json";
|
||||
|
||||
return exports.get(params);
|
||||
exports.post = function(url, data, opts) {
|
||||
return exports.ajaxWithData("POST", url, data, noCache(opts));
|
||||
};
|
||||
|
||||
exports.postJson = function(data, opts) {
|
||||
opts = opts || {};
|
||||
|
||||
var params = $.extend({}, opts);
|
||||
params.contentType = "application/json; charset=UTF-8";
|
||||
params.dataType = "json";
|
||||
|
||||
return exports.post(JSON.stringify(data), params);
|
||||
exports.postJson = function(url, data, opts) {
|
||||
return exports.post(url, JSON.stringify(data), contentTypeJson(opts));
|
||||
};
|
||||
|
||||
exports.put = function(url, data, opts) {
|
||||
return exports.ajaxWithData("PUT", url, data, noCache(opts));
|
||||
};
|
||||
|
||||
exports.putJson = function(url, data, opts) {
|
||||
return exports.put(url, data, contentTypeJson(opts));
|
||||
};
|
||||
|
||||
exports.patch = function(url, data, opts) {
|
||||
return exports.ajaxWithData("PATCH", url, data, noCache(opts));
|
||||
};
|
||||
|
||||
exports.patchJson = function(url, data, opts) {
|
||||
return exports.patch(url, JSON.stringify(data), contentTypeJson(opts));
|
||||
};
|
||||
|
||||
exports.delete = function(url, opts) {
|
||||
return exports.ajax("DELETE", url, opts);
|
||||
};
|
||||
|
||||
exports.download = function(url, opts) {
|
||||
var params = $.extend({}, opts || {});
|
||||
params.dataType = "text";
|
||||
return exports.get(url, params);
|
||||
};
|
||||
|
||||
exports.upload = function(url, file, filename, additional) {
|
||||
additional = additional || {};
|
||||
|
||||
var fileData;
|
||||
if (file instanceof jQuery) {
|
||||
fileData = file[0].files[0];
|
||||
} else if (typeof file == "string") {
|
||||
fileData = $(file)[0].files[0];
|
||||
} else {
|
||||
fileData = file;
|
||||
}
|
||||
|
||||
filename = filename || fileData.name;
|
||||
|
||||
var form = new FormData();
|
||||
form.append("file", fileData, filename);
|
||||
|
||||
_.each(additional, function(value, key) {
|
||||
form.append(key, value);
|
||||
});
|
||||
|
||||
var deferred = $.Deferred();
|
||||
|
||||
var request = new XMLHttpRequest();
|
||||
request.onreadystatechange = function() {
|
||||
if (request.readyState == 4) {
|
||||
deferred.notify({loaded: filesize, total: filesize});
|
||||
|
||||
var success = request.status >= 200 && request.status < 300
|
||||
|| request.status === 304;
|
||||
var error, json, statusText;
|
||||
|
||||
try {
|
||||
json = JSON.parse(request.response);
|
||||
statusText = "success";
|
||||
} catch (e) {
|
||||
success = false;
|
||||
error = e;
|
||||
statusText = "parsererror";
|
||||
}
|
||||
|
||||
if (success) {
|
||||
deferred.resolve([json, statusText, request]);
|
||||
} else {
|
||||
if (!statusText) {
|
||||
statusText = request.statusText;
|
||||
}
|
||||
deferred.reject([request, statusText, error]);
|
||||
}
|
||||
}
|
||||
};
|
||||
request.ontimeout = function() {
|
||||
deferred.reject([request, "timeout", "Timeout"]);
|
||||
};
|
||||
request.upload.addEventListener("loadstart", function(e) {
|
||||
deferred.notify({loaded: e.loaded, total: e.total});
|
||||
});
|
||||
request.upload.addEventListener("progress", function(e) {
|
||||
deferred.notify({loaded: e.loaded, total: e.total});
|
||||
});
|
||||
request.upload.addEventListener("loadend", function(e) {
|
||||
deferred.notify({loaded: e.loaded, total: e.total});
|
||||
});
|
||||
|
||||
var headers = OctoPrint.getRequestHeaders();
|
||||
|
||||
request.open("POST", OctoPrint.getBaseUrl() + url);
|
||||
_.each(headers, function(value, key) {
|
||||
request.setRequestHeader(key, value);
|
||||
});
|
||||
request.send(form);
|
||||
|
||||
return deferred.promise();
|
||||
};
|
||||
|
||||
exports.issueCommand = function(url, command, payload, opts) {
|
||||
payload = payload || {};
|
||||
|
||||
var data = $.extend({}, payload);
|
||||
data.command = command;
|
||||
|
||||
return exports.postJson(url, data, opts);
|
||||
};
|
||||
|
||||
exports.getSimpleApiUrl = function(plugin) {
|
||||
return "api/plugin/" + plugin;
|
||||
};
|
||||
|
||||
exports.simpleApiGet = function(plugin, opts) {
|
||||
return OctoPrint.get(exports.getSimpleApiUrl(plugin), opts);
|
||||
};
|
||||
|
||||
exports.simpleApiCommand = function(plugin, command, payload, opts) {
|
||||
return OctoPrint.issueCommand(exports.getSimpleApiUrl(plugin), command, payload, opts);
|
||||
};
|
||||
|
||||
exports.getBlueprintUrl = function(plugin) {
|
||||
return "plugin/" + plugin + "/";
|
||||
};
|
||||
|
||||
exports.createRejectedDeferred = function() {
|
||||
var deferred = $.Deferred();
|
||||
deferred.reject(arguments);
|
||||
return deferred;
|
||||
};
|
||||
|
||||
exports.createCustomException = function(name) {
|
||||
var constructor;
|
||||
|
||||
if (_.isFunction(name)) {
|
||||
constructor = name;
|
||||
} else {
|
||||
constructor = function(message) {
|
||||
this.name = name;
|
||||
this.message = message;
|
||||
this.stack = (new Error()).stack;
|
||||
};
|
||||
}
|
||||
|
||||
constructor.prototype = Object.create(Error.prototype);
|
||||
constructor.prototype.constructor = constructor;
|
||||
|
||||
return constructor;
|
||||
};
|
||||
|
||||
exports.InvalidArgumentError = exports.createCustomException("InvalidArgumentError");
|
||||
|
||||
return exports;
|
||||
})($, _);
|
||||
|
|
|
|||
197
src/octoprint/static/js/app/client/printer.js
Normal file
197
src/octoprint/static/js/app/client/printer.js
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
OctoPrint.printer = (function($, _) {
|
||||
var exports = {};
|
||||
|
||||
var issuePrintheadCommand = function(command, payload, opts) {
|
||||
return OctoPrint.issueCommand("api/printer/printhead", command, payload, opts);
|
||||
};
|
||||
|
||||
var issueToolCommand = function(command, payload, opts) {
|
||||
return OctoPrint.issueCommand("api/printer/tool", command, payload, opts);
|
||||
};
|
||||
|
||||
var issueBedCommand = function(command, payload, opts) {
|
||||
return OctoPrint.issueCommand("api/printer/bed", command, payload, opts);
|
||||
};
|
||||
|
||||
var issueSdCommand = function(command, payload, opts) {
|
||||
return OctoPrint.issueCommand("api/printer/sd", command, payload, opts);
|
||||
};
|
||||
|
||||
exports.getFullState = function(data, opts) {
|
||||
data = data || {};
|
||||
|
||||
var history = data.history || undefined;
|
||||
var limit = data.limit || undefined;
|
||||
var exclude = data.exclude || undefined;
|
||||
|
||||
var url = "api/printer";
|
||||
if (history || exclude) {
|
||||
url += "?";
|
||||
if (history) {
|
||||
url += "history=true&";
|
||||
if (limit) {
|
||||
url += "limit=" + limit + "&";
|
||||
}
|
||||
}
|
||||
|
||||
if (exclude) {
|
||||
url += "exclude=" + exclude.join(",") + "&";
|
||||
}
|
||||
}
|
||||
|
||||
return OctoPrint.get(url, opts);
|
||||
};
|
||||
|
||||
exports.getToolState = function(data, opts) {
|
||||
data = data || {};
|
||||
|
||||
var history = data.history || undefined;
|
||||
var limit = data.limit || undefined;
|
||||
|
||||
var url = "api/printer/tool";
|
||||
if (history) {
|
||||
url += "?history=true";
|
||||
if (limit) {
|
||||
url += "&limit=" + limit;
|
||||
}
|
||||
}
|
||||
|
||||
return OctoPrint.get(url, opts);
|
||||
};
|
||||
|
||||
exports.getBedState = function(data, opts) {
|
||||
data = data || {};
|
||||
|
||||
var history = data.history || undefined;
|
||||
var limit = data.limit || undefined;
|
||||
|
||||
var url = "api/printer/bed";
|
||||
if (history) {
|
||||
url += "?history=true";
|
||||
if (limit) {
|
||||
url += "&limit=" + limit;
|
||||
}
|
||||
}
|
||||
|
||||
return OctoPrint.get(url, opts);
|
||||
};
|
||||
|
||||
exports.getSdState = function(opts) {
|
||||
return OctoPrint.get("api/printer/sd", opts);
|
||||
};
|
||||
|
||||
exports.jog = function(data, opts) {
|
||||
data = data || {};
|
||||
|
||||
var payload = {};
|
||||
if (data.x) payload.x = data.x;
|
||||
if (data.y) payload.y = data.y;
|
||||
if (data.z) payload.z = data.z;
|
||||
|
||||
return issuePrintheadCommand("jog", payload, opts);
|
||||
};
|
||||
|
||||
exports.home = function(axes, opts) {
|
||||
axes = axes || [];
|
||||
|
||||
var payload = {
|
||||
axes: axes
|
||||
};
|
||||
|
||||
return issuePrintheadCommand("home", payload, opts);
|
||||
};
|
||||
|
||||
exports.setFeedrate = function(factor, opts) {
|
||||
factor = factor || 100;
|
||||
|
||||
var payload = {
|
||||
factor: factor
|
||||
};
|
||||
|
||||
return issuePrintheadCommand("feedrate", payload, opts);
|
||||
};
|
||||
|
||||
exports.setToolTargetTemperatures = function(targets, opts) {
|
||||
targets = targets || {};
|
||||
|
||||
var payload = {
|
||||
targets: targets
|
||||
};
|
||||
|
||||
return issueToolCommand("target", payload, opts);
|
||||
};
|
||||
|
||||
exports.setToolTemperatureOffsets = function(offsets, opts) {
|
||||
offsets = offsets || {};
|
||||
|
||||
var payload = {
|
||||
offsets: offsets
|
||||
};
|
||||
|
||||
return issueToolCommand("offset", payload, opts);
|
||||
};
|
||||
|
||||
exports.selectTool = function(tool, opts) {
|
||||
tool = tool || undefined;
|
||||
|
||||
var payload = {
|
||||
tool: tool
|
||||
};
|
||||
|
||||
return issueToolCommand("select", payload, opts);
|
||||
};
|
||||
|
||||
exports.extrude = function(amount, opts) {
|
||||
amount = amount || undefined;
|
||||
|
||||
var payload = {
|
||||
amount: amount
|
||||
};
|
||||
|
||||
return issueToolCommand("extrude", payload, opts);
|
||||
};
|
||||
|
||||
exports.setFlowrate = function(factor, opts) {
|
||||
factor = factor || 100;
|
||||
|
||||
var payload = {
|
||||
factor: factor
|
||||
};
|
||||
|
||||
return issueToolCommand("flowrate", payload, opts);
|
||||
};
|
||||
|
||||
exports.setBedTargetTemperature = function(temperature, opts) {
|
||||
temperature = temperature || 0;
|
||||
|
||||
var payload = {
|
||||
target: temperature
|
||||
};
|
||||
|
||||
return issueBedCommand("target", payload, opts);
|
||||
};
|
||||
|
||||
exports.setBedTemperatureOffset = function(offset, opts) {
|
||||
offset = offset || 0;
|
||||
|
||||
var payload = {
|
||||
offset: offset
|
||||
};
|
||||
|
||||
return issueBedCommand("offset", payload, opts);
|
||||
};
|
||||
|
||||
exports.initSd = function(opts) {
|
||||
return issueSdCommand("init", {}, opts);
|
||||
};
|
||||
|
||||
exports.refreshSd = function(opts) {
|
||||
return issueSdCommand("refresh", {}, opts);
|
||||
};
|
||||
|
||||
exports.releaseSd = function(opts) {
|
||||
return issueSdCommand("release", {}, opts);
|
||||
};
|
||||
|
||||
return exports;
|
||||
})($, _);
|
||||
37
src/octoprint/static/js/app/client/printerprofiles.js
Normal file
37
src/octoprint/static/js/app/client/printerprofiles.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
OctoPrint.printerprofiles = (function($, _) {
|
||||
var exports = {};
|
||||
|
||||
var url = "api/printerprofiles";
|
||||
|
||||
exports.get = function(opts) {
|
||||
return OctoPrint.get(url, opts);
|
||||
};
|
||||
|
||||
exports.add = function(profile, additional, opts) {
|
||||
profile = profile || {};
|
||||
additional = additional || {};
|
||||
|
||||
var data = $.extend({}, additional);
|
||||
data.profile = profile;
|
||||
|
||||
return OctoPrint.postJson(url, data, opts);
|
||||
};
|
||||
|
||||
exports.update = function(id, profile, additional, opts) {
|
||||
profile = profile || {};
|
||||
additional = addtional || {};
|
||||
|
||||
var data = $.extend({}, additional);
|
||||
data.profile = profile;
|
||||
|
||||
var profileUrl = url + "/" + id;
|
||||
return OctoPrint.patchJson(profileUrl, data, opts);
|
||||
};
|
||||
|
||||
exports.delete = function(id, opts) {
|
||||
var profileUrl = url + "/" + id;
|
||||
return OctoPrint.delete(profileUrl, opts);
|
||||
};
|
||||
|
||||
return exports;
|
||||
})($, _);
|
||||
16
src/octoprint/static/js/app/client/settings.js
Normal file
16
src/octoprint/static/js/app/client/settings.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
OctoPrint.settings = (function($, _) {
|
||||
var exports = {};
|
||||
|
||||
var url = "api/settings";
|
||||
|
||||
exports.get = function(opts) {
|
||||
return OctoPrint.get(url, opts);
|
||||
};
|
||||
|
||||
exports.save = function(settings, opts) {
|
||||
settings = settings || {};
|
||||
return OctoPrint.postJson(url, settings, opts);
|
||||
};
|
||||
|
||||
return exports;
|
||||
})($, _);
|
||||
38
src/octoprint/static/js/app/client/slicing.js
Normal file
38
src/octoprint/static/js/app/client/slicing.js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
OctoPrint.slicing = (function($, _) {
|
||||
var exports = {};
|
||||
|
||||
var url = "api/slicing";
|
||||
|
||||
var getProfileUrl = function(slicer, profileId) {
|
||||
return url + "/" + slicer + "/profiles/" + profileId;
|
||||
};
|
||||
|
||||
exports.listAllSlicersAndProfiles = function(opts) {
|
||||
return OctoPrint.get(url, opts);
|
||||
};
|
||||
|
||||
exports.listProfilesForSlicer = function(slicer, opts) {
|
||||
var slicerUrl = url + "/" + slicer + "/profiles";
|
||||
return OctoPrint.get(slicerUrl, opts);
|
||||
};
|
||||
|
||||
exports.getProfileForSlicer = function(slicer, profileId, opts) {
|
||||
return OctoPrint.get(getProfileUrl(slicer, profileId), opts);
|
||||
};
|
||||
|
||||
exports.addProfileForSlicer = function(slicer, profileId, profile, opts) {
|
||||
profile = profile || {};
|
||||
return OctoPrint.putJson(getProfileUrl(slicer, profileId), profile, opts);
|
||||
};
|
||||
|
||||
exports.updateProfileForSlicer = function(slicer, profileId, profile, opts) {
|
||||
profile = profile || {};
|
||||
return OctoPrint.patchJson(getProfileUrl(slicer, profileId), profile, opts);
|
||||
};
|
||||
|
||||
exports.deleteProfileForSlicer = function(slicer, profileId, opts) {
|
||||
return OctoPrint.delete(getProfileUrl(slicer, profileId), opts);
|
||||
};
|
||||
|
||||
return exports;
|
||||
})($, _);
|
||||
|
|
@ -10,6 +10,7 @@ OctoPrint.socket = (function($, _, SockJS) {
|
|||
var socket = undefined;
|
||||
var reconnecting = false;
|
||||
var reconnectTrial = 0;
|
||||
var registeredHandlers = {};
|
||||
|
||||
var onOpen = function() {
|
||||
reconnecting = false;
|
||||
|
|
@ -35,45 +36,30 @@ OctoPrint.socket = (function($, _, SockJS) {
|
|||
};
|
||||
|
||||
var onMessage = function(msg) {
|
||||
for (var prop in msg.data) {
|
||||
if (!msg.data.hasOwnProperty(prop)) {
|
||||
continue;
|
||||
}
|
||||
_.each(msg.data, function(data, key) {
|
||||
propagateMessage(key, data);
|
||||
});
|
||||
};
|
||||
|
||||
var data = msg.data[prop];
|
||||
var propagateMessage = function(event, data) {
|
||||
if (!registeredHandlers.hasOwnProperty(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (prop) {
|
||||
case "connected": {
|
||||
exports.onConnected(data);
|
||||
break;
|
||||
}
|
||||
case "history": {
|
||||
exports.onHistoryData(data);
|
||||
break;
|
||||
}
|
||||
case "current": {
|
||||
exports.onCurrentData(data);
|
||||
break;
|
||||
}
|
||||
case "event": {
|
||||
var event = data["type"];
|
||||
var payload = data["payload"];
|
||||
exports.onEvent(event, payload);
|
||||
break;
|
||||
}
|
||||
case "plugin": {
|
||||
exports.onPluginMessage(data.plugin, data.data);
|
||||
break;
|
||||
}
|
||||
case "timelapse": {
|
||||
exports.onTimelapseSettings(data);
|
||||
break;
|
||||
}
|
||||
case "slicingProgress": {
|
||||
exports.onSlicingProgress(data.slicer, data.model_path, data.machinecode_path, data.progress);
|
||||
break;
|
||||
}
|
||||
}
|
||||
var eventObj = {event: event, data: data};
|
||||
|
||||
var catchAllHandlers = registeredHandlers["*"];
|
||||
if (catchAllHandlers && catchAllHandlers.length) {
|
||||
_.each(catchAllHandlers, function(handler) {
|
||||
handler({event: eventObj})
|
||||
});
|
||||
}
|
||||
|
||||
var handlers = registeredHandlers[event];
|
||||
if (handlers && handlers.length) {
|
||||
_.each(handlers, function(handler) {
|
||||
handler(eventObj);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -105,13 +91,14 @@ OctoPrint.socket = (function($, _, SockJS) {
|
|||
}
|
||||
};
|
||||
|
||||
exports.onConnected = function(data) {};
|
||||
exports.onCurrentData = function(data) {};
|
||||
exports.onHistoryData = function(data) {};
|
||||
exports.onEvent = function(event, data) {};
|
||||
exports.onPluginMessage = function(plugin, message) {};
|
||||
exports.onTimelapseSettings = function(data) {};
|
||||
exports.onSlicingProgress = function(slicer, modelPath, machinecodePath, progress) {};
|
||||
exports.onMessage = function(message, handler) {
|
||||
if (!registeredHandlers.hasOwnProperty(message)) {
|
||||
registeredHandlers[message] = [];
|
||||
}
|
||||
registeredHandlers[message].push(handler);
|
||||
return exports;
|
||||
};
|
||||
|
||||
exports.onReconnectAttempt = function(trial) {};
|
||||
exports.onReconnectFailed = function() {};
|
||||
|
||||
|
|
|
|||
50
src/octoprint/static/js/app/client/timelapse.js
Normal file
50
src/octoprint/static/js/app/client/timelapse.js
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
OctoPrint.timelapse = (function($, _) {
|
||||
var exports = {};
|
||||
|
||||
var url = "api/timelapse";
|
||||
|
||||
exports.get = function(opts) {
|
||||
return OctoPrint.get(url, opts);
|
||||
};
|
||||
|
||||
exports.list = function(opts) {
|
||||
var deferred = $.Deferred();
|
||||
|
||||
exports.get(opts)
|
||||
.done(function(response, status, request) {
|
||||
deferred.resolve(response.files, status, request);
|
||||
})
|
||||
.fail(function() {
|
||||
deferred.reject.apply(null, arguments);
|
||||
});
|
||||
|
||||
return deferred.promise();
|
||||
};
|
||||
|
||||
exports.download = function(filename, opts) {
|
||||
return OctoPrint.download(url + "/" + filename, opts);
|
||||
};
|
||||
|
||||
exports.delete = function(filename, opts) {
|
||||
return OctoPrint.delete(url + "/" + filename, opts);
|
||||
};
|
||||
|
||||
exports.getConfig = function(opts) {
|
||||
var deferred = $.Deferred();
|
||||
exports.get(opts)
|
||||
.done(function(response, status, request) {
|
||||
deferred.resolve(response.config, status, request);
|
||||
})
|
||||
.fail(function() {
|
||||
deferred.reject.apply(null, arguments);
|
||||
});
|
||||
return deferred.promise();
|
||||
};
|
||||
|
||||
exports.saveConfig = function(config, opts) {
|
||||
config = config || {};
|
||||
return OctoPrint.postJson(url, config, opts);
|
||||
};
|
||||
|
||||
return exports;
|
||||
})($, _);
|
||||
74
src/octoprint/static/js/app/client/users.js
Normal file
74
src/octoprint/static/js/app/client/users.js
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
OctoPrint.users = (function($, _) {
|
||||
var exports = {};
|
||||
|
||||
var baseUrl = "api/users";
|
||||
|
||||
var url = function() {
|
||||
if (arguments.length) {
|
||||
return baseUrl + "/" + Array.prototype.join.call(arguments, "/");
|
||||
} else {
|
||||
return baseUrl;
|
||||
}
|
||||
};
|
||||
|
||||
exports.list = function(opts) {
|
||||
return OctoPrint.get(url(), opts);
|
||||
};
|
||||
|
||||
exports.add = function(user, opts) {
|
||||
if (!user.name || !user.password) {
|
||||
throw new OctoPrint.InvalidArgumentError("Both user's name and password need to be set");
|
||||
}
|
||||
|
||||
var data = {
|
||||
name: user.name,
|
||||
password: user.password,
|
||||
active: user.hasOwnProperty("active") ? !!user.active : true,
|
||||
admin: user.hasOwnProperty("admin") ? !!user.admin : false
|
||||
};
|
||||
|
||||
return OctoPrint.postJson(url(), data, opts);
|
||||
};
|
||||
|
||||
exports.get = function(name, opts) {
|
||||
return OctoPrint.get(url(name), opts);
|
||||
};
|
||||
|
||||
exports.update = function(name, active, admin, opts) {
|
||||
var data = {
|
||||
active: !!active,
|
||||
admin: !!admin
|
||||
};
|
||||
return OctoPrint.putJson(url(name), data, opts);
|
||||
};
|
||||
|
||||
exports.delete = function(name, opts) {
|
||||
return OctoPrint.delete(url(name), opts);
|
||||
};
|
||||
|
||||
exports.changePassword = function(name, password, opts) {
|
||||
var data = {
|
||||
password: password
|
||||
};
|
||||
return OctoPrint.putJson(url(name, "password"), data, opts);
|
||||
};
|
||||
|
||||
exports.generateApiKey = function(name, opts) {
|
||||
return OctoPrint.postJson(url(name, "apikey"), opts);
|
||||
};
|
||||
|
||||
exports.resetApiKey = function(name, opts) {
|
||||
return OctoPrint.delete(url(name, "apikey"), opts);
|
||||
};
|
||||
|
||||
exports.getSettings = function(name, opts) {
|
||||
return OctoPrint.get(url(name, "settings"), opts);
|
||||
};
|
||||
|
||||
exports.saveSettings = function(name, settings, opts) {
|
||||
settings = settings || {};
|
||||
return OctoPrint.patchJson(url(name, "settings"), settings, opts);
|
||||
};
|
||||
|
||||
return exports;
|
||||
})($, _);
|
||||
11
src/octoprint/static/js/app/client/util.js
Normal file
11
src/octoprint/static/js/app/client/util.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
OctoPrint.util = (function($, _) {
|
||||
var exports = {};
|
||||
|
||||
var url = "api/util";
|
||||
|
||||
exports.test = function(command, data, opts) {
|
||||
return OctoPrint.issueCommand(url + "/test", command, data, opts);
|
||||
};
|
||||
|
||||
return exports;
|
||||
})($, _);
|
||||
15
src/octoprint/static/js/app/client/wizard.js
Normal file
15
src/octoprint/static/js/app/client/wizard.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
OctoPrint.wizard = (function($, _) {
|
||||
var exports = {};
|
||||
|
||||
var url = "api/setup/wizard";
|
||||
|
||||
exports.get = function(opts) {
|
||||
return OctoPrint.get(url, opts);
|
||||
};
|
||||
|
||||
exports.finish = function(handled, opts) {
|
||||
return OctoPrint.postJson(url, {handled: handled || []}, opts);
|
||||
};
|
||||
|
||||
return exports;
|
||||
})($, _);
|
||||
Loading…
Reference in a new issue