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. 19
      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. 124
      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.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;
}

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

@ -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) {

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

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

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

@ -40,7 +40,11 @@ function wpTd(){
projectIdentifier: '=',
column: '=',
displayType: '@',
displayEmpty: '@'
displayEmpty: '@',
schema: '=',
object: '=',
resource: '=',
attribute: '='
},
bindToController: true,
@ -52,103 +56,47 @@ 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] || '';
}
}

@ -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();
}
}
}
};

Loading…
Cancel
Save