From 4d19852d1ceff6b6ba0d145e7a5f198b5e4f74a6 Mon Sep 17 00:00:00 2001 From: Tim Habermaas Date: Sun, 16 Aug 2015 18:54:21 +0200 Subject: [PATCH] Fix listing of attributes on fullscreen WorkPackage page. --- frontend/app/routing.js | 1 + .../app/work_packages/controllers/index.js | 4 ++ .../work-package-show-controller.js | 56 ++++++++++++++++++- 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/frontend/app/routing.js b/frontend/app/routing.js index d034c763b8..8e7694289b 100644 --- a/frontend/app/routing.js +++ b/frontend/app/routing.js @@ -72,6 +72,7 @@ angular.module('openproject') url: '/{workPackageId:[0-9]+}?query_props', templateUrl: '/templates/work_packages.show.html', controller: 'WorkPackageShowController', + controllerAs: 'vm', resolve: { workPackage: function(WorkPackageService, $stateParams) { return WorkPackageService.getWorkPackage($stateParams.workPackageId); diff --git a/frontend/app/work_packages/controllers/index.js b/frontend/app/work_packages/controllers/index.js index d1b90d3f86..d7b9e9a535 100644 --- a/frontend/app/work_packages/controllers/index.js +++ b/frontend/app/work_packages/controllers/index.js @@ -126,7 +126,11 @@ angular.module('openproject.workPackages.controllers') 'CommonRelationsHandler', 'ChildrenRelationsHandler', 'ParentRelationsHandler', + 'WorkPackagesOverviewService', + 'WorkPackageFieldService', 'EditableFieldsState', + 'WorkPackagesDisplayHelper', + 'NotificationsService', require('./work-package-show-controller') ]) .controller('WorkPackagesController', [ diff --git a/frontend/app/work_packages/controllers/work-package-show-controller.js b/frontend/app/work_packages/controllers/work-package-show-controller.js index b8a13789ca..99e90948bc 100644 --- a/frontend/app/work_packages/controllers/work-package-show-controller.js +++ b/frontend/app/work_packages/controllers/work-package-show-controller.js @@ -41,7 +41,12 @@ module.exports = function($scope, WorkPackageService, CommonRelationsHandler, ChildrenRelationsHandler, - ParentRelationsHandler + ParentRelationsHandler, + WorkPackagesOverviewService, + WorkPackageFieldService, + EditableFieldsState, + WorkPackagesDisplayHelper, + NotificationsService ) { $scope.$on('$stateChangeSuccess', function(event, toState){ latestTab.registerState(toState.name); @@ -203,4 +208,53 @@ module.exports = function($scope, $state.current.url.replace(/\//, ''), $scope.workPackage ); + + // Stuff copied from DetailsTabOverviewController + var vm = this; + + vm.groupedFields = []; + vm.hideEmptyFields = true; + vm.workPackage = $scope.workPackage; + + vm.isGroupHideable = WorkPackagesDisplayHelper.isGroupHideable; + vm.isFieldHideable = WorkPackagesDisplayHelper.isFieldHideable; + vm.getLabel = WorkPackagesDisplayHelper.getLabel; + vm.isSpecified = WorkPackagesDisplayHelper.isSpecified; + vm.hasNiceStar = WorkPackagesDisplayHelper.hasNiceStar; + vm.showToggleButton = WorkPackagesDisplayHelper.showToggleButton; + + activate(); + + function activate() { + EditableFieldsState.forcedEditState = false; + $scope.$watch('workPackage.schema', function(schema) { + if (schema) { + WorkPackagesDisplayHelper.setFocus(); + vm.workPackage = $scope.workPackage; + } + }); + vm.groupedFields = WorkPackagesOverviewService.getGroupedWorkPackageOverviewAttributes(); + + $scope.$watchCollection('vm.workPackage.form', function(form) { + var schema = WorkPackageFieldService.getSchema(vm.workPackage); + var otherGroup = _.find(vm.groupedFields, {groupName: 'other'}); + otherGroup.attributes = []; + _.forEach(schema.props, function(prop, propName) { + if (propName.match(/^customField/)) { + otherGroup.attributes.push(propName); + } + }); + otherGroup.attributes.sort(function(a, b) { + var getLabel = function(field) { + return vm.getLabel(vm.workPackage, field); + }; + var left = getLabel(a).toLowerCase(), + right = getLabel(b).toLowerCase(); + return left.localeCompare(right); + }); + }); + $scope.$on('workPackageUpdatedInEditor', function() { + NotificationsService.addSuccess(I18n.t('js.label_successful_update')); + }); + } };