[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", "name": "Export Timeline as CSV",
"category": "contextual", "category": "contextual",
"implementation": ExportTimelineAsCSVAction, "implementation": ExportTimelineAsCSVAction,
"depends": [ "exportService", "notificationService" ] "depends": [
"exportService",
"notificationService",
"resources[]"
]
} }
], ],
"constants": [ "constants": [

View File

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

View File

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

View File

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