Skip to content
Snippets Groups Projects
Commit 93f9ddd1 authored by Deleted User's avatar Deleted User
Browse files

putting labels in order. All that remains is to add the right intentation before.

parent 515ee546
No related branches found
No related tags found
3 merge requests!13First official merge,!4WIP: Affichages des tutos,!3Master
......@@ -5,17 +5,7 @@
</head>
<body>
<ul id="tuto">
<li v-for="(value, index) in fruits" @click="getFruit(index)">
{{ index }} => {{ value }}
</li>
</ul>
<!---<div>
<div id="test" v-for="value in labels" @click="clickLabel()">
{{ value }}
</div>
</div>-->
</body>
<script>
......@@ -31,71 +21,100 @@
return (xhr.responseText);
};
//add \t to the child in function
function print_elem(txt, nb_tabs) {
var new_msg = "";
for (var i = 0; i < nb_tabs; i++)
new_msg += '\t';
new_msg += txt;
console.log(nb_tabs + new_msg);
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);
}
//print the tab that represent labels with theirs childs
function print_tab(tab, nb_tabs) {
for (var i = 0; tab[i]; i++) {
if (Array.isArray(tab[i - 1]))
nb_tabs--;
if (Array.isArray(tab[i])) {
nb_tabs++;
print_tab(tab[i], nb_tabs)
} else
print_elem(tab[i], nb_tabs);
}
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);
}
var tab = ['addition', 'soustraction', 'complexe', ['c1', 'c2', ['lol1', 'lol2'], 'c3'], 'easy', ['un', ['deux', ['trois', ['quatre']]]], 'ok'];
var labels_tab = JSON.parse(request("get_datas/labels"))
var labels_list = []
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;
for (var i = 0; labels_tab[i]; i++) {
if (labels_tab[i][2] == null)
labels_list.push(labels_tab[i][0])
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);
}
console.log(labels_tab)
console.log('\n================\n', labels_list)
console.log(labels_tab[0][2])
//crrer l'espece de liste sur la gaucje
//print_tab(tab, 0);
/*new Vue({
el: '#test',
data: {
labels: ['a', 'b', 'c']
},
methods: {
clickLabel: function() {
alert("clique");
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++;
}
result.push(inter);
inter = 0;
}
});*/
new Vue({
el: '#tuto',
data: {
fruits: [
'pomme',
'cerise',
'abricot'
]
},
methods: {
getFruit: function(index) {
alert('Je suis ' + this.fruits[index]);
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]);
}
//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.
}
});
}
var labels_tab = JSON.parse(request("get_datas/labels"))
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);
</script>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment