From 79966e352c789cb328485ef7df1344ed0faf7b6e Mon Sep 17 00:00:00 2001 From: Jan Szumiec Date: Fri, 17 Jun 2016 23:49:45 +0100 Subject: [PATCH] Fixed some issues on the sidebar. --- octoprint_cost/static/js/cost.js | 20 +++++++++++++------- setup.py | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/octoprint_cost/static/js/cost.js b/octoprint_cost/static/js/cost.js index 63030e7..5733e7e 100644 --- a/octoprint_cost/static/js/cost.js +++ b/octoprint_cost/static/js/cost.js @@ -32,16 +32,22 @@ $(function() { filesState.getAdditionalData = function(data) { var output = originalGetAdditionalData(data); - var currency = settingsState.settings.plugins.cost.currency(); - var cost_per_meter = settingsState.settings.plugins.cost.cost_per_meter(); - var cost_per_hour = settingsState.settings.plugins.cost.cost_per_hour(); + if (data.hasOwnProperty('gcodeAnalysis')) { + var gcode = data.gcodeAnalysis; + if (gcode.hasOwnProperty('filament') && gcode.filament.hasOwnProperty('tool0') && gcode.hasOwnProperty('estimatedPrintTime')) { + var currency = settingsState.settings.plugins.cost.currency(); + var cost_per_meter = settingsState.settings.plugins.cost.cost_per_meter(); + var cost_per_hour = settingsState.settings.plugins.cost.cost_per_hour(); - var filament_used_meters = data["gcodeAnalysis"]["filament"]["tool0"].length / 1000; - var expected_time_hours = data["gcodeAnalysis"]["estimatedPrintTime"] / 3600; + var filament_used_meters = gcode.filament.tool0.length / 1000; + var expected_time_hours = gcode.estimatedPrintTime / 3600; - var totalCost = cost_per_meter * filament_used_meters + expected_time_hours * cost_per_hour; + var totalCost = cost_per_meter * filament_used_meters + expected_time_hours * cost_per_hour; - output += gettext("Cost") + ": " + currency + totalCost.toFixed(2);; + output += gettext("Cost") + ": " + currency + totalCost.toFixed(2); + } + } + return output; }; diff --git a/setup.py b/setup.py index 18efa78..d7a9194 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ plugin_name = "OctoPrint-Cost" # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module -plugin_version = "0.1.1" +plugin_version = "0.1.2" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module