diff --git a/client/ListItems/listItemsForm.html b/client/ListItems/listItemsForm.html index 1e71cb4..05e8f33 100644 --- a/client/ListItems/listItemsForm.html +++ b/client/ListItems/listItemsForm.html @@ -37,7 +37,7 @@ {{else}}
-
+
@@ -46,4 +46,4 @@
{{/if}} - \ No newline at end of file + diff --git a/client/ListItems/listItemsForm.js b/client/ListItems/listItemsForm.js index 678fe85..ff1b481 100644 --- a/client/ListItems/listItemsForm.js +++ b/client/ListItems/listItemsForm.js @@ -117,11 +117,12 @@ Template.listItemsForm.events({ } }, 'click #filterOn' (event) { - event.preventDefault(); Session.set("filtering", true); }, 'click #filterOff' (event) { - event.preventDefault(); + // clear filter field + Session.set("searchVal", ""); + $("#searchListItems").val(""); Session.set("filtering", false); } }); @@ -130,4 +131,4 @@ getDataList = function(listItemInfo) { let listItemObjArray = []; listItemObjArray = listItemInfo.map(info => ({ id: info._id, text: info.prodName, store: info.prodStore })) Session.set("findListItems", listItemObjArray); -} \ No newline at end of file +} diff --git a/client/MenuItems/menuItemsForm.js b/client/MenuItems/menuItemsForm.js index 9fdb96e..c22f5c9 100644 --- a/client/MenuItems/menuItemsForm.js +++ b/client/MenuItems/menuItemsForm.js @@ -114,7 +114,7 @@ Template.menuItemsForm.events({ if (err) { console.log(" ERROR shifting meal days: " + err); } else { - // console.log(" SUCCESS shifting meal date."); + showSnackbar("Items Shifted Out by 1 Calendar Day", "green"); } }); } diff --git a/client/MenuItems/menuitemsForm.html b/client/MenuItems/menuitemsForm.html index 0650769..9ec9b46 100644 --- a/client/MenuItems/menuitemsForm.html +++ b/client/MenuItems/menuitemsForm.html @@ -20,4 +20,5 @@ + {{> snackbar}} diff --git a/server/main.js b/server/main.js index 76c1c6a..c82781f 100644 --- a/server/main.js +++ b/server/main.js @@ -2,6 +2,8 @@ import { Meteor } from 'meteor/meteor'; import { SysConfig } from '../imports/api/systemConfig'; import { MenuItems } from '../imports/api/menuItems'; import { Products } from '../imports/api/products.js'; +import { Menus } from '../imports/api/menu.js'; +import { MScripts } from '../imports/api/mScripts.js'; Meteor.startup(() => { // code to run on server at startup @@ -10,60 +12,135 @@ Meteor.startup(() => { Roles.createRole("systemadmin", {unlessExists: true}); // set the systemconfig defaults for registration - let regPolicy = SysConfig.findOne({}); - if (typeof regPolicy == 'undefined') { - return SysConfig.insert({ - SysAdminReg: false, - dateAdded: new Date(), - allowReg: true, - }); - } else { - // console.log("Registration policy already set."); + // check if this has already been run + let regPolRun = MScripts.findOne({ scriptName: "DefaultRegPolicy", scriptRun: true }); + if (typeof regPolRun == "undefined" || regPolRun == null || regPolRun == "") { + let regPolicy = SysConfig.findOne({}); + if (typeof regPolicy == 'undefined') { + return SysConfig.insert({ + SysAdminReg: false, + dateAdded: new Date(), + allowReg: true, + }); + } else { + // console.log("Registration policy already set."); + markScriptRun("DefaultRegPolicy"); + } } + // check if the isLInked item exists on menuitems, and if not, add it (data cleanup task) - let itemInfoNoLink = MenuItems.find({ isLinked: { $exists: false } }).fetch(); - // console.log("No Ites with isLinked not set: " + itemInfoNoLink.length); - if (itemInfoNoLink.length > 0) { - // console.log("found items with isLinked not set."); - // console.dir(itemInfoNoLink); - let infoLength = itemInfoNoLink.length; - for (i=0; i < infoLength; i++) { - MenuItems.update({ _id: itemInfoNoLink[i]._id }, { - $set: { - isLinked: false, + // see if already updated + let linkUpdateRun = MScripts.findOne({ scriptName: "updateMenuItemLinks", scriptRun: true }); + if (typeof linkUpdateRun == 'undefined' || linkUpdateRun == null || linkUpdateRun == "") { + let itemInfoNoLink = MenuItems.find({ isLinked: { $exists: false } }).fetch(); + // console.log("No Ites with isLinked not set: " + itemInfoNoLink.length); + if (itemInfoNoLink.length > 0) { + // console.log("found items with isLinked not set."); + // console.dir(itemInfoNoLink); + let infoLength = itemInfoNoLink.length; + for (i=0; i < infoLength; i++) { + MenuItems.update({ _id: itemInfoNoLink[i]._id }, { + $set: { + isLinked: false, + } + }); + if (i == (infoLength -1)) { + markScriptRun("updateMenuItemLinks"); } - }); + } + } else { + // this will show if all items are found to have isLInked set. + // console.log("No items with isLinked not set."); + markScriptRun("updateMenuItemLinks"); } - } else { - // this will show if all items are found to have isLInked set. - console.log("No itesm with isLinked not set."); } + // update Products to be able to have multiple stores in the document - let prodInfo = Products.find({}).fetch(); - let prodCount = prodInfo.length; - console.log("Updating Products to allow multiple store assocation for " + prodCount + " products."); - for (j = 0; j < prodCount; j++) { - if (typeof prodInfo[j].prodStore == 'object') { - // console.log(typeof prodInfo[j].prodStore); - // console.log("Is Array already"); - } else { - let prodStoreArray = []; - // console.log("---- ---- ----"); - // console.log(typeof prodInfo[j].prodStore); - // console.log("---- Is Not Array."); - let prodStore = prodInfo[j].prodStore; + // check if update already run + let prodStoreArrayRun = MScripts.findOne({ scriptName: "changeProdStoreToArray", scriptRun: true }); + if (!prodStoreArrayRun) { + let prodInfo = Products.find({}).fetch(); + let prodCount = prodInfo.length; + console.log("Updating Products to allow multiple store assocation for " + prodCount + " products."); + for (j = 0; j < prodCount; j++) { + if (typeof prodInfo[j].prodStore == 'object') { + // console.log(typeof prodInfo[j].prodStore); + // console.log("Is Array already"); + } else { + let prodStoreArray = []; + // console.log("---- ---- ----"); + // console.log(typeof prodInfo[j].prodStore); + // console.log("---- Is Not Array."); + let prodStore = prodInfo[j].prodStore; - prodStoreArray.push(prodStore); - // console.dir(prodStoreArray); - Products.update({ _id: prodInfo[j]._id }, { - $set: { - prodStore: prodStoreArray, - } - }); + prodStoreArray.push(prodStore); + // console.dir(prodStoreArray); + Products.update({ _id: prodInfo[j]._id }, { + $set: { + prodStore: prodStoreArray, + } + }); + } + if (j == (prodCount -1)) { + markScriptRun("changeProdStoreToArray"); + } } } + // update menu items to new format so they get the linked products + // check if this update has run + let menuItemUpdRun = MScripts.findOne({ scriptName: "updateMenuProdLinks", scriptRun: true }); + if (!menuItemUpdRun) { + let openMenus = Menus.find({ menuComplete: false }).fetch(); + let openMenuCount = openMenus.length; + // console.log("Open Menu count is: " + openMenuCount); + for (k = 0; k < openMenuCount; k++) { + if (typeof openMenus.menuItems == 'object') { + // console.log(openMenus.menuName + " appears to be converted."); + markScriptRun("updateMenuProdLinks"); + } else { + let menuId = openMenus[k]._id; + + let thisMenuItems = MenuItems.find({ menuId: menuId }).fetch(); + + let itemCount = thisMenuItems.length; + + for (l = 0; l < itemCount; l++) { + Menus.update({ _id: menuId }, { + $addToSet: { + menuItems: + { + menuItemId: thisMenuItems[l]._id, + menuItemName: thisMenuItems[l].itemName, + serveDate: thisMenuItems[l].serveDate, + serveDateActual: thisMenuItems[l].serveDateActual, + isLinked: thisMenuItems[l].isLinked + }, + } + }); + } + } + if (k == (openMenuCount - 1)) { + markScriptRun("updateMenuProdLinks"); + } + } + } }); + +var markScriptRun = function(scriptName) { + // check if this is already set + let scriptRun = MScripts.findOne({ scriptName: scriptName }); + + if (scriptRun) { + console.log(scriptName + " already set as run on " + scriptRun.runOn); + } else { + MScripts.insert({ + scriptName: scriptName, + scriptRun: true, + runOn: new Date() + }); + } +}