Updated menus to work better with list item linking

Lots of changes made (almost a refactor <--- four letter word to me...
- Menu Items collection is now the "permanent" storage location for menu item for any day.  So, if i set Green Chile Chicken Enchiladas, Beans, and Rice as an item for a day, it will be stored as a Menu Item for later use.
- Linking menu items to items that can be added to a shopping list - This has been updated to be more reusable. So as you re-choose a menu item that's already got list items linked, it just shows up for you to use to build a shopping list as needed.
- Deleting menu items from a menu - changed to delete them only from the menu, and not from the database.
- Dashboard updated to pull today's menu item from the menu, and not the menu item list.
This commit is contained in:
Brian McGonagill 2024-08-14 11:38:13 -05:00
parent 3f6618d906
commit 88fa7c1d22
13 changed files with 216 additions and 149 deletions

View file

@ -17,6 +17,9 @@ Template.menuItemsForm.onRendered(function() {
Session.set("menuItemErr", false);
Session.set("menuListItems", {});
var elemt = document.querySelectorAll('.tooltipped');
var instancet = M.Tooltip.init(elemt, {});
this.autorun(() => {
var elema = document.querySelectorAll('.autocomplete');
var instancea = M.Autocomplete.init(elema, {
@ -52,18 +55,50 @@ Template.menuItemsForm.events({
let dateSrv = $("#dateServed").val();
let menuId = Session.get("menuId");
if (menuItem == null || menuItem == "") {
Session.set("menuItemErr", true);
let menuItemExists = MenuItems.findOne({ itemName: menuItem });
if (typeof menuItemExists != 'undefined' && menuItemExists != null && menuItemExists != "") {
// use the existing item on the menu
let menuItemId = menuItemExists._id;
let isLinked = menuItemExists.isLinked;
if (menuItem == null || menuItem == "") {
Session.set("menuItemErr", true);
} else {
Meteor.call('addto.Menu', menuId, menuItem, menuItemId, dateSrv, isLinked, function(error, nresult) {
if (error) {
console.log(" ERROR adding menuitem to menu: " + error);
} else {
// console.log("Added item to menu - no problem.");
$("#menuItemInp").val("");
$("#dateServed").val("");
}
});
}
} else {
Meteor.call('add.menuItem', menuItem, dateSrv, menuId, function(err, result) {
if (err) {
console.log(" ERROR adding menu item: " + err);
} else {
console.log(" SUCCESS adding menu item.");
$("#menuItemInp").val("");
$("#dateServed").val("");
}
});
// add the item as new and add to the menu
if (menuItem == null || menuItem == "") {
Session.set("menuItemErr", true);
} else {
Meteor.call('add.menuItem', menuItem, function(err, result) {
if (err) {
console.log(" ERROR adding menu item: " + err);
} else {
// console.log(" SUCCESS adding menu item.");
$("#menuItemInp").val("");
$("#dateServed").val("");
// now add this item to the menu
Meteor.call('addto.Menu', menuId, menuItem, result, dateSrv, function(error, nresult) {
if (error) {
console.log(" ERROR adding menuitem to menu: " + error);
} else {
// console.log("Added item to menu - no problem.");
}
});
}
});
}
}
},
'click .shiftOneDay' (event) {
@ -77,7 +112,7 @@ Template.menuItemsForm.events({
// console.log(momentAddDay);
Meteor.call('shiftDate', menuItemId, momentAddDay, function(err,result) {
if (err) {
// console.log(" ERROR shifting meal days: " + err);
console.log(" ERROR shifting meal days: " + err);
} else {
// console.log(" SUCCESS shifting meal date.");
}
@ -99,4 +134,4 @@ getMenuItemList = function(menuItemInfo) {
let menuItemObjArray = [];
menuItemObjArray = menuItemInfo.map(info => ({ id: info._id, text: info.itemName }));
Session.set("menuListItems", menuItemObjArray);
}
}