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

Support for pulling cost from Spooman #26

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion octoprint_costestimation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
35 changes: 33 additions & 2 deletions octoprint_costestimation/static/js/costestimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() ?
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
});
};
Expand Down Expand Up @@ -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.remaining_weight || 0,
Hillshum marked this conversation as resolved.
Show resolved Hide resolved
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;
Expand Down Expand Up @@ -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"]
});
});
12 changes: 12 additions & 0 deletions octoprint_costestimation/templates/costestimation_settings.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@
<!-- /ko -->
</label>
</div>
<div class="controls">
<label class="checkbox">
<input name="filamentTracker" type="checkbox" data-bind="checked: $root.settings.settings.plugins.costestimation.useSpoolman, enable: $root.spoolman !== null">
{{ _('Use <a target="_blank" href="https://github.com/OllisGit/OctoPrint-Spoolman">Spoolman</a>') }}
<!-- ko if: $root.spoolman !== null -->
<span class="text-success">{{ _("(installed)") }}</span>
<!-- /ko -->
<!-- ko if: $root.spoolman === null -->
<span class="text-error">{{ _("(not installed)") }}</span>
<!-- /ko -->
</label>
</div>
</div>

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