2015-12-10 14:27:54 -05:00
|
|
|
angularIO.directive('apiList', function () {
|
2015-12-14 06:12:23 -05:00
|
|
|
var API_FILTER_KEY = 'apiFilter';
|
|
|
|
var API_TYPE_KEY = 'apiType';
|
2015-12-10 14:27:54 -05:00
|
|
|
return {
|
|
|
|
restrict: 'E',
|
|
|
|
template:
|
|
|
|
'<div ng-cloak="ng-cloak" class="banner">' +
|
|
|
|
' <dl class="api-key">' +
|
|
|
|
' <dt>Display:</dt>' +
|
2015-12-15 16:03:41 -05:00
|
|
|
' <dd ng-class="{ active: !$ctrl.apiType }" ng-click="$ctrl.apiType = null">All</dd>' +
|
2015-12-10 14:27:54 -05:00
|
|
|
' <dd ng-repeat="apiType in $ctrl.apiTypes" ng-class="{ active: $ctrl.apiType === apiType }" ng-click="$ctrl.setType(apiType)" class="{{apiType.cssClass}}">{{apiType.title}}</dd>' +
|
|
|
|
' </dl>' +
|
|
|
|
' <input placeholder="Filter" ng-model="$ctrl.apiFilter" class="api-filter">' +
|
|
|
|
'</div>' +
|
|
|
|
'<article class="l-content-small grid-fluid docs-content">' +
|
|
|
|
' <div ng-repeat="section in $ctrl.filteredSections" ng-cloak="ng-cloak">' +
|
|
|
|
' <h3>{{ section.title }}</h3>' +
|
|
|
|
' <ul class="api-list">' +
|
|
|
|
' <li ng-repeat="item in section.items" class="api-item">' +
|
|
|
|
' <a ng-href="{{ item.path }}"><span class="symbol {{ item.docType }}"></span>{{ item.title }}</a>' +
|
|
|
|
' </li>' +
|
|
|
|
' </ul>' +
|
|
|
|
' </div>' +
|
|
|
|
'</article>',
|
|
|
|
controllerAs: '$ctrl',
|
2015-12-14 06:12:23 -05:00
|
|
|
controller: function($scope, $attrs, $http, $location) {
|
2015-12-10 14:27:54 -05:00
|
|
|
var $ctrl = this;
|
|
|
|
|
2015-12-14 06:12:23 -05:00
|
|
|
$ctrl.apiTypes = [
|
|
|
|
{ cssClass: 'directive', title: 'Directive', matches: ['directive'] },
|
2015-12-15 05:43:43 -05:00
|
|
|
{ cssClass: 'decorator', title: 'Decorator', matches: ['decorator'] },
|
2015-12-14 06:12:23 -05:00
|
|
|
{ cssClass: 'class', title: 'Class', matches: ['class'] },
|
|
|
|
{ cssClass: 'interface', title: 'Interface', matches: ['interface'] },
|
2015-12-15 05:43:43 -05:00
|
|
|
{ cssClass: 'function', title: 'Function', matches: ['function'] },
|
2015-12-14 06:12:23 -05:00
|
|
|
{ cssClass: 'const', title: 'Const or Enum', matches: ['const', 'enum'] },
|
|
|
|
{ cssClass: 'var', title: 'Variable', matches: ['var', 'let'] }
|
|
|
|
];
|
|
|
|
|
|
|
|
$ctrl.apiFilter = getApiFilterFromLocation();
|
|
|
|
$ctrl.apiType = getApiTypeFromLocation();
|
2015-12-10 14:27:54 -05:00
|
|
|
$ctrl.filteredSections = [];
|
|
|
|
|
|
|
|
$ctrl.setType = function (type) {
|
|
|
|
if (type === $ctrl.apiType) $ctrl.apiType = null;
|
|
|
|
else $ctrl.apiType = type;
|
|
|
|
};
|
|
|
|
|
|
|
|
$http.get($attrs.src).then(function(response) {
|
|
|
|
$ctrl.sections = response.data;
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.$watchGroup(
|
|
|
|
[function() { return $ctrl.apiFilter}, function() { return $ctrl.apiType; }, function() { return $ctrl.sections; }],
|
2015-12-14 06:12:23 -05:00
|
|
|
function() {
|
|
|
|
var apiFilter = ($ctrl.apiFilter || '').toLowerCase();
|
|
|
|
|
|
|
|
$location.search(API_FILTER_KEY, apiFilter || null);
|
|
|
|
$location.search(API_TYPE_KEY, $ctrl.apiType && $ctrl.apiType.title || null);
|
|
|
|
|
2015-12-10 14:27:54 -05:00
|
|
|
$ctrl.filteredSections.length = 0;
|
|
|
|
angular.forEach($ctrl.sections, function(section, title) {
|
2015-12-14 06:12:23 -05:00
|
|
|
var matchesModule = $ctrl.apiFilter === '' || $ctrl.apiFilter === null || title.toLowerCase().indexOf($ctrl.apiFilter.toLowerCase()) !== -1;
|
2015-12-10 14:27:54 -05:00
|
|
|
var filteredItems = section.filter(function(item) {
|
|
|
|
var matchesDocType = !$ctrl.apiType || $ctrl.apiType.matches.indexOf(item.docType) !== -1;
|
2015-12-14 06:12:23 -05:00
|
|
|
var matchesTitle = !apiFilter || item.title.toLowerCase().indexOf(apiFilter) !== -1;
|
2015-12-14 04:52:58 -05:00
|
|
|
return matchesDocType && (matchesTitle || matchesModule);
|
2015-12-10 14:27:54 -05:00
|
|
|
});
|
|
|
|
if (filteredItems.length) {
|
|
|
|
$ctrl.filteredSections.push({ title: title, items: filteredItems });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2015-12-14 06:12:23 -05:00
|
|
|
|
|
|
|
function getApiFilterFromLocation() {
|
|
|
|
return $location.search()[API_FILTER_KEY] || null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getApiTypeFromLocation() {
|
|
|
|
var apiFilter = $location.search()[API_TYPE_KEY];
|
|
|
|
if (!apiFilter) {
|
|
|
|
return null;
|
|
|
|
} else if (!$ctrl.apiFilter || $ctrl.apiFilter.title != apiFilter) {
|
|
|
|
for(var i = 0, ii = $ctrl.apiTypes.length; i < ii; i++) {
|
|
|
|
if ($ctrl.apiTypes[i].title == apiFilter) {
|
|
|
|
return $ctrl.apiTypes[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If we get here then the apiType query didn't match any apiTypes
|
|
|
|
$location.search(API_TYPE_KEY, null);
|
|
|
|
}
|
2015-12-10 14:27:54 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|