diff --git a/public/resources/js/directives/api-list.js b/public/resources/js/directives/api-list.js index 80557780d7..339ebb6ee6 100644 --- a/public/resources/js/directives/api-list.js +++ b/public/resources/js/directives/api-list.js @@ -10,13 +10,13 @@ angularIO.directive('apiList', function () { '
All
' + '
{{apiType.title}}
' + ' ' + - ' ' + + ' ' + '' + '
' + - '
' + + '
' + '

{{ section.title }}

' + ' ' + @@ -38,15 +38,36 @@ angularIO.directive('apiList', function () { $ctrl.apiFilter = getApiFilterFromLocation(); $ctrl.apiType = getApiTypeFromLocation(); - $ctrl.filteredSections = []; + $ctrl.groupedSections = []; $ctrl.setType = function (type) { if (type === $ctrl.apiType) $ctrl.apiType = null; else $ctrl.apiType = type; }; + $ctrl.isFiltered = function(section) { + var apiFilter = ($ctrl.apiFilter || '').toLowerCase(); + var matchesModule = $ctrl.apiFilter === '' || $ctrl.apiFilter === null || section.title.toLowerCase().indexOf($ctrl.apiFilter.toLowerCase()) !== -1; + var isVisible = false; + + section.items.forEach(function(item) { + var matchesDocType = !$ctrl.apiType || $ctrl.apiType.matches.indexOf(item.docType) !== -1; + var matchesTitle = !apiFilter || item.title.toLowerCase().indexOf(apiFilter) !== -1; + item.show = matchesDocType && (matchesTitle || matchesModule); + + if (item.show) { + isVisible = true; + } + }); + + return isVisible; + }; + $http.get($attrs.src).then(function(response) { $ctrl.sections = response.data; + $ctrl.groupedSections = Object.keys($ctrl.sections).map(function(title) { + return { title: title, items: $ctrl.sections[title] }; + }); }); $scope.$watchGroup( @@ -56,19 +77,6 @@ angularIO.directive('apiList', function () { $location.search(API_FILTER_KEY, apiFilter || null); $location.search(API_TYPE_KEY, $ctrl.apiType && $ctrl.apiType.title || null); - - $ctrl.filteredSections.length = 0; - angular.forEach($ctrl.sections, function(section, title) { - var matchesModule = $ctrl.apiFilter === '' || $ctrl.apiFilter === null || title.toLowerCase().indexOf($ctrl.apiFilter.toLowerCase()) !== -1; - var filteredItems = section.filter(function(item) { - var matchesDocType = !$ctrl.apiType || $ctrl.apiType.matches.indexOf(item.docType) !== -1; - var matchesTitle = !apiFilter || item.title.toLowerCase().indexOf(apiFilter) !== -1; - return matchesDocType && (matchesTitle || matchesModule); - }); - if (filteredItems.length) { - $ctrl.filteredSections.push({ title: title, items: filteredItems }); - } - }); } ); @@ -81,7 +89,7 @@ angularIO.directive('apiList', function () { if (!apiFilter) { return null; } else if (!$ctrl.apiFilter || $ctrl.apiFilter.title != apiFilter) { - for(var i = 0, ii = $ctrl.apiTypes.length; i < ii; i++) { + for (var i = 0, ii = $ctrl.apiTypes.length; i < ii; i++) { if ($ctrl.apiTypes[i].title == apiFilter) { return $ctrl.apiTypes[i]; }