Add reverse view model attribute

pull/3913/head
Alex Dik 9 years ago
parent 1e135e8c21
commit 5d9f26eb26
  1. 4
      frontend/app/components/wp-panels/activity-panel/activity-panel-overview.directive.html
  2. 2
      frontend/app/components/wp-panels/activity-panel/activity-panel.controller.js
  3. 7
      frontend/app/ui_components/filters/latest-items-filter.js
  4. 4
      frontend/tests/unit/tests/ui_components/filters/latest-items-filter-test.js

@ -2,14 +2,14 @@
activities="vm.activities" activities="vm.activities"
autocomplete-path="{{ vm.autocompletePath }}"> autocomplete-path="{{ vm.autocompletePath }}">
<ul class='work-package-details-activities-list'> <ul class='work-package-details-activities-list'>
<li ng-repeat="activity in vm.activities | latestItems : vm.order === 'desc' : 3" <li ng-repeat="activity in vm.activities | latestItems : vm.reverse : 3"
class="work-package-details-activities-activity" class="work-package-details-activities-activity"
ng-init="inf = vm.info(activity, $index)"> ng-init="inf = vm.info(activity, $index)">
<activity-entry work-package="vm.workPackage" <activity-entry work-package="vm.workPackage"
activity="activity" activity="activity"
activity-no="inf.number(vm.order !== 'desc')" activity-no="inf.number(vm.reverse)"
is-initial="inf.isInitial" is-initial="inf.isInitial"
autocomplete-path="vm.autocompletePath"> autocomplete-path="vm.autocompletePath">
</activity-entry> </activity-entry>

@ -35,7 +35,7 @@ function ActivityPanelController($scope, wpActivity, PathHelper){
var vm = this; var vm = this;
vm.activities = wpActivity.activities; vm.activities = wpActivity.activities;
vm.order = wpActivity.order; vm.reverse = wpActivity.order === 'asc';
vm.info = wpActivity.info; vm.info = wpActivity.info;
var projectId = vm.workPackage.embedded.project.props.id; var projectId = vm.workPackage.embedded.project.props.id;

@ -27,10 +27,7 @@
//++ //++
module.exports = function() { module.exports = function() {
return function(items, isDescending, visible) { return function(items, reverse, visible) {
return reverse ? items.slice(-visible).reverse() : items.slice(0,visible);
// We want to enforce descending order here, and when the setting
// is already descending, we no longer have to do that ourselves.
return isDescending ? items.slice(0,visible) : items.slice(-visible).reverse();
}; };
}; };

@ -44,11 +44,11 @@ describe('Latest items filter', function() {
})); }));
it('should return the first 3 items', inject(function($filter) { it('should return the first 3 items', inject(function($filter) {
expect($filter('latestItems')(items, false, 3)).to.eql([9,8,7]); expect($filter('latestItems')(items, true, 3)).to.eql([9,8,7]);
})); }));
it('should return the last 3 items reversed', inject(function($filter) { it('should return the last 3 items reversed', inject(function($filter) {
expect($filter('latestItems')(items, true, 3)).to.eql([1,2,3]); expect($filter('latestItems')(items, false, 3)).to.eql([1,2,3]);
})); }));
}); });

Loading…
Cancel
Save