diff --git a/client/admin/homebrewAdmin/brewSearch.jsx b/client/admin/homebrewAdmin/brewSearch.jsx new file mode 100644 index 0000000..09ca881 --- /dev/null +++ b/client/admin/homebrewAdmin/brewSearch.jsx @@ -0,0 +1,72 @@ +var React = require('react'); +var _ = require('lodash'); +var cx = require('classnames'); + +var request = require('superagent'); + +var BrewSearch = React.createClass({ + + getDefaultProps: function() { + return { + admin_key : '' + }; + }, + + getInitialState: function() { + return { + searchTerm: '', + brew : null, + searching : false + }; + }, + + + search : function(){ + this.setState({ + searching : true + }); + + request.get('/homebrew/api/search?id=' + this.state.searchTerm) + .query({ + admin_key : this.props.admin_key, + }) + .end((err, res)=>{ + console.log(err, res, res.body.brews[0]); + this.setState({ + brew : res.body.brews[0], + + searching : false + }) + }); + }, + + handleChange : function(e){ + this.setState({ + searchTerm : e.target.value + }); + }, + handleSearchClick : function(){ + this.search(); + }, + + renderBrew : function(){ + if(!this.state.brew) return null; + return
+
Edit id : {this.state.brew.editId}
+
Share id : {this.state.brew.shareId}
+
+ }, + + render : function(){ + return
+ + + + + {this.renderBrew()} +
+ }, + +}); + +module.exports = BrewSearch; \ No newline at end of file diff --git a/client/admin/homebrewAdmin/homebrewAdmin.jsx b/client/admin/homebrewAdmin/homebrewAdmin.jsx index 0dd9213..807f584 100644 --- a/client/admin/homebrewAdmin/homebrewAdmin.jsx +++ b/client/admin/homebrewAdmin/homebrewAdmin.jsx @@ -5,6 +5,9 @@ var request = require('superagent'); var Moment = require('moment'); +var BrewSearch = require('./brewSearch.jsx'); + + var HomebrewAdmin = React.createClass({ getDefaultProps: function() { return { @@ -82,6 +85,7 @@ var HomebrewAdmin = React.createClass({ this.changePageTo(this.state.page + dir); }, + renderPagnination : function(){ var outOf; if(this.state.total){ @@ -98,7 +102,7 @@ var HomebrewAdmin = React.createClass({ renderBrews : function(){ var brews = this.state.brewCache[this.state.page] || _.times(this.state.count); return _.map(brews, (brew)=>{ - return + return {brew.editId} {brew.shareId} {Moment(brew.createdAt).fromNow()} @@ -146,6 +150,8 @@ var HomebrewAdmin = React.createClass({ + + } }); diff --git a/server/homebrew.api.js b/server/homebrew.api.js index a9cd15c..9a630ce 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -98,7 +98,18 @@ module.exports = function(app){ var page = req.query.page || 0; var count = req.query.count || 20; - HomebrewModel.find({}, { + var query = {}; + if(req.query && req.query.id){ + query = { + "$or" : [{ + editId : req.query.id + },{ + shareId : req.query.id + }] + }; + } + + HomebrewModel.find(query, { text : 0 //omit the text }, { skip: page*count,