diff --git a/ext/lib/api/topics/index.js b/ext/lib/api/topics/index.js index 86c13b9..b21a816 100644 --- a/ext/lib/api/topics/index.js +++ b/ext/lib/api/topics/index.js @@ -58,6 +58,10 @@ app.get('/topics', years: { type: 'string', default: '' + }, + kwords: { + type: 'string', + default: '' } }) }, { formats }), @@ -65,6 +69,7 @@ app.get('/topics', utils.parseStates, utils.parseTipoIdea, utils.parseYears, + utils.parseKWords, utils.parseZonas, utils.parseTags, middlewares.forums.privileges.canView, @@ -73,7 +78,6 @@ app.get('/topics', opts.forum = req.forum opts.user = req.user opts.state = opts.tipoIdea - opts.years = opts.years Promise.all([ utils.findTopics(opts).then(topics => apiNoExt.user.populateOwners(topics)), utils.findTopicsCount(opts) diff --git a/ext/lib/api/topics/utils.js b/ext/lib/api/topics/utils.js index e886105..ddd9feb 100644 --- a/ext/lib/api/topics/utils.js +++ b/ext/lib/api/topics/utils.js @@ -28,6 +28,11 @@ exports.parseYears = (req, res, next) => { next() } +exports.parseKWords = (req, res, next) => { + req.query.kwords = req.query.kwords.split(' ').filter((t) => !!t) + next() +} + exports.findForum = (req, res, next) => { api.forums.find({ name: req.query.forumName }) .findOne() @@ -51,7 +56,8 @@ const queryTopics = (opts) => { owners, zonas, zona, - years + years, + kwords } = opts const query = { forum: forum._id, @@ -65,7 +71,8 @@ const queryTopics = (opts) => { if (related && related.length > 0) query['attrs.admin-comment-referencia'] = { $regex: `.*${related}.*` } if (years && years.length > 0) query.$or = years.map(year => ({createdAt: {$gte: new Date(year,0,1),$lte: new Date(year,11,31)}})) - + if (kwords && kwords.length > 0) query.mediaTitle = { $in: kwords.map(regex => new RegExp(regex))} + // console.log(kwords) // if (years && years.length > 0) query.$where = function (){ // const year = this.createdAt.getFullYear().toString() // return years.includes(year); diff --git a/ext/lib/site/home-catalogo/component.js b/ext/lib/site/home-catalogo/component.js index 8c04e75..bee9883 100644 --- a/ext/lib/site/home-catalogo/component.js +++ b/ext/lib/site/home-catalogo/component.js @@ -63,15 +63,16 @@ class HomePropuestas extends Component { noMore: null, selectedProyecto: null, - searchableProyectos: [], archive: false, years: [], + kwords: '' } this.handleInputChange = this.handleInputChange.bind(this) this.renderSortFilter = this.renderSortFilter.bind(this) + this.handleInputSearch = this.handleInputSearch.bind(this) } componentDidMount () { @@ -114,7 +115,8 @@ class HomePropuestas extends Component { tags: this.state.tag, sort: this.state.sort, tipoIdea: this.state.tipoIdea, - years: this.state.years + years: this.state.years, + kwords: this.state.kwords } let queryString = Object.keys(query) @@ -152,7 +154,6 @@ class HomePropuestas extends Component { topics: page == 1 ? topics : prevState.topics.concat(topics), page: page, noMore: noMore, - searchableProyectos: topics.map(p => ({label: `${p.mediaTitle}`, value: p.id})) })) return topics }) @@ -325,32 +326,14 @@ class HomePropuestas extends Component { ) } - handleSelectedProyecto = (selectedProyecto) => { - //console.log(`Option selected:`, selectedProyecto); - - const topicId = selectedProyecto.value - if (this.state.topics.find(t => t.id == selectedProyecto.value) == undefined){ - // si el topic no está en la actual lista de resultados lo vamos a buscar - //console.log('Topic not found, searching it:', topicId) - topicStore.getTopic(topicId).then(topic => { - if (!topic) - return - - //console.log('Adding topic:', topic.id) - this.setState(prevState => ({ - topics: prevState.topics.concat(topic), - selectedProyecto - })); - }) - }else{ - //console.log('Topic found, filtering it') - this.setState({ selectedProyecto }); - } + handleInputSearch = () => { + const {kwords} = this.state + this.fetchTopics(); } render () { - const { forum, topics, zonas, searchableProyectos, selectedProyecto } = this.state + const { forum, topics, zonas, kwords, selectedProyecto } = this.state const {archive} = this.props let filteredTopics; @@ -411,17 +394,18 @@ class HomePropuestas extends Component {