diff --git a/client/admin/adminSearch/adminSearch.jsx b/client/admin/adminSearch/adminSearch.jsx
index 15d0972..a9ab876 100644
--- a/client/admin/adminSearch/adminSearch.jsx
+++ b/client/admin/adminSearch/adminSearch.jsx
@@ -2,16 +2,83 @@
const React = require('react');
const _ = require('lodash');
const cx = require('classnames');
+const request = require('superagent');
+
+const BrewTable = require('../brewTable/brewTable.jsx');
+
+const LIMIT = 10;
const AdminSearch = React.createClass({
getDefaultProps: function() {
return {
-
+ adminKey : '',
};
},
+ getInitialState: function() {
+ return {
+ totalBrews : 1,
+ brews: [],
+
+ searching : false,
+ error : null,
+
+ page : 1,
+ searchTerms : ''
+ };
+ },
+
+ handleSearch : function(e){
+ this.setState({
+ searchTerms : e.target.value
+ });
+ },
+ handlePage : function(e){
+ this.setState({
+ page : e.target.value
+ });
+ },
+
+ search : function(){
+ this.setState({ searching : true, error : null });
+
+ request.get(`/api/brew`)
+ .query({
+ terms : this.state.searchTerms,
+ limit : LIMIT,
+ page : this.state.page - 1
+ })
+ .set('x-homebrew-admin', this.props.adminKey)
+ .end((err, res) => {
+ if(err){
+ this.setState({
+ searching : false,
+ error : err && err.toString()
+ });
+ }else{
+ this.setState({
+ brews : res.body.brews,
+ totalBrews : res.body.total
+ });
+ }
+ });
+ },
+
render: function(){
return
}
});
diff --git a/client/admin/adminSearch/adminSearch.less b/client/admin/adminSearch/adminSearch.less
index dc1de6e..b66896d 100644
--- a/client/admin/adminSearch/adminSearch.less
+++ b/client/admin/adminSearch/adminSearch.less
@@ -1,3 +1,17 @@
-.adminSearch{
+.adminSearch{
+ .controls{
+ margin-bottom : 20px;
+ input.search{
+ height : 33px;
+ padding : 10px;
+ }
+ .page {
+ float : right;
+ font-weight : 800;
+ input{
+ width : 20px;
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/client/admin/brewLookup/brewLookup.jsx b/client/admin/brewLookup/brewLookup.jsx
index b7aa033..abb38dc 100644
--- a/client/admin/brewLookup/brewLookup.jsx
+++ b/client/admin/brewLookup/brewLookup.jsx
@@ -15,7 +15,8 @@ const BrewLookup = React.createClass({
return {
query:'',
resultBrew : null,
- searching : false
+ searching : false,
+ error : null
};
},
@@ -25,13 +26,14 @@ const BrewLookup = React.createClass({
})
},
lookup : function(){
- this.setState({ searching : true });
+ this.setState({ searching : true, error : null });
request.get(`/admin/lookup/${this.state.query}`)
- .query({ admin_key : this.props.adminKey })
+ .set('x-homebrew-admin', this.props.adminKey)
.end((err, res) => {
this.setState({
searching : false,
+ error : err && err.toString(),
resultBrew : (err ? null : res.body)
});
})
@@ -43,6 +45,7 @@ const BrewLookup = React.createClass({
return
+ /*
const brew = this.state.resultBrew;
return
{brew.title}
@@ -57,6 +60,15 @@ const BrewLookup = React.createClass({
+ */
+ },
+
+ renderError : function(){
+ if(!this.state.error) return;
+
+ return
+ {this.state.error}
+
},
render: function(){
@@ -66,6 +78,7 @@ const BrewLookup = React.createClass({
{this.renderFoundBrew()}
+ {this.renderError()}
}
});
diff --git a/client/admin/brewLookup/brewLookup.less b/client/admin/brewLookup/brewLookup.less
index dfec861..87434c4 100644
--- a/client/admin/brewLookup/brewLookup.less
+++ b/client/admin/brewLookup/brewLookup.less
@@ -2,8 +2,12 @@
.brewLookup{
height : 200px;
input{
- height : 33px;
- padding : 0px 10px;
- margin-bottom: 20px;
+ height : 33px;
+ margin-bottom : 20px;
+ padding : 0px 10px;
+ }
+ .error{
+ font-weight : 800;
+ color : @red;
}
}
\ No newline at end of file
diff --git a/client/admin/homebrewAdmin/brewLookup/brewLookup.jsx b/client/admin/homebrewAdmin/brewLookup/brewLookup.jsx
deleted file mode 100644
index ad43b13..0000000
--- a/client/admin/homebrewAdmin/brewLookup/brewLookup.jsx
+++ /dev/null
@@ -1,67 +0,0 @@
-const React = require('react');
-const _ = require('lodash');
-const cx = require('classnames');
-
-const request = require('superagent');
-const Moment = require('moment');
-
-
-const BrewLookup = React.createClass({
- getDefaultProps: function() {
- return {
- adminKey : '',
- };
- },
- getInitialState: function() {
- return {
- query:'',
- resultBrew : null,
- searching : false
- };
- },
-
- handleChange : function(e){
- this.setState({
- query : e.target.value
- })
- },
- lookup : function(){
- this.setState({ searching : true });
-
- request.get(`/admin/lookup/${this.state.query}`)
- .query({ admin_key : this.props.adminKey })
- .end((err, res) => {
- this.setState({
- searching : false,
- resultBrew : (err ? null : res.body)
- });
- })
- },
-
- renderFoundBrew : function(){
- if(this.state.searching) return
;
- if(!this.state.resultBrew) return No brew found.
;
-
- const brew = this.state.resultBrew;
- return
-
{brew.title}
-
{brew.authors.join(', ')}
-
-
-
{Moment(brew.updatedAt).fromNow()}
-
{brew.views}
-
- },
-
- render: function(){
- return
-
Brew Lookup
-
-
-
- {this.renderFoundBrew()}
-
- }
-});
-
-module.exports = BrewLookup;
diff --git a/client/admin/homebrewAdmin/brewLookup/brewLookup.less b/client/admin/homebrewAdmin/brewLookup/brewLookup.less
deleted file mode 100644
index 071028c..0000000
--- a/client/admin/homebrewAdmin/brewLookup/brewLookup.less
+++ /dev/null
@@ -1,8 +0,0 @@
-.brewLookup{
- height : 200px;
- input{
- height : 33px;
- padding : 0px 10px;
- margin-bottom: 20px;
- }
-}
\ No newline at end of file
diff --git a/client/admin/homebrewAdmin/brewSearch.jsx b/client/admin/homebrewAdmin/brewSearch.jsx
deleted file mode 100644
index f2334d7..0000000
--- a/client/admin/homebrewAdmin/brewSearch.jsx
+++ /dev/null
@@ -1,72 +0,0 @@
-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
deleted file mode 100644
index 70b593c..0000000
--- a/client/admin/homebrewAdmin/homebrewAdmin.jsx
+++ /dev/null
@@ -1,172 +0,0 @@
-var React = require('react');
-var _ = require('lodash');
-var cx = require('classnames');
-var request = require('superagent');
-
-var Moment = require('moment');
-
-var BrewSearch = require('./brewSearch.jsx');
-
-var BrewLookup = require('./brewLookup/brewLookup.jsx');
-
-
-var HomebrewAdmin = React.createClass({
- getDefaultProps: function() {
- return {
- admin_key : ''
- };
- },
-
- getInitialState: function() {
- return {
- page: 0,
- count : 20,
- brewCache : {},
- total : 0,
-
- processingOldBrews : false
- };
- },
-
-
- fetchBrews : function(page){
- request.get('/api/search')
- .query({
- admin_key : this.props.admin_key,
- count : this.state.count,
- page : page
- })
- .end((err, res)=>{
- if(err || !res.body || !res.body.brews) return;
- this.state.brewCache[page] = res.body.brews;
- this.setState({
- brewCache : this.state.brewCache,
- total : res.body.total,
- count : res.body.count
- })
- })
- },
-
- componentDidMount: function() {
- this.fetchBrews(this.state.page);
- },
-
- changePageTo : function(page){
- if(!this.state.brewCache[page]){
- this.fetchBrews(page);
- }
- this.setState({
- page : page
- })
- },
-
-
- clearInvalidBrews : function(){
- request.get('/api/invalid')
- .query({admin_key : this.props.admin_key})
- .end((err, res)=>{
- if(!confirm("This will remove " + res.body.count + " brews. Are you sure?")) return;
- request.get('/api/invalid')
- .query({admin_key : this.props.admin_key, do_it : true})
- .end((err, res)=>{
- alert("Done!")
- });
- });
- },
-
-
- deleteBrew : function(brewId){
- if(!confirm("Are you sure you want to delete '" + brewId + "'?")) return;
- request.get('/api/remove/' + brewId)
- .query({admin_key : this.props.admin_key})
- .end(function(err, res){
- window.location.reload();
- })
- },
-
- handlePageChange : function(dir){
- this.changePageTo(this.state.page + dir);
- },
-
-
- renderPagnination : function(){
- var outOf;
- if(this.state.total){
- outOf = this.state.page + ' / ' + Math.round(this.state.total/this.state.count);
- }
- return
-
- {outOf}
-
-
- },
-
-
- renderBrews : function(){
- var brews = this.state.brewCache[this.state.page] || _.times(this.state.count);
- return _.map(brews, (brew)=>{
- return
- | {brew.editId} |
- {brew.shareId} |
- {Moment(brew.createdAt).fromNow()} |
- {Moment(brew.updatedAt).fromNow()} |
- {Moment(brew.lastViewed).fromNow()} |
- {brew.views} |
-
-
-
-
- |
-
- });
- },
-
- renderBrewTable : function(){
- return
-
-
-
- | Edit Id |
- Share Id |
- Created At |
- Last Updated |
- Last Viewed |
- Views |
-
-
-
- {this.renderBrews()}
-
-
-
- },
-
- render : function(){
- var self = this;
- return
-
-
-
- {/*
-
- Homebrews - {this.state.total}
-
-
-
-
-
-
- {this.renderPagnination()}
- {this.renderBrewTable()}
-
-
-
-
- */}
-
- }
-});
-
-module.exports = HomebrewAdmin;
diff --git a/client/admin/homebrewAdmin/homebrewAdmin.less b/client/admin/homebrewAdmin/homebrewAdmin.less
deleted file mode 100644
index 6cfc3d5..0000000
--- a/client/admin/homebrewAdmin/homebrewAdmin.less
+++ /dev/null
@@ -1,53 +0,0 @@
-
-.homebrewAdmin{
- margin-bottom: 80px;
- .brewTable{
- table{
-
- th{
- padding : 10px;
- font-weight : 800;
- }
- tr:nth-child(even){
- background-color : fade(@green, 10%);
- }
- tr.isEmpty{
- background-color : fade(@red, 30%);
- }
- td{
- min-width : 100px;
- padding : 10px;
- text-align : center;
-
- &.preview{
- position : relative;
- &:hover{
- .content{
- display : block;
- }
- }
- .content{
- position : absolute;
- display : none;
- top : 100%;
- left : 0px;
- z-index : 1000;
- max-height : 500px;
- width : 300px;
- padding : 30px;
- background-color : white;
- font-family : monospace;
- text-align : left;
- pointer-events : none;
- }
- }
- }
- }
- }
- .deleteButton{
- cursor: pointer;
- }
- button.clearOldButton{
- float : right;
- }
-}
\ No newline at end of file
diff --git a/client/admin/invalidBrew/invalidBrew.jsx b/client/admin/invalidBrew/invalidBrew.jsx
index bafeb2f..28ae01d 100644
--- a/client/admin/invalidBrew/invalidBrew.jsx
+++ b/client/admin/invalidBrew/invalidBrew.jsx
@@ -9,7 +9,7 @@ const BrewTable = require('../brewTable/brewTable.jsx');
const InvalidBrew = React.createClass({
getDefaultProps: function() {
return {
-
+ adminKey : '',
};
},
getInitialState: function() {
@@ -19,7 +19,7 @@ const InvalidBrew = React.createClass({
},
getInvalid : function(){
request.get(`/admin/invalid`)
- .query({ admin_key : this.props.adminKey })
+ .set('x-homebrew-admin', this.props.adminKey)
.end((err, res) => {
this.setState({
brews : res.body
@@ -32,7 +32,7 @@ const InvalidBrew = React.createClass({
if(!confirm('Sure you are sure?')) return;
request.delete(`/admin/invalid`)
- .query({ admin_key : this.props.adminKey })
+ .set('x-homebrew-admin', this.props.adminKey)
.end((err, res) => {
console.log(err, res.body);
alert('Invalid brews removed!');
@@ -42,9 +42,9 @@ const InvalidBrew = React.createClass({
render: function(){
return
Remove Invalid Brews
- This will removes all brews older than 3 days and shorter than a tweet.
+
This will removes all brews older than 3 days and shorter than a tweet.
-
+
diff --git a/client/admin/invalidBrew/invalidBrew.less b/client/admin/invalidBrew/invalidBrew.less
index f937095..495d04f 100644
--- a/client/admin/invalidBrew/invalidBrew.less
+++ b/client/admin/invalidBrew/invalidBrew.less
@@ -1,3 +1,5 @@
.invalidBrew{
-
+ button{
+ margin: 10px 4px;
+ }
}
\ No newline at end of file
diff --git a/client/homebrew/homebrew.jsx b/client/homebrew/homebrew.jsx
index 411da99..4cf9769 100644
--- a/client/homebrew/homebrew.jsx
+++ b/client/homebrew/homebrew.jsx
@@ -37,9 +37,6 @@ const Homebrew = React.createClass({
loginPath : this.props.loginPath
});
- console.log(this.props.brew);
-
-
Router = CreateRouter({
'/edit/:id' : ,
'/share/:id' : ,
diff --git a/scripts/populate.js b/scripts/populate.js
index 7a392af..e002590 100644
--- a/scripts/populate.js
+++ b/scripts/populate.js
@@ -10,11 +10,11 @@ return Promise.resolve()
.then(BrewData.removeAll)
.then(() => {
console.log('Adding random brews...');
- return return BrewGen.populateDB(BrewGen.random(5));
+ return BrewGen.populateDB(BrewGen.random(50));
})
.then(() => {
console.log('Adding specific brews...');
- return return BrewGen.populateDB(BrewGen.static());
+ return BrewGen.populateDB(BrewGen.static());
})
.then(() => {
return DB.close();
diff --git a/server/admin.routes.js b/server/admin.routes.js
index 956b730..cf3cf85 100644
--- a/server/admin.routes.js
+++ b/server/admin.routes.js
@@ -46,11 +46,8 @@ router.delete('/admin/invalid', mw.adminOnly, (req, res, next)=>{
});
router.get('/admin/lookup/:search', mw.adminOnly, (req, res, next) => {
- //search for mathcing edit id
- //search for matching share id
- // search for partial match
-
BrewData.get({ $or:[
+ //Searches for partial matches on either edit or share
{editId : { "$regex": req.params.search, "$options": "i" }},
{shareId : { "$regex": req.params.search, "$options": "i" }},
]})
diff --git a/shared/homebrewery/account.store.js b/shared/homebrewery/account.store.js
index b79bd9f..c1813f7 100644
--- a/shared/homebrewery/account.store.js
+++ b/shared/homebrewery/account.store.js
@@ -16,7 +16,6 @@ Store.init = (state)=>{
Store.getLoginPath = ()=>{
let path = State.loginPath;
if(typeof window !== 'undefined'){
- console.log('yo here');
path = `${path}?redirect=${encodeURIComponent(window.location.href)}`;
}
return path;