|
|
@ -40,7 +40,11 @@ function wpTd(){ |
|
|
|
projectIdentifier: '=', |
|
|
|
projectIdentifier: '=', |
|
|
|
column: '=', |
|
|
|
column: '=', |
|
|
|
displayType: '@', |
|
|
|
displayType: '@', |
|
|
|
displayEmpty: '@' |
|
|
|
displayEmpty: '@', |
|
|
|
|
|
|
|
schema: '=', |
|
|
|
|
|
|
|
object: '=', |
|
|
|
|
|
|
|
resource: '=', |
|
|
|
|
|
|
|
attribute: '=' |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
bindToController: true, |
|
|
|
bindToController: true, |
|
|
@ -52,103 +56,47 @@ function wpTd(){ |
|
|
|
function WorkPackageTdController($scope, PathHelper, WorkPackagesHelper) { |
|
|
|
function WorkPackageTdController($scope, PathHelper, WorkPackagesHelper) { |
|
|
|
var vm = this; |
|
|
|
var vm = this; |
|
|
|
|
|
|
|
|
|
|
|
vm.displayType = vm.displayType || 'text'; |
|
|
|
if (vm.workPackage) { |
|
|
|
|
|
|
|
vm.workPackage.getSchema().then(function(schema) { |
|
|
|
$scope.$watch(dataAvailable, setColumnData); |
|
|
|
if (schema[vm.column.name] && vm.column.name === 'percentageDone') { |
|
|
|
$scope.$watch('vm.workPackage', setColumnData, true); |
|
|
|
// TODO: Check if we might alter the wp schema
|
|
|
|
|
|
|
|
vm.displayType = 'Percent'; |
|
|
|
function dataAvailable() { |
|
|
|
|
|
|
|
if (!vm.workPackage) return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (vm.column.custom_field) { |
|
|
|
|
|
|
|
return customValueAvailable(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else if (schema[vm.column.name]) { |
|
|
|
return vm.workPackage.hasOwnProperty(vm.column.name); |
|
|
|
vm.displayType = schema[vm.column.name].type; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
function customValueAvailable() { |
|
|
|
vm.displayType = 'String'; |
|
|
|
var customFieldId = vm.column.custom_field.id; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return vm.workPackage.custom_values && |
|
|
|
|
|
|
|
vm.workPackage.custom_values.filter(function(customValue){ |
|
|
|
|
|
|
|
return customValue && customValue.custom_field_id === customFieldId; |
|
|
|
|
|
|
|
}).length; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function setColumnData() { |
|
|
|
setText(vm.displayType); |
|
|
|
setDisplayText(getFormattedColumnValue()); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (vm.column.meta_data.link.display) { |
|
|
|
|
|
|
|
var id = WorkPackagesHelper.getColumnDataId(vm.workPackage, vm.column) |
|
|
|
|
|
|
|
if (id) { |
|
|
|
|
|
|
|
displayDataAsLink(id); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
setCustomDisplayType(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getFormattedColumnValue() { |
|
|
|
if (vm.schema) { |
|
|
|
var custom_field = vm.column.custom_field; |
|
|
|
if (!vm.schema[vm.attribute] || !vm.object[vm.attribute] ) { return; } |
|
|
|
|
|
|
|
|
|
|
|
if (custom_field) { |
|
|
|
vm.displayType = vm.schema[vm.attribute].type; |
|
|
|
return WorkPackagesHelper.getFormattedCustomValue(vm.workPackage, custom_field); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
var text = vm.object[vm.attribute].value || |
|
|
|
return WorkPackagesHelper.getFormattedColumnData(vm.workPackage, vm.column); |
|
|
|
vm.object[vm.attribute].name || |
|
|
|
} |
|
|
|
vm.object[vm.attribute]; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function setDisplayText(value) { |
|
|
|
vm.displayText = WorkPackagesHelper.formatValue(text, vm.displayType); |
|
|
|
vm.displayText = vm.displayEmpty || ''; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof value === 'number' || value){ |
|
|
|
|
|
|
|
vm.displayText = value; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function setCustomDisplayType() { |
|
|
|
function setText(type) { |
|
|
|
if (vm.column.name === 'done_ratio') vm.displayType = 'progress_bar'; |
|
|
|
if (vm.workPackage[vm.column.name] === null || vm.workPackage[vm.column.name] === undefined) { |
|
|
|
|
|
|
|
vm.displayText = ''; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else if (vm.workPackage[vm.column.name].value !== undefined) { |
|
|
|
function displayDataAsLink(id) { |
|
|
|
vm.displayText = WorkPackagesHelper.formatValue(vm.workPackage[vm.column.name].value, type); |
|
|
|
var linkMeta = vm.column.meta_data.link; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (linkMeta.model_type === 'work_package') { |
|
|
|
|
|
|
|
var projectId = vm.projectIdentifier || ''; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vm.displayType = 'ref'; |
|
|
|
|
|
|
|
vm.stateRef = "work-packages.show.activity({projectPath: '" + projectId + |
|
|
|
|
|
|
|
"', workPackageId: " + id + "})"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
vm.displayType = 'link'; |
|
|
|
|
|
|
|
vm.url = getLinkFor(id, linkMeta); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else if (vm.workPackage[vm.column.name].name !== undefined) { |
|
|
|
|
|
|
|
vm.displayText = WorkPackagesHelper.formatValue(vm.workPackage[vm.column.name].name, type); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
function getLinkFor(id, linkMeta){ |
|
|
|
vm.displayText = WorkPackagesHelper.formatValue(vm.workPackage[vm.column.name], type); |
|
|
|
var types = { |
|
|
|
|
|
|
|
get user() { |
|
|
|
|
|
|
|
if (vm.workPackage[vm.column.name] && vm.workPackage[vm.column.name].type == 'Group') { |
|
|
|
|
|
|
|
vm.displayType = 'text'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ''; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return PathHelper.userPath(id); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get version() { |
|
|
|
|
|
|
|
return PathHelper.versionPath(id); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get project() { |
|
|
|
|
|
|
|
return PathHelper.projectPath(id); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return types[linkMeta.model_type] || ''; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|