kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
4.3 KiB
118 lines
4.3 KiB
11 years ago
|
//-- copyright
|
||
|
// OpenProject is a project management system.
|
||
|
// Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
|
||
|
//
|
||
|
// This program is free software; you can redistribute it and/or
|
||
|
// modify it under the terms of the GNU General Public License version 3.
|
||
|
//
|
||
|
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||
|
// Copyright (C) 2006-2013 Jean-Philippe Lang
|
||
|
// Copyright (C) 2010-2013 the ChiliProject Team
|
||
|
//
|
||
|
// This program is free software; you can redistribute it and/or
|
||
|
// modify it under the terms of the GNU General Public License
|
||
|
// as published by the Free Software Foundation; either version 2
|
||
|
// of the License, or (at your option) any later version.
|
||
|
//
|
||
|
// This program is distributed in the hope that it will be useful,
|
||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
// GNU General Public License for more details.
|
||
|
//
|
||
|
// You should have received a copy of the GNU General Public License
|
||
|
// along with this program; if not, write to the Free Software
|
||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
//
|
||
|
// See doc/COPYRIGHT.rdoc for more details.
|
||
|
//++
|
||
|
|
||
11 years ago
|
angular.module('openproject.timelines.directives')
|
||
|
|
||
|
.constant('WORK_PACKAGE_DATE_COLUMNS', ['start_date', 'due_date'])
|
||
11 years ago
|
.directive('timelineColumnData', ['WORK_PACKAGE_DATE_COLUMNS', 'I18n', 'CustomFieldHelper', function(WORK_PACKAGE_DATE_COLUMNS, I18n, CustomFieldHelper) {
|
||
11 years ago
|
|
||
|
|
||
11 years ago
|
return {
|
||
|
restrict: 'A',
|
||
|
scope: {
|
||
|
rowObject: '=',
|
||
|
columnName: '=',
|
||
11 years ago
|
timeline: '=',
|
||
|
customFields: '='
|
||
11 years ago
|
},
|
||
11 years ago
|
templateUrl: '/templates/timelines/timeline_column_data.html',
|
||
11 years ago
|
link: function(scope, element) {
|
||
|
scope.isDateColumn = WORK_PACKAGE_DATE_COLUMNS.indexOf(scope.columnName) !== -1;
|
||
11 years ago
|
|
||
|
if (CustomFieldHelper.isCustomFieldKey(scope.columnName)) {
|
||
|
// watch custom field because they are loaded after the rows are being iterated
|
||
|
scope.$watch('timeline.custom_fields', function() {
|
||
11 years ago
|
scope.columnData = getCustomFieldColumnData(scope.rowObject, scope.columnName, scope.customFields, scope.timeline.users);
|
||
11 years ago
|
});
|
||
|
} else {
|
||
|
scope.columnData = getColumnData();
|
||
|
}
|
||
|
|
||
11 years ago
|
setHistoricalData(scope);
|
||
11 years ago
|
|
||
|
function getColumnData() {
|
||
|
switch(scope.columnName) {
|
||
|
case 'start_date':
|
||
|
return scope.rowObject.start_date;
|
||
|
case 'due_date':
|
||
|
return scope.rowObject.due_date;
|
||
|
default:
|
||
11 years ago
|
return scope.rowObject.getAttribute(getAttributeAccessor(scope.columnName));
|
||
11 years ago
|
}
|
||
|
}
|
||
|
|
||
11 years ago
|
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));
|
||
|
}
|
||
|
|
||
11 years ago
|
function getCustomFieldColumnData(object, customFieldName, customFields, users) {
|
||
|
if(!customFields) return; // custom_fields provides necessary meta information about the custom field column
|
||
|
|
||
|
var customField = customFields[CustomFieldHelper.getCustomFieldId(customFieldName)];
|
||
11 years ago
|
|
||
11 years ago
|
if (customField) {
|
||
|
return CustomFieldHelper.formatCustomFieldValue(object[customFieldName], customField.field_format, users);
|
||
11 years ago
|
}
|
||
|
}
|
||
11 years ago
|
|
||
|
function setHistoricalData() {
|
||
11 years ago
|
scope.historicalDataDiffers = hasChanged(scope.rowObject, scope.columnName);
|
||
11 years ago
|
|
||
|
scope.historicalDateKind = getHistoricalDateKind(scope.rowObject, scope.columnName);
|
||
|
scope.labelTimelineChanged = I18n.t('js.timelines.change');
|
||
|
|
||
|
if (scope.rowObject.historical_element) {
|
||
11 years ago
|
scope.historicalData = scope.rowObject.historical_element.getAttribute(getAttributeAccessor(scope.columnName)) || I18n.t('js.timelines.empty');
|
||
11 years ago
|
}
|
||
|
}
|
||
|
|
||
11 years ago
|
function getHistoricalDateKind(planningElement, attr) {
|
||
|
if (!hasChanged(planningElement, attr)) return;
|
||
11 years ago
|
|
||
11 years ago
|
var newDate = planningElement[attr];
|
||
|
var oldDate = planningElement.historical_element[attr];
|
||
11 years ago
|
|
||
|
if (oldDate && newDate) {
|
||
11 years ago
|
return (newDate < oldDate ? 'preponed' : 'postponed');
|
||
11 years ago
|
}
|
||
|
return "changed";
|
||
|
}
|
||
11 years ago
|
}
|
||
|
};
|
||
|
}]);
|