diff --git a/app/assets/templates/work_packages/cost_entry.html b/app/assets/templates/work_packages/cost_entry.html
new file mode 100644
index 0000000000..a7deaabd2a
--- /dev/null
+++ b/app/assets/templates/work_packages/cost_entry.html
@@ -0,0 +1,3 @@
+
+ {{ spentUnits }} {{ unit }}
+
diff --git a/app/assets/templates/work_packages/summarized_cost_entries.html b/app/assets/templates/work_packages/summarized_cost_entries.html
index 42d04b78fa..c54a59ecd9 100644
--- a/app/assets/templates/work_packages/summarized_cost_entries.html
+++ b/app/assets/templates/work_packages/summarized_cost_entries.html
@@ -1,13 +1,7 @@
-
- {{ costType.props.spentUnits }}
-
- {{ costType.embedded.costType.props.unit }}
- {{ costType.embedded.costType.props.unitPlural }}
-
-
+
,
--
\ No newline at end of file
+-
diff --git a/frontend/app/openproject-costs-app.js b/frontend/app/openproject-costs-app.js
index 77ad990ea0..ec2a8bf535 100644
--- a/frontend/app/openproject-costs-app.js
+++ b/frontend/app/openproject-costs-app.js
@@ -93,5 +93,7 @@ openprojectCostsApp.run(['HookService',
});
}]);
+require('./services/cost-type-service');
require('./work_packages/directives/cost-object-directive');
require('./work_packages/directives/summarized-cost-entries-directive');
+require('./work_packages/directives/cost-entry-directive');
diff --git a/frontend/app/services/cost-entry-service.js b/frontend/app/services/cost-entry-service.js
new file mode 100644
index 0000000000..b133269630
--- /dev/null
+++ b/frontend/app/services/cost-entry-service.js
@@ -0,0 +1,12 @@
+angular.module('openproject.services')
+
+.service('costEntryService', ['HALAPIResource', function(HALAPIResource) {
+ var CostEntryService = {
+ getCostEntry: function(url) {
+ var resource = HALAPIResource.setup(url);
+ return resource.fetch();
+ }
+ };
+
+ return CostEntryService;
+}]);
diff --git a/frontend/app/services/cost-type-service.js b/frontend/app/services/cost-type-service.js
new file mode 100644
index 0000000000..b36bb08063
--- /dev/null
+++ b/frontend/app/services/cost-type-service.js
@@ -0,0 +1,12 @@
+angular.module('openproject.services')
+
+.service('CostTypeService', ['HALAPIResource', function(HALAPIResource) {
+ var CostTypeService = {
+ getCostType: function(url) {
+ var resource = HALAPIResource.setup(url, { fullyQualified: true });
+ return resource.fetch();
+ }
+ };
+
+ return CostTypeService;
+}]);
diff --git a/frontend/app/work_packages/directives/cost-entry-directive.js b/frontend/app/work_packages/directives/cost-entry-directive.js
new file mode 100644
index 0000000000..b45a7ecb50
--- /dev/null
+++ b/frontend/app/work_packages/directives/cost-entry-directive.js
@@ -0,0 +1,72 @@
+//-- copyright
+// OpenProject is a project management system.
+// Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License version 3.
+//
+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+// Copyright (C) 2006-2013 Jean-Philippe Lang
+// Copyright (C) 2010-2013 the ChiliProject Team
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See doc/COPYRIGHT.rdoc for more details.
+//++
+
+angular.module('openproject.workPackages.directives')
+
+.directive('costEntry', ['PathHelper', 'CostTypeService', function(PathHelper, CostTypeService) {
+ return {
+ restrict: 'E',
+ trasclude: true,
+ templateUrl: '/assets/work_packages/cost_entry.html',
+ scope: {
+ workPackage: "=",
+ costEntry: "="
+ },
+ controller: function($scope) {
+ $scope.spentUnits = $scope.costEntry.props.spentUnits;
+
+ CostTypeService.getCostType($scope.costEntry.links.costType.props.href)
+ .then(function(costType) {
+
+ $scope.costType = costType;
+
+ setUnitName();
+
+ setLink();
+ });
+
+ var setUnitName = function() {
+ if ($scope.spentUnits === "1") {
+ $scope.unit = $scope.costType.props.unit;
+ }
+ else {
+ $scope.unit = $scope.costType.props.unitPlural;
+ }
+ };
+
+ var setLink = function() {
+ var link = PathHelper.staticWorkPackagePath($scope.workPackage.props.id);
+
+ link += '/cost_entries?cost_type_id=' + $scope.costType.props.id;
+ link += '&project_id=' + $scope.workPackage.embedded.project.props.id;
+
+ $scope.summaryLink = link;
+ };
+ }
+ };
+}]);
diff --git a/frontend/app/work_packages/directives/summarized-cost-entries-directive.js b/frontend/app/work_packages/directives/summarized-cost-entries-directive.js
index 601e7067ba..0e59cf20be 100644
--- a/frontend/app/work_packages/directives/summarized-cost-entries-directive.js
+++ b/frontend/app/work_packages/directives/summarized-cost-entries-directive.js
@@ -28,7 +28,7 @@
angular.module('openproject.workPackages.directives')
-.directive('summarizedCostEntries', ['PathHelper', function(PathHelper) {
+.directive('summarizedCostEntries', function() {
return {
restrict: 'E',
trasclude: true,
@@ -41,14 +41,6 @@ angular.module('openproject.workPackages.directives')
.embedded
.costsByType
.embedded.elements;
- scope.linkToSummary = function(costType) {
- var link = PathHelper.staticWorkPackagePath(scope.workPackage.props.id);
-
- link += '/cost_entries?cost_type_id=' + costType.props.id;
- link += '&project_id=' + scope.workPackage.embedded.project.props.id;
-
- return link;
- };
}
};
-}]);
+});