mirror of
https://github.com/nasa/openmct.git
synced 2025-04-19 08:36:24 +00:00
[Timelines] Separate out timeline traversal
...from rest of CSV export.
This commit is contained in:
parent
d8b1e570d9
commit
4adb075a2b
@ -24,74 +24,40 @@
|
||||
/**
|
||||
* Module defining ExportTimelineAsCSVTask. Created by vwoeltje on 2/8/16.
|
||||
*/
|
||||
define([], function () {
|
||||
define([
|
||||
"TimelineTraverser"
|
||||
], function (TimelineTraverser, TimelineCSVExporter) {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
*
|
||||
* @constructor
|
||||
* @memberof {platform/features/timeline}
|
||||
* @implements {Task}
|
||||
*/
|
||||
function ExportTimelineAsCSVTask(domainObject) {
|
||||
function ExportTimelineAsCSVTask(exportService, domainObject) {
|
||||
this.domainObject = domainObject;
|
||||
this.exportService = exportService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ExportTimelineAsCSVTask.prototype.buildObjectList = function () {
|
||||
var idSet = {},
|
||||
objects = [];
|
||||
ExportTimelineAsCSVTask.prototype.run = function (progress) {
|
||||
var name = this.domainObject.getModel().name,
|
||||
exportService = this.exportService;
|
||||
|
||||
function addObject(domainObject) {
|
||||
var id = domainObject.getId(),
|
||||
subtasks = [];
|
||||
|
||||
function addCompositionObjects() {
|
||||
return domainObject.useCapability('composition')
|
||||
.then(function (childObjects) {
|
||||
return Promise.all(childObjects.map(addObject));
|
||||
});
|
||||
}
|
||||
|
||||
function addRelationships() {
|
||||
var relationship = domainObject.getCapability('relationship');
|
||||
relationship.getRelatedObjects('modes')
|
||||
.then(function (modeObjects) {
|
||||
return Promise.all(modeObjects.map(addObject));
|
||||
});
|
||||
}
|
||||
|
||||
if (!idSet[id]) {
|
||||
idSet[id] = true;
|
||||
objects.push(domainObject);
|
||||
if (domainObject.hasCapability('composition')) {
|
||||
subtasks.push(addCompositionObjects());
|
||||
}
|
||||
if (domainObject.hasCapability('relationship')) {
|
||||
subtasks.push(addRelationships());
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.all(subtasks);
|
||||
function doExport(objects) {
|
||||
var exporter = new TimelineCSVExporter(objects);
|
||||
return exportService.exportCSV(
|
||||
exporter.rows(),
|
||||
exporter.options()
|
||||
);
|
||||
}
|
||||
|
||||
return addObject(this.domainObject).then(function () {
|
||||
return objects;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
ExportTimelineAsCSVTask.prototype.run = function (progressCallback) {
|
||||
var name = this.domainObject.getModel().name;
|
||||
|
||||
progressCallback({
|
||||
progress({
|
||||
title: "Preparing to export " + name
|
||||
});
|
||||
|
||||
this.buildObjectList().then(function (objects) {
|
||||
|
||||
});
|
||||
return new TimelineTraverser().buildObjectList()
|
||||
.then(doExport);
|
||||
};
|
||||
|
||||
return ExportTimelineAsCSVTask;
|
||||
|
74
platform/features/timeline/src/actions/TimelineTraverser.js
Normal file
74
platform/features/timeline/src/actions/TimelineTraverser.js
Normal file
@ -0,0 +1,74 @@
|
||||
/*****************************************************************************
|
||||
* 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,Promise*/
|
||||
|
||||
define([], function () {
|
||||
|
||||
function TimelineTraverser(domainObject) {
|
||||
this.domainObject = domainObject;
|
||||
}
|
||||
|
||||
TimelineTraverser.prototype.buildObjectList = function () {
|
||||
var idSet = {},
|
||||
objects = [];
|
||||
|
||||
function addObject(domainObject) {
|
||||
var id = domainObject.getId(),
|
||||
subtasks = [];
|
||||
|
||||
function addCompositionObjects() {
|
||||
return domainObject.useCapability('composition')
|
||||
.then(function (childObjects) {
|
||||
return Promise.all(childObjects.map(addObject));
|
||||
});
|
||||
}
|
||||
|
||||
function addRelationships() {
|
||||
var relationship = domainObject.getCapability('relationship');
|
||||
relationship.getRelatedObjects('modes')
|
||||
.then(function (modeObjects) {
|
||||
return Promise.all(modeObjects.map(addObject));
|
||||
});
|
||||
}
|
||||
|
||||
if (!idSet[id]) {
|
||||
idSet[id] = true;
|
||||
objects.push(domainObject);
|
||||
if (domainObject.hasCapability('composition')) {
|
||||
subtasks.push(addCompositionObjects());
|
||||
}
|
||||
if (domainObject.hasCapability('relationship')) {
|
||||
subtasks.push(addRelationships());
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.all(subtasks);
|
||||
}
|
||||
|
||||
return addObject(this.domainObject).then(function () {
|
||||
return objects;
|
||||
});
|
||||
};
|
||||
|
||||
return TimelineTraverser;
|
||||
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user