From b1a380a4bfd3dcb17a689656832896f65e1bec73 Mon Sep 17 00:00:00 2001
From: thelastWallE <12502210+thelastWallE@users.noreply.github.com>
Date: Thu, 21 Jan 2021 23:53:51 +0100
Subject: [PATCH 06/10] Update2
Prettified
hide buttons if someone has no permissions
---
octoprint_klipper/static/css/klipper.css | 18 ++
octoprint_klipper/static/js/klipper.js | 269 +++++++++---------
.../templates/klipper_sidebar.jinja2 | 2 +-
3 files changed, 160 insertions(+), 129 deletions(-)
diff --git a/octoprint_klipper/static/css/klipper.css b/octoprint_klipper/static/css/klipper.css
index c151695..ec51ade 100644
--- a/octoprint_klipper/static/css/klipper.css
+++ b/octoprint_klipper/static/css/klipper.css
@@ -57,6 +57,24 @@ ul#klipper-settings {
font-family: monospace;
}
+#tab_plugin_klipper_main .row-fluid {
+ display: flex;
+ flex-direction: row;
+ flex-wrap: wrap;
+}
+
+#tab_plugin_klipper_main .span8 {
+ min-width: 50%;
+ width: auto;
+ flex-grow: 6;
+}
+
+#tab_plugin_klipper_main .span4 {
+ flex-grow: 1;
+ flex-shrink: 1;
+ width: auto;
+}
+
#settings_plugin_klipper {
height: 100%;
}
diff --git a/octoprint_klipper/static/js/klipper.js b/octoprint_klipper/static/js/klipper.js
index 033243f..b213c8f 100644
--- a/octoprint_klipper/static/js/klipper.js
+++ b/octoprint_klipper/static/js/klipper.js
@@ -4,16 +4,16 @@
// 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.
-
+
// 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.
-
+
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
-$(function() {
+$(function () {
function KlipperViewModel(parameters) {
var self = this;
@@ -23,148 +23,161 @@ $(function() {
self.levelingViewModel = parameters[3];
self.paramMacroViewModel = parameters[4];
self.access = parameters[5];
-
+
self.shortStatus = ko.observable();
self.logMessages = ko.observableArray();
- self.hasRight = ko.observable(false);
-
- 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;
-
- 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() {
+ 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;
+
+ if (!this.hasRight("MACROS")) return;
+
+ 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 () {
$("#tab_plugin_klipper_main_link").find("a").click();
- }
-
- 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, "
")}
- );
- }
-
- self.onClearLog = function() {
- self.logMessages.removeAll();
+ self.onGetStatus = function () {
+ OctoPrint.control.sendGcode("Status");
};
-
- self.isActive = function() {
- return self.connectionState.isOperational() && self.loginState.hasPermission(self.access.permissions.PLUGIN_KLIPPER_CONFIG); //was: && self.loginState.isUser();
- }
- self.hasRight = function (right_role) {
- var arg = eval("access.permissions.PLUGIN_KLIPPER_"+right_role);
- return self.loginState.hasPermissionKo(arg);
- }
+ 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, "
"),
+ });
+ };
+
+ self.onClearLog = function () {
+ self.logMessages.removeAll();
+ };
+
+ self.isActive = function () {
+ return self.connectionState.isOperational() && hasRight("CONFIG");
+ };
+
+ 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);
+ };
// OctoKlipper settings link
- self.openOctoKlipperSettings = function(profile_type) {
+ self.openOctoKlipperSettings = function (profile_type) {
+ if (!this.hasRight("CONFIG")) return;
- if (
- !self.loginState.hasPermission(
- self.access.permissions.PLUGIN_KLIPPER_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();
- }
+ $("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();
+ }
};
}
OCTOPRINT_VIEWMODELS.push({
construct: KlipperViewModel,
dependencies: [
- "settingsViewModel",
- "loginStateViewModel",
- "connectionViewModel",
- "klipperLevelingViewModel",
- "klipperMacroDialogViewModel",
- "accessViewModel"
+ "settingsViewModel",
+ "loginStateViewModel",
+ "connectionViewModel",
+ "klipperLevelingViewModel",
+ "klipperMacroDialogViewModel",
+ "accessViewModel",
+ ],
+ elements: [
+ "#tab_plugin_klipper_main",
+ "#sidebar_plugin_klipper",
+ "#navbar_plugin_klipper",
],
- elements: ["#tab_plugin_klipper_main", "#sidebar_plugin_klipper", "#navbar_plugin_klipper"]
});
});
diff --git a/octoprint_klipper/templates/klipper_sidebar.jinja2 b/octoprint_klipper/templates/klipper_sidebar.jinja2
index 558740a..bdadac1 100644
--- a/octoprint_klipper/templates/klipper_sidebar.jinja2
+++ b/octoprint_klipper/templates/klipper_sidebar.jinja2
@@ -5,7 +5,7 @@
+
From 782b9aa91b01b8561f2f7b0b61eeaf4bf52f912b Mon Sep 17 00:00:00 2001
From: thelastWallE <12502210+thelastWallE@users.noreply.github.com>
Date: Thu, 11 Feb 2021 23:34:25 +0100
Subject: [PATCH 07/10] bugfix of buttonenable and some styling
---
octoprint_klipper/static/css/klipper.css | 18 ++++++++++++++----
octoprint_klipper/static/js/klipper.js | 2 +-
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/octoprint_klipper/static/css/klipper.css b/octoprint_klipper/static/css/klipper.css
index ec51ade..841c7d4 100644
--- a/octoprint_klipper/static/css/klipper.css
+++ b/octoprint_klipper/static/css/klipper.css
@@ -3,6 +3,7 @@
overflow-y: scroll;
height: 400px;
border: 1px solid #eee;
+ width: 100%;
}
.plugin-klipper-log .log-item {
@@ -34,6 +35,7 @@
.clear-btn {
margin-top: 6px;
+ margin-bottom: 6px;
}
#level .add-on {
@@ -65,14 +67,22 @@ ul#klipper-settings {
#tab_plugin_klipper_main .span8 {
min-width: 50%;
- width: auto;
- flex-grow: 6;
+ width: unset;
+ flex-grow: 8;
+ float: left;
+ box-sizing: border-box;
+}
+
+#tab_plugin_klipper_main .span8 label {
+ float: left;
}
#tab_plugin_klipper_main .span4 {
- flex-grow: 1;
+ flex-grow: 0;
flex-shrink: 1;
- width: auto;
+ max-width: 13%;
+ float: left;
+ box-sizing: border-box;
}
#settings_plugin_klipper {
diff --git a/octoprint_klipper/static/js/klipper.js b/octoprint_klipper/static/js/klipper.js
index b213c8f..a3bb837 100644
--- a/octoprint_klipper/static/js/klipper.js
+++ b/octoprint_klipper/static/js/klipper.js
@@ -134,7 +134,7 @@ $(function () {
};
self.isActive = function () {
- return self.connectionState.isOperational() && hasRight("CONFIG");
+ return self.connectionState.isOperational() && this.hasRight("CONFIG");
};
self.hasRight = function (right_role, type) {
From fc8d74e8983e69a36eaaf811c353ea0a477cbcc1 Mon Sep 17 00:00:00 2001
From: thelastWallE <12502210+thelastWallE@users.noreply.github.com>
Date: Sat, 13 Feb 2021 15:48:23 +0100
Subject: [PATCH 08/10] typo in executeMacro for permissions
---
octoprint_klipper/static/js/klipper.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/octoprint_klipper/static/js/klipper.js b/octoprint_klipper/static/js/klipper.js
index a3bb837..10ca040 100644
--- a/octoprint_klipper/static/js/klipper.js
+++ b/octoprint_klipper/static/js/klipper.js
@@ -66,7 +66,7 @@ $(function () {
self.executeMacro = function (macro) {
var paramObjRegex = /{(.*?)}/g;
- if (!this.hasRight("MACROS")) return;
+ if (!this.hasRight("MACRO")) return;
if (macro.macro().match(paramObjRegex) == null) {
OctoPrint.control.sendGcode(
From 6931d375704a2aafe0435acb3a4b48dfab32c22a Mon Sep 17 00:00:00 2001
From: thelastWallE <12502210+thelastWallE@users.noreply.github.com>
Date: Fri, 5 Mar 2021 22:36:32 +0100
Subject: [PATCH 09/10] Rights on Macros changed
---
octoprint_klipper/static/js/klipper.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/octoprint_klipper/static/js/klipper.js b/octoprint_klipper/static/js/klipper.js
index 10ca040..c9b5213 100644
--- a/octoprint_klipper/static/js/klipper.js
+++ b/octoprint_klipper/static/js/klipper.js
@@ -66,7 +66,7 @@ $(function () {
self.executeMacro = function (macro) {
var paramObjRegex = /{(.*?)}/g;
- if (!this.hasRight("MACRO")) return;
+ if (!self.hasRight("MACRO")) return;
if (macro.macro().match(paramObjRegex) == null) {
OctoPrint.control.sendGcode(
@@ -150,7 +150,7 @@ $(function () {
// OctoKlipper settings link
self.openOctoKlipperSettings = function (profile_type) {
- if (!this.hasRight("CONFIG")) return;
+ if (!self.hasRight("CONFIG")) return;
$("a#navbar_show_settings").click();
$("li#settings_plugin_klipper_link a").click();
From ea961767c48b0396d81399d33a27dc025ccf3134 Mon Sep 17 00:00:00 2001
From: thelastWallE <12502210+thelastWallE@users.noreply.github.com>
Date: Fri, 12 Mar 2021 00:58:12 +0100
Subject: [PATCH 10/10] cleaning of rebase
---
octoprint_klipper/templates/klipper_sidebar.jinja2 | 6 +-----
octoprint_klipper/templates/klipper_tab_main.jinja2 | 4 ++--
2 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/octoprint_klipper/templates/klipper_sidebar.jinja2 b/octoprint_klipper/templates/klipper_sidebar.jinja2
index bdadac1..6482e3f 100644
--- a/octoprint_klipper/templates/klipper_sidebar.jinja2
+++ b/octoprint_klipper/templates/klipper_sidebar.jinja2
@@ -3,14 +3,10 @@
+