diff --git a/public/directives/wz-table/wz-table-rows.js b/public/directives/wz-table/wz-table-rows.js new file mode 100644 index 000000000..b4b2e7dfd --- /dev/null +++ b/public/directives/wz-table/wz-table-rows.js @@ -0,0 +1,17 @@ +/* + * Wazuh app - Wazuh table directive helper + * Copyright (C) 2018 Wazuh, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Find more information about this on the LICENSE file. + */ +export default (windowHeight, sizes) => { + if(windowHeight >= 950) return sizes[0]; + if(windowHeight >= 850 && windowHeight < 950) return sizes[1]; + if(windowHeight >= 750 && windowHeight < 850) return sizes[2]; + return 8; +} \ No newline at end of file diff --git a/public/directives/wz-table/wz-table.js b/public/directives/wz-table/wz-table.js index 1c4c94085..efc9b3e4d 100644 --- a/public/directives/wz-table/wz-table.js +++ b/public/directives/wz-table/wz-table.js @@ -14,10 +14,11 @@ import template from './wz-table.html'; import { uiModules } from 'ui/modules'; import DataFactory from '../../services/data-factory'; import KeyEquivalenece from '../../../util/csv-key-equivalence'; +import CheckRows from './wz-table-rows' const app = uiModules.get('app/wazuh', []); -app.directive('wazuhTable', function() { +app.directive('wzTable', function() { return { restrict: 'E', scope: { @@ -25,10 +26,25 @@ app.directive('wazuhTable', function() { keys: '=keys', allowClick: '=allowClick', implicitFilter: '=implicitFilter', - rowsPerPage: '=rowsPerPage', + rowSizes: '=rowSizes', extraLimit: '=extraLimit' }, - controller: function($scope, apiReq, $timeout, shareAgent, $location, errorHandler, wzTableFilter) { + controller: function($scope, apiReq, $timeout, shareAgent, $location, errorHandler, wzTableFilter, $window) { + /** + * Calculate number of table rows depending on the screen height + */ + const rowSizes = $scope.rowSizes || [15,13,11] + let doit; + $window.onresize = () => { + clearTimeout(doit); + doit = setTimeout(() => { + $scope.rowsPerPage = CheckRows($window.innerHeight,rowSizes); + $scope.itemsPerPage = $scope.rowsPerPage; + init() + }, 150); + }; + $scope.rowsPerPage = CheckRows($window.innerHeight,rowSizes); + $scope.keyEquivalence = KeyEquivalenece; $scope.totalItems = 0; @@ -285,6 +301,7 @@ app.directive('wazuhTable', function() { item; $scope.$on('$destroy',() => { + $window.onresize = null; realTime = null; wzTableFilter.set([]); }); @@ -304,7 +321,6 @@ app.directive('wazuhTable', function() { (item.details && item.details.order ? item.details.order : false) || '---' : checkIfArray(item[key.value || key]) || '---'; }; - }, template: template } diff --git a/public/templates/agents-prev/agents-prev.html b/public/templates/agents-prev/agents-prev.html index 1c65b48a1..9ce0e9080 100644 --- a/public/templates/agents-prev/agents-prev.html +++ b/public/templates/agents-prev/agents-prev.html @@ -101,13 +101,13 @@