Parcourir la source

Bug Fix: calculator list was not removing items before adding new ones.
Bug Fix: js for calculator was interacting directly with the table rather than the table body.

Lee Morgan il y a 5 ans
Parent
commit
6e2e46962e

+ 5 - 1
views/dashboardPage/bundle.js

@@ -2643,10 +2643,14 @@ module.exports = newTransaction;
 },{}],14:[function(require,module,exports){
 let orderCalculator = {
     display: function(){
-        let calculatorItems = document.getElementById("calculatorItems");
+        let calculatorItems = document.getElementById("calculatorItemsBody");
         let template = document.getElementById("calculatorItem").content.children[0];
         let calculations = this.predict();
 
+        while(calculatorItems.children.length > 0){
+            calculatorItems.removeChild(calculatorItems.firstChild);
+        }
+
         for(let i = 0; i < calculations.length; i++){
             let item = template.cloneNode(true);
             item.children[0].innerText = calculations[i].ingredient.name,

+ 5 - 1
views/dashboardPage/js/sidebars/orderCalculator.js

@@ -1,9 +1,13 @@
 let orderCalculator = {
     display: function(){
-        let calculatorItems = document.getElementById("calculatorItems");
+        let calculatorItems = document.getElementById("calculatorItemsBody");
         let template = document.getElementById("calculatorItem").content.children[0];
         let calculations = this.predict();
 
+        while(calculatorItems.children.length > 0){
+            calculatorItems.removeChild(calculatorItems.firstChild);
+        }
+
         for(let i = 0; i < calculations.length; i++){
             let item = template.cloneNode(true);
             item.children[0].innerText = calculations[i].ingredient.name,

+ 1 - 1
views/dashboardPage/sidebars/orderCalculator.ejs

@@ -16,7 +16,7 @@
                 <th>INGREDIENT</th>
                 <th>USAGE / DAY (PREDICTED)</th>
             </thead>
-            <tbody></tbody>
+            <tbody id="calculatorItemsBody"></tbody>
         </table>
     </div>