From bdc911c415fe6c276720f6cdd1928d4cf8750bc7 Mon Sep 17 00:00:00 2001 From: "Michal Dziekonski (mdz)" Date: Thu, 24 Oct 2024 02:36:40 +0200 Subject: [PATCH] feat: Improve info formatting in the Sidebar (GH-52) (#70) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Dziekoński --- octoprint_Spoolman/static/css/Spoolman.css | 7 ++ .../static/js/common/formatting.js | 11 +- .../templates/Spoolman_sidebar.jinja2 | 118 +++++++++++------- 3 files changed, 89 insertions(+), 47 deletions(-) diff --git a/octoprint_Spoolman/static/css/Spoolman.css b/octoprint_Spoolman/static/css/Spoolman.css index a0f5e02..5710d44 100644 --- a/octoprint_Spoolman/static/css/Spoolman.css +++ b/octoprint_Spoolman/static/css/Spoolman.css @@ -15,6 +15,13 @@ white-space: pre-wrap; overflow-wrap: anywhere; } +.sidebar-spool-info { + display: flex; + flex-direction: column; + flex-wrap: wrap; + + overflow-wrap: anywhere; +} .tool-row { display: flex; diff --git a/octoprint_Spoolman/static/js/common/formatting.js b/octoprint_Spoolman/static/js/common/formatting.js index ec52763..2caa688 100644 --- a/octoprint_Spoolman/static/js/common/formatting.js +++ b/octoprint_Spoolman/static/js/common/formatting.js @@ -2,11 +2,12 @@ /** * @param {number} weight * @param {{ -* constants: Record +* constants: Record; +* precision?: number * }} params */ const toWeight = (weight, params) => { - return `${weight.toFixed(1)}${params.constants['weight_unit']}`; + return `${weight.toFixed(params.precision ?? 1)}${params.constants['weight_unit']}`; }; /** @@ -53,6 +54,12 @@ const toSpoolForDisplay = (spool, params) => { ), }, }, + initial_weight: { + displayValue: toWeight((spool.filament.weight ?? 0), { + ...params, + precision: 0, + }) + }, used_weight: { displayValue: spool.used_weight.toFixed(1), }, diff --git a/octoprint_Spoolman/templates/Spoolman_sidebar.jinja2 b/octoprint_Spoolman/templates/Spoolman_sidebar.jinja2 index 6f86cae..8d7ee45 100644 --- a/octoprint_Spoolman/templates/Spoolman_sidebar.jinja2 +++ b/octoprint_Spoolman/templates/Spoolman_sidebar.jinja2 @@ -68,19 +68,26 @@
- -
- Tool #: -
- - -
- - Unknown spool selected - - - No spool selected +
+ +
+
@@ -107,48 +114,69 @@
- -
- Tool #: -
- -
-
- [] - - () - - - +