use the halResource to display the table sums

pull/4159/head
Jens Ulferts 9 years ago
parent d32127465b
commit 5b77978fc3
  1. 8
      frontend/app/components/routing/wp-list/wp-list.controller.ts
  2. 1
      frontend/app/components/routing/wp-list/wp.list.html
  3. 4
      frontend/app/components/wp-table/wp-row/wp-row.directive.js
  4. 17
      frontend/app/components/wp-table/wp-table.directive.html
  5. 2
      frontend/app/components/wp-table/wp-table.directive.js
  6. 2
      frontend/app/components/wp-table/wp-table.service.js
  7. 116
      frontend/app/components/wp-table/wp-td/wp-td.directive.js
  8. 63
      frontend/app/components/wp-table/wp-total-sums/wp-total-sums.directive.js

@ -194,6 +194,7 @@ function WorkPackagesListController($scope,
$scope.groupableColumns = WorkPackagesTableService.getGroupableColumns(); $scope.groupableColumns = WorkPackagesTableService.getGroupableColumns();
$scope.workPackageCountByGroup = meta.groups; $scope.workPackageCountByGroup = meta.groups;
$scope.totalEntries = QueryService.getTotalEntries(); $scope.totalEntries = QueryService.getTotalEntries();
$scope.resource = json.resource;
// Authorisation // Authorisation
AuthorisationService.initModelAuth("work_package", meta._links); AuthorisationService.initModelAuth("work_package", meta._links);
@ -243,12 +244,7 @@ function WorkPackagesListController($scope,
function mergeApiResponses(exJson, workPackages) { function mergeApiResponses(exJson, workPackages) {
exJson.work_packages = workPackages.elements; exJson.work_packages = workPackages.elements;
exJson.resource = workPackages;
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.meta.total_entries = workPackages.total; exJson.meta.total_entries = workPackages.total;
exJson.meta.groups = workPackages.groups; exJson.meta.groups = workPackages.groups;
} }

@ -82,6 +82,7 @@
display-sums="query.displaySums" display-sums="query.displaySums"
total-sums="totalSums" total-sums="totalSums"
group-sums="groupSums" group-sums="groupSums"
resource ="resource"
activation-callback="showWorkPackageDetails(id, force)"> activation-callback="showWorkPackageDetails(id, force)">
</wp-table> </wp-table>
</div> </div>

@ -49,6 +49,10 @@ function wpRow(WorkPackagesTableService){
scope.workPackage = scope.row.object; scope.workPackage = scope.row.object;
setCheckboxTitle(scope); setCheckboxTitle(scope);
if (!scope.row.object.schema.$loaded) {
scope.row.object.schema.$load();
}
if (scope.row.parent) setHiddenWorkPackageLabel(scope); if (scope.row.parent) setHiddenWorkPackageLabel(scope);
scope.$watch('row.checked', function(checked, formerState) { scope.$watch('row.checked', function(checked, formerState) {

@ -119,10 +119,10 @@
lang="{{column.custom_field && column.custom_field.name_locale || locale}}" lang="{{column.custom_field && column.custom_field.name_locale || locale}}"
wp-edit-field="column.name" wp-edit-field="column.name"
ng-class="column.name == 'id' && '-short'"> ng-class="column.name == 'id' && '-short'">
<wp-td work-package="row.object" <wp-td attribute="column.name"
column="column" schema="row.object.schema"
display-type="{{column.meta_data.data_type}}" object="row.object"
project-identifier="projectIdentifier" ng-if="row.object.schema.$loaded"
ng-class="[row.level > 0 && column.name == 'subject' && 'icon-context icon-arrow-right5 icon-small']"> ng-class="[row.level > 0 && column.name == 'subject' && 'icon-context icon-arrow-right5 icon-small']">
</wp-td> </wp-td>
</td> </td>
@ -170,9 +170,12 @@
</div> </div>
</td> </td>
<td ng-repeat="column in columns"> <td ng-repeat="column in columns">
<div class="generic-table--footer-outer"> <wp-td class="generic-table--footer-outer"
{{ column.total_sum }} attribute="column.name"
</div> schema="resource.sumsSchema"
object="resource.totalSums"
ng-if="resource.sumsSchema.$loaded">
</wp-td>
</td> </td>
</tr> </tr>

@ -44,8 +44,8 @@ function wpTable(WorkPackagesTableService, $window, featureFlags, PathHelper){
groupBy: '=', groupBy: '=',
groupByColumn: '=', groupByColumn: '=',
displaySums: '=', displaySums: '=',
totalSums: '=',
groupSums: '=', groupSums: '=',
resource: '=',
activationCallback: '&' activationCallback: '&'
}, },

@ -65,8 +65,6 @@ function WorkPackagesTableService($filter, QueryService, WorkPackagesTableHelper
addColumnMetaData: function(metaData) { addColumnMetaData: function(metaData) {
angular.forEach(workPackagesTableData.columns, function(column, i){ angular.forEach(workPackagesTableData.columns, function(column, i){
column.total_sum = metaData.sums[i];
if (metaData.group_sums) column.group_sums = metaData.group_sums[i]; if (metaData.group_sums) column.group_sums = metaData.group_sums[i];
}); });

@ -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] || '';
} }
} }

@ -30,43 +30,64 @@ angular
.module('openproject.workPackages.directives') .module('openproject.workPackages.directives')
.directive('wpTotalSums', wpTotalSums); .directive('wpTotalSums', wpTotalSums);
function wpTotalSums(WorkPackageService) { function wpTotalSums(apiWorkPackages) {
return { return {
restrict: 'A', restrict: 'A',
scope: true, scope: true,
link: function(scope) { link: function(scope) {
if (!totalSumsFetched()) fetchTotalSums(); if (!totalSumsFetched()) fetchTotalSums();
if (!sumsSchemaFetched()) fetchSumsSchema();
scope.$watch(columnNames, function(columnNames, formerNames) { //scope.$watch(columnNames, function(columnNames, formerNames) {
if (!angular.equals(columnNames, formerNames) && !totalSumsFetched()) { // if (!angular.equals(columnNames, formerNames) && !totalSumsFetched()) {
fetchTotalSums(); // fetchTotalSums();
scope.$emit('queryStateChange'); // scope.$emit('queryStateChange');
} // }
}, true); //}, true);
scope.$watch('resource', function() {
fetchSumsSchema();
});
function fetchTotalSums() { function fetchTotalSums() {
scope.fetchTotalSums = WorkPackageService.getWorkPackagesSums(scope.projectIdentifier, scope.query, scope.columns) apiWorkPackages
.then(function(data){ .list(1, 1, scope.query)
angular.forEach(scope.columns, function(column, i){ .then(function(workPackageCollection) {
column.total_sum = data.column_sums[i]; angular.extend(scope.resource, workPackageCollection);
}); fetchSumsSchema();
}); });
// scope.resource.
return scope.fetchTotalSums; // 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() { function totalSumsFetched() {
return scope.columns.every(function(column) { return !!scope.resource.totalSums;
return column.hasOwnProperty('total_sum');
});
} }
function columnNames() { //function columnNames() {
return scope.columns.map(function(column) { // return scope.columns.map(function(column) {
return column.name; // return column.name;
}); // });
//}
function sumsSchemaFetched() {
return scope.resource.sumsSchema && scope.resource.sumsSchema.$loaded;
}
function fetchSumsSchema() {
if (scope.resource.sumsSchema) {
scope.resource.sumsSchema.$load();
}
} }
} }
}; };

Loading…
Cancel
Save