From c8902c9b5dbaa44cda6afbcfd47eb197ebb92dbc Mon Sep 17 00:00:00 2001 From: Ben Lye Date: Fri, 27 Nov 2020 17:17:10 +0000 Subject: [PATCH] Add a navbar icon for accessing the firmware updater --- octoprint_firmwareupdater/__init__.py | 1 + .../static/js/firmwareupdater.js | 20 +++++++++++++++++-- .../templates/firmwareupdater_navbar.jinja2 | 1 + .../templates/firmwareupdater_settings.jinja2 | 12 ++++++++++- setup.py | 2 +- 5 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 octoprint_firmwareupdater/templates/firmwareupdater_navbar.jinja2 diff --git a/octoprint_firmwareupdater/__init__.py b/octoprint_firmwareupdater/__init__.py index 7cb664e..ea0b550 100644 --- a/octoprint_firmwareupdater/__init__.py +++ b/octoprint_firmwareupdater/__init__.py @@ -297,6 +297,7 @@ def _flash_worker(self, method, firmware, printer_port): def get_settings_defaults(self): return { "flash_method": None, + "enable_navbar": False, "avrdude_path": None, "avrdude_conf": None, "avrdude_avrmcu": None, diff --git a/octoprint_firmwareupdater/static/js/firmwareupdater.js b/octoprint_firmwareupdater/static/js/firmwareupdater.js index c5ab8cc..dc481ee 100644 --- a/octoprint_firmwareupdater/static/js/firmwareupdater.js +++ b/octoprint_firmwareupdater/static/js/firmwareupdater.js @@ -6,9 +6,12 @@ $(function() { self.loginState = parameters[1]; self.connection = parameters[2]; self.printerState = parameters[3]; + self.access = parameters[4]; // General settings self.configFlashMethod = ko.observable(); + self.configShowNavbarIcon = ko.observable(); + self.showFirmwareUpdaterNavbarIcon = ko.observable(false); self.showAdvancedConfig = ko.observable(false); self.showAvrdudeConfig = ko.observable(false); self.showBossacConfig = ko.observable(false); @@ -123,6 +126,17 @@ $(function() { self.inSettingsDialog = false; + self.onAllBound = function(allViewModels) { + self.configShowNavbarIcon(self.settingsViewModel.settings.plugins.firmwareupdater.enable_navbar()); + if (self.loginState.isAdmin() && self.configShowNavbarIcon()) { + self.showFirmwareUpdaterNavbarIcon(true); + } + } + + self.showFirmwareUpdater = function(){ + self.settingsViewModel.show("#settings_plugin_firmwareupdater"); + } + self.connection.selectedPort.subscribe(function(value) { if (value === undefined) return; self.flashPort(value); @@ -437,6 +451,7 @@ $(function() { self.showPluginConfig = function() { // Load the general settings self.configFlashMethod(self.settingsViewModel.settings.plugins.firmwareupdater.flash_method()); + self.configShowNavbarIcon(self.settingsViewModel.settings.plugins.firmwareupdater.enable_navbar()); self.configPreflashCommandline(self.settingsViewModel.settings.plugins.firmwareupdater.preflash_commandline()); self.configPostflashCommandline(self.settingsViewModel.settings.plugins.firmwareupdater.postflash_commandline()); self.configPostflashDelay(self.settingsViewModel.settings.plugins.firmwareupdater.postflash_delay()); @@ -526,6 +541,7 @@ $(function() { plugins: { firmwareupdater: { flash_method: self.configFlashMethod(), + enable_navbar: self.configShowNavbarIcon(), avrdude_path: self.configAvrdudePath(), avrdude_conf: self.configAvrdudeConfigFile(), avrdude_avrmcu: self.configAvrdudeMcu(), @@ -841,7 +857,7 @@ $(function() { OCTOPRINT_VIEWMODELS.push([ FirmwareUpdaterViewModel, - ["settingsViewModel", "loginStateViewModel", "connectionViewModel", "printerStateViewModel"], - [document.getElementById("settings_plugin_firmwareupdater")] + ["settingsViewModel", "loginStateViewModel", "connectionViewModel", "printerStateViewModel", "accessViewModel"], + ["#settings_plugin_firmwareupdater", "#navbar_plugin_firmwareupdater"] ]); }); diff --git a/octoprint_firmwareupdater/templates/firmwareupdater_navbar.jinja2 b/octoprint_firmwareupdater/templates/firmwareupdater_navbar.jinja2 new file mode 100644 index 0000000..a487413 --- /dev/null +++ b/octoprint_firmwareupdater/templates/firmwareupdater_navbar.jinja2 @@ -0,0 +1 @@ + diff --git a/octoprint_firmwareupdater/templates/firmwareupdater_settings.jinja2 b/octoprint_firmwareupdater/templates/firmwareupdater_settings.jinja2 index 7942970..c1abb81 100644 --- a/octoprint_firmwareupdater/templates/firmwareupdater_settings.jinja2 +++ b/octoprint_firmwareupdater/templates/firmwareupdater_settings.jinja2 @@ -212,6 +212,17 @@ +
+ +
+
+ +
+ {{ _('Enables a link to the Firmware Updater in the OctoPrint navbar. (Reload after enabling/disabling.)') }} +
+
+
+
@@ -547,4 +558,3 @@
- diff --git a/setup.py b/setup.py index ad44bb5..8ddd9ae 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ plugin_name = "OctoPrint-FirmwareUpdater" # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module -plugin_version = "1.7.1" +plugin_version = "1.7.2" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module