[Timeline] Inject resources into CSV action

This commit is contained in:
Victor Woeltjen 2016-04-15 08:51:22 -07:00
parent f683ca44a2
commit f16a107105
4 changed files with 21 additions and 13 deletions

View File

@ -93,7 +93,11 @@ define([
"name": "Export Timeline as CSV",
"category": "contextual",
"implementation": ExportTimelineAsCSVAction,
"depends": [ "exportService", "notificationService" ]
"depends": [
"exportService",
"notificationService",
"resources[]"
]
}
],
"constants": [

View File

@ -29,14 +29,21 @@ define(["./ExportTimelineAsCSVTask"], function (ExportTimelineAsCSVTask) {
*
* @param exportService the service used to perform the CSV export
* @param notificationService the service used to show notifications
* @param {Array} resources an array of `resources` extensions
* @param context the Action's context
* @implements {Action}
* @constructor
* @memberof {platform/features/timeline}
*/
function ExportTimelineAsCSVAction(exportService, notificationService, context) {
function ExportTimelineAsCSVAction(
exportService,
notificationService,
resources,
context
) {
this.task = new ExportTimelineAsCSVTask(
exportService,
resources,
context.domainObject
);
this.notificationService = notificationService;

View File

@ -37,11 +37,13 @@ define([
* @constructor
* @memberof {platform/features/timeline}
* @param exportService the service used to export as CSV
* @param resources the `resources` extension category
* @param {DomainObject} domainObject the timeline being exported
*/
function ExportTimelineAsCSVTask(exportService, domainObject) {
function ExportTimelineAsCSVTask(exportService, resources, domainObject) {
this.domainObject = domainObject;
this.exportService = exportService;
this.resources = resources;
}
/**
@ -54,7 +56,7 @@ define([
var exportService = this.exportService;
function doExport(objects) {
var exporter = new TimelineColumnizer(objects),
var exporter = new TimelineColumnizer(objects, this.resources),
options = { headers: exporter.headers() };
return exporter.rows().then(function (rows) {
return exportService.exportCSV(rows, options);

View File

@ -68,12 +68,11 @@ define([
* @constructor
* @memberof {platform/features/timeline}
*/
function TimelineColumnizer(domainObjects, resourceMap) {
function TimelineColumnizer(domainObjects, resources) {
var maxComposition = 0,
maxRelationships = 0,
columnNames = {},
columns = [],
costKeys = [],
foundTimespan = false,
i;
@ -114,10 +113,6 @@ define([
foundTimespan = true;
}
if (domainObject.hasCapability('cost')) {
addCostProperties(domainObject.getCapability('cost'));
}
if (metadataProperties) {
metadataProperties.forEach(addMetadataProperty);
}
@ -128,8 +123,8 @@ define([
columns.push(new TimespanColumn(false));
}
costKeys.forEach(function (key) {
columns.push(new UtilizationColumn(resourceMap[key]));
resources.forEach(function (resource) {
columns.push(new UtilizationColumn(resource));
});
for (i = 0; i < maxComposition; i += 1) {