2020-08-30 01:23:22 +03:00
|
|
|
// <Octoprint Klipper Plugin>
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
// License, or (at your option) any later version.
|
2021-01-22 01:53:51 +03:00
|
|
|
|
2020-08-30 01:23:22 +03:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
2021-01-22 01:53:51 +03:00
|
|
|
|
2020-08-30 01:23:22 +03:00
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2018-08-19 14:49:24 +03:00
|
|
|
|
2021-01-22 01:53:51 +03:00
|
|
|
$(function () {
|
2018-01-23 17:01:58 +03:00
|
|
|
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-08-25 17:55:48 +03:00
|
|
|
self.paramMacroViewModel = parameters[4];
|
2021-03-11 21:42:05 +03:00
|
|
|
self.access = parameters[5];
|
2021-01-22 01:53:51 +03:00
|
|
|
|
2018-01-23 17:01:58 +03:00
|
|
|
self.shortStatus = ko.observable();
|
|
|
|
self.logMessages = ko.observableArray();
|
2021-01-22 01:53:51 +03:00
|
|
|
|
|
|
|
self.showLevelingDialog = function () {
|
|
|
|
var dialog = $("#klipper_leveling_dialog");
|
|
|
|
dialog.modal({
|
|
|
|
show: "true",
|
|
|
|
backdrop: "static",
|
|
|
|
keyboard: false,
|
|
|
|
});
|
|
|
|
self.levelingViewModel.initView();
|
|
|
|
};
|
|
|
|
|
|
|
|
self.showPidTuningDialog = function () {
|
|
|
|
var dialog = $("#klipper_pid_tuning_dialog");
|
|
|
|
dialog.modal({
|
|
|
|
show: "true",
|
|
|
|
backdrop: "static",
|
|
|
|
keyboard: false,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
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",
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
self.executeMacro = function (macro) {
|
|
|
|
var paramObjRegex = /{(.*?)}/g;
|
|
|
|
|
2021-02-13 17:48:23 +03:00
|
|
|
if (!this.hasRight("MACRO")) return;
|
2021-01-22 01:53:51 +03:00
|
|
|
|
|
|
|
if (macro.macro().match(paramObjRegex) == null) {
|
|
|
|
OctoPrint.control.sendGcode(
|
|
|
|
// Use .split to create an array of strings which is sent to
|
|
|
|
// OctoPrint.control.sendGcode instead of a single string.
|
|
|
|
macro.macro().split(/\r\n|\r|\n/)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
self.paramMacroViewModel.process(macro);
|
|
|
|
|
|
|
|
var dialog = $("#klipper_macro_dialog");
|
|
|
|
dialog.modal({
|
|
|
|
show: "true",
|
|
|
|
backdrop: "static",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
self.navbarClicked = function () {
|
2021-01-06 06:57:49 +03:00
|
|
|
$("#tab_plugin_klipper_main_link").find("a").click();
|
2021-01-22 01:53:51 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
self.onGetStatus = function () {
|
|
|
|
OctoPrint.control.sendGcode("Status");
|
|
|
|
};
|
|
|
|
|
|
|
|
self.onRestartFirmware = function () {
|
|
|
|
OctoPrint.control.sendGcode("FIRMWARE_RESTART");
|
|
|
|
};
|
|
|
|
|
|
|
|
self.onRestartHost = function () {
|
|
|
|
OctoPrint.control.sendGcode("RESTART");
|
|
|
|
};
|
|
|
|
|
|
|
|
self.onAfterBinding = function () {
|
|
|
|
self.connectionState.selectedPort(
|
|
|
|
self.settings.settings.plugins.klipper.connection.port()
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
self.onDataUpdaterPluginMessage = function (plugin, message) {
|
|
|
|
if (plugin == "klipper") {
|
|
|
|
if (message["type"] == "status") {
|
|
|
|
self.shortStatus(message["payload"]);
|
|
|
|
} else {
|
|
|
|
self.logMessage(
|
|
|
|
message["time"],
|
|
|
|
message["subtype"],
|
|
|
|
message["payload"]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
self.logMessage = function (timestamp, type, message) {
|
|
|
|
self.logMessages.push({
|
|
|
|
time: timestamp,
|
|
|
|
type: type,
|
|
|
|
msg: message.replace(/\n/gi, "<br>"),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
self.onClearLog = function () {
|
|
|
|
self.logMessages.removeAll();
|
|
|
|
};
|
|
|
|
|
|
|
|
self.isActive = function () {
|
2021-02-12 01:34:25 +03:00
|
|
|
return self.connectionState.isOperational() && this.hasRight("CONFIG");
|
2021-01-22 01:53:51 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
self.hasRight = function (right_role, type) {
|
|
|
|
var arg = eval(
|
|
|
|
"self.access.permissions.PLUGIN_KLIPPER_" + right_role
|
|
|
|
);
|
|
|
|
|
|
|
|
if (type == "Ko") {
|
|
|
|
return self.loginState.hasPermissionKo(arg);
|
|
|
|
}
|
|
|
|
return self.loginState.hasPermission(arg);
|
|
|
|
};
|
2021-03-11 21:42:05 +03:00
|
|
|
|
|
|
|
// OctoKlipper settings link
|
2021-01-22 01:53:51 +03:00
|
|
|
self.openOctoKlipperSettings = function (profile_type) {
|
|
|
|
if (!this.hasRight("CONFIG")) return;
|
|
|
|
|
|
|
|
$("a#navbar_show_settings").click();
|
|
|
|
$("li#settings_plugin_klipper_link a").click();
|
|
|
|
if (profile_type) {
|
|
|
|
var query =
|
|
|
|
"#klipper-settings a[data-profile-type='" +
|
|
|
|
profile_type +
|
|
|
|
"']";
|
|
|
|
$(query).click();
|
|
|
|
}
|
2021-03-11 21:42:05 +03:00
|
|
|
};
|
2018-01-23 17:01:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
OCTOPRINT_VIEWMODELS.push({
|
|
|
|
construct: KlipperViewModel,
|
2018-08-25 17:55:48 +03:00
|
|
|
dependencies: [
|
2021-01-22 01:53:51 +03:00
|
|
|
"settingsViewModel",
|
|
|
|
"loginStateViewModel",
|
|
|
|
"connectionViewModel",
|
|
|
|
"klipperLevelingViewModel",
|
|
|
|
"klipperMacroDialogViewModel",
|
|
|
|
"accessViewModel",
|
|
|
|
],
|
|
|
|
elements: [
|
|
|
|
"#tab_plugin_klipper_main",
|
|
|
|
"#sidebar_plugin_klipper",
|
|
|
|
"#navbar_plugin_klipper",
|
2018-08-25 17:55:48 +03:00
|
|
|
],
|
2018-01-23 17:01:58 +03:00
|
|
|
});
|
2020-08-30 01:23:22 +03:00
|
|
|
});
|