From 47187557be06a51e7f131b37c264306e1bd489e9 Mon Sep 17 00:00:00 2001 From: Ihor Brazhnichenko Date: Tue, 29 Nov 2022 19:40:29 +0200 Subject: [PATCH] #23 Add filters for responsive-table and use operations-table like an example --- app/images/filter-on.svg | 3 + .../operations/operations-table.directive.js | 81 +++++++++++++++++-- app/ui/responsive-table.directive.js | 9 +++ app/ui/responsive-table.html | 54 +++++++++++++ 4 files changed, 141 insertions(+), 6 deletions(-) create mode 100644 app/images/filter-on.svg diff --git a/app/images/filter-on.svg b/app/images/filter-on.svg new file mode 100644 index 0000000..b3a29a4 --- /dev/null +++ b/app/images/filter-on.svg @@ -0,0 +1,3 @@ + + + diff --git a/app/sections/operations/operations-table.directive.js b/app/sections/operations/operations-table.directive.js index eb4dfea..072e2fd 100644 --- a/app/sections/operations/operations-table.directive.js +++ b/app/sections/operations/operations-table.directive.js @@ -88,7 +88,7 @@ Use this field show / hide user filters if(!name) return false; return { - id: key, + value: key, name, } }).filter((item) => !!item); @@ -119,12 +119,81 @@ Use this field show / hide user filters // see the issue: https://github.com/blocksights/blocksights-open-explorer/issues/15 $scope.userOpenedFirstPageTime = null; + const filters = [ + $scope.filterByAssetIdEnabled !== false ? { + width: '150px', + defaultValue: '', + placeholder: 'Search by asset', + onChange: (value) => { + $scope.filters.assetIdOrName = value; + $scope.select(1, true); + }, + modelOptions: { + debounce: 500, + getterSetter: true + } + } : null, + $scope.filterByAccountIdEnabled !== false ? { + width: '150px', + defaultValue: '', + placeholder: 'Search by account', + onChange: (value) => { + $scope.filters.accountIdOrName = value; + $scope.select(1, true); + }, + modelOptions: { + debounce: 500, + getterSetter: true + } + } : null, + ].filter((item) => !!item); + $scope.operationsColumns = $scope.columns || [ - OperationsService.columns.OPERATION_TEXT, - OperationsService.columns.OPERATION_ID, - OperationsService.columns.DATETIME, - OperationsService.columns.BLOCK, - OperationsService.columns.TYPE, + { + title: $filter('translate')('Operation'), + index: 'operation_text', + onFilterCancel: () => { + $scope.filters.assetIdOrName = undefined; + $scope.filters.accountIdOrName = undefined; + $scope.select(1, true) + }, + filter: filters.length ? filters : undefined + }, + { + title: $filter('translate')('ID'), + index: 'operation_id', + }, + { + title: $filter('translate')('Date and time'), + index: 'time', + hidden: ['xs'] + }, + { + title: $filter('translate')('Block'), + index: 'block_num', + hidden: ['xs', 'sm'] + }, + { + title: $filter('translate')('Type'), + index: 'type', + hidden: ['xs', 'sm', 'md'], + onFilterCancel: () => { + $scope.filters.operationType = '-1'; + $scope.select(1, true) + }, + filter: $scope.filterByOperationTypeEnabled !== false ? [ + { + width: '300px', + placeholder: 'Filter by operation id', + defaultValue: '-1', + onChange: (value) => { + $scope.filters.operationType = value; + $scope.select(1, true); + }, + options: $scope.operationTypes + } + ] : undefined + } ]; $scope.loadMore = () => { diff --git a/app/ui/responsive-table.directive.js b/app/ui/responsive-table.directive.js index 50900bd..4ae91d8 100644 --- a/app/ui/responsive-table.directive.js +++ b/app/ui/responsive-table.directive.js @@ -38,6 +38,15 @@ * * columns[].sortReverse {boolean} - Reverse the sorting when user sort the column * columns[].sortByDefault {boolean} - Turns on the sorting for the column when page loads + * + * columns[].filter[] - use an array to apply one or more filters to specific column + * columns[].filter[].width - The width of input/select + * columns[].filter[].placeholder - The placeholder of input/select + * columns[].filter[].defaultValue - Default value, please use '-1' for select + * columns[].filter[].onChange(value) - Handler for filter changes + * columns[].filter[].onFilterCancel - Handler when filter canceled (for e.g. to fetch non filtered data) + * columns[].filter[].modelOptions - ng-model-options + * columns[].filter[].options - use this for + + + +
+ +
+ @@ -53,6 +80,33 @@ {{column.title}}: + + + + +
+ +
+