Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for spool manager plugin #30

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions octoprint_costestimation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 34 additions & 4 deletions octoprint_costestimation/static/js/costestimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ $(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() ?
self.loginState.isUser() : true;
});

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 "-";
Expand All @@ -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
Expand Down Expand Up @@ -100,13 +108,35 @@ $(function() {
element.before("<div id='costestimation_string' data-bind='visible: showEstimatedCost()'><span title='" + text + "'>" + name + "</span>: <strong data-bind='text: estimatedCostString'></strong></div>");
}
};

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"]
});
});
12 changes: 12 additions & 0 deletions octoprint_costestimation/templates/costestimation_settings.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@
<!-- /ko -->
</label>
</div>
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: $root.settings.settings.plugins.costestimation.useSpoolManager">
{{ _('Use <a target="_blank" href="https://github.com/OllisGit/OctoPrint-SpoolManager">Spool Manager Plugin</a>') }}
<!-- ko if: $root.spoolManager !== null -->
<span class="text-success">{{ _("(installed)") }}</span>
<!-- /ko -->
<!-- ko if: $root.spoolManager === null -->
<span class="text-error">{{ _("(not installed)") }}</span>
<!-- /ko -->
</label>
</div>
</div>

<div data-bind="visible: $root.showFilamentGroup">
Expand Down