From 974be0ae2c0f98a9b4d1ce2a77867ac22872a111 Mon Sep 17 00:00:00 2001 From: Andrew Henry Date: Tue, 27 Aug 2019 09:26:58 -0700 Subject: [PATCH] Auto-correct lint errors (#2450) * Auto-fixed linting errors and manually corrected spacing on some comments --- .../commonUI/dialog/src/OverlayService.js | 2 +- src/adapter/views/LegacyViewProvider.js | 2 +- .../views/TypeInspectorViewProvider.js | 2 +- src/api/Branding.js | 2 +- src/api/notifications/NotificationAPI.js | 2 +- src/api/telemetry/TelemetryAPISpec.js | 10 +- src/exporters/CSVExporter.js | 2 +- .../AlphanumericFormatViewProvider.js | 4 +- .../displayLayout/DisplayLayoutToolbar.js | 112 ++--- .../displayLayout/DisplayLayoutType.js | 2 +- src/plugins/displayLayout/plugin.js | 2 +- src/plugins/flexibleLayout/utils/container.js | 2 +- .../src/controllers/EntryController.js | 4 +- .../telemetryTable/TelemetryTableColumn.js | 2 +- .../TelemetryTableConfiguration.js | 2 +- .../telemetryTable/TelemetryTableRow.js | 2 +- .../TelemetryTableViewProvider.js | 2 +- .../collections/FilteredTableRowCollection.js | 12 +- .../collections/SortedTableRowCollection.js | 2 +- src/selection/Selection.js | 394 +++++++++--------- src/ui/mixins/toggle-mixin.js | 2 +- src/ui/registries/ViewRegistry.js | 2 +- 22 files changed, 284 insertions(+), 284 deletions(-) diff --git a/platform/commonUI/dialog/src/OverlayService.js b/platform/commonUI/dialog/src/OverlayService.js index 05ead9f6c6..5780f00b80 100644 --- a/platform/commonUI/dialog/src/OverlayService.js +++ b/platform/commonUI/dialog/src/OverlayService.js @@ -97,7 +97,7 @@ define( this.$timeout(() => { // Create the overlay element and add it to the document's body element = this.$compile(TEMPLATE)(scope); - + // Append so that most recent dialog is last in DOM. This means the most recent dialog will be on top when // multiple overlays with the same z-index are active. this.findBody().append(element); diff --git a/src/adapter/views/LegacyViewProvider.js b/src/adapter/views/LegacyViewProvider.js index 96ca51235d..da7a388a98 100644 --- a/src/adapter/views/LegacyViewProvider.js +++ b/src/adapter/views/LegacyViewProvider.js @@ -129,7 +129,7 @@ define([ return priority; } }; - }; + } return LegacyViewProvider; diff --git a/src/adapter/views/TypeInspectorViewProvider.js b/src/adapter/views/TypeInspectorViewProvider.js index 5a1d832106..fedb861221 100644 --- a/src/adapter/views/TypeInspectorViewProvider.js +++ b/src/adapter/views/TypeInspectorViewProvider.js @@ -102,7 +102,7 @@ define([ } } }; - }; + } return TypeInspectorViewProvider; diff --git a/src/api/Branding.js b/src/api/Branding.js index 84890335b5..c7af9168f7 100644 --- a/src/api/Branding.js +++ b/src/api/Branding.js @@ -33,7 +33,7 @@ let brandingOptions = {}; */ /** - * Set branding options for the application. These will override certain visual elements + * Set branding options for the application. These will override certain visual elements * of the application and allow for customization of the application. * @param {BrandingOptions} options */ diff --git a/src/api/notifications/NotificationAPI.js b/src/api/notifications/NotificationAPI.js index a579d31138..505af91b47 100644 --- a/src/api/notifications/NotificationAPI.js +++ b/src/api/notifications/NotificationAPI.js @@ -42,7 +42,7 @@ import EventEmitter from 'EventEmitter'; * * @typedef {object} NotificationModel * @property {string} message The message to be displayed by the notification - * @property {number | 'unknown'} [progress] The progres of some ongoing task. Should be a number between 0 and 100, or + * @property {number | 'unknown'} [progress] The progres of some ongoing task. Should be a number between 0 and 100, or * with the string literal 'unknown'. * @property {string} [progressText] A message conveying progress of some ongoing task. diff --git a/src/api/telemetry/TelemetryAPISpec.js b/src/api/telemetry/TelemetryAPISpec.js index 7b123253a3..2ddf167e7f 100644 --- a/src/api/telemetry/TelemetryAPISpec.js +++ b/src/api/telemetry/TelemetryAPISpec.js @@ -329,7 +329,7 @@ define([ hints: { priority: 2 } - + }, { key: "timestamp", @@ -365,7 +365,7 @@ define([ { key: "name", name: "Name" - + }, { key: "timestamp", @@ -392,7 +392,7 @@ define([ { key: "name", name: "Name" - + }, { key: "timestamp-utc", @@ -434,7 +434,7 @@ define([ { key: "name", name: "Name" - + }, { key: "timestamp-utc", @@ -486,7 +486,7 @@ define([ hints: { priority: 1 } - + }, { key: "timestamp-utc", diff --git a/src/exporters/CSVExporter.js b/src/exporters/CSVExporter.js index e1fba993ae..a959b5c28e 100644 --- a/src/exporters/CSVExporter.js +++ b/src/exporters/CSVExporter.js @@ -32,6 +32,6 @@ class CSVExporter { let blob = new Blob([csvText], { type: "text/csv" }); saveAs(blob, filename); } -}; +} export default CSVExporter; diff --git a/src/plugins/displayLayout/AlphanumericFormatViewProvider.js b/src/plugins/displayLayout/AlphanumericFormatViewProvider.js index ab1cc2fdc2..49a651b064 100644 --- a/src/plugins/displayLayout/AlphanumericFormatViewProvider.js +++ b/src/plugins/displayLayout/AlphanumericFormatViewProvider.js @@ -29,7 +29,7 @@ define([ function isTelemetryObject(selectionPath) { let selectedObject = selectionPath[0].context.item; let parentObject = selectionPath[1].context.item; - return parentObject && + return parentObject && parentObject.type === 'layout' && selectedObject && openmct.telemetry.isTelemetryObject(selectedObject) && @@ -75,4 +75,4 @@ define([ } return AlphanumericFormatViewProvider; -}); \ No newline at end of file +}); diff --git a/src/plugins/displayLayout/DisplayLayoutToolbar.js b/src/plugins/displayLayout/DisplayLayoutToolbar.js index 44e298ad64..180b088da5 100644 --- a/src/plugins/displayLayout/DisplayLayoutToolbar.js +++ b/src/plugins/displayLayout/DisplayLayoutToolbar.js @@ -140,7 +140,7 @@ define([], function () { return { control: "toggle-button", domainObject: selectedParent, - applicableSelectedItems: selection.filter(selectionPath => + applicableSelectedItems: selection.filter(selectionPath => selectionPath[0].context.layoutItem.type === 'subobject-view' ), property: function (selectionPath) { @@ -254,7 +254,7 @@ define([], function () { return getPath(selectionPath) + ".y"; }, label: "Y:", - title: "Y position", + title: "Y position" }; } } @@ -322,7 +322,7 @@ define([], function () { return getPath(selectionPath) + ".y2"; }, label: "Y2:", - title: "Y2 position", + title: "Y2 position" }; } } @@ -416,24 +416,24 @@ define([], function () { }, icon: "icon-image", title: "Edit image properties", - dialog: DIALOG_FORM['image'] + dialog: DIALOG_FORM.image }; } function getTextButton(selectedParent, selection) { - return { - control: "button", - domainObject: selectedParent, - applicableSelectedItems: selection.filter(selectionPath => { - return selectionPath[0].context.layoutItem.type === 'text-view'; - }), - property: function (selectionPath) { - return getPath(selectionPath); - }, - icon: "icon-gear", - title: "Edit text properties", - dialog: DIALOG_FORM['text'] - }; + return { + control: "button", + domainObject: selectedParent, + applicableSelectedItems: selection.filter(selectionPath => { + return selectionPath[0].context.layoutItem.type === 'text-view'; + }), + property: function (selectionPath) { + return getPath(selectionPath); + }, + icon: "icon-gear", + title: "Edit text properties", + dialog: DIALOG_FORM.text + }; } function getTelemetryValueMenu(selectionPath, selection) { @@ -514,7 +514,7 @@ define([], function () { 'position': [], 'text': [], 'url': [], - 'remove': [], + 'remove': [] }; selection.forEach(selectionPath => { @@ -528,8 +528,8 @@ define([], function () { if (toolbar['toggle-frame'].length === 0) { toolbar['toggle-frame'] = [getToggleFrameButton(selectedParent, selection)]; } - if (toolbar['position'].length === 0) { - toolbar['position'] = [ + if (toolbar.position.length === 0) { + toolbar.position = [ getStackOrder(selectedParent, selectionPath), getXInput(selectedParent, selection), getYInput(selectedParent, selection), @@ -537,8 +537,8 @@ define([], function () { getWidthInput(selectedParent, selection) ]; } - if (toolbar['remove'].length === 0) { - toolbar['remove'] = [getRemoveButton(selectedParent, selectionPath, selection)]; + if (toolbar.remove.length === 0) { + toolbar.remove = [getRemoveButton(selectedParent, selectionPath, selection)]; } } else if (layoutItem.type === 'telemetry-view') { if (toolbar['display-mode'].length === 0) { @@ -547,8 +547,8 @@ define([], function () { if (toolbar['telemetry-value'].length === 0) { toolbar['telemetry-value'] = [getTelemetryValueMenu(selectionPath, selection)]; } - if (toolbar['style'].length < 2) { - toolbar['style'] = [ + if (toolbar.style.length < 2) { + toolbar.style = [ getFillMenu(selectedParent, selection), getStrokeMenu(selectedParent, selection) ]; @@ -559,8 +559,8 @@ define([], function () { getTextSizeMenu(selectedParent, selection) ]; } - if (toolbar['position'].length === 0) { - toolbar['position'] = [ + if (toolbar.position.length === 0) { + toolbar.position = [ getStackOrder(selectedParent, selectionPath), getXInput(selectedParent, selection), getYInput(selectedParent, selection), @@ -568,12 +568,12 @@ define([], function () { getWidthInput(selectedParent, selection) ]; } - if (toolbar['remove'].length === 0) { - toolbar['remove'] = [getRemoveButton(selectedParent, selectionPath, selection)]; + if (toolbar.remove.length === 0) { + toolbar.remove = [getRemoveButton(selectedParent, selectionPath, selection)]; } } else if (layoutItem.type === 'text-view') { - if (toolbar['style'].length < 2) { - toolbar['style'] = [ + if (toolbar.style.length < 2) { + toolbar.style = [ getFillMenu(selectedParent, selection), getStrokeMenu(selectedParent, selection) ]; @@ -584,8 +584,8 @@ define([], function () { getTextSizeMenu(selectedParent, selection) ]; } - if (toolbar['position'].length === 0) { - toolbar['position'] = [ + if (toolbar.position.length === 0) { + toolbar.position = [ getStackOrder(selectedParent, selectionPath), getXInput(selectedParent, selection), getYInput(selectedParent, selection), @@ -593,21 +593,21 @@ define([], function () { getWidthInput(selectedParent, selection) ]; } - if (toolbar['text'].length === 0) { - toolbar['text'] = [getTextButton(selectedParent, selection)]; + if (toolbar.text.length === 0) { + toolbar.text = [getTextButton(selectedParent, selection)]; } - if (toolbar['remove'].length === 0) { - toolbar['remove'] = [getRemoveButton(selectedParent, selectionPath, selection)]; + if (toolbar.remove.length === 0) { + toolbar.remove = [getRemoveButton(selectedParent, selectionPath, selection)]; } } else if (layoutItem.type === 'box-view') { - if (toolbar['style'].length < 2) { - toolbar['style'] = [ + if (toolbar.style.length < 2) { + toolbar.style = [ getFillMenu(selectedParent, selection), getStrokeMenu(selectedParent, selection) ]; } - if (toolbar['position'].length === 0) { - toolbar['position'] = [ + if (toolbar.position.length === 0) { + toolbar.position = [ getStackOrder(selectedParent, selectionPath), getXInput(selectedParent, selection), getYInput(selectedParent, selection), @@ -615,17 +615,17 @@ define([], function () { getWidthInput(selectedParent, selection) ]; } - if (toolbar['remove'].length === 0) { - toolbar['remove'] = [getRemoveButton(selectedParent, selectionPath, selection)]; + if (toolbar.remove.length === 0) { + toolbar.remove = [getRemoveButton(selectedParent, selectionPath, selection)]; } } else if (layoutItem.type === 'image-view') { - if (toolbar['style'].length === 0) { - toolbar['style'] = [ + if (toolbar.style.length === 0) { + toolbar.style = [ getStrokeMenu(selectedParent, selection) ]; } - if (toolbar['position'].length === 0) { - toolbar['position'] = [ + if (toolbar.position.length === 0) { + toolbar.position = [ getStackOrder(selectedParent, selectionPath), getXInput(selectedParent, selection), getYInput(selectedParent, selection), @@ -633,20 +633,20 @@ define([], function () { getWidthInput(selectedParent, selection) ]; } - if (toolbar['url'].length === 0) { - toolbar['url'] = [getURLButton(selectedParent, selection)]; + if (toolbar.url.length === 0) { + toolbar.url = [getURLButton(selectedParent, selection)]; } - if (toolbar['remove'].length === 0) { - toolbar['remove'] = [getRemoveButton(selectedParent, selectionPath, selection)]; + if (toolbar.remove.length === 0) { + toolbar.remove = [getRemoveButton(selectedParent, selectionPath, selection)]; } } else if (layoutItem.type === 'line-view') { - if (toolbar['style'].length === 0) { - toolbar['style'] = [ + if (toolbar.style.length === 0) { + toolbar.style = [ getStrokeMenu(selectedParent, selection) ]; } - if (toolbar['position'].length === 0) { - toolbar['position'] = [ + if (toolbar.position.length === 0) { + toolbar.position = [ getStackOrder(selectedParent, selectionPath), getXInput(selectedParent, selection), getYInput(selectedParent, selection), @@ -654,8 +654,8 @@ define([], function () { getY2Input(selectedParent, selection) ]; } - if (toolbar['remove'].length === 0) { - toolbar['remove'] = [getRemoveButton(selectedParent, selectionPath, selection)]; + if (toolbar.remove.length === 0) { + toolbar.remove = [getRemoveButton(selectedParent, selectionPath, selection)]; } } }); diff --git a/src/plugins/displayLayout/DisplayLayoutType.js b/src/plugins/displayLayout/DisplayLayoutType.js index 7f9289dd6e..8841635c85 100644 --- a/src/plugins/displayLayout/DisplayLayoutType.js +++ b/src/plugins/displayLayout/DisplayLayoutType.js @@ -31,7 +31,7 @@ define(function () { domainObject.composition = []; domainObject.configuration = { items: [], - layoutGrid: [10, 10], + layoutGrid: [10, 10] }; }, form: [ diff --git a/src/plugins/displayLayout/plugin.js b/src/plugins/displayLayout/plugin.js index ab36cf4fa8..250d128f09 100644 --- a/src/plugins/displayLayout/plugin.js +++ b/src/plugins/displayLayout/plugin.js @@ -53,7 +53,7 @@ export default function DisplayLayoutPlugin(options) { objectPath }, el: container, - data () { + data() { return { domainObject: domainObject }; diff --git a/src/plugins/flexibleLayout/utils/container.js b/src/plugins/flexibleLayout/utils/container.js index ec351b8ade..9ee51b2255 100644 --- a/src/plugins/flexibleLayout/utils/container.js +++ b/src/plugins/flexibleLayout/utils/container.js @@ -1,7 +1,7 @@ import uuid from 'uuid'; class Container { - constructor (size) { + constructor(size) { this.id = uuid(); this.frames = []; this.size = size; diff --git a/src/plugins/notebook/src/controllers/EntryController.js b/src/plugins/notebook/src/controllers/EntryController.js index fbfd780370..a64253c9f8 100644 --- a/src/plugins/notebook/src/controllers/EntryController.js +++ b/src/plugins/notebook/src/controllers/EntryController.js @@ -27,7 +27,7 @@ function ( Moment ) { - function EntryController (openmct, domainObject) { + function EntryController(openmct, domainObject) { this.openmct = openmct; this.domainObject = domainObject; @@ -111,7 +111,7 @@ function ( domainObject = objectPath[0], domainObjectKey = domainObject.identifier.key, domainObjectType = this.openmct.types.get(domainObject.type), - cssClass = domainObjectType && domainObjectType.definition ? + cssClass = domainObjectType && domainObjectType.definition ? domainObjectType.definition.cssClass : 'icon-object-unknown', entryPos = this.entryPosById(entryid), currentEntryEmbeds = this.domainObject.entries[entryPos].embeds, diff --git a/src/plugins/telemetryTable/TelemetryTableColumn.js b/src/plugins/telemetryTable/TelemetryTableColumn.js index ad157832c4..c517bb1336 100644 --- a/src/plugins/telemetryTable/TelemetryTableColumn.js +++ b/src/plugins/telemetryTable/TelemetryTableColumn.js @@ -21,7 +21,7 @@ *****************************************************************************/ define(function () { class TelemetryTableColumn { - constructor (openmct, metadatum, options = {selectable: false}) { + constructor(openmct, metadatum, options = {selectable: false}) { this.metadatum = metadatum; this.formatter = openmct.telemetry.getValueFormatter(metadatum); this.titleValue = this.metadatum.name; diff --git a/src/plugins/telemetryTable/TelemetryTableConfiguration.js b/src/plugins/telemetryTable/TelemetryTableConfiguration.js index d2c81b8235..5946779c4d 100644 --- a/src/plugins/telemetryTable/TelemetryTableConfiguration.js +++ b/src/plugins/telemetryTable/TelemetryTableConfiguration.js @@ -58,7 +58,7 @@ define([ /** * @private - * @param {*} object + * @param {*} object */ objectMutated(object) { //Synchronize domain object reference. Duplicate object otherwise change detection becomes impossible. diff --git a/src/plugins/telemetryTable/TelemetryTableRow.js b/src/plugins/telemetryTable/TelemetryTableRow.js index 3b12144a10..33f2195e8d 100644 --- a/src/plugins/telemetryTable/TelemetryTableRow.js +++ b/src/plugins/telemetryTable/TelemetryTableRow.js @@ -79,7 +79,7 @@ define([], function () { * Maps all sources to keys. * @private * @param {*} telemetryDatum - * @param {*} metadataValues + * @param {*} metadataValues */ function createNormalizedDatum(datum, columns) { return Object.values(columns).reduce((normalizedDatum, column) => { diff --git a/src/plugins/telemetryTable/TelemetryTableViewProvider.js b/src/plugins/telemetryTable/TelemetryTableViewProvider.js index faf82ccc1c..051fe18df7 100644 --- a/src/plugins/telemetryTable/TelemetryTableViewProvider.js +++ b/src/plugins/telemetryTable/TelemetryTableViewProvider.js @@ -60,7 +60,7 @@ define([ } }, components: { - TableComponent: TableComponent.default, + TableComponent: TableComponent.default }, provide: { openmct, diff --git a/src/plugins/telemetryTable/collections/FilteredTableRowCollection.js b/src/plugins/telemetryTable/collections/FilteredTableRowCollection.js index 14f866fb49..15d3387a50 100644 --- a/src/plugins/telemetryTable/collections/FilteredTableRowCollection.js +++ b/src/plugins/telemetryTable/collections/FilteredTableRowCollection.js @@ -37,7 +37,7 @@ define( //Synchronize with master collection this.masterCollection.on('add', this.add); this.masterCollection.on('remove', this.remove); - + //Default to master collection's sort options this.sortOptions = masterCollection.sortBy(); } @@ -70,9 +70,9 @@ define( * @private */ isSubsetOfCurrentFilter(columnKey, filter) { - return this.columnFilters[columnKey] && + return this.columnFilters[columnKey] && filter.startsWith(this.columnFilters[columnKey]) && - // startsWith check will otherwise fail when filter cleared + // startsWith check will otherwise fail when filter cleared // because anyString.startsWith('') === true filter !== ''; } @@ -91,8 +91,8 @@ define( return false; } else { let formattedValue = row.getFormattedValue(key).toLowerCase(); - doesMatchFilters = doesMatchFilters && - formattedValue.indexOf(this.columnFilters[key]) !== -1; + doesMatchFilters = doesMatchFilters && + formattedValue.indexOf(this.columnFilters[key]) !== -1; } } return doesMatchFilters; @@ -109,4 +109,4 @@ define( } return FilteredTableRowCollection; - }); \ No newline at end of file + }); diff --git a/src/plugins/telemetryTable/collections/SortedTableRowCollection.js b/src/plugins/telemetryTable/collections/SortedTableRowCollection.js index 82b953fcfd..cded96cf09 100644 --- a/src/plugins/telemetryTable/collections/SortedTableRowCollection.js +++ b/src/plugins/telemetryTable/collections/SortedTableRowCollection.js @@ -37,7 +37,7 @@ define( * @constructor */ class SortedTableRowCollection extends EventEmitter { - constructor () { + constructor() { super(); this.dupeCheck = false; diff --git a/src/selection/Selection.js b/src/selection/Selection.js index 0231e54b60..7e8354c6dd 100644 --- a/src/selection/Selection.js +++ b/src/selection/Selection.js @@ -28,213 +28,213 @@ define( function ( EventEmitter, _ -) { + ) { - /** - * Manages selection state for Open MCT - * @private - */ - function Selection(openmct) { - EventEmitter.call(this); + /** + * Manages selection state for Open MCT + * @private + */ + function Selection(openmct) { + EventEmitter.call(this); - this.openmct = openmct; - this.selected = []; - } - - Selection.prototype = Object.create(EventEmitter.prototype); - - /** - * Gets the selected object. - * @public - */ - Selection.prototype.get = function () { - return this.selected; - }; - - /** - * Selects the selectable object and emits the 'change' event. - * - * @param {object} selectable an object with element and context properties - * @param {Boolean} isMultiSelectEvent flag indication shift key is pressed or not - * @private - */ - Selection.prototype.select = function (selectable, isMultiSelectEvent) { - if (!Array.isArray(selectable)) { - selectable = [selectable]; + this.openmct = openmct; + this.selected = []; } - let multiSelect = isMultiSelectEvent && - this.parentSupportsMultiSelect(selectable) && - this.isPeer(selectable) && - !this.selectionContainsParent(selectable); + Selection.prototype = Object.create(EventEmitter.prototype); - if (multiSelect) { - this.handleMultiSelect(selectable); - } else { - this.setSelectionStyles(selectable); - this.selected = [selectable]; - } - - this.emit('change', this.selected); - }; - - /** - * @private - */ - Selection.prototype.handleMultiSelect = function (selectable) { - if (this.elementSelected(selectable)) { - this.remove(selectable); - } else { - this.addSelectionAttributes(selectable); - this.selected.push(selectable); - } - }; - - /** - * @private - */ - Selection.prototype.elementSelected = function (selectable) { - return this.selected.some(selectionPath => _.isEqual(selectionPath, selectable)); - }; - - /** - * @private - */ - Selection.prototype.remove = function (selectable) { - this.selected = this.selected.filter(selectionPath => !_.isEqual(selectionPath, selectable)); - - if (this.selected.length === 0) { - this.removeSelectionAttributes(selectable); - selectable[1].element.click(); // Select the parent if there is no selection. - } else { - this.removeSelectionAttributes(selectable, true); - } - }; - - /** - * @private - */ - Selection.prototype.setSelectionStyles = function (selectable) { - this.selected.map(selectionPath => { - this.removeSelectionAttributes(selectionPath); - }); - this.addSelectionAttributes(selectable); - }; - - Selection.prototype.removeSelectionAttributes = function (selectionPath, keepParentStyle) { - if (selectionPath[0] && selectionPath[0].element) { - selectionPath[0].element.removeAttribute('s-selected'); - } - - if (selectionPath[1] && selectionPath[1].element && !keepParentStyle) { - selectionPath[1].element.removeAttribute('s-selected-parent'); - } - }; - - /* - * Adds selection attributes to the selected element and its parent. - * @private - */ - Selection.prototype.addSelectionAttributes = function (selectable) { - if (selectable[0] && selectable[0].element) { - selectable[0].element.setAttribute('s-selected', ""); - } - - if (selectable[1] && selectable[1].element) { - selectable[1].element.setAttribute('s-selected-parent', ""); - } - }; - - /** - * @private - */ - Selection.prototype.parentSupportsMultiSelect = function (selectable) { - return selectable[1] && selectable[1].context.supportsMultiSelect; - }; - - /** - * @private - */ - Selection.prototype.selectionContainsParent = function (selectable) { - return this.selected.some(selectionPath => _.isEqual(selectionPath[0], selectable[1])); - }; - - /** - * @private - */ - Selection.prototype.isPeer = function (selectable) { - return this.selected.some(selectionPath => _.isEqual(selectionPath[1], selectable[1])); - }; - - /** - * @private - */ - Selection.prototype.capture = function (selectable) { - let capturingContainsSelectable = this.capturing && this.capturing.includes(selectable); - - if (!this.capturing || capturingContainsSelectable) { - this.capturing = []; - } - - this.capturing.push(selectable); - }; - - /** - * @private - */ - Selection.prototype.selectCapture = function (selectable, event) { - if (!this.capturing) { - return; - } - - let reversedCapturing = this.capturing.reverse(); - delete this.capturing; - this.select(reversedCapturing, event.shiftKey); - }; - - /** - * Attaches the click handlers to the element. - * - * @param element an html element - * @param context object which defines item or other arbitrary properties. - * e.g. { - * item: domainObject, - * elementProxy: element, - * controller: fixedController - * } - * @param select a flag to select the element if true - * @returns a function that removes the click handlers from the element - * @public - */ - Selection.prototype.selectable = function (element, context, select) { - let selectable = { - context: context, - element: element + /** + * Gets the selected object. + * @public + */ + Selection.prototype.get = function () { + return this.selected; }; - var capture = this.capture.bind(this, selectable); - var selectCapture = this.selectCapture.bind(this, selectable); - element.addEventListener('click', capture, true); - element.addEventListener('click', selectCapture); - if (context.item) { - var unlisten = this.openmct.objects.observe(context.item, "*", function (newItem) { - context.item = newItem; - }); - } + /** + * Selects the selectable object and emits the 'change' event. + * + * @param {object} selectable an object with element and context properties + * @param {Boolean} isMultiSelectEvent flag indication shift key is pressed or not + * @private + */ + Selection.prototype.select = function (selectable, isMultiSelectEvent) { + if (!Array.isArray(selectable)) { + selectable = [selectable]; + } - if (select) { - element.click(); - } + let multiSelect = isMultiSelectEvent && + this.parentSupportsMultiSelect(selectable) && + this.isPeer(selectable) && + !this.selectionContainsParent(selectable); - return function () { - element.removeEventListener('click', capture, true); - element.removeEventListener('click', selectCapture); + if (multiSelect) { + this.handleMultiSelect(selectable); + } else { + this.setSelectionStyles(selectable); + this.selected = [selectable]; + } - if (unlisten) { - unlisten(); + this.emit('change', this.selected); + }; + + /** + * @private + */ + Selection.prototype.handleMultiSelect = function (selectable) { + if (this.elementSelected(selectable)) { + this.remove(selectable); + } else { + this.addSelectionAttributes(selectable); + this.selected.push(selectable); } }; - }; - return Selection; -}); + /** + * @private + */ + Selection.prototype.elementSelected = function (selectable) { + return this.selected.some(selectionPath => _.isEqual(selectionPath, selectable)); + }; + + /** + * @private + */ + Selection.prototype.remove = function (selectable) { + this.selected = this.selected.filter(selectionPath => !_.isEqual(selectionPath, selectable)); + + if (this.selected.length === 0) { + this.removeSelectionAttributes(selectable); + selectable[1].element.click(); // Select the parent if there is no selection. + } else { + this.removeSelectionAttributes(selectable, true); + } + }; + + /** + * @private + */ + Selection.prototype.setSelectionStyles = function (selectable) { + this.selected.map(selectionPath => { + this.removeSelectionAttributes(selectionPath); + }); + this.addSelectionAttributes(selectable); + }; + + Selection.prototype.removeSelectionAttributes = function (selectionPath, keepParentStyle) { + if (selectionPath[0] && selectionPath[0].element) { + selectionPath[0].element.removeAttribute('s-selected'); + } + + if (selectionPath[1] && selectionPath[1].element && !keepParentStyle) { + selectionPath[1].element.removeAttribute('s-selected-parent'); + } + }; + + /* + * Adds selection attributes to the selected element and its parent. + * @private + */ + Selection.prototype.addSelectionAttributes = function (selectable) { + if (selectable[0] && selectable[0].element) { + selectable[0].element.setAttribute('s-selected', ""); + } + + if (selectable[1] && selectable[1].element) { + selectable[1].element.setAttribute('s-selected-parent', ""); + } + }; + + /** + * @private + */ + Selection.prototype.parentSupportsMultiSelect = function (selectable) { + return selectable[1] && selectable[1].context.supportsMultiSelect; + }; + + /** + * @private + */ + Selection.prototype.selectionContainsParent = function (selectable) { + return this.selected.some(selectionPath => _.isEqual(selectionPath[0], selectable[1])); + }; + + /** + * @private + */ + Selection.prototype.isPeer = function (selectable) { + return this.selected.some(selectionPath => _.isEqual(selectionPath[1], selectable[1])); + }; + + /** + * @private + */ + Selection.prototype.capture = function (selectable) { + let capturingContainsSelectable = this.capturing && this.capturing.includes(selectable); + + if (!this.capturing || capturingContainsSelectable) { + this.capturing = []; + } + + this.capturing.push(selectable); + }; + + /** + * @private + */ + Selection.prototype.selectCapture = function (selectable, event) { + if (!this.capturing) { + return; + } + + let reversedCapturing = this.capturing.reverse(); + delete this.capturing; + this.select(reversedCapturing, event.shiftKey); + }; + + /** + * Attaches the click handlers to the element. + * + * @param element an html element + * @param context object which defines item or other arbitrary properties. + * e.g. { + * item: domainObject, + * elementProxy: element, + * controller: fixedController + * } + * @param select a flag to select the element if true + * @returns a function that removes the click handlers from the element + * @public + */ + Selection.prototype.selectable = function (element, context, select) { + let selectable = { + context: context, + element: element + }; + var capture = this.capture.bind(this, selectable); + var selectCapture = this.selectCapture.bind(this, selectable); + element.addEventListener('click', capture, true); + element.addEventListener('click', selectCapture); + + if (context.item) { + var unlisten = this.openmct.objects.observe(context.item, "*", function (newItem) { + context.item = newItem; + }); + } + + if (select) { + element.click(); + } + + return function () { + element.removeEventListener('click', capture, true); + element.removeEventListener('click', selectCapture); + + if (unlisten) { + unlisten(); + } + }; + }; + + return Selection; + }); diff --git a/src/ui/mixins/toggle-mixin.js b/src/ui/mixins/toggle-mixin.js index 9985c1aeed..779f65677d 100644 --- a/src/ui/mixins/toggle-mixin.js +++ b/src/ui/mixins/toggle-mixin.js @@ -25,5 +25,5 @@ export default { }, destroyed() { document.removeEventListener('click', this.toggle); - }, + } } diff --git a/src/ui/registries/ViewRegistry.js b/src/ui/registries/ViewRegistry.js index b8a754b1c4..ed8b3e3f0c 100644 --- a/src/ui/registries/ViewRegistry.js +++ b/src/ui/registries/ViewRegistry.js @@ -195,7 +195,7 @@ define(['EventEmitter'], function (EventEmitter) { * OR * * Return a {@link openmct.View} from the `view` function defining a read-only view. * AND - * * Define an {@link openmct.ViewProvider#Edit} function on the view provider that returns an + * * Define an {@link openmct.ViewProvider#Edit} function on the view provider that returns an * editing-specific view. * * @method canEdit