Skip to content

Commit

Permalink
add option to use drop down menu, #305
Browse files Browse the repository at this point in the history
  • Loading branch information
jneilliii committed Apr 23, 2022
1 parent 694ff3a commit b0f6715
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 35 deletions.
47 changes: 17 additions & 30 deletions octoprint_tplinksmartplug/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,28 +162,13 @@ def on_after_startup(self):
##~~ SettingsPlugin mixin

def get_settings_defaults(self):
return dict(
debug_logging=False,
arrSmartplugs=[],
pollingInterval=15,
pollingEnabled=False,
thermal_runaway_monitoring=False,
thermal_runaway_max_bed=0,
thermal_runaway_max_extruder=0,
event_on_error_monitoring=False,
event_on_disconnect_monitoring=False,
event_on_upload_monitoring=False,
event_on_upload_monitoring_always=False,
event_on_startup_monitoring=False,
event_on_shutdown_monitoring=False,
cost_rate=0,
abortTimeout=30,
powerOffWhenIdle=False,
idleTimeout=30,
idleIgnoreCommands='M105',
idleTimeoutWaitTemp=50,
progress_polling=False
)
return {'debug_logging': False, 'arrSmartplugs': [], 'pollingInterval': 15, 'pollingEnabled': False,
'thermal_runaway_monitoring': False, 'thermal_runaway_max_bed': 0, 'thermal_runaway_max_extruder': 0,
'event_on_error_monitoring': False, 'event_on_disconnect_monitoring': False,
'event_on_upload_monitoring': False, 'event_on_upload_monitoring_always': False,
'event_on_startup_monitoring': False, 'event_on_shutdown_monitoring': False, 'cost_rate': 0,
'abortTimeout': 30, 'powerOffWhenIdle': False, 'idleTimeout': 30, 'idleIgnoreCommands': 'M105',
'idleTimeoutWaitTemp': 50, 'progress_polling': False, 'useDropDown': False}

def on_settings_save(self, data):
old_debug_logging = self._settings.get_boolean(["debug_logging"])
Expand Down Expand Up @@ -353,13 +338,14 @@ def get_assets(self):
##~~ TemplatePlugin mixin

def get_template_configs(self):
templates_to_load = [dict(type="navbar", custom_bindings=True), dict(type="settings", custom_bindings=True),
dict(type="sidebar", icon="plug", custom_bindings=True,
data_bind="visible: arrSmartplugs().length > 0",
template="tplinksmartplug_sidebar.jinja2",
template_header="tplinksmartplug_sidebar_header.jinja2"),
dict(type="tab", custom_bindings=True, data_bind="visible: show_sidebar()",
template="tplinksmartplug_tab.jinja2")]
templates_to_load = [{'type': "navbar", 'custom_bindings': True, 'classes': ["dropdown"]},
{'type': "settings", 'custom_bindings': True},
{'type': "sidebar", 'icon': "plug", 'custom_bindings': True,
'data_bind': "visible: arrSmartplugs().length > 0",
'template': "tplinksmartplug_sidebar.jinja2",
'template_header': "tplinksmartplug_sidebar_header.jinja2"},
{'type': "tab", 'custom_bindings': True, 'data_bind': "visible: show_sidebar()",
'template': "tplinksmartplug_tab.jinja2"}]
return templates_to_load

##~~ ProgressPlugin mixin
Expand Down Expand Up @@ -760,7 +746,8 @@ def on_event(self, event, payload):
self._autostart_file = None
# File Uploaded Event
if event == Events.UPLOAD and self._settings.get_boolean(["event_on_upload_monitoring"]):
if payload.get("print", False) or self._settings.get_boolean(["event_on_upload_monitoring_always"]): # implemented in OctoPrint version 1.4.1
if payload.get("print", False) or self._settings.get_boolean(
["event_on_upload_monitoring_always"]): # implemented in OctoPrint version 1.4.1
self._tplinksmartplug_logger.debug(
"File uploaded: %s. Turning enabled plugs on." % payload.get("name", ""))
self._tplinksmartplug_logger.debug(payload)
Expand Down
8 changes: 6 additions & 2 deletions octoprint_tplinksmartplug/static/css/tplinksmartplug.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#navbar_plugin_tplinksmartplug > a > i.on {
#navbar_plugin_tplinksmartplug > a > i.on,
#navbar_plugin_tplinksmartplug > ul > li > a > i.on
{
color: #00FF00 !important;
}

#navbar_plugin_tplinksmartplug > a > i.off {
#navbar_plugin_tplinksmartplug > a > i.off,
#navbar_plugin_tplinksmartplug > ul > li > a > i.off
{
color: #FF0000 !important;
}

Expand Down
18 changes: 16 additions & 2 deletions octoprint_tplinksmartplug/templates/tplinksmartplug_navbar.jinja2
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
<!-- ko if: settings.settings.plugins.tplinksmartplug.useDropDown -->
<a href="javascript:void(0)" title="TPLink SmartPlugs" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-plug"></i>
<b class="caret"></b>
</a>
<ul class="dropdown-menu" data-bind="foreach: arrSmartplugs">
<li>
<a href="#" data-toggle="tooltip" data-html="true" data-bind="click: $root.toggleRelay, visible: $root.loginState.loggedIn(), tooltip: {title: label, placement: 'bottom'}"><i class="icon" data-bind="css: [currentState(), icon(),(($root.processing().indexOf(ip()) > -1) ? 'icon-spin' : '')].join(' ')"></i> <span data-bind="text: label"></span></a>
</li>
</ul>
<!-- /ko -->
<!-- ko if: !(settings.settings.plugins.tplinksmartplug.useDropDown()) -->
<!-- ko foreach: arrSmartplugs -->
<a class="pull-right" href="#" data-toggle="tooltip" data-html="true" data-bind="click: $root.toggleRelay, visible: $root.loginState.loggedIn(), tooltip: {title: label, placement: 'bottom'}" style="float: left;"><i class="icon" data-bind="css: [currentState(), icon(),(($root.processing().indexOf(ip()) > -1) ? 'icon-spin' : '')].join(' ')"></i><span data-bind="text: label"></span></a>
<a class="pull-right" href="#" data-toggle="tooltip" data-html="true" data-bind="click: $root.toggleRelay, visible: $root.loginState.loggedIn(), tooltip: {title: label, placement: 'bottom'}" style="float: left;"><i class="icon" data-bind="css: [currentState(), icon(),(($root.processing().indexOf(ip()) > -1) ? 'icon-spin' : '')].join(' ')"></i><span data-bind="text: label"></span></a>
<!-- /ko -->
<!-- /ko -->


<div id="TPLinkSmartPlugWarning" data-bind="with: selectedPlug" class="modal hide fade">
<div class="modal-header">
<a href="#" class="close" data-dismiss="modal" aria-hidden="true">&times;</a>
<h3>TP-Link Smartplug</h3>
</div>
<div class="modal-body">
<p>
<!--ko text: label()--><!--/ko--> is currently <!--ko text: currentState()--><!--/ko-->.
<!--ko text: label()--><!--/ko--> is currently <!--ko text: currentState()--><!--/ko-->.
</p>
<p>
{{ _('Are you sure you want to proceed?') }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@
</div>
</div>
</div>
<div class="row-fluid">
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" title="{{ _('Put all control buttons in a drop-down menu.') }}" data-toggle="tooltip" data-bind="checked: settings.settings.plugins.tplinksmartplug.useDropDown, tooltip: {}" /> {{ _('Use Drop Down Menu') }}
</label>
</div>
</div>
</div>
</div>
</div>
<div class="row-fluid">
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plugin_name = "OctoPrint-TPLinkSmartplug"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "1.0.2"
plugin_version = "1.0.3rc1"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit b0f6715

Please sign in to comment.