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

Table directive improvements #627

Merged
merged 2 commits into from Jun 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 27 additions & 26 deletions public/directives/wazuh-table/controller.js
Expand Up @@ -47,7 +47,7 @@ app.directive('wazuhTable', function() {
} else if(instance.path === '/cluster/nodes') {
$scope.$emit('wazuhShowClusterNode',{node:item})
}
}
};

let realTime = false;

Expand Down Expand Up @@ -79,6 +79,7 @@ app.directive('wazuhTable', function() {
}
}
};

$scope.range = function (size,start, end) {
const ret = [];

Expand Down Expand Up @@ -109,8 +110,8 @@ app.directive('wazuhTable', function() {
};
////////////////////////////////////

const instance = new DataFactory(apiReq,$scope.path,$scope.implicitFilter)
$scope.items = []
const instance = new DataFactory(apiReq,$scope.path,$scope.implicitFilter);
$scope.items = [];

$scope.sort = async field => {
try {
Expand All @@ -131,7 +132,7 @@ app.directive('wazuhTable', function() {
errorHandler.handle(error,'Data factory')
}
return;
}
};

const search = async (term, removeFilters) => {
try {
Expand All @@ -152,7 +153,7 @@ app.directive('wazuhTable', function() {
errorHandler.handle(error,'Data factory')
}
return;
}
};

const filter = async filter => {
try {
Expand All @@ -179,26 +180,26 @@ app.directive('wazuhTable', function() {
errorHandler.handle(error,'Data factory')
}
return;
}
};

$scope.$on('wazuhUpdateInstancePath',(event,parameters) => {
instance.path = parameters.path;
return init();
})
});

$scope.$on('wazuhFilter',(event,parameters) => {
return filter(parameters.filter)
})
});

$scope.$on('wazuhSearch',(event,parameters) => {
return search(parameters.term,parameters.removeFilters)
})
});

$scope.$on('wazuhRemoveFilter',(event,parameters) => {
instance.filters = instance.filters.filter(item => item.name !== parameters.filterName);
wzTableFilter.set(instance.filters)
return init();
})
});

const realTimeFunction = async () => {
try {
Expand All @@ -218,24 +219,24 @@ app.directive('wazuhTable', function() {
errorHandler.handle(error,'Data factory')
}
return;
}
};

$scope.$on('wazuhPlayRealTime',() => {
realTime = true;
return realTimeFunction();
})
});

$scope.$on('wazuhStopRealTime',() => {
realTime = false;
return init();
})
});

const checkGap = () => {
const gap = items.length / 20;
const gapInteger = parseInt(items.length / 20);
$scope.gap = gap - parseInt(items.length / 20) > 0 ? gapInteger + 1 : gapInteger;
const gap = items.length / $scope.itemsPerPage;
const gapInteger = parseInt(gap);
$scope.gap = gap - gapInteger > 0 ? gapInteger + 1 : gapInteger;
if($scope.gap > 5) $scope.gap = 5;
}
};

const init = async () => {
try {
Expand All @@ -254,9 +255,9 @@ app.directive('wazuhTable', function() {
errorHandler.handle(error,'Data factory')
}
return;
}
};

init()
init();

const splitArray = array => {
if(Array.isArray(array)){
Expand All @@ -267,18 +268,18 @@ app.directive('wazuhTable', function() {
return str;
}
return array;
}
};

$scope.checkIfArray = item => {
return typeof item === 'object' ?
splitArray(item) :
item == 0 ? '0' : item;
}
};

$scope.$on('$destroy',() => {
realTime = null;
wzTableFilter.set([])
})
wzTableFilter.set([]);
});

},
template: template
Expand All @@ -287,7 +288,7 @@ app.directive('wazuhTable', function() {
.service('wzTableFilter',() => {
const filters = [];
return {
set: array => { if(Array.isArray(array)) { filters.length = 0; filters.push(...array) } },
set: array => { if(Array.isArray(array)) { filters.length = 0; filters.push(...array); } },
get: () => filters
}
})
};
});
6 changes: 3 additions & 3 deletions public/directives/wazuh-table/template.html
Expand Up @@ -41,16 +41,16 @@
<span ng-show="!wazuh_table_loading" class="color-grey">{{ totalItems }} items ({{time | number: 2}} seconds)</span>
<div ng-show="items.length >= itemsPerPage" class="pagination pull-right" style="margin:0 !important">
<ul layout="row">
<li ng-class="{disabled: currentPage == 0}" class="md-padding">
<li ng-show="currentPage" class="md-padding">
<a href ng-click="prevPage()">« Prev</a>
</li>

<li ng-repeat="n in range(pagedItems.length, currentPage, currentPage + gap) " ng-class="{active: n == currentPage}" ng-click="setPage()"
<li ng-repeat="n in range(pagedItems.length, currentPage, currentPage + gap) " ng-class="{'wz-text-active': n == currentPage}" ng-click="setPage()"
class="md-padding">
<a href ng-bind="n + 1">1</a>
</li>

<li ng-class="{disabled: (currentPage) == pagedItems.length - 1}" class="md-padding">
<li ng-show="currentPage < pagedItems.length - 1" class="md-padding">
<a href ng-click="nextPage()">Next »</a>
</li>
</ul>
Expand Down