lokesh341 commited on
Commit
83f1ed1
·
verified ·
1 Parent(s): edc8acc

Update templates/chef-bot.html

Browse files
Files changed (1) hide show
  1. templates/chef-bot.html +47 -11
templates/chef-bot.html CHANGED
@@ -502,8 +502,6 @@
502
  <div class="chat-messages" id="chatMessages">
503
  <div class="bot-message">Hello! I’m Chef Bot, your culinary assistant! What’s your name?</div>
504
  </div>
505
- <div class="suggestions-list" id="suggestionsList"></div>
506
- <div class="ingredients-list" id="menuItemsList"></div>
507
  <div class="chat-input">
508
  <input type="text" id="userInput" placeholder="Type here (e.g., paneer, chicken)...">
509
  <button onclick="sendMessage()">Send</button>
@@ -516,6 +514,7 @@
516
  ];
517
  let selectedItems = [];
518
  let selectionBoxVisible = false;
 
519
 
520
  function addMessage(role, message) {
521
  const chatMessages = document.getElementById('chatMessages');
@@ -555,7 +554,7 @@
555
  let botResponse = '';
556
 
557
  if (conversation.length === 2) {
558
- botResponse = `Hi ${userInput}! 🍳 Search for a dish or choose a preference below!`;
559
  displayOptions([
560
  { text: 'Vegetarian', class: 'green' },
561
  { text: 'Non-Vegetarian', class: 'red' },
@@ -563,13 +562,14 @@
563
  ]);
564
  addMessage('bot', botResponse);
565
  } else if (lowerInput === 'vegetarian' || lowerInput === 'non-vegetarian' || lowerInput === 'both') {
 
566
  botResponse = `Fetching ${lowerInput} dishes...`;
567
  addMessage('bot', botResponse);
568
  fetchMenuItems(lowerInput);
569
  } else {
570
  botResponse = `Looking for "${userInput}"...`;
571
  addMessage('bot', botResponse);
572
- fetchMenuItems(null, userInput);
573
  }
574
  }
575
 
@@ -648,7 +648,6 @@
648
  contentDiv.appendChild(showButton);
649
  }
650
 
651
- // Add ingredient input for customization
652
  const ingredientInput = document.createElement('input');
653
  ingredientInput.type = 'text';
654
  ingredientInput.placeholder = 'Add ingredient...';
@@ -676,7 +675,6 @@
676
 
677
  selectionBox.appendChild(itemContainer);
678
 
679
- // Display original item if customized
680
  if (item.additionalIngredients && item.additionalIngredients.length > 0) {
681
  const originalContainer = document.createElement('div');
682
  originalContainer.className = 'selected-item';
@@ -703,6 +701,19 @@
703
  originalContentDiv.appendChild(originalShowButton);
704
  }
705
 
 
 
 
 
 
 
 
 
 
 
 
 
 
706
  originalContainer.appendChild(originalContentDiv);
707
 
708
  const originalRemoveButton = document.createElement('button');
@@ -726,6 +737,8 @@
726
  textInput.addEventListener('keypress', (e) => {
727
  if (e.key === 'Enter' && textInput.value.trim()) {
728
  const itemName = textInput.value.trim();
 
 
729
  fetchSectorItemDetails(itemName);
730
  textInput.value = '';
731
  }
@@ -795,11 +808,19 @@
795
  .then(response => response.json())
796
  .then(data => {
797
  if (data.error) {
798
- addMessage('bot', `No "${itemName}" found. Try another!`);
799
  } else {
800
  const details = data.item_details;
 
 
 
 
 
 
 
 
 
801
  if (itemIndex !== null) {
802
- // Adding as an additional ingredient
803
  if (!selectedItems[itemIndex].additionalIngredients) {
804
  selectedItems[itemIndex].additionalIngredients = [];
805
  }
@@ -811,7 +832,6 @@
811
  addMessage('bot', `"${details.name}" already added to "${selectedItems[itemIndex].name}"!`);
812
  }
813
  } else {
814
- // Adding as a new item
815
  if (selectedItems.some(item => item.name === details.name && !item.additionalIngredients)) {
816
  addMessage('bot', `"${details.name}" already selected!`);
817
  } else {
@@ -852,10 +872,25 @@
852
  return;
853
  }
854
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
855
  const itemsGrid = document.createElement('div');
856
  itemsGrid.className = 'items-grid';
857
 
858
- items.forEach(item => {
859
  const itemDiv = document.createElement('div');
860
  itemDiv.className = 'item-card';
861
 
@@ -1020,9 +1055,10 @@
1020
  conversation = [
1021
  { role: 'bot', message: `Hello! I’m Chef Bot, your culinary assistant! What’s your name?` },
1022
  { role: 'user', message: userName },
1023
- { role: 'bot', message: `Hi ${userName}! 🍳 Search for a dish or choose a preference below!` }
1024
  ];
1025
  selectedItems = [];
 
1026
  selectionBoxVisible = true;
1027
  const chatMessages = document.getElementById('chatMessages');
1028
  chatMessages.innerHTML = '';
 
502
  <div class="chat-messages" id="chatMessages">
503
  <div class="bot-message">Hello! I’m Chef Bot, your culinary assistant! What’s your name?</div>
504
  </div>
 
 
505
  <div class="chat-input">
506
  <input type="text" id="userInput" placeholder="Type here (e.g., paneer, chicken)...">
507
  <button onclick="sendMessage()">Send</button>
 
514
  ];
515
  let selectedItems = [];
516
  let selectionBoxVisible = false;
517
+ let currentDietaryPreference = '';
518
 
519
  function addMessage(role, message) {
520
  const chatMessages = document.getElementById('chatMessages');
 
554
  let botResponse = '';
555
 
556
  if (conversation.length === 2) {
557
+ botResponse = `Hi ${userInput}! 🍳 Please choose a dietary preference: Vegetarian, Non-Vegetarian, or Both.`;
558
  displayOptions([
559
  { text: 'Vegetarian', class: 'green' },
560
  { text: 'Non-Vegetarian', class: 'red' },
 
562
  ]);
563
  addMessage('bot', botResponse);
564
  } else if (lowerInput === 'vegetarian' || lowerInput === 'non-vegetarian' || lowerInput === 'both') {
565
+ currentDietaryPreference = lowerInput;
566
  botResponse = `Fetching ${lowerInput} dishes...`;
567
  addMessage('bot', botResponse);
568
  fetchMenuItems(lowerInput);
569
  } else {
570
  botResponse = `Looking for "${userInput}"...`;
571
  addMessage('bot', botResponse);
572
+ fetchMenuItems(currentDietaryPreference, userInput);
573
  }
574
  }
575
 
 
648
  contentDiv.appendChild(showButton);
649
  }
650
 
 
651
  const ingredientInput = document.createElement('input');
652
  ingredientInput.type = 'text';
653
  ingredientInput.placeholder = 'Add ingredient...';
 
675
 
676
  selectionBox.appendChild(itemContainer);
677
 
 
678
  if (item.additionalIngredients && item.additionalIngredients.length > 0) {
679
  const originalContainer = document.createElement('div');
680
  originalContainer.className = 'selected-item';
 
701
  originalContentDiv.appendChild(originalShowButton);
702
  }
703
 
704
+ const originalIngredientInput = document.createElement('input');
705
+ originalIngredientInput.type = 'text';
706
+ originalIngredientInput.placeholder = 'Add ingredient...';
707
+ originalIngredientInput.className = 'ingredient-input';
708
+ originalIngredientInput.addEventListener('keypress', (e) => {
709
+ if (e.key === 'Enter' && originalIngredientInput.value.trim()) {
710
+ const ingredientName = originalIngredientInput.value.trim();
711
+ fetchSectorItemDetails(ingredientName, index);
712
+ originalIngredientInput.value = '';
713
+ }
714
+ });
715
+ originalContentDiv.appendChild(originalIngredientInput);
716
+
717
  originalContainer.appendChild(originalContentDiv);
718
 
719
  const originalRemoveButton = document.createElement('button');
 
737
  textInput.addEventListener('keypress', (e) => {
738
  if (e.key === 'Enter' && textInput.value.trim()) {
739
  const itemName = textInput.value.trim();
740
+ addMessage('user', itemName);
741
+ conversation.push({ role: 'user', message: itemName });
742
  fetchSectorItemDetails(itemName);
743
  textInput.value = '';
744
  }
 
808
  .then(response => response.json())
809
  .then(data => {
810
  if (data.error) {
811
+ addMessage('bot', `No "${itemName}" found in Sector_Detail__c. Try another!`);
812
  } else {
813
  const details = data.item_details;
814
+ // Validate dietary preference
815
+ if (currentDietaryPreference === 'vegetarian' && details.category !== 'Veg') {
816
+ addMessage('bot', `"${details.name}" is not vegetarian. Please choose a vegetarian item.`);
817
+ return;
818
+ }
819
+ if (currentDietaryPreference === 'non-vegetarian' && details.category !== 'Non-Veg') {
820
+ addMessage('bot', `"${details.name}" is not non-vegetarian. Please choose a non-vegetarian item.`);
821
+ return;
822
+ }
823
  if (itemIndex !== null) {
 
824
  if (!selectedItems[itemIndex].additionalIngredients) {
825
  selectedItems[itemIndex].additionalIngredients = [];
826
  }
 
832
  addMessage('bot', `"${details.name}" already added to "${selectedItems[itemIndex].name}"!`);
833
  }
834
  } else {
 
835
  if (selectedItems.some(item => item.name === details.name && !item.additionalIngredients)) {
836
  addMessage('bot', `"${details.name}" already selected!`);
837
  } else {
 
872
  return;
873
  }
874
 
875
+ // Filter items based on dietary preference
876
+ const filteredItems = items.filter(item => {
877
+ if (currentDietaryPreference === 'vegetarian') {
878
+ return item.veg_nonveg === 'Vegetarian' || item.category === 'Veg';
879
+ } else if (currentDietaryPreference === 'non-vegetarian') {
880
+ return item.veg_nonveg === 'Non-Vegetarian' || item.category === 'Non-Veg';
881
+ }
882
+ return true;
883
+ });
884
+
885
+ if (filteredItems.length === 0) {
886
+ addMessage('bot', `No ${currentDietaryPreference} items found. Try another search!`);
887
+ return;
888
+ }
889
+
890
  const itemsGrid = document.createElement('div');
891
  itemsGrid.className = 'items-grid';
892
 
893
+ filteredItems.forEach(item => {
894
  const itemDiv = document.createElement('div');
895
  itemDiv.className = 'item-card';
896
 
 
1055
  conversation = [
1056
  { role: 'bot', message: `Hello! I’m Chef Bot, your culinary assistant! What’s your name?` },
1057
  { role: 'user', message: userName },
1058
+ { role: 'bot', message: `Hi ${userName}! 🍳 Please choose a dietary preference: Vegetarian, Non-Vegetarian, or Both.` }
1059
  ];
1060
  selectedItems = [];
1061
+ currentDietaryPreference = '';
1062
  selectionBoxVisible = true;
1063
  const chatMessages = document.getElementById('chatMessages');
1064
  chatMessages.innerHTML = '';