diff --git a/octoprint_costestimation/__init__.py b/octoprint_costestimation/__init__.py index 9e90fac..78ab53b 100644 --- a/octoprint_costestimation/__init__.py +++ b/octoprint_costestimation/__init__.py @@ -71,13 +71,14 @@ def get_settings_defaults(self): requiresLogin=False, useFilamentManager=True, useSpoolManager=False, + useSpoolman=False, priceOfPrinter=0, # € lifespanOfPrinter=0, # h maintenanceCosts=0, # €/h ) def get_settings_version(self): - return 3 + return 4 def on_settings_migrate(self, target, current=None): if current is None or current == 1: diff --git a/octoprint_costestimation/static/js/costestimation.js b/octoprint_costestimation/static/js/costestimation.js index 332d761..2f131c8 100644 --- a/octoprint_costestimation/static/js/costestimation.js +++ b/octoprint_costestimation/static/js/costestimation.js @@ -19,6 +19,7 @@ $(function() { self.filamentManager = parameters[3]; self.spoolManager = parameters[4]; self.filesViewModel = parameters[5]; + self.spoolman = parameters[6]; self.showEstimatedCost = ko.pureComputed(function() { return self.settings.settings.plugins.costestimation.requiresLogin() ? @@ -52,6 +53,8 @@ $(function() { spoolData = self.filamentManager.selectedSpools(); } else if (self.spoolManager !== null && pluginSettings.useSpoolManager()) { spoolData = self.readSpoolManagerData(); + } else if (self.spoolman !== null && pluginSettings.useSpoolman()) { + spoolData = self.readSpoolmanData(); } // - calculating filament cost @@ -175,11 +178,19 @@ $(function() { self.settings.settings.plugins.costestimation.useFilamentManager.subscribe(function(newValue){ if (newValue == true){ self.settings.settings.plugins.costestimation.useSpoolManager(false); + self.settings.settings.plugins.costestimation.useSpoolman(false); } }); self.settings.settings.plugins.costestimation.useSpoolManager.subscribe(function(newValue){ if (newValue == true){ self.settings.settings.plugins.costestimation.useFilamentManager(false); + self.settings.settings.plugins.costestimation.useSpoolman(false); + } + }); + self.settings.settings.plugins.costestimation.useSpoolman.subscribe(function(newValue){ + if (newValue == true){ + self.settings.settings.plugins.costestimation.useFilamentManager(false); + self.settings.settings.plugins.costestimation.useSpoolManager(false); } }); }; @@ -214,8 +225,28 @@ $(function() { if (self.spoolManager === null){ self.settings.settings.plugins.costestimation.useSpoolManager(false); } + if (self.spoolman === null){ + self.settings.settings.plugins.costestimation.useSpoolman(false); + } } + self.readSpoolmanData = ko.computed(function() { + const result = []; + for (const spool of self.spoolman.templateData.selectedSpoolsByToolIdx()) { + if (spool.spoolId == null) continue; + const pulledData = { + cost: spool.spoolData.price || spool.spoolData.filament.price || 0, + weight: spool.spoolData.initial_weight || 0, + profile: { + density: spool.spoolData.filament.density || 0, + diameter: spool.spoolData.filament.diameter || 0 + } + }; + result.push(pulledData) + } + return result; + }) + self.readSpoolManagerData = function() { // needed data // costOfFilament = spoolData[tool].cost; @@ -270,8 +301,8 @@ $(function() { construct: CostEstimationViewModel, dependencies: ["printerStateViewModel", "settingsViewModel", "loginStateViewModel", "filamentManagerViewModel", - "spoolManagerViewModel", "filesViewModel"], - optional: ["filamentManagerViewModel","spoolManagerViewModel"], + "spoolManagerViewModel", "filesViewModel", "spoolmanSidebarViewModel"], + optional: ["filamentManagerViewModel","spoolManagerViewModel", "spoolmanSidebarViewModel"], elements: ["#costestimation_string", "#settings_plugin_costestimation"] }); }); diff --git a/octoprint_costestimation/templates/costestimation_settings.jinja2 b/octoprint_costestimation/templates/costestimation_settings.jinja2 index aaa6ac9..4d5ed3e 100644 --- a/octoprint_costestimation/templates/costestimation_settings.jinja2 +++ b/octoprint_costestimation/templates/costestimation_settings.jinja2 @@ -27,6 +27,18 @@ +