mirror of
https://github.com/nasa/openmct.git
synced 2025-03-21 11:35:59 +00:00
[Timeline] Export start/end to CSV
This commit is contained in:
parent
a509dfb840
commit
b383921f2a
@ -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)
|
||||
|
@ -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 () {
|
||||
|
44
platform/features/timeline/src/actions/TimespanColumn.js
Normal file
44
platform/features/timeline/src/actions/TimespanColumn.js
Normal file
@ -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;
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user