From b383921f2a913b6a64a95a6a4866b286c80978f6 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen <victor.woeltjen@nasa.gov> Date: Mon, 7 Mar 2016 16:00:13 -0800 Subject: [PATCH] [Timeline] Export start/end to CSV --- .../src/actions/ExportTimelineAsCSVTask.js | 12 +++-- .../src/actions/TimelineCSVExporter.js | 24 ++++++---- .../timeline/src/actions/TimespanColumn.js | 44 +++++++++++++++++++ 3 files changed, 65 insertions(+), 15 deletions(-) create mode 100644 platform/features/timeline/src/actions/TimespanColumn.js diff --git a/platform/features/timeline/src/actions/ExportTimelineAsCSVTask.js b/platform/features/timeline/src/actions/ExportTimelineAsCSVTask.js index 77f0702497..8a0b60ca94 100644 --- a/platform/features/timeline/src/actions/ExportTimelineAsCSVTask.js +++ b/platform/features/timeline/src/actions/ExportTimelineAsCSVTask.js @@ -41,16 +41,14 @@ define([ this.exportService = exportService; } - ExportTimelineAsCSVTask.prototype.run = function (progress) { - var name = this.domainObject.getModel().name, - exportService = this.exportService; + ExportTimelineAsCSVTask.prototype.run = function () { + var exportService = this.exportService; function doExport(objects) { var exporter = new TimelineCSVExporter(objects); - return exportService.exportCSV( - exporter.rows(), - exporter.options() - ); + return exporter.rows().then(function (rows) { + return exportService.exportCSV(rows, exporter.options()); + }); } return new TimelineTraverser(this.domainObject) diff --git a/platform/features/timeline/src/actions/TimelineCSVExporter.js b/platform/features/timeline/src/actions/TimelineCSVExporter.js index ed7bf2b953..4ef27b3bc3 100644 --- a/platform/features/timeline/src/actions/TimelineCSVExporter.js +++ b/platform/features/timeline/src/actions/TimelineCSVExporter.js @@ -24,8 +24,9 @@ define([ "./ModeColumn", "./CompositionColumn", - "./MetadataColumn" -], function (ModeColumn, CompositionColumn, MetadataColumn) { + "./MetadataColumn", + "./TimespanColumn" +], function (ModeColumn, CompositionColumn, MetadataColumn, TimespanColumn) { 'use strict'; function TimelineCSVExporter(domainObjects) { @@ -33,6 +34,7 @@ define([ maxRelationships = 0, columnNames = {}, columns = [], + foundTimespan = false, i; function addMetadataProperty(property) { @@ -56,9 +58,17 @@ define([ maxComposition = Math.max(maxComposition, compositionLength); maxRelationships = Math.max(maxRelationships, relationshipLength); + foundTimespan = + foundTimespan || domainObject.hasCapability('timespan'); + metadataProperties.forEach(addMetadataProperty); }); + if (foundTimespan) { + columns.push(new TimespanColumn(true)); + columns.push(new TimespanColumn(false)); + } + for (i = 0; i < maxComposition; i += 1) { columns.push(new CompositionColumn(i)); } @@ -75,14 +85,12 @@ define([ var columns = this.columns; function toRow(domainObject) { - var row = {}; - columns.forEach(function (column) { - row[column.name()] = column.value(domainObject); - }); - return row; + return Promise.all(columns.map(function (column) { + return column.value(domainObject); + })); } - return this.domainObjects.map(toRow); + return Promise.all(this.domainObjects.map(toRow)); }; TimelineCSVExporter.prototype.options = function () { diff --git a/platform/features/timeline/src/actions/TimespanColumn.js b/platform/features/timeline/src/actions/TimespanColumn.js new file mode 100644 index 0000000000..e6cb118591 --- /dev/null +++ b/platform/features/timeline/src/actions/TimespanColumn.js @@ -0,0 +1,44 @@ +/***************************************************************************** + * Open MCT Web, Copyright (c) 2009-2015, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT Web 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 Web 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. + *****************************************************************************/ +/*global define*/ + +define([], function () { + "use strict"; + + function TimespanColumn(isStart) { + this.isStart = isStart; + } + + TimespanColumn.prototype.name = function () { + return this.isStart ? "Start" : "End"; + }; + + TimespanColumn.prototype.value = function (domainObject) { + var isStart = this.isStart; + return domainObject.hasCapability('timespan') ? + domainObject.useCapability('timespan').then(function (timespan) { + return isStart ? timespan.getStart() : timespan.getEnd(); + }) : ""; + }; + + return TimespanColumn; +});