Skip to content

Commit

Permalink
full export working
Browse files Browse the repository at this point in the history
  • Loading branch information
Ltochon committed Jun 4, 2022
1 parent 070c1d8 commit 5c84c83
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 24 deletions.
5 changes: 3 additions & 2 deletions K-AnoTool/generalization/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,12 @@ button:hover{
line-height: 1.5;
font-size: 1rem;
padding: 2px 7px;
cursor: pointer;
}

.fileupload:hover {
background-color: white;
color: green;
background-color: rgb(161, 162, 161);
color: black;
}

.fileupload input {
Expand Down
93 changes: 72 additions & 21 deletions K-AnoTool/generalization/templates/generalization.html
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,22 @@
})
.remove();

link.enter().insert("text", "g")
.attr("x", function(d) { return ((d.target.depth -1)*105); })
.attr("y", function(d) { return (50); })
.text(function(d) { return ("Step " + (d.target.depth -1) + " to " + d.target.depth); })
.style('fill', 'rgb(87, 183, 215)')
.attr("font-weight", '800');
if(localStorage.getItem("type_" + localStorage.getItem("qid").replace("hiera_",'')) === "int"){
link.enter().insert("text", "g")
.attr("x", function(d) { return ((d.target.depth -1)*105); })
.attr("y", function(d) { return (50); })
.text(function(d) { return ("Step " + (d.target.depth -1) + " to " + d.target.depth); })
.style('fill', 'rgb(87, 183, 215)')
.attr("font-weight", '800');
}
else{
link.enter().insert("text", "g")
.attr("x", function(d) { return ((d.target.depth -1)*105); })
.attr("y", function(d) { return (200); })
.text(function(d) { return ("Step " + (d.target.depth -1) + " to " + d.target.depth); })
.style('fill', 'rgb(87, 183, 215)')
.attr("font-weight", '800');
}

// Stash the old positions for transition.
nodes.forEach(function(d) {
Expand Down Expand Up @@ -515,7 +525,7 @@
}
else{
p.classList.remove("plaw");
p.style.color = "black";
p.style.color = "rgb(87, 183, 215)";
p.style.fontStyle = "normal";
}
}
Expand Down Expand Up @@ -585,8 +595,6 @@
}
else{
let allchildren = document.getElementById("original").children;
//TO DO

let namel = "Other";
let allselected = document.querySelectorAll('#original p');
let tabselect = [];
Expand All @@ -596,18 +604,20 @@
}
});
console.log(tabselect)
if(diccatfinal[namel] === undefined){
let stringlaw = "";
diccatfinal[namel] = tabselect;
stringlaw = "'" + namel + "' : [";
for(elem in tabselect){
stringlaw += tabselect[elem] + ", "
if(tabselect.length > 0){
if(diccatfinal[namel] === undefined){
let stringlaw = "";
diccatfinal[namel] = tabselect;
stringlaw = "'" + namel + "' : [";
for(elem in tabselect){
stringlaw += tabselect[elem] + ", "
}
let div3 = document.getElementById("printlaw");
div3.innerHTML += stringlaw.slice(0, -2) + "]<br>";
}
else{
alert("This category has already been defined !")
}
let div3 = document.getElementById("printlaw");
div3.innerHTML += stringlaw.slice(0, -2) + "]<br>";
}
else{
alert("This category has already been defined !")
}

//
Expand Down Expand Up @@ -722,6 +732,46 @@
localStorage.setItem("weights_" + localStorage.getItem("qid").replace("hiera_",''),tabweight);
}

function savejson(){
let blob;
if(localStorage.getItem("diccategories_" + localStorage.getItem("qid").replace("hiera_",'')) != null){
let full = localStorage.getItem("diccategories_" + localStorage.getItem("qid").replace("hiera_",'')).replaceAll(";",",").split("|");
let dictojson = {}
for(elem in full){
dictojson[(parseInt(elem)+1).toString()] = [JSON.parse(full[elem])];
}
console.log(dictojson)
blob = new Blob([JSON.stringify(dictojson).replaceAll("}],","}],\n")], {type: 'text'});
}
else if(localStorage.getItem("tabfinalstr_" + localStorage.getItem("qid").replace("hiera_",'')) != null){
let full = localStorage.getItem("tabfinalstr_" + localStorage.getItem("qid").replace("hiera_",'')).replaceAll("[[","[").replaceAll("]]","]").replaceAll("],[","];[").split(";");
let dictojson = {}
for(elem in full){
dictojson[(parseInt(elem)+1).toString()] = JSON.parse(full[elem]);
}
console.log(dictojson)
blob = new Blob([JSON.stringify(dictojson).replaceAll("],","],\n")], {type: 'text'});
}
else{
let full = localStorage.getItem("dictint_" + localStorage.getItem("qid").replace("hiera_",'')).replaceAll("],","];;\n").split(";;");
blob = new Blob([full], {type: 'text'});
console.log(full)
}

if(window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveBlob(blob, "test.json");
}
else{
const elem = window.document.createElement('a');
elem.href = window.URL.createObjectURL(blob);
elem.download = "test.json";
document.body.appendChild(elem);
elem.click();
document.body.removeChild(elem);
}
}


var sub = (function(){
var savenodes = tree.nodes(root).reverse(),links = tree.links(savenodes);
allnodes = savenodes.reverse()
Expand Down Expand Up @@ -822,6 +872,7 @@
<input type="file" id="importedfile" accept=".json" onchange="readText(event)"/>
Import VGH
</div>
<div onclick="savejson()" class="fileupload" style="margin-left: auto;margin-right: auto; margin-top: 10px;">Export VGH</div>
<div style="color: red; cursor: pointer; margin-top: 1px; margin-bottom: 5px;" onclick="printinfo()"> <u>Informations about imports</u></div>
<button type="submit" class="btn btn-primary" style="margin-top : 10px">Save</button>

Expand Down Expand Up @@ -939,7 +990,7 @@ <h6 id="txtnew" style="font-weight: bold; margin-top: 3px;"></h6>
}
else{
p.classList.remove("plaw");
p.style.color = "black";
p.style.color = "rgb(87, 183, 215)";
p.style.fontStyle = "normal";
}
}
Expand Down
3 changes: 2 additions & 1 deletion todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ make shiny
k-anon pas k-ano OK
data sans s OK
pas lattice mais VGH OK
ajouter niveau sur arrete
ajouter niveau sur arrete OK
Other dans categorical OK
export JSON OK

test more qid > 2

0 comments on commit 5c84c83

Please sign in to comment.