Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure filters limit their search where needed
Browse files Browse the repository at this point in the history
macite committed Mar 3, 2023
1 parent 1549c46 commit f51b0a4
Showing 7 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ <h4 class="panel-title">Units</h4>
</tr>
</thead>
<tbody>
<tr ng-repeat="unit in filteredUnits = (teachingPeriod.units | filter:search) | orderBy:sortOrder:reverse | startFrom:(currentPage - 1) * pageSize | limitTo: pageSize" ui-sref="units/admin({unitId: unit.id})" >
<tr ng-repeat="unit in filteredUnits = (teachingPeriod.units | unitFilter:search) | orderBy:sortOrder:reverse | startFrom:(currentPage - 1) * pageSize | limitTo: pageSize" ui-sref="units/admin({unitId: unit.id})" >
<td>
<label class="label label-info">
{{unit.code}}
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ <h4 class="panel-title">Teaching Periods</h4>
Modify Teaching Periods registered with {{externalName.value}}
</div>
<form role="search" class="pull-right form-horizontal">
<input id="searchbar" class="input-md form-control" placeholder="Search for teaching periods..." type="search" ng-model="search.$" typeahead="teachingperiod.period for teachingperiod in teachingPeriods | filter:$viewValue | limitTo:8" />
<input id="searchbar" class="input-md form-control" placeholder="Search for teaching periods..." type="search" ng-model="search" typeahead="teachingperiod.period for teachingperiod in teachingPeriods | filter:$viewValue | limitTo:8" />
</form>
</div>
<div class="panel-body">
@@ -21,7 +21,7 @@ <h4 class="panel-title">Teaching Periods</h4>
</tr>
</thead>
<tbody>
<tr ng-repeat="teachingperiod in filteredTeachingPeriods = (teachingPeriods | filter:search) | orderBy:sortOrder:reverse | startFrom:(currentPage - 1) * pageSize | limitTo: pageSize" ui-sref="admin/teachingperiods/edit({teachingPeriodId: teachingperiod.id})" >
<tr ng-repeat="teachingperiod in filteredTeachingPeriods = (teachingPeriods | teachingPeriodFilter:search) | orderBy:sortOrder:reverse | startFrom:(currentPage - 1) * pageSize | limitTo: pageSize" ui-sref="admin/teachingperiods/edit({teachingPeriodId: teachingperiod.id})" >
<td>{{teachingperiod.name()}}</td>
<td>{{teachingperiod.startDate | date: 'EEE d MMM'}}</td>
<td>{{teachingperiod.endDate | date: 'EEE d MMM'}}</td>
2 changes: 1 addition & 1 deletion src/app/admin/states/units/units.tpl.html
Original file line number Diff line number Diff line change
@@ -75,7 +75,7 @@ <h4 class="panel-title">Units</h4>
</thead>
<tbody>
<tr
ng-repeat="unit in filteredUnits = (units | filter:search) | orderBy:sortOrder:reverse | startFrom:(currentPage - 1) * pageSize | limitTo: pageSize"
ng-repeat="unit in filteredUnits = (units | unitFilter:search) | orderBy:sortOrder:reverse | startFrom:(currentPage - 1) * pageSize | limitTo: pageSize"
ui-sref="units/admin({unitId: unit.id})"
>
<td>
2 changes: 1 addition & 1 deletion src/app/admin/states/users/users.tpl.html
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ <h4 class="panel-title">{{externalName.value}} Users</h4>
<tbody>
<tr
class="pointer"
ng-repeat="user in filteredUsers = (users | filter:search) | orderBy:sortOrder:reverse | startFrom:(currentPage - 1) * pageSize | limitTo: pageSize"
ng-repeat="user in filteredUsers = (users | unitFilter:search) | orderBy:sortOrder:reverse | startFrom:(currentPage - 1) * pageSize | limitTo: pageSize"
ng-click="showUserModal(user)"
>
<td>
10 changes: 10 additions & 0 deletions src/app/api/models/unit-role.ts
Original file line number Diff line number Diff line change
@@ -18,6 +18,16 @@ export class UnitRole extends Entity {
*/
roleId: number;

/**
* Compare this unit role against a lowercase text string
*
* @param text the lowercase text to match
* @returns true if this role relates to that text
*/
public matches(text: string): boolean {
return this.user.matches(text) || this.unit.matches(text);
}

public override toJson<T extends Entity>(mappingData: EntityMapping<T>, ignoreKeys?: string[]): object {
return {
unit_role: super.toJson(mappingData, ignoreKeys),
18 changes: 18 additions & 0 deletions src/app/common/filters/filters.coffee
Original file line number Diff line number Diff line change
@@ -140,6 +140,24 @@ angular.module("doubtfire.common.filters", [])
input
)

.filter('unitFilter', ->
(input, text) ->
if _.isString(text) && text.length > 0 && input
matchText = text.toLowerCase()
_.filter input, (unit) -> (unit?) && unit.matches(matchText)
else
input
)

.filter('teachingPeriodFilter', ->
(input, text) ->
if _.isString(text) && text.length > 0 && input
matchText = text.toLowerCase()
_.filter input, (tp) -> (tp?) && tp.period.toLowerCase().indexOf(matchText) >= 0
else
input
)


.filter('taskForPortfolio', (newTaskService) ->
(input, apply) ->
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ <h4 class="panel-title">Units</h4>
</tr>
</thead>
<tbody>
<tr ng-repeat="unitRole in filteredUnitRoles = (unitRoles | filter:search) | orderBy:sortOrder:reverse | startFrom:(currentPage - 1) * pageSize | limitTo: pageSize" ui-sref="units/tasks/inbox({ unitId: unitRole.unit.id })">
<tr ng-repeat="unitRole in filteredUnitRoles = (unitRoles | unitFilter:search) | orderBy:sortOrder:reverse | startFrom:(currentPage - 1) * pageSize | limitTo: pageSize" ui-sref="units/tasks/inbox({ unitId: unitRole.unit.id })">
<td>
<label class="label label-info">
{{unitRole.unit.code}}

0 comments on commit f51b0a4

Please sign in to comment.