Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overview and Agents refactor #564

Merged
merged 13 commits into from
Jun 12, 2018
19 changes: 15 additions & 4 deletions public/controllers/agents-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ app.controller('agentsPreviewController', function ($scope, $rootScope, $routePa
const data = await Promise.all([
$scope.agents.nextPage(),
apiReq.request('GET', '/agents/summary', { }),
genericReq.request('GET', tmpUrl),
apiReq.request('GET', '/agents', { sort:'-dateAdd', limit:9999999 })
genericReq.request('GET', tmpUrl)
]);

// Agents summary
Expand Down Expand Up @@ -151,10 +150,22 @@ app.controller('agentsPreviewController', function ($scope, $rootScope, $routePa
}
}

// Fetch agents sorting by -dateAdd and using pagination
const agents = [];
const total_items = data[1].data.data.Total;
let offset = 0;
const limit = 1000;
while(agents.length < total_items){
const page = await apiReq.request('GET', '/agents', { sort:'-dateAdd', limit, offset });
agents.push(...page.data.data.items)
offset += limit;
}


// Last agent
$scope.lastAgent = data[3].data.data.items[0];
$scope.lastAgent = agents[0];

retrieveList(data[3].data.data.items);
retrieveList(agents);

$scope.loading = false;
if(!$scope.$$phase) $scope.$digest();
Expand Down