[enh] The delete action should work
This commit is contained in:
parent
3ce2e4514d
commit
b0c6043741
4
index.js
4
index.js
@ -29,8 +29,6 @@ dbInit.init({
|
||||
seed : process.env.DB_SEED
|
||||
});
|
||||
|
||||
console.log( "exit")
|
||||
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
|
||||
@ -71,7 +69,7 @@ app.post('/*', routes.add);
|
||||
app.get('/*', routes.main);
|
||||
app.patch('/*', routes.main);
|
||||
app.put('/*', routes.main);
|
||||
app.delete('/*', routes.main);
|
||||
app.delete('/delete/:id', routes.delete);
|
||||
|
||||
|
||||
app.listen(port, () => {
|
||||
|
@ -1,5 +1,7 @@
|
||||
/* global initData, authorizationToken */
|
||||
|
||||
$(function(){
|
||||
|
||||
// List of HTML entities for escaping.
|
||||
var htmlEscapes = {
|
||||
'&': '&',
|
||||
@ -37,7 +39,7 @@ date = function(string){
|
||||
};
|
||||
mailRegexp = /(.*) <(.+@.+)>/;
|
||||
mail = function( string ){
|
||||
return ''+string.replace(mailRegexp, '<a href="mailto:$2">$1</a>');
|
||||
return ''+string.replace(mailRegexp, `<a href="mailto:${string}">$1</a>`);
|
||||
};
|
||||
function updatePage(data){
|
||||
|
||||
@ -66,7 +68,7 @@ function updatePage(data){
|
||||
<a class="actions-toggle btn-link btn-sm">Actions</a>
|
||||
</p>
|
||||
<div class="actions btn-group btn-group-sm" role="group" aria-label="log actions">
|
||||
<a class="destroy btn btn btn-outline-secondary" href="/destroy/${id}">Remove</a>
|
||||
<a class="delete btn btn btn-outline-secondary" href="/delete/${id}">Remove</a>
|
||||
<a class="edit btn btn btn-outline-secondary" href="/edit/${id}">Edit</a>
|
||||
</div>
|
||||
</div>
|
||||
@ -105,3 +107,22 @@ updatePage( initData );
|
||||
|
||||
$(".actions-toggle").on("click",(e) => { var el=e.target; $(el).parent().siblings('.actions').show(); $(el).hide(); } )
|
||||
|
||||
$('.delete').on('click', (e) => {
|
||||
const el = $(e.target);
|
||||
const url = el.attr('href');
|
||||
$.ajax(url,{
|
||||
method: "DELETE",
|
||||
beforeSend: function(request) {
|
||||
request.setRequestHeader("authorizationToken", authorizationToken);
|
||||
}
|
||||
})
|
||||
.done(function(data) {
|
||||
$(el).parents('.log').remove();
|
||||
})
|
||||
.fail(function() {
|
||||
alert( "error" );
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -54,6 +54,53 @@ const routes = {
|
||||
res.json({"health":0,"msg":"Lost connection to ES"});
|
||||
});
|
||||
},
|
||||
delete: (req,res) => {
|
||||
const id= req.params.id;
|
||||
// Reindex the doc to the "trash" index
|
||||
var log = client.reindex({
|
||||
refresh: true,
|
||||
max_docs: 1,
|
||||
body: {
|
||||
source: {
|
||||
index: 'changelog',
|
||||
query: {
|
||||
term: {
|
||||
_id: id
|
||||
}
|
||||
}
|
||||
},
|
||||
dest: {
|
||||
index: 'changelog-trash',
|
||||
}
|
||||
}
|
||||
})
|
||||
.then( (results, err) => {
|
||||
|
||||
console.log(`reindexing success for id ${id}`)
|
||||
// Remove it from the original index
|
||||
return client.delete({
|
||||
index: "changelog",
|
||||
id: id
|
||||
});
|
||||
|
||||
}, (e) => {
|
||||
|
||||
console.log("reindexing error")
|
||||
res.status(400);
|
||||
res.end("error");
|
||||
|
||||
})
|
||||
.then( (results, err) => {
|
||||
|
||||
console.log(`Delete success for id ${id}`)
|
||||
res.end("ok");
|
||||
|
||||
},(results, err) => {
|
||||
console.log(`Delete error for id ${id}`)
|
||||
res.status(400);
|
||||
res.end("error");
|
||||
});
|
||||
},
|
||||
add: (req, res) => {
|
||||
|
||||
const body = req.body;
|
||||
|
Loading…
Reference in New Issue
Block a user