Auto-correct lint errors (#2450)

* Auto-fixed linting errors and manually corrected spacing on some comments
This commit is contained in:
Andrew Henry 2019-08-27 09:26:58 -07:00 committed by GitHub
parent 3dc6dac12d
commit 974be0ae2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 284 additions and 284 deletions

View File

@ -97,7 +97,7 @@ define(
this.$timeout(() => { this.$timeout(() => {
// Create the overlay element and add it to the document's body // Create the overlay element and add it to the document's body
element = this.$compile(TEMPLATE)(scope); 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 // 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. // multiple overlays with the same z-index are active.
this.findBody().append(element); this.findBody().append(element);

View File

@ -129,7 +129,7 @@ define([
return priority; return priority;
} }
}; };
}; }
return LegacyViewProvider; return LegacyViewProvider;

View File

@ -102,7 +102,7 @@ define([
} }
} }
}; };
}; }
return TypeInspectorViewProvider; return TypeInspectorViewProvider;

View File

@ -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. * of the application and allow for customization of the application.
* @param {BrandingOptions} options * @param {BrandingOptions} options
*/ */

View File

@ -42,7 +42,7 @@ import EventEmitter from 'EventEmitter';
* *
* @typedef {object} NotificationModel * @typedef {object} NotificationModel
* @property {string} message The message to be displayed by the notification * @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'. * with the string literal 'unknown'.
* @property {string} [progressText] A message conveying progress of some ongoing task. * @property {string} [progressText] A message conveying progress of some ongoing task.

View File

@ -329,7 +329,7 @@ define([
hints: { hints: {
priority: 2 priority: 2
} }
}, },
{ {
key: "timestamp", key: "timestamp",
@ -365,7 +365,7 @@ define([
{ {
key: "name", key: "name",
name: "Name" name: "Name"
}, },
{ {
key: "timestamp", key: "timestamp",
@ -392,7 +392,7 @@ define([
{ {
key: "name", key: "name",
name: "Name" name: "Name"
}, },
{ {
key: "timestamp-utc", key: "timestamp-utc",
@ -434,7 +434,7 @@ define([
{ {
key: "name", key: "name",
name: "Name" name: "Name"
}, },
{ {
key: "timestamp-utc", key: "timestamp-utc",
@ -486,7 +486,7 @@ define([
hints: { hints: {
priority: 1 priority: 1
} }
}, },
{ {
key: "timestamp-utc", key: "timestamp-utc",

View File

@ -32,6 +32,6 @@ class CSVExporter {
let blob = new Blob([csvText], { type: "text/csv" }); let blob = new Blob([csvText], { type: "text/csv" });
saveAs(blob, filename); saveAs(blob, filename);
} }
}; }
export default CSVExporter; export default CSVExporter;

View File

@ -29,7 +29,7 @@ define([
function isTelemetryObject(selectionPath) { function isTelemetryObject(selectionPath) {
let selectedObject = selectionPath[0].context.item; let selectedObject = selectionPath[0].context.item;
let parentObject = selectionPath[1].context.item; let parentObject = selectionPath[1].context.item;
return parentObject && return parentObject &&
parentObject.type === 'layout' && parentObject.type === 'layout' &&
selectedObject && selectedObject &&
openmct.telemetry.isTelemetryObject(selectedObject) && openmct.telemetry.isTelemetryObject(selectedObject) &&
@ -75,4 +75,4 @@ define([
} }
return AlphanumericFormatViewProvider; return AlphanumericFormatViewProvider;
}); });

View File

@ -140,7 +140,7 @@ define([], function () {
return { return {
control: "toggle-button", control: "toggle-button",
domainObject: selectedParent, domainObject: selectedParent,
applicableSelectedItems: selection.filter(selectionPath => applicableSelectedItems: selection.filter(selectionPath =>
selectionPath[0].context.layoutItem.type === 'subobject-view' selectionPath[0].context.layoutItem.type === 'subobject-view'
), ),
property: function (selectionPath) { property: function (selectionPath) {
@ -254,7 +254,7 @@ define([], function () {
return getPath(selectionPath) + ".y"; return getPath(selectionPath) + ".y";
}, },
label: "Y:", label: "Y:",
title: "Y position", title: "Y position"
}; };
} }
} }
@ -322,7 +322,7 @@ define([], function () {
return getPath(selectionPath) + ".y2"; return getPath(selectionPath) + ".y2";
}, },
label: "Y2:", label: "Y2:",
title: "Y2 position", title: "Y2 position"
}; };
} }
} }
@ -416,24 +416,24 @@ define([], function () {
}, },
icon: "icon-image", icon: "icon-image",
title: "Edit image properties", title: "Edit image properties",
dialog: DIALOG_FORM['image'] dialog: DIALOG_FORM.image
}; };
} }
function getTextButton(selectedParent, selection) { function getTextButton(selectedParent, selection) {
return { return {
control: "button", control: "button",
domainObject: selectedParent, domainObject: selectedParent,
applicableSelectedItems: selection.filter(selectionPath => { applicableSelectedItems: selection.filter(selectionPath => {
return selectionPath[0].context.layoutItem.type === 'text-view'; return selectionPath[0].context.layoutItem.type === 'text-view';
}), }),
property: function (selectionPath) { property: function (selectionPath) {
return getPath(selectionPath); return getPath(selectionPath);
}, },
icon: "icon-gear", icon: "icon-gear",
title: "Edit text properties", title: "Edit text properties",
dialog: DIALOG_FORM['text'] dialog: DIALOG_FORM.text
}; };
} }
function getTelemetryValueMenu(selectionPath, selection) { function getTelemetryValueMenu(selectionPath, selection) {
@ -514,7 +514,7 @@ define([], function () {
'position': [], 'position': [],
'text': [], 'text': [],
'url': [], 'url': [],
'remove': [], 'remove': []
}; };
selection.forEach(selectionPath => { selection.forEach(selectionPath => {
@ -528,8 +528,8 @@ define([], function () {
if (toolbar['toggle-frame'].length === 0) { if (toolbar['toggle-frame'].length === 0) {
toolbar['toggle-frame'] = [getToggleFrameButton(selectedParent, selection)]; toolbar['toggle-frame'] = [getToggleFrameButton(selectedParent, selection)];
} }
if (toolbar['position'].length === 0) { if (toolbar.position.length === 0) {
toolbar['position'] = [ toolbar.position = [
getStackOrder(selectedParent, selectionPath), getStackOrder(selectedParent, selectionPath),
getXInput(selectedParent, selection), getXInput(selectedParent, selection),
getYInput(selectedParent, selection), getYInput(selectedParent, selection),
@ -537,8 +537,8 @@ define([], function () {
getWidthInput(selectedParent, selection) getWidthInput(selectedParent, selection)
]; ];
} }
if (toolbar['remove'].length === 0) { if (toolbar.remove.length === 0) {
toolbar['remove'] = [getRemoveButton(selectedParent, selectionPath, selection)]; toolbar.remove = [getRemoveButton(selectedParent, selectionPath, selection)];
} }
} else if (layoutItem.type === 'telemetry-view') { } else if (layoutItem.type === 'telemetry-view') {
if (toolbar['display-mode'].length === 0) { if (toolbar['display-mode'].length === 0) {
@ -547,8 +547,8 @@ define([], function () {
if (toolbar['telemetry-value'].length === 0) { if (toolbar['telemetry-value'].length === 0) {
toolbar['telemetry-value'] = [getTelemetryValueMenu(selectionPath, selection)]; toolbar['telemetry-value'] = [getTelemetryValueMenu(selectionPath, selection)];
} }
if (toolbar['style'].length < 2) { if (toolbar.style.length < 2) {
toolbar['style'] = [ toolbar.style = [
getFillMenu(selectedParent, selection), getFillMenu(selectedParent, selection),
getStrokeMenu(selectedParent, selection) getStrokeMenu(selectedParent, selection)
]; ];
@ -559,8 +559,8 @@ define([], function () {
getTextSizeMenu(selectedParent, selection) getTextSizeMenu(selectedParent, selection)
]; ];
} }
if (toolbar['position'].length === 0) { if (toolbar.position.length === 0) {
toolbar['position'] = [ toolbar.position = [
getStackOrder(selectedParent, selectionPath), getStackOrder(selectedParent, selectionPath),
getXInput(selectedParent, selection), getXInput(selectedParent, selection),
getYInput(selectedParent, selection), getYInput(selectedParent, selection),
@ -568,12 +568,12 @@ define([], function () {
getWidthInput(selectedParent, selection) getWidthInput(selectedParent, selection)
]; ];
} }
if (toolbar['remove'].length === 0) { if (toolbar.remove.length === 0) {
toolbar['remove'] = [getRemoveButton(selectedParent, selectionPath, selection)]; toolbar.remove = [getRemoveButton(selectedParent, selectionPath, selection)];
} }
} else if (layoutItem.type === 'text-view') { } else if (layoutItem.type === 'text-view') {
if (toolbar['style'].length < 2) { if (toolbar.style.length < 2) {
toolbar['style'] = [ toolbar.style = [
getFillMenu(selectedParent, selection), getFillMenu(selectedParent, selection),
getStrokeMenu(selectedParent, selection) getStrokeMenu(selectedParent, selection)
]; ];
@ -584,8 +584,8 @@ define([], function () {
getTextSizeMenu(selectedParent, selection) getTextSizeMenu(selectedParent, selection)
]; ];
} }
if (toolbar['position'].length === 0) { if (toolbar.position.length === 0) {
toolbar['position'] = [ toolbar.position = [
getStackOrder(selectedParent, selectionPath), getStackOrder(selectedParent, selectionPath),
getXInput(selectedParent, selection), getXInput(selectedParent, selection),
getYInput(selectedParent, selection), getYInput(selectedParent, selection),
@ -593,21 +593,21 @@ define([], function () {
getWidthInput(selectedParent, selection) getWidthInput(selectedParent, selection)
]; ];
} }
if (toolbar['text'].length === 0) { if (toolbar.text.length === 0) {
toolbar['text'] = [getTextButton(selectedParent, selection)]; toolbar.text = [getTextButton(selectedParent, selection)];
} }
if (toolbar['remove'].length === 0) { if (toolbar.remove.length === 0) {
toolbar['remove'] = [getRemoveButton(selectedParent, selectionPath, selection)]; toolbar.remove = [getRemoveButton(selectedParent, selectionPath, selection)];
} }
} else if (layoutItem.type === 'box-view') { } else if (layoutItem.type === 'box-view') {
if (toolbar['style'].length < 2) { if (toolbar.style.length < 2) {
toolbar['style'] = [ toolbar.style = [
getFillMenu(selectedParent, selection), getFillMenu(selectedParent, selection),
getStrokeMenu(selectedParent, selection) getStrokeMenu(selectedParent, selection)
]; ];
} }
if (toolbar['position'].length === 0) { if (toolbar.position.length === 0) {
toolbar['position'] = [ toolbar.position = [
getStackOrder(selectedParent, selectionPath), getStackOrder(selectedParent, selectionPath),
getXInput(selectedParent, selection), getXInput(selectedParent, selection),
getYInput(selectedParent, selection), getYInput(selectedParent, selection),
@ -615,17 +615,17 @@ define([], function () {
getWidthInput(selectedParent, selection) getWidthInput(selectedParent, selection)
]; ];
} }
if (toolbar['remove'].length === 0) { if (toolbar.remove.length === 0) {
toolbar['remove'] = [getRemoveButton(selectedParent, selectionPath, selection)]; toolbar.remove = [getRemoveButton(selectedParent, selectionPath, selection)];
} }
} else if (layoutItem.type === 'image-view') { } else if (layoutItem.type === 'image-view') {
if (toolbar['style'].length === 0) { if (toolbar.style.length === 0) {
toolbar['style'] = [ toolbar.style = [
getStrokeMenu(selectedParent, selection) getStrokeMenu(selectedParent, selection)
]; ];
} }
if (toolbar['position'].length === 0) { if (toolbar.position.length === 0) {
toolbar['position'] = [ toolbar.position = [
getStackOrder(selectedParent, selectionPath), getStackOrder(selectedParent, selectionPath),
getXInput(selectedParent, selection), getXInput(selectedParent, selection),
getYInput(selectedParent, selection), getYInput(selectedParent, selection),
@ -633,20 +633,20 @@ define([], function () {
getWidthInput(selectedParent, selection) getWidthInput(selectedParent, selection)
]; ];
} }
if (toolbar['url'].length === 0) { if (toolbar.url.length === 0) {
toolbar['url'] = [getURLButton(selectedParent, selection)]; toolbar.url = [getURLButton(selectedParent, selection)];
} }
if (toolbar['remove'].length === 0) { if (toolbar.remove.length === 0) {
toolbar['remove'] = [getRemoveButton(selectedParent, selectionPath, selection)]; toolbar.remove = [getRemoveButton(selectedParent, selectionPath, selection)];
} }
} else if (layoutItem.type === 'line-view') { } else if (layoutItem.type === 'line-view') {
if (toolbar['style'].length === 0) { if (toolbar.style.length === 0) {
toolbar['style'] = [ toolbar.style = [
getStrokeMenu(selectedParent, selection) getStrokeMenu(selectedParent, selection)
]; ];
} }
if (toolbar['position'].length === 0) { if (toolbar.position.length === 0) {
toolbar['position'] = [ toolbar.position = [
getStackOrder(selectedParent, selectionPath), getStackOrder(selectedParent, selectionPath),
getXInput(selectedParent, selection), getXInput(selectedParent, selection),
getYInput(selectedParent, selection), getYInput(selectedParent, selection),
@ -654,8 +654,8 @@ define([], function () {
getY2Input(selectedParent, selection) getY2Input(selectedParent, selection)
]; ];
} }
if (toolbar['remove'].length === 0) { if (toolbar.remove.length === 0) {
toolbar['remove'] = [getRemoveButton(selectedParent, selectionPath, selection)]; toolbar.remove = [getRemoveButton(selectedParent, selectionPath, selection)];
} }
} }
}); });

View File

@ -31,7 +31,7 @@ define(function () {
domainObject.composition = []; domainObject.composition = [];
domainObject.configuration = { domainObject.configuration = {
items: [], items: [],
layoutGrid: [10, 10], layoutGrid: [10, 10]
}; };
}, },
form: [ form: [

View File

@ -53,7 +53,7 @@ export default function DisplayLayoutPlugin(options) {
objectPath objectPath
}, },
el: container, el: container,
data () { data() {
return { return {
domainObject: domainObject domainObject: domainObject
}; };

View File

@ -1,7 +1,7 @@
import uuid from 'uuid'; import uuid from 'uuid';
class Container { class Container {
constructor (size) { constructor(size) {
this.id = uuid(); this.id = uuid();
this.frames = []; this.frames = [];
this.size = size; this.size = size;

View File

@ -27,7 +27,7 @@ function (
Moment Moment
) { ) {
function EntryController (openmct, domainObject) { function EntryController(openmct, domainObject) {
this.openmct = openmct; this.openmct = openmct;
this.domainObject = domainObject; this.domainObject = domainObject;
@ -111,7 +111,7 @@ function (
domainObject = objectPath[0], domainObject = objectPath[0],
domainObjectKey = domainObject.identifier.key, domainObjectKey = domainObject.identifier.key,
domainObjectType = this.openmct.types.get(domainObject.type), domainObjectType = this.openmct.types.get(domainObject.type),
cssClass = domainObjectType && domainObjectType.definition ? cssClass = domainObjectType && domainObjectType.definition ?
domainObjectType.definition.cssClass : 'icon-object-unknown', domainObjectType.definition.cssClass : 'icon-object-unknown',
entryPos = this.entryPosById(entryid), entryPos = this.entryPosById(entryid),
currentEntryEmbeds = this.domainObject.entries[entryPos].embeds, currentEntryEmbeds = this.domainObject.entries[entryPos].embeds,

View File

@ -21,7 +21,7 @@
*****************************************************************************/ *****************************************************************************/
define(function () { define(function () {
class TelemetryTableColumn { class TelemetryTableColumn {
constructor (openmct, metadatum, options = {selectable: false}) { constructor(openmct, metadatum, options = {selectable: false}) {
this.metadatum = metadatum; this.metadatum = metadatum;
this.formatter = openmct.telemetry.getValueFormatter(metadatum); this.formatter = openmct.telemetry.getValueFormatter(metadatum);
this.titleValue = this.metadatum.name; this.titleValue = this.metadatum.name;

View File

@ -58,7 +58,7 @@ define([
/** /**
* @private * @private
* @param {*} object * @param {*} object
*/ */
objectMutated(object) { objectMutated(object) {
//Synchronize domain object reference. Duplicate object otherwise change detection becomes impossible. //Synchronize domain object reference. Duplicate object otherwise change detection becomes impossible.

View File

@ -79,7 +79,7 @@ define([], function () {
* Maps all sources to keys. * Maps all sources to keys.
* @private * @private
* @param {*} telemetryDatum * @param {*} telemetryDatum
* @param {*} metadataValues * @param {*} metadataValues
*/ */
function createNormalizedDatum(datum, columns) { function createNormalizedDatum(datum, columns) {
return Object.values(columns).reduce((normalizedDatum, column) => { return Object.values(columns).reduce((normalizedDatum, column) => {

View File

@ -60,7 +60,7 @@ define([
} }
}, },
components: { components: {
TableComponent: TableComponent.default, TableComponent: TableComponent.default
}, },
provide: { provide: {
openmct, openmct,

View File

@ -37,7 +37,7 @@ define(
//Synchronize with master collection //Synchronize with master collection
this.masterCollection.on('add', this.add); this.masterCollection.on('add', this.add);
this.masterCollection.on('remove', this.remove); this.masterCollection.on('remove', this.remove);
//Default to master collection's sort options //Default to master collection's sort options
this.sortOptions = masterCollection.sortBy(); this.sortOptions = masterCollection.sortBy();
} }
@ -70,9 +70,9 @@ define(
* @private * @private
*/ */
isSubsetOfCurrentFilter(columnKey, filter) { isSubsetOfCurrentFilter(columnKey, filter) {
return this.columnFilters[columnKey] && return this.columnFilters[columnKey] &&
filter.startsWith(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 // because anyString.startsWith('') === true
filter !== ''; filter !== '';
} }
@ -91,8 +91,8 @@ define(
return false; return false;
} else { } else {
let formattedValue = row.getFormattedValue(key).toLowerCase(); let formattedValue = row.getFormattedValue(key).toLowerCase();
doesMatchFilters = doesMatchFilters && doesMatchFilters = doesMatchFilters &&
formattedValue.indexOf(this.columnFilters[key]) !== -1; formattedValue.indexOf(this.columnFilters[key]) !== -1;
} }
} }
return doesMatchFilters; return doesMatchFilters;
@ -109,4 +109,4 @@ define(
} }
return FilteredTableRowCollection; return FilteredTableRowCollection;
}); });

View File

@ -37,7 +37,7 @@ define(
* @constructor * @constructor
*/ */
class SortedTableRowCollection extends EventEmitter { class SortedTableRowCollection extends EventEmitter {
constructor () { constructor() {
super(); super();
this.dupeCheck = false; this.dupeCheck = false;

View File

@ -28,213 +28,213 @@ define(
function ( function (
EventEmitter, EventEmitter,
_ _
) { ) {
/** /**
* Manages selection state for Open MCT * Manages selection state for Open MCT
* @private * @private
*/ */
function Selection(openmct) { function Selection(openmct) {
EventEmitter.call(this); EventEmitter.call(this);
this.openmct = openmct; this.openmct = openmct;
this.selected = []; 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];
} }
let multiSelect = isMultiSelectEvent && Selection.prototype = Object.create(EventEmitter.prototype);
this.parentSupportsMultiSelect(selectable) &&
this.isPeer(selectable) &&
!this.selectionContainsParent(selectable);
if (multiSelect) { /**
this.handleMultiSelect(selectable); * Gets the selected object.
} else { * @public
this.setSelectionStyles(selectable); */
this.selected = [selectable]; Selection.prototype.get = function () {
} return this.selected;
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
}; };
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) { * Selects the selectable object and emits the 'change' event.
context.item = newItem; *
}); * @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) { let multiSelect = isMultiSelectEvent &&
element.click(); this.parentSupportsMultiSelect(selectable) &&
} this.isPeer(selectable) &&
!this.selectionContainsParent(selectable);
return function () { if (multiSelect) {
element.removeEventListener('click', capture, true); this.handleMultiSelect(selectable);
element.removeEventListener('click', selectCapture); } else {
this.setSelectionStyles(selectable);
this.selected = [selectable];
}
if (unlisten) { this.emit('change', this.selected);
unlisten(); };
/**
* @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;
});

View File

@ -25,5 +25,5 @@ export default {
}, },
destroyed() { destroyed() {
document.removeEventListener('click', this.toggle); document.removeEventListener('click', this.toggle);
}, }
} }

View File

@ -195,7 +195,7 @@ define(['EventEmitter'], function (EventEmitter) {
* OR * OR
* * Return a {@link openmct.View} from the `view` function defining a read-only view. * * Return a {@link openmct.View} from the `view` function defining a read-only view.
* AND * 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. * editing-specific view.
* *
* @method canEdit * @method canEdit