Skip to content

Commit

Permalink
#23 Add pagination for operations
Browse files Browse the repository at this point in the history
  • Loading branch information
ihorml committed Nov 9, 2022
1 parent 93f5399 commit 10f4261
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 9 deletions.
2 changes: 2 additions & 0 deletions app/sections/credit_offers/credit_offer.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
group-by-credit-offer-id="credit_offer_id"
filter-by-asset-id-enabled="false"
show-filters="showFilters"
default-date-from="now-1y"
filters-date-from="now-1y"
/>
</div>
</div>
5 changes: 4 additions & 1 deletion app/sections/dashboard/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@
<img src="images/filter.svg" ng-click="showFilters = !showFilters" class="operations-filter"/>
</div>

<operations-table total-items="total_ops" show-filters="showFilters"/>
<operations-table total-items="total_ops"
show-filters="showFilters"
default-date-from="now-1M"
filters-date-from="now-1y"/>

</div>
</div>
25 changes: 19 additions & 6 deletions app/sections/operations/operations-table.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ This show/hide filtering fields for the user to filter all operations by account
_ _ _ _ _ _ _ _
| Date From |
- - - - - - - -
Use this field to optimize ES search by date limits
Use this fields to optimize ES search by date limits
// By default: now-1M
(Example)
<operations-table date-from="now-1y"/>
<operations-table default-date-from="now-1y"/> this is a date-from which applies when no filters
<operations-table filters-date-from="now-1y"/> this is a date-from which applies when any filter defined by the user
_ _ _ _ _ _ _ _ _
| Show filters |
Expand All @@ -63,7 +64,8 @@ Use this field show / hide user filters
groupByAccountId: '=',
groupByCreditOfferId: '=',
groupByPoolId: '=',
dateFrom: "@",
defaultDateFrom: "@",
filtersDateFrom: "@",
filterByAccountIdEnabled: '=',
filterByAssetIdEnabled: '=',
filterByOperationTypeEnabled: '=',
Expand All @@ -74,6 +76,10 @@ Use this field show / hide user filters

function operationsTableController($scope, $filter, Notify, OperationsService, utilities) {

function filtersDefined() {
return $scope.filters.operationType !== '-1' || $scope.filters.accountIdOrName || $scope.filters.assetIdOrName;
}

// list of values for filter by operation type <select>
$scope.operationTypes = new Array(75).fill('#').map((item, key) => {
const name = utilities.operationType(key)[0]
Expand All @@ -85,7 +91,10 @@ Use this field show / hide user filters
}
}).filter((item) => !!item);

$scope.dateFrom = $scope.dateFrom || 'now-1M'
$scope.totalItems = 0;

$scope.defaultDateFrom = $scope.defaultDateFrom || 'now-1M'
$scope.filtersDateFrom = $scope.filtersDateFrom || 'now-1y'

// default values for filtering fields
$scope.filters = {
Expand Down Expand Up @@ -113,6 +122,9 @@ Use this field show / hide user filters
];

$scope.select = function (page_operations) {
if(page_operations === 1)
$scope.totalItems = 0;

const page = page_operations - 1;
const limit = 20;
const offset = page * limit;
Expand All @@ -129,7 +141,7 @@ Use this field show / hide user filters
limit,
offset,
date_to,
date_from: $scope.dateFrom || undefined,
date_from: filtersDefined() ? $scope.filtersDateFrom : $scope.defaultDateFrom || undefined,
assetId: $scope.filters.assetIdOrName,
accountId: $scope.groupByAccountId || $scope.filters.accountIdOrName,
creditOfferId: $scope.groupByCreditOfferId,
Expand Down Expand Up @@ -158,7 +170,8 @@ Use this field show / hide user filters
allowMultiple: true
});
} else {
$scope.operations = response;
$scope.totalItems += response.length;
$scope.operations = response.slice(0, limit); // remove the additional item which defines the existence of the next page
$scope.currentPage = page_operations;
if (page_operations == 1) {
if (response.length > 0) {
Expand Down
5 changes: 4 additions & 1 deletion app/sections/operations/operations.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<img src="images/filter.svg" ng-click="showFilters = !showFilters" class="operations-filter"/>
</div>

<operations-table show-filters="showFilters"/>
<operations-table show-filters="showFilters"
default-date-from="now-1M"
filters-date-from="now-1y"
/>
</div>
</div>
2 changes: 1 addition & 1 deletion app/sections/operations/operations.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

return $http.get(appConfig.urls.elasticsearch_wrapper() + "/history", {
params: {
"limit": limit,
"limit": limit + 1, // fetch a one more item to define is there a next page
"offset": offset,
"from_date": date_from ? date_from : (offset < MAGIC_NUMBER ? "now-1M" : "2015-10-10"),
"to_date": date_to,
Expand Down
2 changes: 2 additions & 0 deletions app/sections/pools/pool.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@
filter-by-asset-id-enabled="false"
filter-by-operation-type-enabled="false"
show-filters="showFilters"
default-date-from="now-1y"
filters-date-from="now-1y"
/>
</div>
</div>
Expand Down

0 comments on commit 10f4261

Please sign in to comment.