Scanning inputs refactor (#974)

* Add support for count nodes

* Add support for menu button
This commit is contained in:
toasted-nutbread 2020-10-31 13:40:10 -04:00 committed by GitHub
parent bcf06105d6
commit ab98caf842
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,6 +26,7 @@ class ScanInputsController {
this._os = null; this._os = null;
this._container = null; this._container = null;
this._addButton = null; this._addButton = null;
this._scanningInputCountNodes = null;
this._entries = []; this._entries = [];
} }
@ -35,6 +36,7 @@ class ScanInputsController {
this._container = document.querySelector('#scan-input-list'); this._container = document.querySelector('#scan-input-list');
this._addButton = document.querySelector('#scan-input-add'); this._addButton = document.querySelector('#scan-input-add');
this._scanningInputCountNodes = document.querySelectorAll('.scanning-input-count');
this._addButton.addEventListener('click', this._onAddButtonClick.bind(this), false); this._addButton.addEventListener('click', this._onAddButtonClick.bind(this), false);
this._settingsController.on('scanInputsChanged', this._onScanInputsChanged.bind(this)); this._settingsController.on('scanInputsChanged', this._onScanInputsChanged.bind(this));
@ -94,6 +96,8 @@ class ScanInputsController {
const {include, exclude} = inputs[i]; const {include, exclude} = inputs[i];
this._addOption(i, include, exclude); this._addOption(i, include, exclude);
} }
this._updateCounts();
} }
_onAddButtonClick(e) { _onAddButtonClick(e) {
@ -103,6 +107,7 @@ class ScanInputsController {
const include = ''; const include = '';
const exclude = ''; const exclude = '';
this._addOption(index, include, exclude); this._addOption(index, include, exclude);
this._updateCounts();
this._modifyProfileSettings([{ this._modifyProfileSettings([{
action: 'splice', action: 'splice',
path: 'scanning.inputs', path: 'scanning.inputs',
@ -118,6 +123,13 @@ class ScanInputsController {
field.prepare(this._container, include, exclude); field.prepare(this._container, include, exclude);
} }
_updateCounts() {
const stringValue = `${this._entries.length}`;
for (const node of this._scanningInputCountNodes) {
node.textContent = stringValue;
}
}
async _modifyProfileSettings(targets) { async _modifyProfileSettings(targets) {
await this._settingsController.modifyProfileSettings(targets); await this._settingsController.modifyProfileSettings(targets);
this._settingsController.trigger('scanInputsChanged', {source: this}); this._settingsController.trigger('scanInputsChanged', {source: this});
@ -169,6 +181,7 @@ class ScanInputField {
const excludeInputNode = node.querySelector('.scan-input-field[data-property=exclude]'); const excludeInputNode = node.querySelector('.scan-input-field[data-property=exclude]');
const excludeMouseButton = node.querySelector('.mouse-button[data-property=exclude]'); const excludeMouseButton = node.querySelector('.mouse-button[data-property=exclude]');
const removeButton = node.querySelector('.scan-input-remove'); const removeButton = node.querySelector('.scan-input-remove');
const menuButton = node.querySelector('.scanning-input-menu-button');
this._node = node; this._node = node;
container.appendChild(node); container.appendChild(node);
@ -181,7 +194,12 @@ class ScanInputField {
this._eventListeners.on(this._includeInputField, 'change', this._onIncludeValueChange.bind(this)); this._eventListeners.on(this._includeInputField, 'change', this._onIncludeValueChange.bind(this));
this._eventListeners.on(this._excludeInputField, 'change', this._onExcludeValueChange.bind(this)); this._eventListeners.on(this._excludeInputField, 'change', this._onExcludeValueChange.bind(this));
if (removeButton !== null) {
this._eventListeners.addEventListener(removeButton, 'click', this._onRemoveClick.bind(this)); this._eventListeners.addEventListener(removeButton, 'click', this._onRemoveClick.bind(this));
}
if (menuButton !== null) {
this._eventListeners.addEventListener(menuButton, 'menuClosed', this._onMenuClosed.bind(this));
}
this._updateDataSettingTargets(); this._updateDataSettingTargets();
} }
@ -209,7 +227,15 @@ class ScanInputField {
_onRemoveClick(e) { _onRemoveClick(e) {
e.preventDefault(); e.preventDefault();
this._parent.removeInput(this._index); this._removeSelf();
}
_onMenuClosed({detail: {action}}) {
switch (action) {
case 'remove':
this._removeSelf();
break;
}
} }
_isPointerTypeSupported(pointerType) { _isPointerTypeSupported(pointerType) {
@ -225,4 +251,8 @@ class ScanInputField {
typeCheckbox.dataset.setting = `scanning.inputs[${index}].${property}`; typeCheckbox.dataset.setting = `scanning.inputs[${index}].${property}`;
} }
} }
_removeSelf() {
this._parent.removeInput(this._index);
}
} }