Skip to content
Snippets Groups Projects
print_labels.html 3.14 KiB
Newer Older
<html>
	<head>
		<title>Print labels</title>
		<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
	</head>

	<body>
	</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);
		};

		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);
		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);
		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])
					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);
		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++;
			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);