From e770940468c9c6f758b6ecc5d6d096f533ab6751 Mon Sep 17 00:00:00 2001 From: Till Breuer Date: Thu, 20 Mar 2014 15:37:07 +0100 Subject: [PATCH] Initialize columns on start up, fix js startup errors --- .../controllers/work-packages-controller.js | 17 +++++++++++------ .../work-packages-options-directive.js | 4 ++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/angular/controllers/work-packages-controller.js b/app/assets/javascripts/angular/controllers/work-packages-controller.js index d082c64443..16a2363e9f 100644 --- a/app/assets/javascripts/angular/controllers/work-packages-controller.js +++ b/app/assets/javascripts/angular/controllers/work-packages-controller.js @@ -10,15 +10,20 @@ angular.module('openproject.workPackages.controllers') $scope.disableFilters = false; setupColumns(); - }; + } function setupColumns(){ + $scope.columns = []; + QueryService.getAvailableColumns($scope.projectIdentifier).then(function(data){ $scope.columns = WorkPackagesTableHelper.getColumnUnionByName(data.available_columns, INITIALLY_SELECTED_COLUMNS); $scope.availableColumns = WorkPackagesTableHelper.getColumnDifference(data.available_columns, $scope.columns); return $scope.availableColumns; - }).then(setupQuery).then(setupPagination).then($scope.updateResults) - }; + }) + .then(setupQuery) + .then(setupPagination) + .then($scope.updateResults); + } function setupQuery() { $scope.query = new Query(DEFAULT_QUERY, { available_work_package_filters: AVAILABLE_WORK_PACKAGE_FILTERS}); @@ -29,7 +34,7 @@ angular.module('openproject.workPackages.controllers') angular.extend($scope.query, { selectedColumns: $scope.columns }); - }; + } function setupPagination(json) { meta = json || PAGINATION_OPTIONS; @@ -38,7 +43,7 @@ angular.module('openproject.workPackages.controllers') perPage: meta.per_page }; $scope.perPageOptions = meta.per_page_options; - }; + } $scope.submitQueryForm = function(){ jQuery("#selected_columns option").attr('selected',true); @@ -65,7 +70,7 @@ angular.module('openproject.workPackages.controllers') function serviceErrorHandler(data) { // TODO RS: This is where we'd want to put an error message on the dom $scope.loading = false; - }; + } /** * @name withLoading diff --git a/app/assets/javascripts/angular/directives/work_packages/work-packages-options-directive.js b/app/assets/javascripts/angular/directives/work_packages/work-packages-options-directive.js index 868797c4d9..1a4f275cd0 100644 --- a/app/assets/javascripts/angular/directives/work_packages/work-packages-options-directive.js +++ b/app/assets/javascripts/angular/directives/work_packages/work-packages-options-directive.js @@ -5,10 +5,10 @@ angular.module('openproject.workPackages.directives') restrict: 'E', templateUrl: '/templates/work_packages/work_packages_options.html', link: function(scope, element, attributes) { - scope.$watch('query.group_by', function() { + scope.$watch('query.group_by', function(groupBy) { var groupByColumnIndex = scope.columns.map(function(column){ return column.name; - }).indexOf(scope.query.group_by); + }).indexOf(groupBy); scope.groupByColumn = scope.columns[groupByColumnIndex]; });