unit coluns in telem tables, need to add config options for those columns

This commit is contained in:
Jamie Vigliotta 2020-07-13 14:24:51 -07:00
parent 0d9558b891
commit d7c266d70f
8 changed files with 183 additions and 11 deletions

View File

@ -41,6 +41,7 @@ define([
{
key: "sin",
name: "Sine",
unit: "Hz",
formatString: '%0.2f',
hints: {
range: 1
@ -49,6 +50,7 @@ define([
{
key: "cos",
name: "Cosine",
unit: "deg",
formatString: '%0.2f',
hints: {
range: 2

View File

@ -134,6 +134,13 @@ define(['lodash'], function (_) {
return `configuration.items[${selectionPath[0].context.index}]`;
}
function getAllOfType(selection, specificType) {
return selection.filter(selectionPath => {
let type = selectionPath[0].context.layoutItem.type;
return type === specificType;
});
}
function getAllTypes(selection) {
return selection.filter(selectionPath => {
let type = selectionPath[0].context.layoutItem.type;
@ -506,6 +513,32 @@ define(['lodash'], function (_) {
return allTelemetry;
}
function getToggleUnitsButton(selectedParent, selection) {
let applicableItems = getAllOfType(selection, 'telemetry-view');
return {
control: "toggle-button",
domainObject: selectedParent,
applicableSelectedItems: applicableItems,
contextMethod: 'toggleUnits',
property: function (selectionPath) {
console.log('path', selectionPath, getPath(selectionPath) + '.showUnits');
return getPath(selectionPath) + '.showUnits';
},
options: [
{
value: true,
icon: 'icon-eye-open',
title: "Show units"
},
{
value: false,
icon: 'icon-eye-disabled',
title: "Hide units"
}
]
};
}
function getViewSwitcherMenu(selectedParent, selectionPath, selection) {
if (selection.length === 1) {
let displayLayoutContext = selectionPath[1].context,
@ -589,6 +622,7 @@ define(['lodash'], function (_) {
'text-style': [],
'position': [],
'duplicate': [],
'unit-toggle': [],
'remove': []
};
@ -649,6 +683,9 @@ define(['lodash'], function (_) {
if (toolbar.viewSwitcher.length === 0) {
toolbar.viewSwitcher = [getViewSwitcherMenu(selectedParent, selectionPath, selectedObjects)];
}
if (toolbar['unit-toggle'].length === 0) {
toolbar['unit-toggle'] = [getToggleUnitsButton(selectedParent, selectedObjects)];
}
} else if (layoutItem.type === 'text-view') {
if (toolbar['text-style'].length === 0) {
toolbar['text-style'] = [

View File

@ -52,6 +52,12 @@
>
<div class="c-telemetry-view__value-text">
{{ telemetryValue }}
<span
v-if="unit && showUnits"
class="c-telemetry-view__value-text__unit"
>
{{ unit }}
</span>
</div>
</div>
</div>
@ -117,7 +123,8 @@ export default {
datum: undefined,
formats: undefined,
domainObject: undefined,
currentObjectPath: undefined
currentObjectPath: undefined,
showUnits: true
}
},
computed: {
@ -129,6 +136,11 @@ export default {
let displayMode = this.item.displayMode;
return displayMode === 'all' || displayMode === 'value';
},
unit() {
let value = this.item.value,
unit = this.metadata.value(value).unit;
return unit;
},
styleObject() {
return Object.assign({}, {
fontSize: this.item.size
@ -248,7 +260,9 @@ export default {
item: domainObject,
layoutItem: this.item,
index: this.index,
updateTelemetryFormat: this.updateTelemetryFormat
updateTelemetryFormat: this.updateTelemetryFormat,
toggleUnits: this.toggleUnits,
showUnits: this.showUnits
};
this.removeSelectable = this.openmct.selection.selectable(
this.$el, this.context, this.immediatelySelect || this.initSelect);
@ -259,6 +273,9 @@ export default {
},
showContextMenu(event) {
this.openmct.contextMenu._showContextMenuForObjectPath(this.currentObjectPath, event.x, event.y, CONTEXT_MENU_ACTIONS);
},
toggleUnits(show) {
this.showUnits = show;
}
}
}

View File

@ -27,6 +27,7 @@ define([
'./collections/FilteredTableRowCollection',
'./TelemetryTableRow',
'./TelemetryTableColumn',
'./TelemetryTableUnitColumn',
'./TelemetryTableConfiguration'
], function (
EventEmitter,
@ -35,6 +36,7 @@ define([
FilteredTableRowCollection,
TelemetryTableRow,
TelemetryTableColumn,
TelemetryTableUnitColumn,
TelemetryTableConfiguration
) {
class TelemetryTable extends EventEmitter {
@ -206,10 +208,14 @@ define([
addColumnsForObject(telemetryObject) {
let metadataValues = this.openmct.telemetry.getMetadata(telemetryObject).values();
metadataValues.forEach(metadatum => {
let column = this.createColumn(metadatum);
this.configuration.addSingleColumnForObject(telemetryObject, column);
// add units column if available
if(metadatum.unit !== undefined) {
let unitColumn = this.createUnitColumn(metadatum);
this.configuration.addSingleColumnForObject(telemetryObject, unitColumn);
}
});
}
@ -217,6 +223,47 @@ define([
return new TelemetryTableColumn(this.openmct, metadatum);
}
createUnitColumn(metadatum) {
return new TelemetryTableUnitColumn(this.openmct, metadatum);
// let unitColumn = {
// isUnit: true,
// metadatum,
// titleValue: metadatum.name + ' Unit',
// selectable: false,
// formatter: {
// format(telemetryDatum) {
// return metadatum.unit;
// },
// parse(telemetryDatum) {
// return metadatum.unit;
// }
// },
// getKey() {
// return this.metadatum.key + '-unit';
// },
// getTitle() {
// return this.titleValue;
// },
// getMetadatum() {
// return this.metadatum;
// },
// hasValueForDatum(telemetryDatum) {
// return telemetryDatum.hasOwnProperty(this.metadatum.source);
// },
// getRawValue(telemetryDatum) {
// return this.metadatum.unit;
// },
// getFormattedValue(telemetryDatum) {
// return this.formatter.format(telemetryDatum);
// },
// getParsedValue(telemetryDatum) {
// return this.formatter.parse(telemetryDatum);
// }
// };
// return unitColumn;
}
subscribeTo(telemetryObject) {
let subscribeOptions = this.buildOptionsFromConfiguration(telemetryObject);
let keyString = this.openmct.objects.makeKeyString(telemetryObject.identifier);

View File

@ -65,8 +65,10 @@ define([], function () {
getCellLimitClasses() {
if (!this.cellLimitClasses) {
this.cellLimitClasses = Object.values(this.columns).reduce((alarmStateMap, column) => {
let limitEvaluation = this.limitEvaluator.evaluate(this.datum, column.getMetadatum());
alarmStateMap[column.getKey()] = limitEvaluation && limitEvaluation.cssClass;
if(!column.isUnit) {
let limitEvaluation = this.limitEvaluator.evaluate(this.datum, column.getMetadatum());
alarmStateMap[column.getKey()] = limitEvaluation && limitEvaluation.cssClass;
}
return alarmStateMap;
}, {});

View File

@ -0,0 +1,64 @@
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2018, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT is licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* Open MCT includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
define([
'./TelemetryTableColumn.js'
], function (
TelemetryTableColumn
) {
class TelemetryTableUnitColumn extends TelemetryTableColumn {
constructor(openmct, metadatum) {
super(openmct, metadatum);
this.isUnit = true;
this.titleValue += ' Unit';
this.formatter = {
format(datum) {
return metadatum.unit;
},
parse(datum) {
return metadatum.unit;
}
};
}
getKey() {
return this.metadatum.key + '-unit';
}
getTitle() {
return this.metadatum.name + ' Unit';
}
getRawValue(telemetryDatum) {
return this.metadatum.unit;
}
getFormattedValue(telemetryDatum) {
return this.formatter.format(telemetryDatum);
}
getParsedValue(telemetryDatum) {
return this.formatter.parse(telemetryDatum);
}
}
return TelemetryTableUnitColumn;
});

View File

@ -80,6 +80,7 @@ export default {
}
},
mounted() {
console.log('table-config mounted');
this.unlisteners = [];
this.openmct.editor.on('isEditing', this.toggleEdit);
let compositionCollection = this.openmct.composition.get(this.tableConfiguration.domainObject);
@ -131,7 +132,7 @@ export default {
},
addColumnsForObject(telemetryObject) {
let metadataValues = this.openmct.telemetry.getMetadata(telemetryObject).values();
console.log(metadataValues);
metadataValues.forEach(metadatum => {
let column = new TelemetryTableColumn(this.openmct, metadatum);
this.tableConfiguration.addSingleColumnForObject(telemetryObject, column);

View File

@ -134,7 +134,6 @@ export default {
value = this.getFormValue(domainObject, toolbarItem);
} else {
let values = [];
if (applicableSelectedItems) {
applicableSelectedItems.forEach(selectionPath => {
values.push(this.getPropertyValue(domainObject, toolbarItem, selectionPath));
@ -160,7 +159,6 @@ export default {
if (formKey) {
property = property + "." + formKey;
}
return _.get(domainObject, property);
},
getFormValue(domainObject, toolbarItem) {
@ -204,7 +202,6 @@ export default {
},
updateObjectValue(value, item) {
let changedItemId = this.openmct.objects.makeKeyString(item.domainObject.identifier);
this.structure = this.structure.map(toolbarItem => {
if (toolbarItem.domainObject) {
let id = this.openmct.objects.makeKeyString(toolbarItem.domainObject.identifier);
@ -234,7 +231,13 @@ export default {
}
});
} else {
if (item.applicableSelectedItems) {
if(item.contextMethod) {
let method = item.contextMethod;
item.applicableSelectedItems.forEach(selectionPath => {
this.mutateObject(item, value, selectionPath);
selectionPath[0].context[method](value);
});
} else if (item.applicableSelectedItems) {
item.applicableSelectedItems.forEach(selectionPath => {
this.mutateObject(item, value, selectionPath);
});
@ -249,7 +252,6 @@ export default {
if (formKey) {
property = property + "." + formKey;
}
this.openmct.objects.mutate(item.domainObject, property, value);
},
triggerMethod(item, event) {