diff --git a/octoprint_costestimation/__init__.py b/octoprint_costestimation/__init__.py index 0ed1575..0c599fa 100644 --- a/octoprint_costestimation/__init__.py +++ b/octoprint_costestimation/__init__.py @@ -26,6 +26,7 @@ def get_settings_defaults(self): currencyFormat="%v %s", # %v - value, %s - currency symbol requiresLogin=False, useFilamentManager=True, + useSpoolManager=False, priceOfPrinter=0, # € lifespanOfPrinter=0, # h maintenanceCosts=0, # €/h diff --git a/octoprint_costestimation/static/js/costestimation.js b/octoprint_costestimation/static/js/costestimation.js index 30a73ab..2f2d1df 100644 --- a/octoprint_costestimation/static/js/costestimation.js +++ b/octoprint_costestimation/static/js/costestimation.js @@ -14,6 +14,7 @@ $(function() { self.settings = parameters[1]; self.loginState = parameters[2]; self.filamentManager = parameters[3]; + self.spoolManager = parameters[4]; self.showEstimatedCost = ko.pureComputed(function() { return self.settings.settings.plugins.costestimation.requiresLogin() ? @@ -21,8 +22,10 @@ $(function() { }); self.showFilamentGroup = ko.pureComputed(function() { - return self.filamentManager === null || !self.settings.settings.plugins.costestimation.useFilamentManager(); - }) + var filamentManagerDisabled = self.filamentManager === null || !self.settings.settings.plugins.costestimation.useFilamentManager(); + var spoolManagerDisabled = self.spoolManager === null || !self.settings.settings.plugins.costestimation.useSpoolManager(); + return !filamentManagerDisabled && !spoolManagerDisabled; + }); self.estimatedCostString = ko.pureComputed(function() { if (!self.showEstimatedCost()) return "-"; @@ -35,6 +38,11 @@ $(function() { if (self.filamentManager !== null && pluginSettings.useFilamentManager()) { spoolData = self.filamentManager.selectedSpools(); + } else if (self.spoolManager !== null && pluginSettings.useSpoolManager()) { + var selectedSpool = self.spoolManager.selectedSpoolForSidebar(); + if (selectedSpool) { + spoolData = [self.parseSpoolManagerData(self.spoolManager)]; + } } // calculating filament cost @@ -100,13 +108,35 @@ $(function() { element.before("
" + name + ":
"); } }; + + self.parseSpoolManagerData = function(spoolManager = null) { + if (!spoolManager) return null; + var selectedSpool = spoolManager.selectedSpoolForSidebar(); + if (!selectedSpool) return null; + return { + id: selectedSpool.databaseId() || 0, + cost: selectedSpool.cost() || 0, + name: selectedSpool.displayName() || "", + profile: { + id: selectedSpool.databaseId() || 0, + density: selectedSpool.density() || 0, + diameter: selectedSpool.diameter() || 0, + material: selectedSpool.material() || "", + vendor: selectedSpool.vendor() || "" + }, + temp_offset: 0, + used: selectedSpool.usedWeight() ? parseInt(selectedSpool.usedWeight(),10) : 0, + weight: selectedSpool.totalWeight() ? parseInt(selectedSpool.totalWeight(),10) : 0, + }; + }; } OCTOPRINT_VIEWMODELS.push({ construct: CostEstimationViewModel, dependencies: ["printerStateViewModel", "settingsViewModel", - "loginStateViewModel", "filamentManagerViewModel"], - optional: ["filamentManagerViewModel"], + "loginStateViewModel", "filamentManagerViewModel", + "spoolManagerViewModel"], + optional: ["filamentManagerViewModel","spoolManagerViewModel"], elements: ["#costestimation_string", "#settings_plugin_costestimation"] }); }); diff --git a/octoprint_costestimation/templates/costestimation_settings.jinja2 b/octoprint_costestimation/templates/costestimation_settings.jinja2 index 936fe29..8bf5c14 100644 --- a/octoprint_costestimation/templates/costestimation_settings.jinja2 +++ b/octoprint_costestimation/templates/costestimation_settings.jinja2 @@ -15,6 +15,18 @@ +
+ +