@@ -5,12 +5,16 @@ import { EKMixin, keyUp, keyDown } from 'ember-keyboard';
55import { on } from '@ember/object/evented' ;
66import { computed } from '@ember/object' ;
77import { task } from 'ember-concurrency' ;
8+ import config from 'dummy/config/environment' ;
9+
10+ const projectName = config [ 'ember-cli-addon-docs' ] . projectName ;
811
912export default Component . extend ( EKMixin , {
1013 layout,
1114
1215 docsSearch : service ( ) ,
1316 router : service ( ) ,
17+ store : service ( ) ,
1418
1519 query : null , // passed in
1620 selectedIndex : null ,
@@ -30,6 +34,10 @@ export default Component.extend(EKMixin, {
3034 this . get ( 'search' ) . perform ( ) ;
3135 } ,
3236
37+ project : computed ( function ( ) {
38+ return this . get ( 'store' ) . peekRecord ( 'project' , projectName ) ;
39+ } ) ,
40+
3341 trimmedQuery : computed ( 'query' , function ( ) {
3442 return this . get ( 'query' ) . trim ( ) ;
3543 } ) ,
@@ -51,17 +59,44 @@ export default Component.extend(EKMixin, {
5159 let routerMicrolib = router . _router . _routerMicrolib || router . _router . router ;
5260
5361 if ( rawSearchResults ) {
54- let filteredSearchResults = this . get ( 'rawSearchResults' )
62+ return this . get ( 'rawSearchResults' )
63+ // If the doc has a route, ensure it exists
5564 . filter ( ( { document } ) => {
56- let routeExists = routerMicrolib . recognizer . names [ document . route ] ;
57- return routeExists && document . route !== 'not-found' ;
65+ if ( document . route ) {
66+ let routeExists = routerMicrolib . recognizer . names [ document . route ] ;
67+
68+ return routeExists && document . route !== 'not-found' && document . route !== 'application' ;
69+ } else {
70+ return true ;
71+ }
5872 } )
73+
74+ // Filter out the templates of the API items' pages, since we handle them separately
5975 . filter ( ( { document } ) => {
60- let isClassTemplate = ( document . route === 'docs.api.class' && document . type === 'template' ) ;
61- return ! isClassTemplate ;
62- } ) ;
76+ let isApiItemTemplate = ( document . route === 'docs.api.item' && document . type === 'template' ) ;
77+ return ! isApiItemTemplate ;
78+ } )
79+
80+ // Filter out modules that are not in the navigationIndex
81+ . filter ( ( { document } ) => {
82+ if ( document . type === 'module' ) {
83+ let navigableModules = this . get ( 'project.navigationIndex.modules' ) . map ( x => x . name ) ;
84+ return navigableModules . includes ( document . title ) ;
85+ } else {
86+ return true ;
87+ }
88+ } )
89+
90+ // Add a reference to the Ember Data model to each API item search result
91+ . map ( searchResult => {
92+ let { document } = searchResult ;
93+ if ( document . type !== 'template' ) {
94+ let store = this . get ( 'store' ) ;
95+ searchResult . model = store . peekRecord ( document . type , document . item . id )
96+ }
6397
64- return filteredSearchResults ;
98+ return searchResult ;
99+ } ) ;
65100 }
66101 } ) ,
67102
@@ -70,8 +105,8 @@ export default Component.extend(EKMixin, {
70105 let selectedResult = this . get ( 'searchResults' ) [ this . get ( 'selectedIndex' ) ] ;
71106 if ( selectedResult . document . type === 'template' ) {
72107 this . get ( 'router' ) . transitionTo ( selectedResult . document . route ) ;
73- } else if ( selectedResult . document . type === 'class' ) {
74- this . get ( 'router' ) . transitionTo ( 'docs.api.class ' , selectedResult . document . class . id ) ;
108+ } else {
109+ this . get ( 'router' ) . transitionTo ( 'docs.api.item ' , selectedResult . model . get ( 'routingId' ) ) ;
75110 }
76111 }
77112
0 commit comments