From b3b007777aba89f194abed38a6e620a4e8633b94 Mon Sep 17 00:00:00 2001 From: madan-ram Date: Thu, 19 May 2022 18:40:09 +0530 Subject: [PATCH] Implemented deleteBlock based on block id and assign flow id --- engine/flowy.js | 204 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 201 insertions(+), 3 deletions(-) diff --git a/engine/flowy.js b/engine/flowy.js index bd6973f..2013a15 100644 --- a/engine/flowy.js +++ b/engine/flowy.js @@ -1,4 +1,19 @@ var flowy = function(canvas, grab, release, snapping, rearrange, spacing_x, spacing_y) { + + function makeid(length, with_timestamp) { + var result = ''; + var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + var charactersLength = characters.length; + for ( var i = 0; i < length; i++ ) { + result += characters.charAt(Math.floor(Math.random() * charactersLength)); + } + if(with_timestamp) { + return result+'_'+Date.now(); + } else { + return result; + } + } + if (!grab) { grab = function() {}; } @@ -36,6 +51,14 @@ var flowy = function(canvas, grab, release, snapping, rearrange, spacing_x, spac }; } var loaded = false; + var with_timestamp=true; + var id_length=6; + var flowy_id = makeid(id_length, with_timestamp); + + flowy.get_id = function() { + return flowy_id; + } + flowy.load = function() { if (!loaded) loaded = true; @@ -64,7 +87,14 @@ var flowy = function(canvas, grab, release, snapping, rearrange, spacing_x, spac el.classList.add('invisible'); canvas_div.appendChild(el); flowy.import = function(output) { + canvas_div.innerHTML = output.html; + if(output.flowy_id == undefined) { + flowy_id = makeid(id_length, with_timestamp); + } else { + flowy_id = output.flowy_id; + } + for (var a = 0; a < output.blockarr.length; a++) { blocks.push({ childwidth: parseFloat(output.blockarr[a].childwidth), @@ -86,7 +116,8 @@ var flowy = function(canvas, grab, release, snapping, rearrange, spacing_x, spac var json_data = { html: html_ser, blockarr: blocks, - blocks: [] + blocks: [], + 'flowy_id': flowy_id }; if (blocks.length > 0) { for (var i = 0; i < blocks.length; i++) { @@ -114,7 +145,172 @@ var flowy = function(canvas, grab, release, snapping, rearrange, spacing_x, spac return json_data; } } + + function moveChildrenToParentPos(id) { + let childern_block_idx = []; + for(let idx=0; idx 1) { + rearrangeMe(); + } + + return Math.max.apply( + Math, + blocks.map((a) => a.id) + ); + + function modifyChildBlocks(parentId) { + let children = []; + let blocko = blocks.map((a) => a.id); + for (var i = blocko.length - 1; i >= 0; i--) { + let currentBlock = blocks.filter((a) => a.id == blocko[i])[0]; + if (currentBlock.parent === parentId) { + children.push(currentBlock.id); + removeBlockEls(currentBlock.id); + blocks.splice(i, 1); + } + } + + for (var i = 0; i < children.length; i++) { + modifyChildBlocks(children[i]); + } + } + function removeBlockEls(id) { + document + .querySelector(".blockid[value='" + id + "']") + .parentNode.remove(); + if (document.querySelector(".arrowid[value='" + id + "']")) { + document + .querySelector(".arrowid[value='" + id + "']") + .parentNode.remove(); + } + } + }; + flowy.deleteBlocks = function() { + flowy_id = makeid(id_length, with_timestamp); blocks = []; canvas_div.innerHTML = ""; } @@ -424,8 +620,9 @@ var flowy = function(canvas, grab, release, snapping, rearrange, spacing_x, spac } function hasParentClass(element, classname) { + if (element.className) { - if (element.className.split(' ').indexOf(classname) >= 0) return true; + if (typeof(element.className) !== 'object' && element.className.split(' ').indexOf(classname) >= 0) return true; } return element.parentNode && hasParentClass(element.parentNode, classname); } @@ -587,6 +784,7 @@ var flowy = function(canvas, grab, release, snapping, rearrange, spacing_x, spac } } } + if (result[z] != -1) { blocks.filter(a => a.id == result[z])[0].childwidth = totalwidth; } @@ -659,4 +857,4 @@ var flowy = function(canvas, grab, release, snapping, rearrange, spacing_x, spac } flowy.load(); -} +} \ No newline at end of file