@@ -19,26 +19,26 @@ var PlanetActions = require('../Actions/PlanetActions')
1919var AuthStore = require ( '../Stores/AuthStore' )
2020var PlanetStore = require ( '../Stores/PlanetStore' )
2121
22- var searchArticle = function ( search , articles ) {
23- if ( search === '' || search == null ) return articles
22+ function basicFilter ( keyword , articles ) {
23+ if ( keyword === '' || keyword == null ) return articles
2424 var firstFiltered = articles . filter ( function ( article ) {
2525
2626 var first = article . type === 'snippet' ? article . callSign : article . title
27- if ( first . match ( new RegExp ( search , 'i' ) ) ) return true
27+ if ( first . match ( new RegExp ( keyword , 'i' ) ) ) return true
2828
2929 return false
3030 } )
3131
3232 var secondFiltered = articles . filter ( function ( article ) {
3333 var second = article . type === 'snippet' ? article . description : article . content
34- if ( second . match ( new RegExp ( search , 'i' ) ) ) return true
34+ if ( second . match ( new RegExp ( keyword , 'i' ) ) ) return true
3535
3636 return false
3737 } )
3838
3939 var thirdFiltered = articles . filter ( function ( article ) {
4040 if ( article . type === 'snippet' ) {
41- if ( article . content . match ( new RegExp ( search , 'i' ) ) ) return true
41+ if ( article . content . match ( new RegExp ( keyword , 'i' ) ) ) return true
4242 }
4343 return false
4444 } )
@@ -48,6 +48,46 @@ var searchArticle = function (search, articles) {
4848 } )
4949}
5050
51+ function snippetFilter ( articles ) {
52+ return articles . filter ( function ( article ) {
53+ return article . type === 'snippet'
54+ } )
55+ }
56+
57+ function blueprintFilter ( articles ) {
58+ return articles . filter ( function ( article ) {
59+ return article . type === 'blueprint'
60+ } )
61+ }
62+
63+ function tagFilter ( keyword , articles ) {
64+ return articles . filter ( function ( article ) {
65+ return article . Tags . some ( function ( tag ) {
66+ return tag . name . match ( new RegExp ( keyword , 'i' ) )
67+ } )
68+ } )
69+ }
70+
71+ function searchArticle ( search , articles ) {
72+ var keywords = search . split ( ' ' )
73+
74+ for ( var keyword of keywords ) {
75+ if ( keyword . match ( / ^ \$ s / , 'i' ) ) {
76+ articles = snippetFilter ( articles )
77+ continue
78+ } else if ( keyword . match ( / ^ \$ b / , 'i' ) ) {
79+ articles = blueprintFilter ( articles )
80+ continue
81+ } else if ( keyword . match ( / ^ # [ A - Z a - z 0 - 9 ] + / ) ) {
82+ articles = tagFilter ( keyword . substring ( 1 , keyword . length ) , articles )
83+ continue
84+ }
85+ articles = basicFilter ( keyword , articles )
86+ }
87+
88+ return articles
89+ }
90+
5191module . exports = React . createClass ( {
5292 mixins : [ ReactRouter . Navigation , ReactRouter . State ] ,
5393 propTypes : {
@@ -208,8 +248,9 @@ module.exports = React.createClass({
208248 return
209249 }
210250
251+ var user
211252 if ( res . status === 'userAdded' ) {
212- var user = res . data
253+ user = res . data
213254 if ( user == null ) {
214255 return null
215256 }
@@ -221,7 +262,7 @@ module.exports = React.createClass({
221262 }
222263
223264 if ( res . status === 'userRemoved' ) {
224- var user = res . data
265+ user = res . data
225266 if ( user == null ) {
226267 return null
227268 }
@@ -286,6 +327,15 @@ module.exports = React.createClass({
286327 this . selectArticleByIndex ( 0 )
287328 } )
288329 } ,
330+ showAll : function ( ) {
331+ this . setState ( { search : '' } )
332+ } ,
333+ showOnlySnippets : function ( ) {
334+ this . setState ( { search : '$s' } )
335+ } ,
336+ showOnlyBlueprints : function ( ) {
337+ this . setState ( { search : '$b' } )
338+ } ,
289339 openLaunchModal : function ( ) {
290340 this . setState ( { isLaunchModalOpen : true } )
291341 } ,
@@ -493,7 +543,9 @@ module.exports = React.createClass({
493543 < PlanetHeader search = { this . state . search }
494544 openSettingModal = { this . openSettingModal } onSearchChange = { this . handleSearchChange } currentPlanet = { this . state . currentPlanet } />
495545
496- < PlanetNavigator openLaunchModal = { this . openLaunchModal } openAddUserModal = { this . openAddUserModal } currentPlanet = { this . state . currentPlanet } />
546+ < PlanetNavigator openLaunchModal = { this . openLaunchModal } openAddUserModal = { this . openAddUserModal }
547+ showAll = { this . showAll }
548+ showOnlySnippets = { this . showOnlySnippets } showOnlyBlueprints = { this . showOnlyBlueprints } currentPlanet = { this . state . currentPlanet } />
497549
498550 < PlanetArticleList ref = 'list' articles = { filteredArticles } />
499551
0 commit comments