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];
|
|
|
|
|
|
|
|
self.shortStatus = ko.observable();
|
|
|
|
self.logMessages = ko.observableArray();
|
2018-01-23 21:30:55 +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
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
self.showPidTuningDialog = function() {
|
|
|
|
var dialog = $("#klipper_pid_tuning_dialog");
|
|
|
|
dialog.modal({
|
|
|
|
show: 'true',
|
|
|
|
backdrop: 'static',
|
|
|
|
keyboard: false
|
|
|
|
});;
|
|
|
|
}
|
|
|
|
|
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() {
|
2018-01-23 23:18:07 +03:00
|
|
|
self.shortStatus("Updating Status ...")
|
2018-01-23 20:33:22 +03:00
|
|
|
OctoPrint.control.sendGcode("Status")
|
2018-01-23 17:01:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
self.onRestartFirmware = function() {
|
2018-01-23 23:18:07 +03:00
|
|
|
self.shortStatus("Restarting Firmware ...");
|
2018-01-23 20:33:22 +03:00
|
|
|
OctoPrint.control.sendGcode("FIRMWARE_RESTART")
|
2018-01-23 17:01:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
self.onRestartHost = function() {
|
2018-01-23 23:18:07 +03:00
|
|
|
self.shortStatus("Restarting Host ...");
|
2018-01-23 20:33:22 +03:00
|
|
|
OctoPrint.control.sendGcode("RESTART")
|
2018-01-23 17:01:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
self.onAfterBinding = function() {
|
2018-01-23 20:33:22 +03:00
|
|
|
self.connectionState.selectedPort(self.settings.settings.plugins.klipper.serialport());
|
2018-01-23 17:01:58 +03:00
|
|
|
self.shortStatus("Idle");
|
|
|
|
}
|
|
|
|
|
|
|
|
self.onDataUpdaterPluginMessage = function(plugin, message) {
|
2018-01-23 21:30:55 +03:00
|
|
|
self.logMessage(message["time"], message["type"], message["message"]);
|
2018-01-23 17:01:58 +03:00
|
|
|
}
|
|
|
|
|
2018-01-23 21:30:55 +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,
|
|
|
|
dependencies: ["settingsViewModel", "loginStateViewModel", "connectionViewModel"],
|
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
|
|
|
});
|
|
|
|
});
|