diff --git a/frontend/app/components/routing/wp-list/wp-list.controller.ts b/frontend/app/components/routing/wp-list/wp-list.controller.ts index 6d17bb44ca..f292c35037 100644 --- a/frontend/app/components/routing/wp-list/wp-list.controller.ts +++ b/frontend/app/components/routing/wp-list/wp-list.controller.ts @@ -194,6 +194,7 @@ function WorkPackagesListController($scope, $scope.groupableColumns = WorkPackagesTableService.getGroupableColumns(); $scope.workPackageCountByGroup = meta.groups; $scope.totalEntries = QueryService.getTotalEntries(); + $scope.resource = json.resource; // Authorisation AuthorisationService.initModelAuth("work_package", meta._links); @@ -243,12 +244,7 @@ function WorkPackagesListController($scope, function mergeApiResponses(exJson, workPackages) { exJson.work_packages = workPackages.elements; - - if (workPackages.totalSums) { - exJson.meta.sums = exJson.meta.columns.map(column => workPackages.totalSums[column.name]); - } else { - exJson.meta.sums = new Array(exJson.meta.columns.length); - } + exJson.resource = workPackages; exJson.meta.total_entries = workPackages.total; exJson.meta.groups = workPackages.groups; } diff --git a/frontend/app/components/routing/wp-list/wp.list.html b/frontend/app/components/routing/wp-list/wp.list.html index 0594dc513f..9142d2cbb4 100644 --- a/frontend/app/components/routing/wp-list/wp.list.html +++ b/frontend/app/components/routing/wp-list/wp.list.html @@ -82,6 +82,7 @@ display-sums="query.displaySums" total-sums="totalSums" group-sums="groupSums" + resource ="resource" activation-callback="showWorkPackageDetails(id, force)"> diff --git a/frontend/app/components/wp-table/wp-row/wp-row.directive.js b/frontend/app/components/wp-table/wp-row/wp-row.directive.js index 29834919da..bd34b37e43 100644 --- a/frontend/app/components/wp-table/wp-row/wp-row.directive.js +++ b/frontend/app/components/wp-table/wp-row/wp-row.directive.js @@ -49,6 +49,10 @@ function wpRow(WorkPackagesTableService){ scope.workPackage = scope.row.object; setCheckboxTitle(scope); + if (!scope.row.object.schema.$loaded) { + scope.row.object.schema.$load(); + } + if (scope.row.parent) setHiddenWorkPackageLabel(scope); scope.$watch('row.checked', function(checked, formerState) { diff --git a/frontend/app/components/wp-table/wp-table.directive.html b/frontend/app/components/wp-table/wp-table.directive.html index 548dd6a319..b2f1debc45 100644 --- a/frontend/app/components/wp-table/wp-table.directive.html +++ b/frontend/app/components/wp-table/wp-table.directive.html @@ -119,11 +119,11 @@ lang="{{column.custom_field && column.custom_field.name_locale || locale}}" wp-edit-field="column.name" ng-class="column.name == 'id' && '-short'"> - + @@ -170,9 +170,12 @@ - + + diff --git a/frontend/app/components/wp-table/wp-table.directive.js b/frontend/app/components/wp-table/wp-table.directive.js index 12eafd3a88..cedd9091ec 100644 --- a/frontend/app/components/wp-table/wp-table.directive.js +++ b/frontend/app/components/wp-table/wp-table.directive.js @@ -44,8 +44,8 @@ function wpTable(WorkPackagesTableService, $window, featureFlags, PathHelper){ groupBy: '=', groupByColumn: '=', displaySums: '=', - totalSums: '=', groupSums: '=', + resource: '=', activationCallback: '&' }, diff --git a/frontend/app/components/wp-table/wp-table.service.js b/frontend/app/components/wp-table/wp-table.service.js index eecddcae7e..b482da84a4 100644 --- a/frontend/app/components/wp-table/wp-table.service.js +++ b/frontend/app/components/wp-table/wp-table.service.js @@ -65,8 +65,6 @@ function WorkPackagesTableService($filter, QueryService, WorkPackagesTableHelper addColumnMetaData: function(metaData) { angular.forEach(workPackagesTableData.columns, function(column, i){ - column.total_sum = metaData.sums[i]; - if (metaData.group_sums) column.group_sums = metaData.group_sums[i]; }); diff --git a/frontend/app/components/wp-table/wp-td/wp-td.directive.js b/frontend/app/components/wp-table/wp-td/wp-td.directive.js index b3d08c1e99..179681b582 100644 --- a/frontend/app/components/wp-table/wp-td/wp-td.directive.js +++ b/frontend/app/components/wp-table/wp-td/wp-td.directive.js @@ -40,7 +40,11 @@ function wpTd(){ projectIdentifier: '=', column: '=', displayType: '@', - displayEmpty: '@' + displayEmpty: '@', + schema: '=', + object: '=', + resource: '=', + attribute: '=' }, bindToController: true, @@ -51,104 +55,48 @@ function wpTd(){ function WorkPackageTdController($scope, PathHelper, WorkPackagesHelper) { var vm = this; - - vm.displayType = vm.displayType || 'text'; - $scope.$watch(dataAvailable, setColumnData); - $scope.$watch('vm.workPackage', setColumnData, true); - - function dataAvailable() { - if (!vm.workPackage) return false; - - if (vm.column.custom_field) { - return customValueAvailable(); - } + if (vm.workPackage) { + vm.workPackage.getSchema().then(function(schema) { + if (schema[vm.column.name] && vm.column.name === 'percentageDone') { + // TODO: Check if we might alter the wp schema + vm.displayType = 'Percent'; + } + else if (schema[vm.column.name]) { + vm.displayType = schema[vm.column.name].type; + } + else { + vm.displayType = 'String'; + } - return vm.workPackage.hasOwnProperty(vm.column.name); + setText(vm.displayType); + }); } - function customValueAvailable() { - var customFieldId = vm.column.custom_field.id; + if (vm.schema) { + if (!vm.schema[vm.attribute] || !vm.object[vm.attribute] ) { return; } - return vm.workPackage.custom_values && - vm.workPackage.custom_values.filter(function(customValue){ - return customValue && customValue.custom_field_id === customFieldId; - }).length; - } + vm.displayType = vm.schema[vm.attribute].type; - function setColumnData() { - setDisplayText(getFormattedColumnValue()); + var text = vm.object[vm.attribute].value || + vm.object[vm.attribute].name || + vm.object[vm.attribute]; - if (vm.column.meta_data.link.display) { - var id = WorkPackagesHelper.getColumnDataId(vm.workPackage, vm.column) - if (id) { - displayDataAsLink(id); - } - } else { - setCustomDisplayType(); - } + vm.displayText = WorkPackagesHelper.formatValue(text, vm.displayType); } - function getFormattedColumnValue() { - var custom_field = vm.column.custom_field; - - if (custom_field) { - return WorkPackagesHelper.getFormattedCustomValue(vm.workPackage, custom_field); - - } else { - return WorkPackagesHelper.getFormattedColumnData(vm.workPackage, vm.column); + function setText(type) { + if (vm.workPackage[vm.column.name] === null || vm.workPackage[vm.column.name] === undefined) { + vm.displayText = ''; } - } - - function setDisplayText(value) { - vm.displayText = vm.displayEmpty || ''; - - if (typeof value === 'number' || value){ - vm.displayText = value; + else if (vm.workPackage[vm.column.name].value !== undefined) { + vm.displayText = WorkPackagesHelper.formatValue(vm.workPackage[vm.column.name].value, type); } - } - - function setCustomDisplayType() { - if (vm.column.name === 'done_ratio') vm.displayType = 'progress_bar'; - } - - function displayDataAsLink(id) { - 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 { + vm.displayText = WorkPackagesHelper.formatValue(vm.workPackage[vm.column.name], type); } - } - - function getLinkFor(id, linkMeta){ - 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] || ''; } } diff --git a/frontend/app/components/wp-table/wp-total-sums/wp-total-sums.directive.js b/frontend/app/components/wp-table/wp-total-sums/wp-total-sums.directive.js index a12242ed13..eb5feb8e71 100644 --- a/frontend/app/components/wp-table/wp-total-sums/wp-total-sums.directive.js +++ b/frontend/app/components/wp-table/wp-total-sums/wp-total-sums.directive.js @@ -30,43 +30,64 @@ angular .module('openproject.workPackages.directives') .directive('wpTotalSums', wpTotalSums); -function wpTotalSums(WorkPackageService) { +function wpTotalSums(apiWorkPackages) { return { restrict: 'A', scope: true, link: function(scope) { if (!totalSumsFetched()) fetchTotalSums(); + if (!sumsSchemaFetched()) fetchSumsSchema(); - scope.$watch(columnNames, function(columnNames, formerNames) { - if (!angular.equals(columnNames, formerNames) && !totalSumsFetched()) { - fetchTotalSums(); - scope.$emit('queryStateChange'); - } - }, true); + //scope.$watch(columnNames, function(columnNames, formerNames) { + // if (!angular.equals(columnNames, formerNames) && !totalSumsFetched()) { + // fetchTotalSums(); + // scope.$emit('queryStateChange'); + // } + //}, true); + scope.$watch('resource', function() { + fetchSumsSchema(); + }); function fetchTotalSums() { - scope.fetchTotalSums = WorkPackageService.getWorkPackagesSums(scope.projectIdentifier, scope.query, scope.columns) - .then(function(data){ - angular.forEach(scope.columns, function(column, i){ - column.total_sum = data.column_sums[i]; - }); + apiWorkPackages + .list(1, 1, scope.query) + .then(function(workPackageCollection) { + angular.extend(scope.resource, workPackageCollection); + fetchSumsSchema(); }); - - return scope.fetchTotalSums; +// scope.resource. +// angular.forEach(scope.columns, function(column, i) { +// column.total_sum = workPackageCollection.totalSums[i]; +// scope.fetchTotalSums = WorkPackageService.getWorkPackagesSums(scope.projectIdentifier, scope.query, scope.columns) +// .then(function(data){ +// angular.forEach(scope.columns, function(column, i){ +// column.total_sum = data.column_sums[i]; +// }); +// }); +// + //return scope.fetchTotalSums; } function totalSumsFetched() { - return scope.columns.every(function(column) { - return column.hasOwnProperty('total_sum'); - }); + return !!scope.resource.totalSums; } - function columnNames() { - return scope.columns.map(function(column) { - return column.name; - }); + //function columnNames() { + // return scope.columns.map(function(column) { + // return column.name; + // }); + //} + + function sumsSchemaFetched() { + return scope.resource.sumsSchema && scope.resource.sumsSchema.$loaded; + } + + function fetchSumsSchema() { + if (scope.resource.sumsSchema) { + scope.resource.sumsSchema.$load(); + } } } };