From e7099d1dbb0c05901e0823e28238c294509ab621 Mon Sep 17 00:00:00 2001 From: Moe Date: Thu, 23 Apr 2020 20:58:30 -0700 Subject: [PATCH] Face Manager : Add drag and drop for faces between folders in UI --- .../faceManagerCustomAutoLoadLibrary/index.js | 50 +++++++++-- .../web/libs/css/super.faceManager.css | 22 +++++ .../web/libs/js/super.faceManager.js | 84 ++++++++++++++++--- .../web/pages/blocks/super.faceManager.ejs | 2 +- 4 files changed, 140 insertions(+), 18 deletions(-) diff --git a/plugins/face/faceManagerCustomAutoLoadLibrary/index.js b/plugins/face/faceManagerCustomAutoLoadLibrary/index.js index 1ad11cab..8dbbf425 100644 --- a/plugins/face/faceManagerCustomAutoLoadLibrary/index.js +++ b/plugins/face/faceManagerCustomAutoLoadLibrary/index.js @@ -91,17 +91,57 @@ module.exports = function(s,config,lang,app,io){ faceName: req.params.name, fileName: req.params.image, }) + getFaceFolderNames((faces) => { + s.sendToAllDetectors({ + f: 'recompileFaceDescriptors', + faces: faces + }) + }) }) } res.end(s.prettyPrint({ ok: true, })) - getFaceFolderNames((faces) => { - s.sendToAllDetectors({ - f: 'recompileFaceDescriptors', - faces: faces + },res,req) + }) + app.get(config.webPaths.superApiPrefix+':auth/faceManager/image/:name/:image/move/:newName/:newImage', function (req,res){ + s.superAuth(req.params,function(resp){ + res.setHeader('Content-Type', 'application/json') + const oldImagePath = config.facesFolder + req.params.name + '/' + req.params.image + const newImagePath = config.facesFolder + req.params.newName + '/' + req.params.newImage + const fileExists = fs.existsSync(oldImagePath) + if(fileExists){ + fs.readFile(oldImagePath,(err,data) => { + fs.writeFile(newImagePath,data,() => { + fs.unlink(oldImagePath,() => { + s.file('delete',oldImagePath) + if(req.query.websocketResponse){ + sendDataToConnectedSuperUsers({ + f:'faceManagerImageDeleted', + faceName: req.params.name, + fileName: req.params.image, + }) + var fileLink = config.webPaths.superApiPrefix + req.params.auth + `/faceManager/image/${req.params.newName}/${req.params.newImage}` + sendDataToConnectedSuperUsers({ + f:'faceManagerImageUploaded', + faceName: req.params.newName, + fileName: req.params.newImage, + url: fileLink + }) + } + getFaceFolderNames((faces) => { + s.sendToAllDetectors({ + f: 'recompileFaceDescriptors', + faces: faces + }) + }) + }) + }) }) - }) + } + res.end(s.prettyPrint({ + ok: fileExists, + })) },res,req) }) app.post(config.webPaths.superApiPrefix+':auth/faceManager/image/:name/:image', fileUpload(), function (req,res){ diff --git a/plugins/face/faceManagerCustomAutoLoadLibrary/web/libs/css/super.faceManager.css b/plugins/face/faceManagerCustomAutoLoadLibrary/web/libs/css/super.faceManager.css index 3198a8bf..9d2a69b1 100644 --- a/plugins/face/faceManagerCustomAutoLoadLibrary/web/libs/css/super.faceManager.css +++ b/plugins/face/faceManagerCustomAutoLoadLibrary/web/libs/css/super.faceManager.css @@ -1,7 +1,29 @@ #faceManagerImages .face-image { + transition: 0s; +} +#faceManagerImages h3:first-child { + margin-top: 0!important; +} +#faceManagerImages > .row { + background: #fafafa; + border-radius: 5px; + padding: 5px; + margin: 0; +} +#faceManagerImages > .row.ui-droppable-hover { + background: #eee; +} +#faceManagerImages > .row:empty { + height: 200px; +} +#faceManagerImages .face-image-bg { + position: relative; background-size: cover; background-position: center; border-radius: 5px; + width: 100%; + height: 100%; + border: 1px solid #eee; } #faceManagerImages .face-image .controls, #faceManagerImages .face-image .controls-bottom { diff --git a/plugins/face/faceManagerCustomAutoLoadLibrary/web/libs/js/super.faceManager.js b/plugins/face/faceManagerCustomAutoLoadLibrary/web/libs/js/super.faceManager.js index d2bb9355..17db98e3 100644 --- a/plugins/face/faceManagerCustomAutoLoadLibrary/web/libs/js/super.faceManager.js +++ b/plugins/face/faceManagerCustomAutoLoadLibrary/web/libs/js/super.faceManager.js @@ -13,32 +13,47 @@ $(document).ready(function(){ callback(response) }) } + var moveFaceImage = function(name,image,newFaceName,callback){ + $.get(superApiPrefix + $user.sessionKey + '/faceManager/image/' + name + '/' + image + '/move/' + newFaceName + '/' + image + '?websocketResponse=1' ,function(response){ + callback(response) + }) + } var getFaceImageHtml = function(name,image){ - return `
-
-
- + return `
+
+
+
+ +
+
+ ${name} +
-
- ${name} +
+ ${image}
-
- ${image} -
` } + var createFaceHeader = function(name){ + return `${name}` + } var drawFaceImages = function(){ getFaceImages(function(faces){ var html = '' $.each(faces,function(name,images){ - html += `
` + // if(images.length === 0)return + html += `${createFaceHeader(name)}
` $.each(images,function(n,image){ html += getFaceImageHtml(name,image) }) html += `
` }) faceManagerImages.html(html) + $.each(faces,function(name,images){ + activateDroppableContainer(name) + }) + activateDraggableImages() prettySizeFaceImages() }) } @@ -47,6 +62,49 @@ $(document).ready(function(){ var faceHeight = faceImagesRendered.first().width() faceImagesRendered.css('height',faceHeight) } + var activateDroppableContainer = function(name){ + var row = faceManagerImages.find(`.row[face="${name}"]`) + try{ + row.droppable("destroy") + }catch(err){ + + } + row.droppable({ + tolerance: "intersect", + accept: ".face-image", + activeClass: "ui-state-default", + hoverClass: "ui-state-hover", + drop: function(event, ui) { + var el = $(this) + var newFace = el.attr('face') + var faceImageElement = $(ui.draggable) + var oldFace = faceImageElement.attr('face') + var fileName = faceImageElement.attr('image') + if(oldFace !== newFace){ + moveFaceImage(oldFace,fileName,newFace) + }else{ + faceImageElement.css({ + top: 0, + left: 0, + }) + } + } + }) + } + var activateDraggableImages = function(name){ + var imageEls = faceManagerImages.find(`.face-image`) + try{ + imageEls.draggable("destroy") + }catch(err){ + + } + imageEls.draggable({ + appendTo: "body", + cursor: "move", + // helper: 'clone', + revert: "invalid" + }); + } faceManagerModal.on('shown.bs.modal',function(){ drawFaceImages() }) @@ -60,7 +118,7 @@ $(document).ready(function(){ var faceImage = el.attr('image') $.confirm.create({ title: lang.deleteImage, - body: lang.deleteImageText, + body: lang.deleteImageText + `
`, clickOptions: { class: 'btn-danger', title: lang.Delete, @@ -98,10 +156,12 @@ $(document).ready(function(){ case'faceManagerImageUploaded': var row = faceManagerImages.find(`.row[face="${d.faceName}"]`) if(row.length === 0){ - faceManagerImages.append(`
`) + faceManagerImages.append(`${createFaceHeader(d.faceName)}
`) row = faceManagerImages.find(`.row[face="${d.faceName}"]`) + activateDroppableContainer(d.faceName) } row.prepend(getFaceImageHtml(d.faceName,d.fileName)) + activateDraggableImages() prettySizeFaceImages() break; case'faceManagerImageDeleted': diff --git a/plugins/face/faceManagerCustomAutoLoadLibrary/web/pages/blocks/super.faceManager.ejs b/plugins/face/faceManagerCustomAutoLoadLibrary/web/pages/blocks/super.faceManager.ejs index 81bb845c..cdbdea0d 100644 --- a/plugins/face/faceManagerCustomAutoLoadLibrary/web/pages/blocks/super.faceManager.ejs +++ b/plugins/face/faceManagerCustomAutoLoadLibrary/web/pages/blocks/super.faceManager.ejs @@ -13,7 +13,7 @@
- +