lokesh341 commited on
Commit
4fe1c57
·
verified ·
1 Parent(s): 380eabf

Update templates/chef-bot.html

Browse files
Files changed (1) hide show
  1. templates/chef-bot.html +53 -33
templates/chef-bot.html CHANGED
@@ -252,7 +252,7 @@
252
  margin-right: 8px;
253
  }
254
 
255
- .ingredient-select, .ingredient-info-input {
256
  padding: 8px;
257
  border: 1px solid #b3d7ff;
258
  border-radius: 6px;
@@ -262,6 +262,21 @@
262
  margin: 5px;
263
  }
264
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
265
  .submit-button {
266
  padding: 10px 20px;
267
  background-color: #0078d4;
@@ -422,7 +437,7 @@
422
  padding: 4px 8px;
423
  }
424
 
425
- .ingredient-select, .ingredient-info-input {
426
  width: 120px;
427
  font-size: 12px;
428
  }
@@ -625,27 +640,22 @@
625
  itemSpan.textContent = `${itemName} (Qty: ${item.quantity || 1})`;
626
  contentDiv.appendChild(itemSpan);
627
 
628
- // Ingredient Selector
629
- const ingredientSelect = document.createElement('select');
630
- ingredientSelect.className = 'ingredient-select';
631
- const defaultOption = document.createElement('option');
632
- defaultOption.value = '';
633
- defaultOption.textContent = 'Add ingredient...';
634
- ingredientSelect.appendChild(defaultOption);
635
  sectorIngredients.forEach(ingredient => {
636
- const option = document.createElement('option');
637
- option.value = ingredient.name;
638
- option.textContent = ingredient.name;
639
- ingredientSelect.appendChild(option);
 
 
 
 
640
  });
641
- ingredientSelect.addEventListener('change', (e) => {
642
- const ingredientName = e.target.value;
643
- if (ingredientName) {
644
- addIngredientToItem(ingredientName, index);
645
- e.target.value = '';
646
- }
647
- });
648
- contentDiv.appendChild(ingredientSelect);
649
 
650
  // Ingredientsinfo Input
651
  const ingredientInfoInput = document.createElement('input');
@@ -766,18 +776,28 @@
766
  }
767
  }
768
 
769
- function addIngredientToItem(ingredientName, itemIndex) {
770
- if (!selectedItems[itemIndex].additionalIngredients) {
771
- selectedItems[itemIndex].additionalIngredients = [];
772
- }
773
- if (!selectedItems[itemIndex].additionalIngredients.includes(ingredientName)) {
774
- selectedItems[itemIndex].additionalIngredients.push(ingredientName);
775
- selectedItems[itemIndex].description += `, with ${ingredientName}`;
776
- addMessage('bot', `Added "${ingredientName}" to "${selectedItems[itemIndex].name}"!`);
777
- } else {
778
- addMessage('bot', `"${ingredientName}" already added to "${selectedItems[itemIndex].name}"!`);
779
- }
780
- updateSelectionBox();
 
 
 
 
 
 
 
 
 
 
781
  }
782
 
783
  function displayItemsList(items) {
 
252
  margin-right: 8px;
253
  }
254
 
255
+ .ingredient-info-input {
256
  padding: 8px;
257
  border: 1px solid #b3d7ff;
258
  border-radius: 6px;
 
262
  margin: 5px;
263
  }
264
 
265
+ .ingredient-button {
266
+ padding: 8px 12px;
267
+ background-color: #6c757d;
268
+ color: #ffffff;
269
+ border: none;
270
+ border-radius: 6px;
271
+ cursor: pointer;
272
+ font-size: 13px;
273
+ margin: 5px;
274
+ }
275
+
276
+ .ingredient-button:hover {
277
+ background-color: #5a6268;
278
+ }
279
+
280
  .submit-button {
281
  padding: 10px 20px;
282
  background-color: #0078d4;
 
437
  padding: 4px 8px;
438
  }
439
 
440
+ .ingredient-info-input, .ingredient-button {
441
  width: 120px;
442
  font-size: 12px;
443
  }
 
640
  itemSpan.textContent = `${itemName} (Qty: ${item.quantity || 1})`;
641
  contentDiv.appendChild(itemSpan);
642
 
643
+ // Ingredient Buttons
644
+ const ingredientButtonsDiv = document.createElement('div');
645
+ ingredientButtonsDiv.style.display = 'flex';
646
+ ingredientButtonsDiv.style.flexWrap = 'wrap';
647
+ ingredientButtonsDiv.style.gap = '5px';
 
 
648
  sectorIngredients.forEach(ingredient => {
649
+ const ingredientButton = document.createElement('button');
650
+ ingredientButton.textContent = ingredient.name;
651
+ ingredientButton.className = 'ingredient-button';
652
+ ingredientButton.onclick = () => {
653
+ addMessage('bot', `Finding dishes with "${ingredient.name}"...`);
654
+ fetchRelatedMenuItems(ingredient.name);
655
+ };
656
+ ingredientButtonsDiv.appendChild(ingredientButton);
657
  });
658
+ contentDiv.appendChild(ingredientButtonsDiv);
 
 
 
 
 
 
 
659
 
660
  // Ingredientsinfo Input
661
  const ingredientInfoInput = document.createElement('input');
 
776
  }
777
  }
778
 
779
+ function fetchRelatedMenuItems(ingredientName) {
780
+ fetch('/get_related_menu_items', {
781
+ method: 'POST',
782
+ headers: { 'Content-Type': 'application/json' },
783
+ body: JSON.stringify({ ingredient_name: ingredientName, dietary_preference: selectedPreference })
784
+ })
785
+ .then(response => response.json())
786
+ .then(data => {
787
+ if (data.error) {
788
+ addMessage('bot', `Error: ${data.error}. Try another ingredient!`);
789
+ } else if (data.menu_items.length > 0) {
790
+ addMessage('bot', `--- Found ${data.menu_items.length} dish${data.menu_items.length > 1 ? 'es' : ''} with "${ingredientName}" ---`);
791
+ displayItemsList(data.menu_items);
792
+ } else {
793
+ addMessage('bot', `No dishes found with "${ingredientName}". Try another!`);
794
+ }
795
+ console.log(`Fetched related items for ${ingredientName}:`, data.menu_items);
796
+ })
797
+ .catch(error => {
798
+ addMessage('bot', `Connection issue: ${error.message}. Retrying...`);
799
+ setTimeout(() => fetchRelatedMenuItems(ingredientName), 2000);
800
+ });
801
  }
802
 
803
  function displayItemsList(items) {