Skip to content
This repository has been archived by the owner on May 8, 2023. It is now read-only.

Commit

Permalink
update settings page, close #13
Browse files Browse the repository at this point in the history
  • Loading branch information
mike1pol committed Dec 2, 2020
1 parent 1d91d06 commit 63a83e8
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 38 deletions.
11 changes: 9 additions & 2 deletions octoprint_macro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ def get_settings_defaults(self):
return dict(
column = 1,
macros = [
dict(name="Home", macro="G28", active=True, type = "default")
dict(name="Home", macro="G28", active=True, type = "default", dop=True)
]
)

def get_settings_version(self):
return 1
return 2

def on_settings_migrate(self, target, current=None):
if current is None or current < 1:
Expand All @@ -26,6 +26,13 @@ def on_settings_migrate(self, target, current=None):
new_macros.append(macros)
self._settings.set(['macros'], new_macros)
self._settings.set(['column'], 1)
if current < 2:
new_macros = []
self._logger.info(self._settings.get(['macros']))
for macros in self._settings.get(['macros']):
macros['dop'] = False
new_macros.append(macros)
self._settings.set(['macros'], new_macros)

def get_template_configs(self):
return [
Expand Down
6 changes: 5 additions & 1 deletion octoprint_macro/static/js/macro.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ $(function () {
self.settings = parameters[0];
self.loginState = parameters[1];
self.connectionState = parameters[2];
self.isActive = function () {
self.isActive = function (data) {
const dop = data.dop();
if (dop && self.connectionState.isPrinting()) {
return false;
}
return self.connectionState.isOperational() && self.loginState.isUser();
}
function executeCommands(commands) {
Expand Down
24 changes: 15 additions & 9 deletions octoprint_macro/static/js/macro_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ $(function () {
name: 'Macro',
macro: '',
type: 'default',
active: true
active: true,
dop: false
});
}
self.bindFor = function (prefix, ctx) {
return `${prefix}-${ctx.$index()}`;
};
self.removeMacro = function (macro) {
self.settings.settings.plugins.macro.macros.remove(macro);
}
Expand All @@ -27,21 +31,23 @@ $(function () {
self.moveItemDown(self.settings.settings.plugins.macro.macros, macro)
}

self.moveItemDown = function(list, item) {
self.moveItemDown = function (list, item) {
var i = list().indexOf(item);
if (i < list().length - 1) {
var rawList = list();
list.splice(i, 2, rawList[i + 1], rawList[i]);
list.splice(i, 2, rawList[i + 1], rawList[i]);
}
}

self.moveItemUp = function(list, item) {
}
self.getBtnClass = function (type) {
return `btn-${typeof type === 'function' ? type() : type}`;
}
self.moveItemUp = function (list, item) {
var i = list().indexOf(item);
if (i > 0) {
var rawList = list();
list.splice(i-1, 2, rawList[i], rawList[i-1]);
var rawList = list();
list.splice(i - 1, 2, rawList[i], rawList[i - 1]);
}
}
}
}
OCTOPRINT_VIEWMODELS.push({
construct: MacroSettingsViewModel,
Expand Down
71 changes: 46 additions & 25 deletions octoprint_macro/templates/macro_settings.jinja2
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
<form class="form-horizontal">
<legend>Settings:</legend>
<div class="control-group">
<label class="control-label">{{ _('Columns:')}}</label>
<label for="mCC" class="control-label">{{ _('Columns:')}}</label>
<div class="controls">
<div class="row-fluid">
<input type="number" class="span2 input-block-level" data-bind="value: settings.settings.plugins.macro.column" />
<input id="mCC" type="number" class="span2 input-block-level" data-bind="value: settings.settings.plugins.macro.column" />
</div>
</div>
</div>
<legend>List:</legend>
<div data-bind="foreach: settings.settings.plugins.macro.macros" style="margin-bottom: 12px">
<div class="control-group">
<label class="control-label">{{ _('Name') }}</label>
<label data-bind="attr: { 'for': $parent.bindFor('mName', $context) }" class="control-label">{{ _('Name') }}</label>
<div class="controls">
<div class="row-fluid">
<div class="span4">
<input type="text" class="input-block-level" data-bind="value: name"/>
<input data-bind="value: name, attr: { 'id': $parent.bindFor('mName', $context) }" type="text" class="input-block-level"/>
</div>
<div class="span4">
<select data-bind="value: type">
<option value="default">Default</option>
<option value="primary">Primary</option>
<option value="info">Info</option>
<option value="success">Success</option>
<option value="danger">Danger</option>
<option value="warning">Warning</option>
</select>
</div>
<div class="span1">
<input type="checkbox" class="input-block-level" data-bind="checked: active"/>
<div class="span5">
</div>
<div class="span2">
<a href='#' data-bind='click: $parent.moveMacroUp' class="fa fa-chevron-up"></a>
Expand All @@ -36,20 +27,50 @@
</div>
</div>
</div>
<label class="control-label">{{ _('Command') }}</label>
<div class="controls macro-mb20">
<div class="row-fluid">
<div class="span8">
<textarea rows="4" class="block" data-bind="value: macro">
</textarea>
<div class="control-group">
<label class="control-label">{{ _('Settings') }}</label>
<div class="controls">
<div class="span4">
{{ _('Active:') }} <input type="checkbox" data-bind="checked: active"/>
</div>
<div class="span4">
{{ _('Disabled when printing:') }} <input type="checkbox" data-bind="checked: dop"/>
</div>
</div>
</div>
<div class="control-group">
<label class="control-label" data-bind="attr: { 'for': $parent.bindFor('mColor', $context) }">{{ _('Color') }}</label>
<div class="controls">
<div class="input-append">
<select data-bind="attr: { 'id': $parent.bindFor('mColor', $context) }, value: type">
<option value="default">Default</option>
<option value="primary">Primary</option>
<option value="info">Info</option>
<option value="success">Success</option>
<option value="danger">Danger</option>
<option value="warning">Warning</option>
</select>
<button class="btn" data-bind="css: $parent.getBtnClass(type)">&nbsp;</button>
</div>
<div class="span2"></div>
</div>
</div>
</div>
<div class="control-group">
<label class="control-label" data-bind="attr: { 'for': $parent.bindFor('mCommand', $context) }">{{ _('Command') }}</label>
<div class="controls">
<div class="row-fluid">
<div class="span8">
<textarea rows="4" class="block" data-bind="attr: { 'id': $parent.bindFor('mCommand', $context) }, value: macro">
</textarea>
</div>
<div class="span2"></div>
</div>
</div>
</div>
<hr>
</div>
<div class="control-group">
<div class="controls">
<button data-bind='click: addMacro' type="button"><i class="fa fa-plus-circle"></i> {{ _('Add Macro') }}</button>
<button class="btn btn-secondary" data-bind='click: addMacro' type="button"><i class="fa fa-plus-circle"></i> {{ _('Add Macro') }}</button>
</div>
</div>
</form>
2 changes: 1 addition & 1 deletion octoprint_macro/templates/macro_sidebar.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="controls">
<div class="macro-btn" data-bind="css: getClass(), foreach: settings.settings.plugins.macro.macros">
<!-- ko if: active -->
<button class="btn btn-block" data-bind="css: $parent.getBtnClass(type), text: name, click: $parent.executeMacro, enable: $parent.isActive()"></button>
<button class="btn btn-block" data-bind="css: $parent.getBtnClass(type), text: name, click: $parent.executeMacro, enable: $parent.isActive($data)"></button>
<!-- /ko -->
</div>
</div>
Expand Down

0 comments on commit 63a83e8

Please sign in to comment.