diff --git a/client/admin/brewLookup/brewLookup.jsx b/client/admin/brewLookup/brewLookup.jsx
index 5910426..b7aa033 100644
--- a/client/admin/brewLookup/brewLookup.jsx
+++ b/client/admin/brewLookup/brewLookup.jsx
@@ -2,9 +2,8 @@ const React = require('react');
const _ = require('lodash');
const cx = require('classnames');
-const Moment = require('moment');
-
const request = require('superagent');
+const BrewTable = require('../brewTable/brewTable.jsx');
const BrewLookup = React.createClass({
getDefaultProps: function() {
@@ -42,7 +41,7 @@ const BrewLookup = React.createClass({
if(this.state.searching) return
No brew found.
;
- console.log(this.state.resultBrew);
+ return
diff --git a/client/admin/brewLookup/brewLookup.less b/client/admin/brewLookup/brewLookup.less
index 31b0dae..dfec861 100644
--- a/client/admin/brewLookup/brewLookup.less
+++ b/client/admin/brewLookup/brewLookup.less
@@ -4,5 +4,6 @@
input{
height : 33px;
padding : 0px 10px;
+ margin-bottom: 20px;
}
}
\ No newline at end of file
diff --git a/client/admin/brewTable/brewTable.jsx b/client/admin/brewTable/brewTable.jsx
new file mode 100644
index 0000000..dfa4500
--- /dev/null
+++ b/client/admin/brewTable/brewTable.jsx
@@ -0,0 +1,54 @@
+const React = require('react');
+const _ = require('lodash');
+const cx = require('classnames');
+
+const Moment = require('moment');
+
+//TODO: Add in delete
+
+const BrewTable = React.createClass({
+ getDefaultProps: function() {
+ return {
+ brews : []
+ };
+ },
+ renderRows : function(){
+ return _.map(this.props.brews, (brew) => {
+ let authors = 'None.';
+ if(brew.authors && brew.authors.length) authors = brew.authors.join(', ');
+
+ return
+ | {brew.title} |
+ {authors} |
+ {brew.editId} |
+ {brew.shareId} |
+ {Moment(brew.updatedAt).fromNow()} |
+ {brew.views} |
+
+
+ |
+
+
+ });
+ },
+ render: function(){
+ return
+
+
+ | Title |
+ Authors |
+ Edit Link |
+ Share Link |
+ Last Updated |
+ Views |
+ Remove |
+
+
+
+ {this.renderRows()}
+
+
+ }
+});
+
+module.exports = BrewTable;
diff --git a/client/admin/brewTable/brewTable.less b/client/admin/brewTable/brewTable.less
new file mode 100644
index 0000000..927242b
--- /dev/null
+++ b/client/admin/brewTable/brewTable.less
@@ -0,0 +1,44 @@
+
+table.brewTable{
+ th{
+ padding : 10px;
+ background-color : fade(@blue, 20%);
+ 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;
+ }
+ }
+ */
+ }
+}
\ No newline at end of file
diff --git a/client/admin/invalidBrew/invalidBrew.jsx b/client/admin/invalidBrew/invalidBrew.jsx
index a70c443..bafeb2f 100644
--- a/client/admin/invalidBrew/invalidBrew.jsx
+++ b/client/admin/invalidBrew/invalidBrew.jsx
@@ -1,17 +1,52 @@
-
const React = require('react');
const _ = require('lodash');
const cx = require('classnames');
+const request = require('superagent');
+const BrewTable = require('../brewTable/brewTable.jsx');
+
+
const InvalidBrew = React.createClass({
getDefaultProps: function() {
return {
};
},
+ getInitialState: function() {
+ return {
+ brews: []
+ };
+ },
+ getInvalid : function(){
+ request.get(`/admin/invalid`)
+ .query({ admin_key : this.props.adminKey })
+ .end((err, res) => {
+ this.setState({
+ brews : res.body
+ });
+ })
+ },
+ removeInvalid : function(){
+ if(!this.state.brews.length) return;
+ if(!confirm(`Are you sure you want to remove ${this.state.brews.length} brews`)) return;
+ if(!confirm('Sure you are sure?')) return;
+
+ request.delete(`/admin/invalid`)
+ .query({ admin_key : this.props.adminKey })
+ .end((err, res) => {
+ console.log(err, res.body);
+ alert('Invalid brews removed!');
+ this.getInvalid();
+ })
+ },
render: function(){
return
- InvalidBrew Component Ready.
+
Remove Invalid Brews
+ This will removes all brews older than 3 days and shorter than a tweet.
+
+
+
+
}
});
diff --git a/server/admin.routes.js b/server/admin.routes.js
index be83166..956b730 100644
--- a/server/admin.routes.js
+++ b/server/admin.routes.js
@@ -3,10 +3,21 @@ const router = require('express').Router();
const vitreumRender = require('vitreum/steps/render');
const templateFn = require('../client/template.js');
const config = require('nconf');
+const Moment = require('moment');
const mw = require('./middleware.js');
const BrewData = require('./brew.data.js');
+
+const getInvalidBrewQuery = ()=>{
+ return BrewData.model.find({
+ '$where' : "this.text.length < 140",
+ createdAt: {
+ $lt: Moment().subtract(3, 'days').toDate()
+ }
+ }).select({ text : false });
+}
+
router.get('/admin', mw.adminLogin, (req, res, next) => {
return vitreumRender('admin', templateFn, {
url : req.originalUrl,
@@ -19,12 +30,17 @@ router.get('/admin', mw.adminLogin, (req, res, next) => {
});
//Removes all empty brews that are older than 3 days and that are shorter than a tweet
+router.get('/admin/invalid', mw.adminOnly, (req, res, next)=>{
+ getInvalidBrewQuery().exec()
+ .then((brews) => {
+ return res.json(brews);
+ })
+ .catch(next);
+});
router.delete('/admin/invalid', mw.adminOnly, (req, res, next)=>{
- BrewData.removeInvalid(!!req.query.do_it)
- .then((removedCount) => {
- return res.join({
- count : removedCount
- });
+ getInvalidBrewQuery().remove()
+ .then(()=>{
+ return res.status(200).send();
})
.catch(next);
});
diff --git a/server/brew.api.js b/server/brew.api.js
index be9365b..d7e30bf 100644
--- a/server/brew.api.js
+++ b/server/brew.api.js
@@ -30,15 +30,12 @@ router.post('/api/brew', (req, res, next)=>{
//Update
router.put('/api/brew/:editId', mw.loadBrew, (req, res, next)=>{
- console.log(req.account);
const brew = req.body || {};
if(req.account){
brew.authors = _.uniq(_.concat(brew.authors, req.account.username));
}
- console.log(brew);
BrewData.update(req.params.editId, brew)
.then((brew) => {
- console.log(brew.toJSON());
return res.json(brew.toJSON());
})
.catch(next);
diff --git a/server/brew.data.js b/server/brew.data.js
index 528fcc2..367d33b 100644
--- a/server/brew.data.js
+++ b/server/brew.data.js
@@ -93,21 +93,6 @@ const BrewData = {
return BrewData.get({ editId });
},
- //Removes all empty brews that are older than 3 days and that are shorter than a tweet
- removeInvalid : (force = false) => {
- const invalidBrewQuery = Brew.find({
- '$where' : "this.text.length < 140",
- createdAt: {
- $lt: Moment().subtract(3, 'days').toDate()
- }
- });
- if(force) return invalidBrewQuery.remove().exec();
- return invalidBrewQuery.exec()
- .then((objs) => {
- return objs.length;
- });
- },
-
search : (query, req={}) => {
//defaults with page and count
//returns a non-text version of brews