diff --git a/app/assets/javascripts/angular/directives/timelines/timeline-column-data-directive.js b/app/assets/javascripts/angular/directives/timelines/timeline-column-data-directive.js
index b4fedb7f54..7262d5a648 100644
--- a/app/assets/javascripts/angular/directives/timelines/timeline-column-data-directive.js
+++ b/app/assets/javascripts/angular/directives/timelines/timeline-column-data-directive.js
@@ -56,24 +56,30 @@ angular.module('openproject.timelines.directives')
setHistoricalData(scope);
function getColumnData() {
- var map = {
- "type": "getTypeName",
- "status": "getStatusName",
- "responsible": "getResponsibleName",
- "assigned_to": "getAssignedName",
- "project": "getProjectName"
- };
-
switch(scope.columnName) {
case 'start_date':
return scope.rowObject.start_date;
case 'due_date':
return scope.rowObject.due_date;
default:
- return scope.rowObject[map[scope.columnName]]();
+ return scope.rowObject.getAttribute(getAttributeAccessor(scope.columnName));
}
}
+ function getAttributeAccessor(attr) {
+ return {
+ "type": "getTypeName",
+ "status": "getStatusName",
+ "responsible": "getResponsibleName",
+ "assigned_to": "getAssignedName",
+ "project": "getProjectName"
+ }[attr] || attr;
+ }
+
+ function hasChanged(planningElement, attr) {
+ return planningElement.does_historical_differ(getAttributeAccessor(attr));
+ }
+
function getCustomFieldColumnData(object, customFieldName, customFields, users) {
if(!customFields) return; // custom_fields provides necessary meta information about the custom field column
@@ -85,21 +91,21 @@ angular.module('openproject.timelines.directives')
}
function setHistoricalData() {
- scope.historicalDataDiffers = scope.rowObject.does_historical_differ(scope.columnName);
+ scope.historicalDataDiffers = hasChanged(scope.rowObject, scope.columnName);
scope.historicalDateKind = getHistoricalDateKind(scope.rowObject, scope.columnName);
scope.labelTimelineChanged = I18n.t('js.timelines.change');
if (scope.rowObject.historical_element) {
- scope.historicalData = scope.rowObject.historical_element[scope.columnName] || I18n.t('js.timelines.empty');
+ scope.historicalData = scope.rowObject.historical_element.getAttribute(getAttributeAccessor(scope.columnName)) || I18n.t('js.timelines.empty');
}
}
- function getHistoricalDateKind(object, value) {
- if (!object.does_historical_differ(value)) return;
+ function getHistoricalDateKind(planningElement, attr) {
+ if (!hasChanged(planningElement, attr)) return;
- var newDate = object[value];
- var oldDate = object.historical()[value];
+ var newDate = planningElement[attr];
+ var oldDate = planningElement.historical_element[attr];
if (oldDate && newDate) {
return (newDate < oldDate ? 'postponed' : 'preponed');
diff --git a/karma/tests/directives/timelines/timeline-column-data-directive-test.js b/karma/tests/directives/timelines/timeline-column-data-directive-test.js
index 1c692ae5ac..6abd3767bb 100644
--- a/karma/tests/directives/timelines/timeline-column-data-directive-test.js
+++ b/karma/tests/directives/timelines/timeline-column-data-directive-test.js
@@ -66,12 +66,12 @@ describe('timelineColumnData Directive', function() {
compile();
});
- it('should render object data', function() {
+ it('should render the object data', function() {
expect(element.find('.tl-column').text()).to.equal(type.name);
});
});
- describe('rendering historical data', function() {
+ describe('rendering a changed historical date', function() {
beforeEach(function() {
historicalStartDate = '2014-04-20';
@@ -83,15 +83,54 @@ describe('timelineColumnData Directive', function() {
compile();
})
- it('should render the historical data', function() {
- var historicalContent = element.find('.tl-historical a').text();
- expect(historicalContent).to.equal(historicalStartDate);
- })
-
it('should assign a historical date kind class to the data container', function() {
var container = element.find('.tl-column');
expect(container.hasClass('tl-preponed')).to.be.true;
});
+
+ describe('the historical data container', function() {
+ beforeEach(function() {
+ historicalDataContainer = element.find('.tl-historical a');
+ });
+
+ it('should contain the historical data', function() {
+ var historicalContent = historicalDataContainer.text();
+ expect(historicalContent).to.equal(historicalStartDate);
+ });
+
+ it('should have a css class indicating the change', function() {
+ expect(historicalDataContainer.hasClass('tl-icon-preponed')).to.be.true;
+ });
+ })
+ });
+
+ describe('rendering changed data which is not a date', function() {
+ beforeEach(function() {
+ historicalType = Factory.build('PlanningElementType');
+
+ scope.rowObject.historical_element = Factory.build("PlanningElement", {
+ planning_element_type: historicalType
+ });
+
+ scope.columnName = 'type';
+ compile();
+ })
+
+ describe('the historical data container', function() {
+ beforeEach(function() {
+ historicalDataContainer = element.find('.tl-historical a');
+ });
+
+ it('should contain the historical data', function() {
+ var historicalContent = historicalDataContainer.text();
+ expect(historicalContent).to.equal(historicalType.name);
+ });
+
+ it('should have a css class indicating the change', function() {
+ expect(historicalDataContainer.hasClass('tl-icon-changed')).to.be.true;
+ });
+ })
+
});
});
});
diff --git a/public/templates/timelines/timeline_column_data.html b/public/templates/timelines/timeline_column_data.html
index abbefa6c97..094963564e 100644
--- a/public/templates/timelines/timeline_column_data.html
+++ b/public/templates/timelines/timeline_column_data.html
@@ -2,7 +2,7 @@