turns spent time into a link on wp pane

pull/2230/head
Jens Ulferts 10 years ago
parent a4217635df
commit b488c94ef6
  1. 22
      app/assets/javascripts/angular/work_packages/controllers/details-tab-overview-controller.js
  2. 2
      app/assets/javascripts/angular/work_packages/controllers/index.js
  3. 31
      karma/tests/work_packages/controllers/details-tab-overview-controller-test.js
  4. 4
      public/templates/work_packages/tabs/overview.html

@ -33,6 +33,7 @@ module.exports = function($scope,
VERSION_TYPE,
CATEGORY_TYPE,
USER_TYPE,
TIME_ENTRY_TYPE,
USER_FIELDS,
CustomFieldHelper,
WorkPackagesHelper,
@ -64,6 +65,12 @@ module.exports = function($scope,
case CATEGORY_TYPE:
return $scope.workPackage.embedded[property];
break;
case TIME_ENTRY_TYPE:
var spentTime = $scope.workPackage.props.spentTime,
timeLinkPresent = !!$scope.workPackage.links.timeEntries,
formattedValue = WorkPackagesHelper.formatWorkPackageProperty(spentTime, property),
timeHref = PathHelper.timeEntriesPath(null, $scope.workPackage.props.id);
return {href: timeHref, title: formattedValue, viewable: timeLinkPresent};
default:
return getFormattedPropertyValue(property);
}
@ -150,11 +157,16 @@ module.exports = function($scope,
}
function getPropertyFormat(property) {
var format = USER_FIELDS.indexOf(property) === -1 ? TEXT_TYPE : USER_TYPE;
format = (property === 'versionName') ? VERSION_TYPE : format;
format = (property === 'category') ? CATEGORY_TYPE : format;
return format;
switch(property) {
case 'versionName':
return VERSION_TYPE;
case 'category':
return CATEGORY_TYPE;
case 'spentTime':
return TIME_ENTRY_TYPE;
default:
return USER_FIELDS.indexOf(property) === -1 ? TEXT_TYPE : USER_TYPE;
}
}
function getCustomPropertyValue(property) {

@ -31,6 +31,7 @@ angular.module('openproject.workPackages.controllers')
.constant('VERSION_TYPE', 'version')
.constant('CATEGORY_TYPE', 'category')
.constant('USER_TYPE', 'user')
.constant('TIME_ENTRY_TYPE', 'time_entry')
.constant('USER_FIELDS', ['assignee', 'author', 'responsible'])
.controller('DetailsTabOverviewController', [
'$scope',
@ -40,6 +41,7 @@ angular.module('openproject.workPackages.controllers')
'VERSION_TYPE',
'CATEGORY_TYPE',
'USER_TYPE',
'TIME_ENTRY_TYPE',
'USER_FIELDS',
'CustomFieldHelper',
'WorkPackagesHelper',

@ -245,7 +245,7 @@ describe('DetailsTabOverviewController', function() {
});
describe('durations', function() {
var shouldBehaveLikeValidHourDescription = function(property, hours) {
var prepareHourDescription = function(property) {
beforeEach(function() {
sinon.stub(I18n, 't', function(locale, parameter) {
if (locale == 'js.work_packages.properties.' + property) {
@ -261,6 +261,15 @@ describe('DetailsTabOverviewController', function() {
afterEach(function() {
I18n.t.restore();
});
};
var shouldBehaveLikeValidHourDescription = function(property, hours) {
workPackage.links = {
spentTime: {
href: '/time_entries'
}
};
prepareHourDescription(property);
it('should show hours', function() {
var description = fetchPresentPropertiesWithName(property)[0].value;
@ -269,6 +278,22 @@ describe('DetailsTabOverviewController', function() {
});
};
var shouldBehaveLikeValidLinkedHourDescription = function(property, hours, link) {
prepareHourDescription(property);
it('should show hours', function() {
var description = fetchPresentPropertiesWithName(property)[0].value.title;
expect(description).to.equal(hours);
});
it('should have a link', function() {
var href = fetchPresentPropertiesWithName(property)[0].value.href;
expect(href).to.equal(link);
});
};
describe('estimated time', function() {
context('default value', function() {
shouldBehaveLikeValidHourDescription('estimatedTime', 0);
@ -285,7 +310,7 @@ describe('DetailsTabOverviewController', function() {
describe('spent time', function() {
context('default value', function() {
shouldBehaveLikeValidHourDescription('spentTime', 0);
shouldBehaveLikeValidLinkedHourDescription('spentTime', 0, '/time_entries');
});
context('time set', function() {
@ -293,7 +318,7 @@ describe('DetailsTabOverviewController', function() {
workPackage.props.spentTime = 'P2DT4H';
});
shouldBehaveLikeValidHourDescription('estimatedTime', 52);
shouldBehaveLikeValidLinkedHourDescription('spentTime', 52, '/time_entries');
});
});
});

@ -41,6 +41,10 @@
<a ng-if="propertyData.value.viewable" title="{{propertyData.value.title}}" ng-href="{{propertyData.value.href}}">{{propertyData.value.title}}</a>
<span ng-if="!propertyData.value.viewable" title="{{propertyData.value.title}}">{{propertyData.value.title}}</span>
</span>
<span ng-switch-when="time_entry">
<a ng-if="propertyData.value.viewable" title="{{propertyData.value.title}}" ng-href="{{propertyData.value.href}}">{{propertyData.value.title}}</a>
<span ng-if="!propertyData.value.viewable" title="{{propertyData.value.title}}">{{propertyData.value.title}}</span>
</span>
<span ng-switch-when="category">{{ propertyData.value.props.name }}</span>
<span ng-switch-default
ng-bind="(propertyData.value !== undefined) ? propertyData.value : '-'"

Loading…
Cancel
Save