OpenProject is the leading open source project management software.
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.
 
 
 
 
 
 
openproject/app/assets/javascripts/angular/work_packages/controllers/details-tab-overview-contro...

155 lines
5.0 KiB

//-- 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.
//++
angular.module('openproject.workPackages.controllers')
.constant('DEFAULT_WORK_PACKAGE_PROPERTIES', [
'status', 'assignee', 'responsible',
'date', 'percentageDone', 'priority',
'estimatedTime', 'versionName'
])
.constant('USER_TYPE', 'user')
.controller('DetailsTabOverviewController', [
'$scope',
'I18n',
'DEFAULT_WORK_PACKAGE_PROPERTIES',
'USER_TYPE',
'CustomFieldHelper',
'WorkPackagesHelper',
'UserService',
'$q',
function($scope, I18n, DEFAULT_WORK_PACKAGE_PROPERTIES, USER_TYPE, CustomFieldHelper, WorkPackagesHelper, UserService, $q) {
// work package properties
$scope.presentWorkPackageProperties = [];
$scope.emptyWorkPackageProperties = [];
$scope.userPath = PathHelper.staticUserPath;
var workPackageProperties = DEFAULT_WORK_PACKAGE_PROPERTIES;
function getPropertyValue(property, format) {
if (format === USER_TYPE) {
return $scope.workPackage.embedded[property];
} else {
return getFormattedPropertyValue(property);
}
}
function getFormattedPropertyValue(property) {
if (property === 'date') {
return getDateProperty();
} else {
return WorkPackagesHelper.formatWorkPackageProperty($scope.workPackage.props[property], property);
}
}
function getDateProperty() {
if ($scope.workPackage.props.startDate || $scope.workPackage.props.dueDate) {
var displayedStartDate = WorkPackagesHelper.formatWorkPackageProperty($scope.workPackage.props.startDate, 'startDate') || I18n.t('js.label_no_start_date'),
displayedEndDate = WorkPackagesHelper.formatWorkPackageProperty($scope.workPackage.props.dueDate, 'dueDate') || I18n.t('js.label_no_due_date');
return displayedStartDate + ' - ' + displayedEndDate;
}
}
function addFormattedValueToPresentProperties(property, label, value, format) {
var propertyData = {
property: property,
label: label,
format: format,
value: null
};
$q.when(value).then(function(value) {
propertyData.value = value;
});
$scope.presentWorkPackageProperties.push(propertyData);
}
function secondRowToBeDisplayed() {
return !!workPackageProperties
.slice(3, 6)
.map(function(property) {
return $scope.workPackage.props[property];
})
.reduce(function(a, b) {
return a || b;
});
}
var userFields = ['assignee', 'author', 'responsible'];
(function setupWorkPackageProperties() {
angular.forEach(workPackageProperties, function(property, index) {
var label = I18n.t('js.work_packages.properties.' + property),
format = userFields.indexOf(property) === -1 ? 'text' : USER_TYPE,
value = getPropertyValue(property, format);
if (!!value ||
index < 3 ||
index < 6 && secondRowToBeDisplayed()) {
addFormattedValueToPresentProperties(property, label, value, format);
} else {
$scope.emptyWorkPackageProperties.push(label);
}
});
})();
function getCustomPropertyValue(customProperty) {
if (!!customProperty.value && customProperty.format === USER_TYPE) {
return UserService.getUser(customProperty.value);
} else {
return CustomFieldHelper.formatCustomFieldValue(customProperty.value, customProperty.format);
}
}
(function setupCustomProperties() {
angular.forEach($scope.workPackage.props.customProperties, function(customProperty) {
var property = customProperty.name,
label = customProperty.name,
value = getCustomPropertyValue(customProperty),
format = customProperty.format;
if (customProperty.value) {
addFormattedValueToPresentProperties(property, label, value, format);
} else {
$scope.emptyWorkPackageProperties.push(label);
}
});
})();
// toggles
$scope.toggleStates = {
hideFullDescription: true,
hideAllAttributes: true
};
}]);