Skip to content

Commit c8c488e

Browse files
committed
Improving process section
1 parent 2b05e4e commit c8c488e

File tree

3 files changed

+59
-5
lines changed

3 files changed

+59
-5
lines changed

index.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<meta name="keywords" content="Traducteur, Python, Langage Naturel, Algorithme, Outil, Générateur">
1414
<!--Search console google-->
1515
<meta name="google-site-verification" content="MFyyD0CuXPtsypisaNggDKDm6JSQkbxXFrszX0k8v7g">
16-
1716
</head>
1817
<body>
1918
<header>
@@ -60,7 +59,15 @@ <h3>Traitement :</h3>
6059
<div id="process1" class="line">
6160
<select class="form-control var-list" id="process1Var" onchange="writeCode()"></select>
6261
<span>Prend la valeur</span>
63-
<input type="text" name="calculus" class="form-control" onchange="writeCode()">
62+
<input type="text" name="calculus" class="form-control short process-element" onchange="writeCode(); checkVariable($(this))">
63+
<select class="form-control process-element" onchange="writeCode(); deleteIfNull($(this))">
64+
<option value=""></option>
65+
<option value="+">+</option>
66+
<option value="-">-</option>
67+
<option value="*">&times;</option>
68+
<option value="/">&divide;</option>
69+
</select>
70+
<button onclick="addProcessElement('1'); writeCode();" class="button-control element-adder">+</button>
6471
</div>
6572
<button onclick="addLine('process')" class="button-control line">+</button>
6673
</div>

scripts.js

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ function addLine(type){
1111
$("#"+type + nbrLine).attr("id",type + newNbrLine)
1212
if (type == "output") {
1313
$("#"+type + newNbrLine + " .swicher").attr("onchange", "swichOutputMode(" + newNbrLine + ")")
14+
} else if (type == "process") {
15+
$("#"+type + newNbrLine + " .element-adder").attr("onclick", "addProcessElement(" + newNbrLine + ")")
1416
}
1517
$("#"+type + newNbrLine).append('<button onclick="delLastLine(\''+type+'\')" class="button-control remove-button">&times;</button>')
1618
if (type == 'var') {
@@ -82,9 +84,16 @@ function writeCode(){
8284
}
8385
//Process
8486
for (var i = getLinesNumber("process"); i >=1 ; i--) { //Foreach process element
85-
if ($("#process" + i + " input").val() && $("#process" + i + " input").val() != '' && $("#process" + i + " select").val() != null) {
87+
if($("#process" + i + " input").val() && $("#process" + i + " input").val() != ''){
8688
CodeMirrorInstance.setValue(
87-
CodeMirrorInstance.getValue() + $('#process'+i+' select').val() + " = "+ $('#process'+i+' input').val() + " \n") // To improve
89+
CodeMirrorInstance.getValue() + $('#process'+i+' select').val() + " = ") // To improve
90+
for (var j = 0; j < $("#process" + i + " .process-element").length ; j++) {
91+
$($("#process" + i + " .process-element")[j])
92+
CodeMirrorInstance.setValue(
93+
CodeMirrorInstance.getValue() + $($("#process" + i + " .process-element")[j]).val())
94+
}
95+
CodeMirrorInstance.setValue(
96+
CodeMirrorInstance.getValue() + "\n")
8897
}
8998
}
9099
//Output
@@ -112,6 +121,39 @@ function toggleMenu(){
112121
left: parseInt($("nav").css('left'),10) == 0 ? -$("nav").outerWidth() : 0
113122
});
114123
}
124+
function deleteIfNull(list){
125+
console.log(list.val())
126+
if (list.val() == "") {
127+
if (list.next().is("input")) {
128+
list.next().remove()
129+
}
130+
list.remove()
131+
}
132+
}
133+
function checkVariable(input){
134+
if (!(getValues("var","input").includes(input.val())) && isNaN(input.val()) && input.val() != ""){
135+
input.css({
136+
color:"red",
137+
fontWeight: "bold"
138+
});
139+
}
140+
else{
141+
input.css({
142+
color:"black",
143+
fontWeight: "normal"
144+
});
145+
}
146+
147+
}
148+
function addProcessElement(id){
149+
var lastElement = $(last_of_array($(".process-element")))
150+
if (lastElement.is("select")) {
151+
$('<input type="text" name="calculus" class="form-control short process-element" onchange="writeCode(); checkVariable($(this))">').insertBefore("#process" + id + " .element-adder");
152+
} else{
153+
$('<select class="form-control process-element" onchange="writeCode(); deleteIfNull($(this))"><option value=""></option><option value="+">+</option><option value="-">-</option><option value="*">&times;</option><option value="/">&divide;</option></select>'
154+
).insertBefore("#process" + id + " .element-adder");
155+
}
156+
}
115157
$(function() {
116158
setVariableLists();
117159
writeCode();
@@ -133,4 +175,6 @@ $( window ).scroll(function() {
133175
top: $("header").outerHeight()-$( window ).scrollTop() //Makes the menu stick the header
134176
})
135177
}
136-
});
178+
});
179+
180+
function last_of_array(array){return array[array.length-1]}

style.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ h2{
176176
position: absolute;
177177
right: 10px;
178178
}
179+
.short{
180+
width: 30px;
181+
}
179182
@media screen and (max-width: 1000px) {
180183
section{
181184
display: block;

0 commit comments

Comments
 (0)