mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
add filter
This commit is contained in:
@@ -7,7 +7,10 @@ var PlanetNavigator = React.createClass({
|
||||
Users: React.PropTypes.array
|
||||
}),
|
||||
openLaunchModal: React.PropTypes.func,
|
||||
openAddUserModal: React.PropTypes.func
|
||||
openAddUserModal: React.PropTypes.func,
|
||||
showAll: React.PropTypes.func,
|
||||
showOnlySnippets: React.PropTypes.func,
|
||||
showOnlyBlueprints: React.PropTypes.func
|
||||
},
|
||||
getInitialState: function () {
|
||||
return {
|
||||
@@ -15,7 +18,6 @@ var PlanetNavigator = React.createClass({
|
||||
}
|
||||
},
|
||||
submitLaunchModal: function (ret) {
|
||||
console.log(ret)
|
||||
this.setState({isLaunchModalOpen: false})
|
||||
},
|
||||
render: function () {
|
||||
@@ -31,13 +33,13 @@ var PlanetNavigator = React.createClass({
|
||||
<i className='fa fa-rocket fa-fw'/> Launch
|
||||
</button>
|
||||
<nav>
|
||||
<a>
|
||||
<a onClick={this.props.showAll}>
|
||||
<i className='fa fa-home fa-fw'/> Home
|
||||
</a>
|
||||
<a>
|
||||
<a onClick={this.props.showOnlySnippets}>
|
||||
<i className='fa fa-code fa-fw'/> Snippets
|
||||
</a>
|
||||
<a>
|
||||
<a onClick={this.props.showOnlyBlueprints}>
|
||||
<i className='fa fa-file-text-o fa-fw'/> Blueprints
|
||||
</a>
|
||||
</nav>
|
||||
|
||||
@@ -19,26 +19,26 @@ var PlanetActions = require('../Actions/PlanetActions')
|
||||
var AuthStore = require('../Stores/AuthStore')
|
||||
var PlanetStore = require('../Stores/PlanetStore')
|
||||
|
||||
var searchArticle = function (search, articles) {
|
||||
if (search === '' || search == null) return articles
|
||||
function basicFilter (keyword, articles) {
|
||||
if (keyword === '' || keyword == null) return articles
|
||||
var firstFiltered = articles.filter(function (article) {
|
||||
|
||||
var first = article.type === 'snippet' ? article.callSign : article.title
|
||||
if (first.match(new RegExp(search, 'i'))) return true
|
||||
if (first.match(new RegExp(keyword, 'i'))) return true
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
var secondFiltered = articles.filter(function (article) {
|
||||
var second = article.type === 'snippet' ? article.description : article.content
|
||||
if (second.match(new RegExp(search, 'i'))) return true
|
||||
if (second.match(new RegExp(keyword, 'i'))) return true
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
var thirdFiltered = articles.filter(function (article) {
|
||||
if (article.type === 'snippet') {
|
||||
if (article.content.match(new RegExp(search, 'i'))) return true
|
||||
if (article.content.match(new RegExp(keyword, 'i'))) return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
@@ -48,6 +48,46 @@ var searchArticle = function (search, articles) {
|
||||
})
|
||||
}
|
||||
|
||||
function snippetFilter (articles) {
|
||||
return articles.filter(function (article) {
|
||||
return article.type === 'snippet'
|
||||
})
|
||||
}
|
||||
|
||||
function blueprintFilter (articles) {
|
||||
return articles.filter(function (article) {
|
||||
return article.type === 'blueprint'
|
||||
})
|
||||
}
|
||||
|
||||
function tagFilter (keyword, articles) {
|
||||
return articles.filter(function (article) {
|
||||
return article.Tags.some(function (tag) {
|
||||
return tag.name.match(new RegExp(keyword, 'i'))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function searchArticle (search, articles) {
|
||||
var keywords = search.split(' ')
|
||||
|
||||
for (var keyword of keywords) {
|
||||
if (keyword.match(/^\$s/, 'i')) {
|
||||
articles = snippetFilter(articles)
|
||||
continue
|
||||
} else if (keyword.match(/^\$b/, 'i')) {
|
||||
articles = blueprintFilter(articles)
|
||||
continue
|
||||
} else if (keyword.match(/^#[A-Za-z0-9]+/)) {
|
||||
articles = tagFilter(keyword.substring(1, keyword.length), articles)
|
||||
continue
|
||||
}
|
||||
articles = basicFilter(keyword, articles)
|
||||
}
|
||||
|
||||
return articles
|
||||
}
|
||||
|
||||
module.exports = React.createClass({
|
||||
mixins: [ReactRouter.Navigation, ReactRouter.State],
|
||||
propTypes: {
|
||||
@@ -208,8 +248,9 @@ module.exports = React.createClass({
|
||||
return
|
||||
}
|
||||
|
||||
var user
|
||||
if (res.status === 'userAdded') {
|
||||
var user = res.data
|
||||
user = res.data
|
||||
if (user == null) {
|
||||
return null
|
||||
}
|
||||
@@ -221,7 +262,7 @@ module.exports = React.createClass({
|
||||
}
|
||||
|
||||
if (res.status === 'userRemoved') {
|
||||
var user = res.data
|
||||
user = res.data
|
||||
if (user == null) {
|
||||
return null
|
||||
}
|
||||
@@ -286,6 +327,15 @@ module.exports = React.createClass({
|
||||
this.selectArticleByIndex(0)
|
||||
})
|
||||
},
|
||||
showAll: function () {
|
||||
this.setState({search: ''})
|
||||
},
|
||||
showOnlySnippets: function () {
|
||||
this.setState({search: '$s'})
|
||||
},
|
||||
showOnlyBlueprints: function () {
|
||||
this.setState({search: '$b'})
|
||||
},
|
||||
openLaunchModal: function () {
|
||||
this.setState({isLaunchModalOpen: true})
|
||||
},
|
||||
@@ -493,7 +543,9 @@ module.exports = React.createClass({
|
||||
<PlanetHeader search={this.state.search}
|
||||
openSettingModal={this.openSettingModal} onSearchChange={this.handleSearchChange} currentPlanet={this.state.currentPlanet}/>
|
||||
|
||||
<PlanetNavigator openLaunchModal={this.openLaunchModal} openAddUserModal={this.openAddUserModal} currentPlanet={this.state.currentPlanet}/>
|
||||
<PlanetNavigator openLaunchModal={this.openLaunchModal} openAddUserModal={this.openAddUserModal}
|
||||
showAll={this.showAll}
|
||||
showOnlySnippets={this.showOnlySnippets} showOnlyBlueprints={this.showOnlyBlueprints} currentPlanet={this.state.currentPlanet}/>
|
||||
|
||||
<PlanetArticleList ref='list' articles={filteredArticles}/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user