add reset button and function for --autoreset
parent
4941a7e5b8
commit
0130518410
7
app.js
7
app.js
|
@ -132,6 +132,13 @@ app.get(routes.backup, function(req, res) {
|
|||
});
|
||||
});
|
||||
|
||||
app.get(routes.reset, function(req, res) {
|
||||
crontab.reset((err) => {
|
||||
if (err) next(err);
|
||||
else res.end();
|
||||
})
|
||||
})
|
||||
|
||||
// This renders the restore page similar to backup page
|
||||
app.get(routes.restore, function(req, res) {
|
||||
// get all the crontabs
|
||||
|
|
23
crontab.js
23
crontab.js
|
@ -240,6 +240,29 @@ exports.backup = (callback) => {
|
|||
});
|
||||
};
|
||||
|
||||
exports.reset = (callback) => {
|
||||
console.log("Resetting crontab-ui");
|
||||
var crontabdb = exports.crontab_db_file;
|
||||
var envdb = exports.env_file;
|
||||
|
||||
console.log("Deleting " + crontabdb);
|
||||
try{
|
||||
fs.unlinkSync(crontabdb);
|
||||
} catch (e) {
|
||||
console.log("Unable to delete " + crontabdb);
|
||||
}
|
||||
|
||||
console.log("Deleting " + envdb);
|
||||
try{
|
||||
fs.unlinkSync(envdb);
|
||||
} catch (e) {
|
||||
console.log("Unable to delete " + envdb);
|
||||
}
|
||||
|
||||
db.loadDatabase();
|
||||
callback();
|
||||
}
|
||||
|
||||
exports.restore = function(db_name){
|
||||
fs.createReadStream(path.join(exports.db_folder, db_name)).pipe(fs.createWriteStream(exports.crontab_db_file));
|
||||
db.loadDatabase(); // reload the database
|
||||
|
|
|
@ -167,6 +167,14 @@ function doBackup(){
|
|||
});
|
||||
}
|
||||
|
||||
function doReset(){
|
||||
messageBox("<p> Do you want to reset crontab-ui? </p>", "Confirm reset", null, null, function(){
|
||||
$.get(routes.reset, {}, function(){
|
||||
location.reload();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function delete_backup(db_name){
|
||||
messageBox("<p> Do you want to delete this backup? </p>", "Confirm delete", null, null, function(){
|
||||
$.get(routes.delete_backup, {db: db_name}, function(){
|
||||
|
|
|
@ -13,6 +13,7 @@ var routes = {
|
|||
"start": "/start",
|
||||
"remove": "/remove",
|
||||
"backup": "/backup",
|
||||
"reset": "/reset",
|
||||
"restore": "/restore",
|
||||
"delete_backup": "/delete",
|
||||
"restore_backup": "/restore_backup",
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
</div>
|
||||
<a class="btn btn-primary" onclick="newJob();"><span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span> New</a>
|
||||
<a class="btn btn-info" onclick="doBackup();"><span class="glyphicon glyphicon-floppy-save" aria-hidden="true"></span> Backup</a>
|
||||
<a class="btn btn-info" onclick="doReset();"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Reset</a>
|
||||
<form id="import_form" enctype="multipart/form-data" action="<%= JSON.parse(routes).import %>" method="post" style="display:none">
|
||||
<input type="file" id="import_file" name="import_file" onchange="$('#import_form').submit()"/>
|
||||
</form>
|
||||
|
|
Loading…
Reference in New Issue