I am displaying users in a table with ng-repeat. One of the columns, "Status" is computed by a function and can return a value 'Active', 'Idle' or 'Locked'. The function uses the current date time to calculate this.
If LastAccess is within the last 5 minutes, the 'Active' status is displayed.
Here is what the table looks like:
Here is the HTML markup:
<tr ng-repeat="user in UserTable.Rows" ng-click="openUser(user.UserID)">
<td>{{user.FirstName}} {{user.LastName}}</td>
<td>{{user.Email}}</td>
<td>{{user.OfficeName}}</td>
<td>{{user.DeptName}}</td>
<td>{{user.RoleName}}</td>
<td><span class="label label-{{getStatus(user)=='Idle'?'default':(getStatus(user)=='Locked'?'danger':'success')}}">{{getStatus(user)}}</span> </td>
<td>{{user.LastAccess|timeAgo}}</td>
</tr>
And here is the function for getStatus:
$scope.getStatus = function (usr) {
if (usr.Locked) return 'Locked';
if (!usr.LastAccess) return 'Idle';
var diff = (new Date().getTime() - new Date(usr.LastAccess).getTime()) / 1000;
console.log(diff);
if (diff < 300) return 'Active'; else return 'Idle';
}
The problem is that the function is called three times every second for each user (as per the console.log function). I understand why it is called three times (as it is used thrice in the HTML). But can I prevent this from updating every second? Calling the function once a minute would be enough for me. How do I do that?
Is there a better way to do this without creating a filter?
