This commit is contained in:
Kyle Spearrin 2017-12-15 14:53:57 -05:00
parent de3a9b9903
commit 8a3fb92bbe
2 changed files with 31 additions and 9 deletions

View File

@ -6,6 +6,7 @@
$scope.events = []; $scope.events = [];
$scope.orgUsers = []; $scope.orgUsers = [];
$scope.loading = true; $scope.loading = true;
$scope.continuationToken = null;
var d = new Date(); var d = new Date();
$scope.filterEnd = new Date(d.getFullYear(), d.getMonth(), d.getDate(), 23, 59); $scope.filterEnd = new Date(d.getFullYear(), d.getMonth(), d.getDate(), 23, 59);
@ -17,7 +18,11 @@
}); });
$scope.refresh = function () { $scope.refresh = function () {
loadEvents(); loadEvents(true);
};
$scope.next = function () {
loadEvents(false);
}; };
var i = 0, var i = 0,
@ -44,13 +49,11 @@
$scope.orgUsers = users; $scope.orgUsers = users;
return loadEvents(); return loadEvents(true);
}); });
} }
function loadEvents() { function loadEvents(clearExisting) {
$scope.loading = true;
var start = null, end = null; var start = null, end = null;
try { try {
var format = 'yyyy-MM-ddTHH:mm'; var format = 'yyyy-MM-ddTHH:mm';
@ -59,16 +62,24 @@
} catch (e) { } } catch (e) { }
if (!start || !end || end < start) { if (!start || !end || end < start) {
$scope.loading = false;
alert('Invalid date range.'); alert('Invalid date range.');
return; return;
} }
if (clearExisting) {
$scope.continuationToken = null;
$scope.events = [];
}
$scope.loading = true;
return apiService.events.listOrganization({ return apiService.events.listOrganization({
orgId: $state.params.orgId, orgId: $state.params.orgId,
start: start, start: start,
end: end end: end,
continuationToken: $scope.continuationToken
}).$promise.then(function (list) { }).$promise.then(function (list) {
$scope.continuationToken = list.ContinuationToken;
var events = []; var events = [];
for (i = 0; i < list.Data.length; i++) { for (i = 0; i < list.Data.length; i++) {
var userId = list.Data[i].ActingUserId || list.Data[i].UserId; var userId = list.Data[i].ActingUserId || list.Data[i].UserId;
@ -81,7 +92,12 @@
date: list.Data[i].Date date: list.Data[i].Date
}); });
} }
if ($scope.events && $scope.events.length > 0) {
$scope.events = $scope.events.concat(events);
}
else {
$scope.events = events; $scope.events = events;
}
$scope.loading = false; $scope.loading = false;
}); });
} }

View File

@ -39,7 +39,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr ng-repeat="event in filteredEvents = (events | orderBy: ['-date'])"> <tr ng-repeat="event in filteredEvents = (events)">
<td style="width: 210px; min-width: 100px;"> <td style="width: 210px; min-width: 100px;">
{{event.date | date:'medium'}} {{event.date | date:'medium'}}
</td> </td>
@ -57,5 +57,11 @@
</table> </table>
</div> </div>
</div> </div>
<div class="box-footer text-center" ng-show="continuationToken">
<button class="btn btn-link btn-block" ng-click="next()" ng-if="!loading">
Load more...
</button>
<i class="fa fa-fw fa-refresh fa-spin text-muted" ng-if="loading"></i>
</div>
</div> </div>
</section> </section>