From eae90cbc2b21455d1e805f146b369f41a5940763 Mon Sep 17 00:00:00 2001 From: Alex Dik Date: Tue, 16 Feb 2016 20:11:15 +0100 Subject: [PATCH] Use WP API service in list view This is a WIP version. We want some of the code there to be moved to the meta API service, or other appropriate ones. --- .../routing/wp-list/wp-list.controller.ts | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) 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 fecb97afb2..4b5c3db206 100644 --- a/frontend/app/components/routing/wp-list/wp-list.controller.ts +++ b/frontend/app/components/routing/wp-list/wp-list.controller.ts @@ -32,6 +32,7 @@ function WorkPackagesListController($scope, $location, WorkPackagesTableService, WorkPackageService, + apiWorkPackages, ProjectService, QueryService, PaginationService, @@ -48,6 +49,16 @@ function WorkPackagesListController($scope, $scope.projectIdentifier = $state.params.projectPath || null; $scope.loadingIndicator = loadingIndicator; + //TODO: Move this somewhere else + var propertyMap = { + assigned_to: 'assignee', + updated_at: 'updatedAt' + }; + var mapColumns = columns => columns.forEach(column => { + //noinspection TypeScriptUnresolvedVariable + column.name = propertyMap[column.name] || column.name; + }); + // Setup function initialSetup() { $scope.operatorsAndLabelsByFilterType = OPERATORS_AND_LABELS_BY_FILTER_TYPE; @@ -98,8 +109,14 @@ function WorkPackagesListController($scope, fetchWorkPackages = WorkPackageService.getWorkPackages($scope.projectIdentifier); } - loadingIndicator.mainPage = fetchWorkPackages.then(function(json) { - setupPage(json, !!queryParams); + //TODO: Move this call and everything that belongs to it to the meta service + loadingIndicator.mainPage = fetchWorkPackages.then(function(json:api.ex.WorkPackagesMeta) { + mapColumns(json.meta.columns); + + apiWorkPackages.list(json.meta.columns).then(function(workPackages) { + json.work_packages = workPackages; + setupPage(json, !!queryParams); + }); QueryService.loadAvailableUnusedColumns($scope.projectIdentifier).then(function(data){ $scope.availableUnusedColumns = data; @@ -218,9 +235,15 @@ function WorkPackagesListController($scope, function updateResults() { $scope.$broadcast('openproject.workPackages.updateResults'); + //TODO: Move this to the WP meta service (see TODO above) loadingIndicator.mainPage = WorkPackageService.getWorkPackages($scope.projectIdentifier, $scope.query, PaginationService.getPaginationOptions()) - .then(setupWorkPackagesTable); + .then(function (json:api.ex.WorkPackagesMeta) { + apiWorkPackages.list().then(function (workPackages) { + json.work_packages = workPackages; + setupWorkPackagesTable(json); + }) + }); } // Go