     _.filter tasks, (task) ->
       task.project().name.toLowerCase().indexOf(searchName) >= 0
 )
+
+.filter('groupsInTutorials', ->
+  (input, unitRole, kind) ->
+    return unless input? && unitRole? && kind?
+    return input if kind == 'all'
+    if kind == 'mine'
+      _.filter(input, (group) -> group.tutorial().tutor_name == unitRole.name)
+)
+
+.filter('groupsForStudent', ->
+  (input, project, groupSet) ->
+    # Filter by tutorial if keep groups in same class
+    return unless input? && groupSet? && project?
+    return input unless groupSet.keep_groups_in_same_class
+    if groupSet.keep_groups_in_same_class
+      _.filter(input, (group) -> group.tutorial_id == project.tutorial?.id)
+)
+
+.filter('paginateAndSort', ($filter) ->
+  (input, pagination, tableSort) ->
+    return unless input? && tableSort? && pagination?
+    return input if input.length == 0
+    pagination.show = input.length > pagination.pageSize
+    pagination.totalSize = input.length
+    input = $filter('orderBy')(input, tableSort.order, tableSort.reverse)
+    input = $filter('startFrom')(input, (pagination.currentPage - 1) * pagination.pageSize)
+    input = $filter('limitTo')(input, pagination.pageSize)
+    input
+)

        _.filter input, (student) -> (student?) && (student.tutorial_id == group.tutorial_id) && (not _.find(members, (mbr) -> student.project_id == mbr.project_id ))
      else
        _.filter input, (student) -> (student?) && not _.find(members, (mbr) -> student.project_id == mbr.project_id )
    else
      input
)

#
# Filter groups for students and in group admin pages
#   gs: group set to determine if keep to class
#   project: nil for admin pages, otherwise student
#   assessingUnitRole: nil for student, otherwise staff details
#   kind: 'all' | 'mine'
#
.filter('groupFilter', ->
  (input, unit, gs, project, assessingUnitRole, kind) ->
    if input
      if assessingUnitRole && ! project # staff only... so tutorial is ignored!
        if kind == 'mine'
          _.filter input, (group) -> unit.tutorialFromId(group.tutorial_id).tutor_name == assessingUnitRole.name
        else # just all
          input
      else  # student...
        if gs.keep_groups_in_same_class # match just those in this tutorial
          _.filter input, (group) -> (project.tutorial?) && group.tutorial_id == project.tutorial.id
        else # all
          input
    else
      input
)

#
.filter('startFrom', ->
  (input, start) ->
    input?.slice(+start)
)

.filter('showStudents', ->
