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 @@ +