From 52c0462a4f367d3a92dc3d721568d7953bc1a79c Mon Sep 17 00:00:00 2001 From: Scott Tolksdorf Date: Tue, 4 Dec 2018 13:37:03 -0500 Subject: [PATCH] Finished the clean up brew ui --- client/admin/admin.jsx | 10 ++-- client/admin/admin.less | 57 ++--------------------- client/admin/brewCleanup/brewCleanup.jsx | 43 +++++++++++++---- client/admin/brewCleanup/brewCleanup.less | 7 +++ client/admin/brewLookup/brewLookup.jsx | 5 +- client/admin/stats/stats.jsx | 5 +- server/admin.api.js | 16 +------ 7 files changed, 52 insertions(+), 91 deletions(-) diff --git a/client/admin/admin.jsx b/client/admin/admin.jsx index fb5f9ad..c5c44cd 100644 --- a/client/admin/admin.jsx +++ b/client/admin/admin.jsx @@ -8,9 +8,7 @@ const Stats = require('./stats/stats.jsx'); const Admin = createClass({ getDefaultProps : function() { - return { - adminKey : '' - }; + return {}; }, render : function(){ @@ -23,11 +21,11 @@ const Admin = createClass({
- +
- +
- +
} diff --git a/client/admin/admin.less b/client/admin/admin.less index 84ffc98..a613358 100644 --- a/client/admin/admin.less +++ b/client/admin/admin.less @@ -36,60 +36,9 @@ body{ } } + hr{ + margin : 30px 0px; + } } - -/*.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/brewCleanup/brewCleanup.jsx b/client/admin/brewCleanup/brewCleanup.jsx index 3cf13f9..3e0ab3a 100644 --- a/client/admin/brewCleanup/brewCleanup.jsx +++ b/client/admin/brewCleanup/brewCleanup.jsx @@ -8,25 +8,22 @@ const request = require('superagent'); const BrewCleanup = createClass({ displayName : 'BrewCleanup', getDefaultProps(){ - return { - adminKey : '', - }; + return {}; }, getInitialState() { return { count : 0, pending : false, - primed : false + primed : false, + err : null }; }, prime(){ - if(this.state.primed) return this.cleanup(); this.setState({ pending: true }); request.get('/admin/cleanup') - .query({ admin_key: this.props.adminKey }) - .then((res)=> this.setState({count : res.body.count })) + .then((res)=> this.setState({count : res.body.count, primed : true })) .catch((err)=>this.setState({ error : err })) .finally(()=>this.setState({ pending : false })) }, @@ -34,14 +31,42 @@ const BrewCleanup = createClass({ this.setState({ pending: true }); request.post('/admin/cleanup') - .query({ admin_key: this.props.adminKey }) .then((res)=> this.setState({count : res.body.count })) .catch((err)=>this.setState({ error : err })) .finally(()=>this.setState({ pending : false, primed : false })) }, + renderPrimed(){ + if(!this.state.primed) return; + + if(!this.state.count){ + return
No Matching Brews found.
+ } + return
+ + Found {this.state.count} Brews that could be removed. +
+ }, render(){ return
- BrewCleanup Component Ready. +

Brew Cleanup

+

Removes very short brews to tidy up the database

+ + + {this.renderPrimed()} + + {this.state.error + &&
{this.state.error.toString()}
+ }
; } }); diff --git a/client/admin/brewCleanup/brewCleanup.less b/client/admin/brewCleanup/brewCleanup.less index d3313d4..ec75828 100644 --- a/client/admin/brewCleanup/brewCleanup.less +++ b/client/admin/brewCleanup/brewCleanup.less @@ -1,3 +1,10 @@ .BrewCleanup{ + .removeBox{ + margin-top: 20px; + button{ + background-color: @red; + margin-right: 10px; + } + } } \ No newline at end of file diff --git a/client/admin/brewLookup/brewLookup.jsx b/client/admin/brewLookup/brewLookup.jsx index e9cac75..24b7172 100644 --- a/client/admin/brewLookup/brewLookup.jsx +++ b/client/admin/brewLookup/brewLookup.jsx @@ -8,9 +8,7 @@ const Moment = require('moment'); const BrewLookup = createClass({ getDefaultProps() { - return { - adminKey : '', - }; + return {}; }, getInitialState() { return { @@ -27,7 +25,6 @@ const BrewLookup = createClass({ this.setState({ searching: true, error: null }); request.get(`/admin/lookup/${this.state.query}`) - //.query({ admin_key: this.props.adminKey }) .then((res)=> this.setState({foundBrew : res.body})) .catch((err)=>this.setState({ error : err })) .finally(()=>this.setState({ searching : false })) diff --git a/client/admin/stats/stats.jsx b/client/admin/stats/stats.jsx index cf67bd1..23a448e 100644 --- a/client/admin/stats/stats.jsx +++ b/client/admin/stats/stats.jsx @@ -8,9 +8,7 @@ const request = require('superagent'); const Stats = createClass({ displayName : 'Stats', getDefaultProps(){ - return { - adminKey : '' - }; + return {}; }, getInitialState(){ return { @@ -26,7 +24,6 @@ const Stats = createClass({ fetchStats(){ this.setState({ fetching : true}) request.get('/admin/stats') - .query({ admin_key : this.props.adminKey }) .then((res)=> this.setState({ stats : res.body })) .finally(()=>this.setState({fetching : false})); }, diff --git a/server/admin.api.js b/server/admin.api.js index a2c07ee..a2ef6af 100644 --- a/server/admin.api.js +++ b/server/admin.api.js @@ -1,16 +1,11 @@ -//const auth = require('basic-auth'); const HomebrewModel = require('./homebrew.model.js').model; const router = require('express').Router(); const Moment = require('moment'); const render = require('vitreum/steps/render'); const templateFn = require('../client/template.js'); - process.env.ADMIN_USER = process.env.ADMIN_USER || 'admin'; process.env.ADMIN_PASS = process.env.ADMIN_PASS || 'password3'; -//process.env.ADMIN_KEY = process.env.ADMIN_KEY || 'admin_key'; - -//FIXME: remove this whole 'ADMIN_KEY' buulshit const mw = { adminOnly : (req, res, next)=>{ @@ -35,7 +30,7 @@ const mw = { const junkBrewQuery = HomebrewModel.find({ '$where' : 'this.text.length < 140', createdAt : { - $lt : Moment().subtract(3, 'days').toDate() + $lt : Moment().subtract(30, 'days').toDate() } }); router.get('/admin/cleanup', mw.adminOnly, (req, res)=>{ @@ -62,7 +57,6 @@ router.get('/admin/lookup/:id', mw.adminOnly, (req, res, next)=>{ }); }); - router.get('/admin/stats', mw.adminOnly, (req, res)=>{ HomebrewModel.count({}, (err, count)=>{ return res.json({ @@ -72,14 +66,8 @@ router.get('/admin/stats', mw.adminOnly, (req, res)=>{ }); router.get('/admin', mw.adminOnly, (req, res)=>{ - // const credentials = auth(req); - // if(!credentials || credentials.name !== process.env.ADMIN_USER || credentials.pass !== process.env.ADMIN_PASS) { - // res.setHeader('WWW-Authenticate', 'Basic realm="example"'); - // return res.status(401).send('Access denied'); - // } render('admin', templateFn, { - url : req.originalUrl, - adminKey : process.env.ADMIN_KEY + url : req.originalUrl }) .then((page)=>res.send(page)) .catch((err)=>res.sendStatus(500))