From c073a21ba6ad87ea8420f0f92868193354d245c9 Mon Sep 17 00:00:00 2001 From: Andrew Henry Date: Wed, 7 Nov 2018 11:04:56 -0800 Subject: [PATCH] [Table] Custom column widths and order (#2204) * Renders with resize hotzones * Implemented basic reordering of columns * Refactored column headers into component * Custom column widths persist during resize * Initial working version of fixed column sizes * Only calculate default sizes when first data received. * Further fixes for fixed column widths. Add option to switch to auto-widths * Fixed bug with table auto-sizing * Only allow reorder and resize in edit mode * Bug fixes * Allow for scroll bar width * Bug fix with tables reverting to 100% width * Fixed bug with drop position indicator when scrolled * Moved events on to component * Do not throttle mouse events. Let Vue throttle them * Do not hard code vertical offset for drop target * Addressed review issues * Clarified mouse event handling on column resize --- .../TelemetryTableConfiguration.js | 48 +++- .../telemetryTable/TelemetryTableType.js | 3 +- .../components/table-column-header.vue | 182 +++++++++++++ .../components/table-configuration.vue | 13 +- .../telemetryTable/components/table-row.vue | 33 ++- .../telemetryTable/components/table.vue | 246 ++++++++++++++---- 6 files changed, 450 insertions(+), 75 deletions(-) create mode 100644 src/plugins/telemetryTable/components/table-column-header.vue diff --git a/src/plugins/telemetryTable/TelemetryTableConfiguration.js b/src/plugins/telemetryTable/TelemetryTableConfiguration.js index c6d5cb6219..f4df3dfc12 100644 --- a/src/plugins/telemetryTable/TelemetryTableConfiguration.js +++ b/src/plugins/telemetryTable/TelemetryTableConfiguration.js @@ -46,6 +46,10 @@ define([ getConfiguration() { let configuration = this.domainObject.configuration || {}; configuration.hiddenColumns = configuration.hiddenColumns || {}; + configuration.columnWidths = configuration.columnWidths || {}; + configuration.columnOrder = configuration.columnOrder || []; + configuration.autosize = configuration.autosize === undefined ? true : configuration.autosize; + return configuration; } @@ -113,7 +117,7 @@ define([ let headers = _.uniq(flattenedColumns, false, column => column.getKey()) .reduce(fromColumnsToHeadersMap, {}); - function fromColumnsToHeadersMap(headersMap, column){ + function fromColumnsToHeadersMap(headersMap, column) { headersMap[column.getKey()] = column.getTitle(); return headersMap; } @@ -122,16 +126,42 @@ define([ } getVisibleHeaders() { - let headers = this.getAllHeaders(); + let allHeaders = this.getAllHeaders(); let configuration = this.getConfiguration(); - Object.keys(headers).forEach((headerKey) => { - if (configuration.hiddenColumns[headerKey] === true) { - delete headers[headerKey]; - } - }); + let orderedColumns = this.getColumnOrder(); + let unorderedColumns = _.difference(Object.keys(allHeaders), orderedColumns); - return headers; + return orderedColumns.concat(unorderedColumns) + .filter((headerKey) => { + return configuration.hiddenColumns[headerKey] !== true; + }) + .reduce((headers, headerKey) => { + headers[headerKey] = allHeaders[headerKey]; + return headers; + }, {}); + } + + getColumnWidths() { + let configuration = this.getConfiguration(); + return configuration.columnWidths; + } + + setColumnWidths(columnWidths) { + let configuration = this.getConfiguration(); + configuration.columnWidths = columnWidths; + this.updateConfiguration(configuration); + } + + getColumnOrder() { + let configuration = this.getConfiguration(); + return configuration.columnOrder; + } + + setColumnOrder(columnOrder) { + let configuration = this.getConfiguration(); + configuration.columnOrder = columnOrder; + this.updateConfiguration(configuration); } destroy() { @@ -140,4 +170,4 @@ define([ } return TelemetryTableConfiguration; -}); \ No newline at end of file +}); diff --git a/src/plugins/telemetryTable/TelemetryTableType.js b/src/plugins/telemetryTable/TelemetryTableType.js index fcb382d0bf..08099a719c 100644 --- a/src/plugins/telemetryTable/TelemetryTableType.js +++ b/src/plugins/telemetryTable/TelemetryTableType.js @@ -29,7 +29,8 @@ define(function () { initialize(domainObject) { domainObject.composition = []; domainObject.configuration = { - columns: {} + columnWidths: {}, + hiddenColumns: {} }; } }; diff --git a/src/plugins/telemetryTable/components/table-column-header.vue b/src/plugins/telemetryTable/components/table-column-header.vue new file mode 100644 index 0000000000..3c706d08a9 --- /dev/null +++ b/src/plugins/telemetryTable/components/table-column-header.vue @@ -0,0 +1,182 @@ +/***************************************************************************** + * 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. + *****************************************************************************/ + + + \ No newline at end of file diff --git a/src/plugins/telemetryTable/components/table-configuration.vue b/src/plugins/telemetryTable/components/table-configuration.vue index 18946993f0..2d308cf659 100644 --- a/src/plugins/telemetryTable/components/table-configuration.vue +++ b/src/plugins/telemetryTable/components/table-configuration.vue @@ -1,6 +1,13 @@