From a72ef13d91181c9e94454bffc936adff61abf7ae Mon Sep 17 00:00:00 2001 From: Till Breuer Date: Tue, 22 Apr 2014 13:28:44 +0200 Subject: [PATCH] Wrap up some work package column directive code in functions --- .../work-package-column-directive.js | 47 +++++++++++++++---- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/angular/directives/work_packages/work-package-column-directive.js b/app/assets/javascripts/angular/directives/work_packages/work-package-column-directive.js index 0afb592a42..385e030203 100644 --- a/app/assets/javascripts/angular/directives/work_packages/work-package-column-directive.js +++ b/app/assets/javascripts/angular/directives/work_packages/work-package-column-directive.js @@ -46,29 +46,56 @@ angular.module('openproject.workPackages.directives') // Set text to be displayed scope.$watch('workPackage', setColumnData, true); + function setColumnData() { + setDisplayText(getFormattedColumnValue()); + + if (scope.column.meta_data.link.display) { + displayDataAsLink(); + } else { + setCustomDisplayType(); + } + } + + function getFormattedColumnValue() { // retrieve column value from work package if (scope.column.custom_field) { var custom_field = scope.column.custom_field; - var formattedValue = WorkPackagesHelper.getFormattedCustomValue(scope.workPackage, custom_field); + return WorkPackagesHelper.getFormattedCustomValue(scope.workPackage, custom_field); } else { - // custom display types - if (scope.column.name === 'done_ratio') scope.displayType = 'progress_bar'; - var formattedValue = WorkPackagesHelper.getFormattedColumnData(scope.workPackage, scope.column); + return WorkPackagesHelper.getFormattedColumnData(scope.workPackage, scope.column); } + } - if (typeof formattedValue == 'number' || formattedValue){ - scope.displayText = formattedValue; + /** + * @name setDisplayText + * @function + * + * @description + * Sets scope.displayText to the passed value or applies a default + * + * @param {String|Number} value The value for scope.displayText + * + * @returns null + */ + function setDisplayText(value) { + if (typeof value == 'number' || value){ + scope.displayText = value; } else { scope.displayText = scope.displayEmpty || ''; } + } + + function setCustomDisplayType() { + if (scope.column.name === 'done_ratio') scope.displayType = 'progress_bar'; + // ... + } + function displayDataAsLink() { // Example of how we can look to the provided meta data to format the column // This relies on the meta being sent from the server - if (scope.column.meta_data.link.display) { - scope.displayType = 'link'; - scope.url = getLinkFor(scope.column.meta_data.link); - } + scope.displayType = 'link'; + scope.url = getLinkFor(scope.column.meta_data.link); } function getLinkFor(link_meta){