diff --git a/app/portainer/components/endpoint-list/endpoint-list-controller.js b/app/portainer/components/endpoint-list/endpoint-list-controller.js new file mode 100644 index 000000000..aab801410 --- /dev/null +++ b/app/portainer/components/endpoint-list/endpoint-list-controller.js @@ -0,0 +1,60 @@ +angular.module('portainer.app').controller('EndpointListController', [ + function EndpointListController() { + var ctrl = this; + ctrl.state = { + textFilter: '', + filteredEndpoints: [] + }; + + ctrl.$onChanges = $onChanges; + ctrl.onFilterChanged = onFilterChanged; + + function $onChanges(changesObj) { + handleEndpointsChange(changesObj.endpoints); + } + + function handleEndpointsChange(endpoints) { + if (!endpoints) { + return; + } + if (!endpoints.currentValue) { + return; + } + + onFilterChanged(); + } + + function onFilterChanged() { + var filterValue = ctrl.state.textFilter; + ctrl.state.filteredEndpoints = filterEndpoints( + ctrl.endpoints, + filterValue + ); + } + + function filterEndpoints(endpoints, filterValue) { + if (!endpoints || !endpoints.length || !filterValue) { + return endpoints; + } + var keywords = filterValue.split(' '); + return _.filter(endpoints, function(endpoint) { + var statusString = convertStatusToString(endpoint.Status); + return _.every(keywords, function(keyword) { + var lowerCaseKeyword = keyword.toLowerCase(); + return ( + _.includes(endpoint.Name.toLowerCase(), lowerCaseKeyword) || + _.includes(endpoint.GroupName.toLowerCase(), lowerCaseKeyword) || + _.some(endpoint.Tags, function(tag) { + return _.includes(tag.toLowerCase(), lowerCaseKeyword); + }) || + _.includes(statusString, keyword) + ); + }); + }); + } + + function convertStatusToString(status) { + return status === 1 ? 'up' : 'down'; + } + } +]); diff --git a/app/portainer/components/endpoint-list/endpoint-list.js b/app/portainer/components/endpoint-list/endpoint-list.js index d6a4bd33e..a622c3db4 100644 --- a/app/portainer/components/endpoint-list/endpoint-list.js +++ b/app/portainer/components/endpoint-list/endpoint-list.js @@ -1,10 +1,6 @@ angular.module('portainer.app').component('endpointList', { templateUrl: 'app/portainer/components/endpoint-list/endpointList.html', - controller: function() { - this.state = { - textFilter: '' - }; - }, + controller: 'EndpointListController', bindings: { titleText: '@', titleIcon: '@', diff --git a/app/portainer/components/endpoint-list/endpointList.html b/app/portainer/components/endpoint-list/endpointList.html index 9b4850dd0..2886916f1 100644 --- a/app/portainer/components/endpoint-list/endpointList.html +++ b/app/portainer/components/endpoint-list/endpointList.html @@ -16,12 +16,17 @@
Loading...
-
+
No endpoint available.