I need to implement a function within the ng-repeat
that will convert the value of Qprogress object in my JSON into a percentage. I already have the function written, but I am struggling with how to trigger it. I attempted to use a forEach loop inside the scope and then utilize the scope as the ng-model for the element I want to modify, but this approach is not yielding desired results.
Below is the HTML structure:
<tr ng-repeat="item in clients" progressCalc>
<td>
<a href="#/details/{{clients.indexOf(item)}}" title="Link to {{item.FirstName}} {{item.LastName}}" class="oly-open">{{item.FirstName}} {{item.LastName}}</a>
</td>
<td ng-hide="item.Progress == 'In Progress'" ng-class="{ 'status-success': item.Progress == 'Questionnaire Completed', 'status-error': item.Progress == 'Unsent'}">
{{item.Progress}}
</td>
<td ng-if="item.Progress == 'In Progress'" ng-model="progressCalc" class="status-info percent">
{{item.Qprogress}}
</td>
<td width="10%">
<a href="#/reports/" title{{$index + 1}}="Reports" ng-show="{{item.Progress == 'Questionnaire Completed'}}">
<span class="stat-icon-report"></span>
</a>
<a href="#/sends/{{$index + 1}}" title="Alert" ng-show="{{item.Progress == 'Unsent'}}">
<span class="stat-icon-bullhorn"></span>
</a>
<a href="#/progress/{{$index + 1}}" title="In Progress" ng-show="{{item.Progress == 'In Progress'}}">
<span class="stat-icon-phone"></span>
</a>
</td>
</tr>
Additionally, here is the corresponding JavaScript code:
myApp.controller('clientStatus', ['$scope', '$http', function($scope, $http) {
$http.get('assets/js/lib/angular/clientList.json').success(function(data) {
$scope.clients = data;
$scope.progressCalc = function() {
angular.forEach(function(item) {
var m = 0.26664;
var s = 0.26664;
var i = 0.694375;
var t = item.Qprogress;
t = t.replace(/m/g,'');
t = t.replace(/s/g,'');
t = t.replace(/i/g,'');
var ta = t.split("/");
var tTotal = (ta[0] * m) + (ta[1] * s) + (ta[2] * i);
tTotal = Math.round(tTotal);
$('.percent').append(tTotal + '%');
});
};
});
}]);
Lastly, here's a snippet of the JSON data format:
"FirstName": "Bill",
"LastName": "Johnson",
"Company": "Texas Instruments",
"CompanyId": "2345672",
"ClientId": "EFTGE6",
"Title": "CIO",
"Phone": "555-555-5555",
"ClientSystemStatus": "Active",
"CreationDate": "06/03/2015, 10:35:59 am",
"Progress": "In Progress",
"Qprogress": "m125/s40/i0",
"Email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e1838b8e89928e8fa19588cf828e8c">[email protected]</a>"
Thank you!