mirror of
https://github.com/stolksdorf/homebrewery.git
synced 2025-12-21 19:51:29 +00:00
added clear old button to the admin page
This commit is contained in:
@@ -24,6 +24,16 @@ var HomebrewAdmin = React.createClass({
|
||||
};
|
||||
},
|
||||
|
||||
clearOldBrews : function(){
|
||||
if(!confirm("Are you sure you want to clear out old brews?")) return;
|
||||
|
||||
request.get('/homebrew/clear_old/?admin_key=' + this.props.admin_key)
|
||||
.send()
|
||||
.end(function(err, res){
|
||||
window.location.reload();
|
||||
})
|
||||
},
|
||||
|
||||
deleteBrew : function(brewId){
|
||||
request.get('/homebrew/remove/' + brewId +'?admin_key=' + this.props.admin_key)
|
||||
.send()
|
||||
@@ -77,7 +87,12 @@ var HomebrewAdmin = React.createClass({
|
||||
render : function(){
|
||||
var self = this;
|
||||
return <div className='homebrewAdmin'>
|
||||
<h2>Homebrews - {this.props.homebrews.length}</h2>
|
||||
<h2>
|
||||
Homebrews - {this.props.homebrews.length}
|
||||
<button className='clearOldButton' onClick={this.clearOldBrews}>
|
||||
Clear Old
|
||||
</button>
|
||||
</h2>
|
||||
{this.renderBrewTable()}
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -48,4 +48,7 @@
|
||||
.deleteButton{
|
||||
cursor: pointer;
|
||||
}
|
||||
button.clearOldButton{
|
||||
float : right;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
var _ = require('lodash');
|
||||
var Moment = require('moment');
|
||||
var vitreumRender = require('vitreum/render');
|
||||
var HomebrewModel = require('./homebrew.model.js').model;
|
||||
|
||||
@@ -58,26 +59,20 @@ module.exports = function(app){
|
||||
//}
|
||||
});
|
||||
|
||||
app.get('/homebrew/clear', function(req, res){
|
||||
//if(req.query && req.query.admin_key == process.env.ADMIN_KEY){
|
||||
|
||||
|
||||
|
||||
HomebrewModel.find({text : ''}, function(err, objs){
|
||||
|
||||
return res.json(objs);
|
||||
|
||||
|
||||
if(!objs.length || err) return res.status(404).send("Can not find homebrew with that id");
|
||||
var resEntry = objs[0];
|
||||
resEntry.remove(function(err){
|
||||
if(err) return res.status(500).send("Error while removing");
|
||||
//Removes all empty brews that are older than 3 days
|
||||
app.get('/homebrew/clear_old', function(req, res){
|
||||
if(req.query && req.query.admin_key == process.env.ADMIN_KEY){
|
||||
HomebrewModel.remove({
|
||||
text : '',
|
||||
createdAt: {
|
||||
$lt: Moment().subtract(3, 'days').toDate()
|
||||
}
|
||||
}, function(err, objs){
|
||||
return res.status(200).send();
|
||||
})
|
||||
});
|
||||
//}else{
|
||||
// return res.status(401).send('Access denied');
|
||||
//}
|
||||
}else{
|
||||
return res.status(401).send('Access denied');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user