Skip to content

Commit

Permalink
More updates
Browse files Browse the repository at this point in the history
  • Loading branch information
VidyasagarMSC committed Jun 12, 2020
1 parent 29f95d7 commit fea0dfb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
21 changes: 13 additions & 8 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,22 @@ promise.then(function(url) {
}
}

async function deleteItem(bucketName, itemName, prefix) {
async function deleteItem(req,res,next,bucketName, itemName, prefix) {
let cos = getCosClient();
let bucketName = process.env.COS_BUCKETNAME;
let bucketname = process.env.COS_BUCKETNAME;
itemName = prefix +"/"+ itemName;
if(prefix==="results")
{
itemName = itemName+".json";
}
console.log(`Deleting item: ${itemName}`);
try {
await cos.deleteObject({
Bucket: bucketName,
Key: itemName,
Prefix: prefix
Bucket: bucketname,
Key: itemName
}).promise();
console.log(`Item: ${itemName} deleted!`);
res.send(`Item: ${itemName} deleted!`);
}
catch (e) {
console.error(`ERROR: ${e.code} - ${e.message}\n`);
Expand Down Expand Up @@ -164,9 +169,9 @@ app.post("/results", getBucketContents, function(req, res, next) {

app.delete("/item", function(req,res,next){
var itemName = req.query.filename;
console.log(prefix);
deleteItem(null, itemName, "images");
deleteItem(null, itemName, "results");
console.log(itemName);
deleteItem(req,res,next,null, itemName, "images");
deleteItem(req,res,next,null, itemName, "results");
//next();
});

Expand Down
29 changes: 21 additions & 8 deletions frontend/public/js/index2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ $(document).ready(function () {
getUploadedImages();
$("p.error").text("");
$("p.success").text("");
$("#uploadbtn").click(function(e){
$("#file").click();
e.preventDefault();
});

$("#file").change(function () {
//$("#column-multiline").empty();
// showUploadedImage(this);
Expand Down Expand Up @@ -37,12 +34,26 @@ $(document).ready(function () {
});

// to delete an image
$("a.is-pulled-right").click(function (){
$("*").click(function (e){
console.log("delete called");
var id=$(this).parent(".card-content").parent(".card").attr("id");
var filename = id.split("-")[0];
e.preventDefault();
e.stopPropagation();
console.log($(e.target.nodeName));
var nodeName = e.target.nodeName;
if(nodeName === "span" || nodeName === "span.icon"){
var filename=$(e.target).parents("a").attr("id");

deleteImage(filename);
getUploadedImages();
$("#column-multiline").remove($(e.target).parents(".card"));
}
else if(nodeName === "button")
{
$("#uploadbtn").click(function(e){
$("#file").click();
e.preventDefault();
});
}
});

$("#classifybtn").click(function () {
Expand Down Expand Up @@ -146,7 +157,9 @@ $(document).ready(function () {
<div class="card-content is-overlay">\
<span class="tag is-info is-pulled-left">\
Not classified\
</span><a href="#" class="is-pulled-right"><span class="icon"><i class="fas fa-trash"></i> </span></a> \
</span><a href="#" id="' +
fileName +
'" class="is-pulled-right"><span class="icon"><i class="fas fa-trash"></i> </span></a> \
</div>\
</div>\
<footer class="card-footer">\
Expand Down

0 comments on commit fea0dfb

Please sign in to comment.