Просмотр исходного кода

Update buttons to work again after changes

Lee Morgan 6 лет назад
Родитель
Сommit
668b109932
3 измененных файлов с 28 добавлено и 30 удалено
  1. 1 1
      views/dataPage/data.ejs
  2. 3 6
      views/dataPage/home.js
  3. 24 23
      views/dataPage/ingredient.js

+ 1 - 1
views/dataPage/data.ejs

@@ -28,7 +28,7 @@
 
                 <input id="to" type="date">
 
-                <button id="dateSort" class="buttonDisabled">Submit</button>
+                <button id="dateSort" class="button">Submit</button>
             </div>
 
             <div class="buttonBox">

+ 3 - 6
views/dataPage/home.js

@@ -108,12 +108,9 @@ window.homeObj = {
         for(let ingredient of soldIngredients){
             let row = document.createElement("tr");
             ingredientsBody.appendChild(row);
-            if(window.dataLoaded){
-                row.classList = "clickableRow";
-                row.onclick = ()=>{window.ingredientObj.display("ingredient", ingredient)};
-            }else{
-                row.ingredient = ingredient;
-            }
+            row.classList = "clickableRow";
+            row.onclick = ()=>{window.ingredientObj.display("ingredient", ingredient)};
+            
 
             let name = document.createElement("td");
             name.innerText = `${ingredient.name} (${ingredient.unit})`;

+ 24 - 23
views/dataPage/ingredient.js

@@ -7,6 +7,10 @@ window.ingredientObj = {
         document.querySelector("#ingredientStrand").style.display = "flex";
         document.querySelector("strand-selector").setAttribute("strand", "ingredient");
 
+        //A grabastic bag of bullshit to get rid of
+        let d = new Date();
+        d.setDate(d.getDate() - 20);
+
         if(!this.isPopulated){
             let ingredientsDiv = document.querySelector("#ingredientOptions");
 
@@ -42,7 +46,7 @@ window.ingredientObj = {
                 "Date",
                 {
                     type: "date",
-                    start: startDate,
+                    start: d,
                     end: new Date()
                 }
             );
@@ -52,9 +56,8 @@ window.ingredientObj = {
 
         if(ingredient){
             this.graph.clear();
-            let d = new Date();
-            d.setDate(d.getDate() - 20);
-            this.graph.addData(this.formatData(type, ingredient.id, d, new Date()));
+            
+            this.graph.addData(this.formatData(ingredient.id, d, new Date()));
 
             for(let label of document.querySelector("#ingredientOptions").children){
                 if(label.innerText === ingredient.name){
@@ -66,34 +69,32 @@ window.ingredientObj = {
         }
     },
 
-    formatData: function(type, id, startDate, endDate){
+    formatData: function(id, startDate, endDate){
         let dataList;
-        
-        if(type === "ingredient"){
-            let dateRange = Math.floor((Date.UTC(endDate.getFullYear(), endDate.getMonth(), endDate.getDate()) - Date.UTC(startDate.getFullYear(), startDate.getMonth(), startDate.getDate())) / (1000 * 60 * 60 * 24));
-            dataList = new Array(Math.abs(dateRange)).fill(0);
+    
+        let dateRange = Math.floor((Date.UTC(endDate.getFullYear(), endDate.getMonth(), endDate.getDate()) - Date.UTC(startDate.getFullYear(), startDate.getMonth(), startDate.getDate())) / (1000 * 60 * 60 * 24));
+        dataList = new Array(Math.abs(dateRange)).fill(0);
 
-            for(let transaction of data.transactions){
-                let transDate = new Date(transaction.date);
-                let diff = Math.floor((Date.UTC(transDate.getFullYear(), transDate.getMonth(), transDate.getDate()) - Date.UTC(endDate.getFullYear(), endDate.getMonth(), endDate.getDate())) / (1000 * 60 * 60 * 24));
+        for(let transaction of data.transactions){
+            let transDate = new Date(transaction.date);
+            let diff = Math.floor((Date.UTC(transDate.getFullYear(), transDate.getMonth(), transDate.getDate()) - Date.UTC(endDate.getFullYear(), endDate.getMonth(), endDate.getDate())) / (1000 * 60 * 60 * 24));
 
-                if(diff <= 0){
-                    for(let recipe of transaction.recipes){
-                        for(let merchRecipe of data.merchant.recipes){
-                            if(merchRecipe._id === recipe.recipe){
-                                for(let ingredient of merchRecipe.ingredients){
-                                    if(ingredient.ingredient === id){
-                                        dataList[dateRange - Math.abs(diff)] += ingredient.quantity;
-                                    }
+            if(diff <= 0){
+                for(let recipe of transaction.recipes){
+                    for(let merchRecipe of data.merchant.recipes){
+                        if(merchRecipe._id === recipe.recipe){
+                            for(let ingredient of merchRecipe.ingredients){
+                                if(ingredient.ingredient === id){
+                                    dataList[dateRange - Math.abs(diff)] += ingredient.quantity;
                                 }
-                                break;
                             }
+                            break;
                         }
                     }
                 }
             }
-
-            return {id: id, set: dataList};
         }
+
+        return {id: id, set: dataList};
     }
 }