OctoprintKlipperPlugin/octoprint_klipper/static/js/klipper.js

97 lines
3.0 KiB
JavaScript
Raw Normal View History

2018-01-23 17:01:58 +03:00
$(function() {
function KlipperViewModel(parameters) {
var self = this;
2018-01-24 19:14:42 +03:00
2018-01-23 17:01:58 +03:00
self.settings = parameters[0];
self.loginState = parameters[1];
self.connectionState = parameters[2];
2018-08-18 15:44:11 +03:00
self.levelingViewModel = parameters[3];
2018-01-23 17:01:58 +03:00
self.shortStatus = ko.observable();
self.logMessages = ko.observableArray();
2018-08-18 15:44:11 +03:00
2018-01-24 19:14:42 +03:00
self.showLevelingDialog = function() {
var dialog = $("#klipper_leveling_dialog");
dialog.modal({
show: 'true',
backdrop: 'static',
keyboard: false
2018-08-18 15:44:11 +03:00
});
self.levelingViewModel.initView();
2018-01-24 19:14:42 +03:00
}
self.showPidTuningDialog = function() {
var dialog = $("#klipper_pid_tuning_dialog");
dialog.modal({
show: 'true',
backdrop: 'static',
keyboard: false
});
2018-01-24 19:14:42 +03:00
}
self.showOffsetDialog = function() {
var dialog = $("#klipper_offset_dialog");
dialog.modal({
show: 'true',
backdrop: 'static'
});
}
self.showGraphDialog = function() {
var dialog = $("#klipper_graph_dialog");
dialog.modal({
show: 'true',
minHeight: "500px",
maxHeight: "600px"
});
}
2018-02-06 17:31:15 +03:00
self.executeMacro = function(macro) {
OctoPrint.control.sendGcode(macro.macro());
}
2018-01-23 17:01:58 +03:00
self.onGetStatus = function() {
OctoPrint.control.sendGcode("Status")
2018-01-23 17:01:58 +03:00
}
self.onRestartFirmware = function() {
OctoPrint.control.sendGcode("FIRMWARE_RESTART")
2018-01-23 17:01:58 +03:00
};
self.onRestartHost = function() {
OctoPrint.control.sendGcode("RESTART")
2018-01-23 17:01:58 +03:00
};
self.onAfterBinding = function() {
2018-08-09 10:25:05 +03:00
self.connectionState.selectedPort(self.settings.settings.plugins.klipper.connection.port());
2018-01-23 17:01:58 +03:00
}
self.onDataUpdaterPluginMessage = function(plugin, message) {
2018-02-08 00:02:16 +03:00
if(plugin == "klipper") {
2018-02-08 18:38:48 +03:00
if(message["type"] == "status") {
self.shortStatus(message["payload"]);
} else {
self.logMessage(message["time"], message["subtype"], message["payload"]);
}
2018-02-08 00:02:16 +03:00
}
2018-01-23 17:01:58 +03:00
}
self.logMessage = function(timestamp, type, message) {
self.logMessages.push({time: timestamp, type: type, msg: message});
2018-01-23 17:01:58 +03:00
}
self.onClearLog = function() {
self.logMessages.removeAll();
};
self.isActive = function() {
return self.connectionState.isOperational() && self.loginState.isUser();
}
}
OCTOPRINT_VIEWMODELS.push({
construct: KlipperViewModel,
2018-08-18 15:44:11 +03:00
dependencies: ["settingsViewModel", "loginStateViewModel", "connectionViewModel", "klipperLevelingViewModel"],
2018-01-24 19:14:42 +03:00
elements: ["#tab_plugin_klipper_main", "#sidebar_plugin_klipper", "#navbar_plugin_klipper"]
2018-01-23 17:01:58 +03:00
});
});