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

Ajout a la liste des labels parent du label cliqué. Si je veux ajouter un tuto...

Ajout a la liste des labels parent du label cliqué. Si je veux ajouter un tuto en Python et que je clique sur le label python. Les labels Programmation, Langages seront ajoutés en plus du label Python.
parent d965fd9c
No related branches found
No related tags found
1 merge request!19Add tuto + modification DB
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
<img v-if='is_active[index] % 2 == 1' src="static/checked.png"> <img v-if='is_active[index] % 2 == 1' src="static/checked.png">
<br> <br>
</span> </span>
<span v-bind:src="labels_add[0]"></span> {{ labels_add }}
<!-- <span v-bind:src="labels_add[0]"></span> -->
<br> <br>
</div> </div>
</div> </div>
...@@ -57,6 +58,7 @@ ...@@ -57,6 +58,7 @@
</body> </body>
<script src="static/create_arbo.js"></script> <script src="static/create_arbo.js"></script>
<script src="static/array_opperations.js"></script>
<script src="static/ajax.js"></script> <script src="static/ajax.js"></script>
<script> <script>
...@@ -82,9 +84,46 @@ ...@@ -82,9 +84,46 @@
return (childs); return (childs);
} }
function get_all_fathers_of_child(tab_labels, child_id) {
/**
* Gets all the fathers (label id) of a child.
*/
var fathers = [];
var posi_child = is_in_tab(child_id, tab_labels, 0, 2);
for (var i = 0; tab_labels[i]; i++) {
if (tab_labels[posi_child][2] == tab_labels[i][0]) {
fathers.push(tab_labels[i][0]);
fathers = fathers.concat(get_all_fathers_of_child(tab_labels, tab_labels[i][0]));
}
}
return (fathers);
}
function selection_label(id_label) {
var all_fathers = get_all_fathers_of_child(hierarchy.all_labels, id_label);
var all_childs = get_all_childs_of_father(hierarchy.all_labels, id_label);
var posi = -1;
console.log(all_fathers);
console.log(all_childs);
hierarchy.labels_add.push(id_label);
for (var i = 0; all_fathers[i]; i++) {
posi = is_in_tab(all_fathers[i], hierarchy.labels_add, 0, 1);
if (posi == -1) {
hierarchy.labels_add.push(all_fathers[i]);
}
}
for (var i = 0; all_childs[i]; i++) {
posi = is_in_tab(all_childs[i], hierarchy.labels_add, 0, 1);
if (posi == -1) {
hierarchy.labels_add.push(all_childs[i]);
}
}
}
var hierarchy = new Vue({ var hierarchy = new Vue({
el: '#hierarchy', el: '#hierarchy',
data: { data: {
all_labels: this.all_labels = JSON.parse(request_ajax("labels")),
table: order_intent_labels_tab(), table: order_intent_labels_tab(),
is_active: create_empty_tab(40), is_active: create_empty_tab(40),
labels_add: [] labels_add: []
...@@ -93,15 +132,13 @@ ...@@ -93,15 +132,13 @@
activate_lo: function (index) { activate_lo: function (index) {
var id_lab = this.table[index][0]; var id_lab = this.table[index][0];
this.is_active[index] += 1; this.is_active[index] += 1;
if (this.is_active[index] % 2 == 1) if (this.is_active[index] % 2 == 1) {
this.labels_add.push(id_lab); selection_label(this.table[index][0]);
else //this.labels_add.push(index);
} else
this.labels_add.splice(this.labels_add.indexOf(id_lab), 1); this.labels_add.splice(this.labels_add.indexOf(id_lab), 1);
document.form1.labels.value = this.labels_add; document.form1.labels.value = this.labels_add;
}, }
get_all_labels: function() {
return (JSON.parse(request_ajax("labels")));
}
} }
}); });
......
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