mirror of
https://github.com/nasa/openmct.git
synced 2025-06-01 15:10:50 +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;
|
this.exportService = exportService;
|
||||||
}
|
}
|
||||||
|
|
||||||
ExportTimelineAsCSVTask.prototype.run = function (progress) {
|
ExportTimelineAsCSVTask.prototype.run = function () {
|
||||||
var name = this.domainObject.getModel().name,
|
var exportService = this.exportService;
|
||||||
exportService = this.exportService;
|
|
||||||
|
|
||||||
function doExport(objects) {
|
function doExport(objects) {
|
||||||
var exporter = new TimelineCSVExporter(objects);
|
var exporter = new TimelineCSVExporter(objects);
|
||||||
return exportService.exportCSV(
|
return exporter.rows().then(function (rows) {
|
||||||
exporter.rows(),
|
return exportService.exportCSV(rows, exporter.options());
|
||||||
exporter.options()
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TimelineTraverser(this.domainObject)
|
return new TimelineTraverser(this.domainObject)
|
||||||
|
@ -24,8 +24,9 @@
|
|||||||
define([
|
define([
|
||||||
"./ModeColumn",
|
"./ModeColumn",
|
||||||
"./CompositionColumn",
|
"./CompositionColumn",
|
||||||
"./MetadataColumn"
|
"./MetadataColumn",
|
||||||
], function (ModeColumn, CompositionColumn, MetadataColumn) {
|
"./TimespanColumn"
|
||||||
|
], function (ModeColumn, CompositionColumn, MetadataColumn, TimespanColumn) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function TimelineCSVExporter(domainObjects) {
|
function TimelineCSVExporter(domainObjects) {
|
||||||
@ -33,6 +34,7 @@ define([
|
|||||||
maxRelationships = 0,
|
maxRelationships = 0,
|
||||||
columnNames = {},
|
columnNames = {},
|
||||||
columns = [],
|
columns = [],
|
||||||
|
foundTimespan = false,
|
||||||
i;
|
i;
|
||||||
|
|
||||||
function addMetadataProperty(property) {
|
function addMetadataProperty(property) {
|
||||||
@ -56,9 +58,17 @@ define([
|
|||||||
maxComposition = Math.max(maxComposition, compositionLength);
|
maxComposition = Math.max(maxComposition, compositionLength);
|
||||||
maxRelationships = Math.max(maxRelationships, relationshipLength);
|
maxRelationships = Math.max(maxRelationships, relationshipLength);
|
||||||
|
|
||||||
|
foundTimespan =
|
||||||
|
foundTimespan || domainObject.hasCapability('timespan');
|
||||||
|
|
||||||
metadataProperties.forEach(addMetadataProperty);
|
metadataProperties.forEach(addMetadataProperty);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (foundTimespan) {
|
||||||
|
columns.push(new TimespanColumn(true));
|
||||||
|
columns.push(new TimespanColumn(false));
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < maxComposition; i += 1) {
|
for (i = 0; i < maxComposition; i += 1) {
|
||||||
columns.push(new CompositionColumn(i));
|
columns.push(new CompositionColumn(i));
|
||||||
}
|
}
|
||||||
@ -75,14 +85,12 @@ define([
|
|||||||
var columns = this.columns;
|
var columns = this.columns;
|
||||||
|
|
||||||
function toRow(domainObject) {
|
function toRow(domainObject) {
|
||||||
var row = {};
|
return Promise.all(columns.map(function (column) {
|
||||||
columns.forEach(function (column) {
|
return column.value(domainObject);
|
||||||
row[column.name()] = column.value(domainObject);
|
}));
|
||||||
});
|
|
||||||
return row;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.domainObjects.map(toRow);
|
return Promise.all(this.domainObjects.map(toRow));
|
||||||
};
|
};
|
||||||
|
|
||||||
TimelineCSVExporter.prototype.options = function () {
|
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