Repaired task reordering issue

* Created `conditionalOrderBy` filter with a similar signature to `orderBy`,
  using a single conditional argument that when false, causes the filter to
  return the array unchanged

* Updated task view to use `conditionalOrderBy`

* Added karma specs for `conditionalOrderBy` filter
This commit is contained in:
Kevin Gisi
2015-04-13 08:51:08 -04:00
parent 02838214c7
commit b503a0fd64
3 changed files with 39 additions and 1 deletions

30
test/spec/filtersSpec.js Normal file
View File

@@ -0,0 +1,30 @@
'use strict';
describe('Custom Filters', function() {
var filter
, orderBySpy = sinon.spy();
beforeEach(function() {
module(function($provide) {
$provide.value('orderByFilter', orderBySpy);
});
inject(function($rootScope, $filter) {
filter = $filter;
});
});
describe('conditionalOrderBy', function() {
describe('when the predicate is true', function() {
it('delegates the arguments to the orderBy filter', function() {
filter('conditionalOrderBy')('array', true, 'sortPredicate', 'reverseOrder');
expect(orderBySpy).to.have.been.calledWith('array','sortPredicate','reverseOrder');
});
});
describe('when the predicate is false', function() {
it('returns the initial array', function() {
expect(filter('conditionalOrderBy')([1,2,3], false)).to.eql([1,2,3]);
});
});
});
});

View File

@@ -21,3 +21,11 @@ angular.module('habitrpg')
(gp > 999) ? (gp / Math.pow(10, 3)).toFixed(1) + "k" : gp; (gp > 999) ? (gp / Math.pow(10, 3)).toFixed(1) + "k" : gp;
} }
}) })
.filter('conditionalOrderBy', function($filter) {
return function (array, predicate, sortPredicate, reverseOrder) {
if (predicate) {
return $filter('orderBy')(array, sortPredicate, reverseOrder);
}
return array;
};
});

View File

@@ -1,4 +1,4 @@
li(bindonce='list', id='task-{{::task.id}}', ng-repeat='task in obj[list.type+"s"] | orderBy:(list.view=="dated" ? "date" : nil)', class='task {{Shared.taskClasses(task, user.filters, user.preferences.dayStart, user.lastCron, list.showCompleted, main)}}', ng-click='spell && (list.type != "reward") && castEnd(task, "task", $event)', ng-class='{"cast-target":spell && (list.type != "reward"), "locked-task":obj._locked === true}', popover-trigger='mouseenter', data-popover-html="{{task.notes | markdown}}", popover-placement="top", popover-append-to-body='{{::modal ? "false":"true"}}', ng-show='shouldShow(task, list, user.preferences)') li(bindonce='list', id='task-{{::task.id}}', ng-repeat='task in obj[list.type+"s"] | conditionalOrderBy: list.view=="dated":"date"', class='task {{Shared.taskClasses(task, user.filters, user.preferences.dayStart, user.lastCron, list.showCompleted, main)}}', ng-click='spell && (list.type != "reward") && castEnd(task, "task", $event)', ng-class='{"cast-target":spell && (list.type != "reward"), "locked-task":obj._locked === true}', popover-trigger='mouseenter', data-popover-html="{{task.notes | markdown}}", popover-placement="top", popover-append-to-body='{{::modal ? "false":"true"}}', ng-show='shouldShow(task, list, user.preferences)')
// right-hand side control buttons // right-hand side control buttons
.task-meta-controls .task-meta-controls