Newer
Older
<html>
<head>
<title>Print labels</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
Deleted User
committed
</body>
<script>
function request(address) {
var xhr = new XMLHttpRequest();
/*xhr.onreadystatechange = function () {
//if (xhr.readyState == 4)
//alert("reponse = " + xhr.responseText);
};*/
xhr.open("GET", "http://127.0.0.1:5000/"+address, false);
xhr.send();
return (xhr.responseText);
};
Deleted User
committed
function have_a_father(labels_tab, father_id) {
/**
* Search in labels_tab if there is a father of a child.
* If it as father return his position else return -1.
*/
for (var i = 0; labels_tab[i]; i++) {
if (labels_tab[i][0] == father_id)
return (i);
}
return (-1);
Deleted User
committed
function add_in_tab(tab, add, posi) {
/**
* Put add in tab[posi] without remove the previous value.
*/
var result = [];
for (var i = 0; i < posi; i++)
result[i] = tab[i];
result.push(add);
for(var i = posi; tab[i]; i++)
result.push(tab[i]);
return(result);
Deleted User
committed
function order_labels_list(labels_tab) {
/**
* Organise labels_tab in this order:
* Before: [[DadA, ...], [DadB, ...], [ChildA, ...], [ChildA, ...]]
* After : [[DadA, ...], [ChildA, ...], [ChildA, ...], [DadB, ...]]
* Dad before his childs. It's for print labels in the order.
* In the first loop we retrieve labels without father and in the
* second we add their childs at their right.
*/
var labels_tab_final = [];
var posi_father = -1;
Deleted User
committed
for (var i = 0; labels_tab[i]; i++) {
if (!labels_tab[i][2])
labels_tab_final.push(labels_tab[i]);
}
for (var i = 0; labels_tab[i]; i++) {
posi_father = -1;
if (labels_tab[i][2]) {
posi_father = have_a_father(labels_tab_final, labels_tab[i][2]);
if (posi_father != -1)
labels_tab_final = add_in_tab(labels_tab_final, labels_tab[i], posi_father + 1);
}
}
return (labels_tab_final);
Deleted User
committed
function create_tab_lvl_intent(labels_tab) {
var result = [];
var inter = 0;
for (var i = 0; labels_tab[i]; i++) {
for (var j = 0; labels_tab[j]; j++) {
if (labels_tab[j][2] && labels_tab[i][0] == labels_tab[j][2])
inter++;
Deleted User
committed
result.push(inter);
inter = 0;
Deleted User
committed
return (result);
}
function intent(labels_tab, tab_lvl_intent) {
var result = labels_tab;
//FAIRE LA FONCTION REVERSE ET C FINI !!!
for (var i = 0; tab_lvl_intent[i]; i++) {
if (lvl_intent[i] != 0) {
labels_tab[i][1] = reverse(labels_tab[i][1]);
for (var p = 0; p < tab_lvl_intent[p]; p++)
labels_tab[i][1].push('\t');
labels_tab[i][1] = reverse(labels_tab[i][1]);
Deleted User
committed
//demander si faire une copie d'une case d'un tableau geant
//de modifier cette copie et de reasigner la copie a la case
//du tavbleau en question est plus optie que de modifie labels_tab
//case du tableau a chaques operations.
Deleted User
committed
}
var labels_tab = JSON.parse(request("get_datas/labels"))
Deleted User
committed
console.log(labels_tab);
labels_tab = order_labels_list(labels_tab);
console.log(labels_tab);
var lvl_intent = create_tab_lvl_intent(labels_tab);
console.log(lvl_intent);