From 9abb198e824c475655a44f90eb3123c0d461447f Mon Sep 17 00:00:00 2001 From: Brian McGonagill Date: Sun, 28 Jul 2024 19:42:23 -0500 Subject: [PATCH] dev work on menu to prod link --- client/AdminMgmt/Tasks/taskForm.js | 4 ++ client/MenuItems/menuItemsTbl.html | 15 +++++++- client/MenuItems/menuItemsTbl.js | 12 ++++++ client/MenuItems/modalLinkProducts.html | 29 ++++++++++++++ client/MenuItems/modalLinkProducts.js | 51 +++++++++++++++++++++++++ imports/api/menuProdLinks.js | 44 +++++++++++++++++++++ server/publish.js | 11 +++++- 7 files changed, 163 insertions(+), 3 deletions(-) create mode 100644 client/MenuItems/modalLinkProducts.html create mode 100644 client/MenuItems/modalLinkProducts.js create mode 100644 imports/api/menuProdLinks.js diff --git a/client/AdminMgmt/Tasks/taskForm.js b/client/AdminMgmt/Tasks/taskForm.js index 28fad17..c445eac 100644 --- a/client/AdminMgmt/Tasks/taskForm.js +++ b/client/AdminMgmt/Tasks/taskForm.js @@ -18,6 +18,10 @@ Template.taskForm.onRendered(function() { placeholder: 'Task Name', secondaryPlaceholder: '+Task Name', }); + + setTimeout(function() { + instances = M.FormSelect.init(elems, {}); + }, 350); Session.set("taskNameErr", false); Session.set("taskUserErr", false); diff --git a/client/MenuItems/menuItemsTbl.html b/client/MenuItems/menuItemsTbl.html index 9e671fa..d3d6e5e 100644 --- a/client/MenuItems/menuItemsTbl.html +++ b/client/MenuItems/menuItemsTbl.html @@ -2,8 +2,15 @@
+ + + + + + + {{#each thisMenuItems}} - + {{/each}}
Menu ItemDate to ServeActions
{{#if $eq itemMade true}} @@ -17,12 +24,16 @@ {{serveDate}} - delete + delete + link
+ +
{{> deleteConfirmationModal}} + {{> modalLinkProducts}} \ No newline at end of file diff --git a/client/MenuItems/menuItemsTbl.js b/client/MenuItems/menuItemsTbl.js index b859532..761ceb9 100644 --- a/client/MenuItems/menuItemsTbl.js +++ b/client/MenuItems/menuItemsTbl.js @@ -10,6 +10,14 @@ Template.menuItemsTbl.onCreated(function() { Template.menuItemsTbl.onRendered(function() { var elems = document.querySelectorAll('.modal'); var instances = M.Modal.init(elems, {}); + + var elemt = document.querySelectorAll('.tooltipped'); + var instancet = M.Tooltip.init(elemt, {}); + + Meteor.setTimeout(function() { + var instances = M.Modal.init(elems, {}); + var instancet = M.Tooltip.init(elemt, {}); + }, 500); }); Template.menuItemsTbl.helpers({ @@ -26,4 +34,8 @@ Template.menuItemsTbl.events({ Session.set("item", this.itemName); Session.set("view", "Menu Items"); }, + 'click .linkToProducts' (event) { + event.preventDefault(); + Session.set("menuItemId", this._id); + } }); \ No newline at end of file diff --git a/client/MenuItems/modalLinkProducts.html b/client/MenuItems/modalLinkProducts.html new file mode 100644 index 0000000..ec47b68 --- /dev/null +++ b/client/MenuItems/modalLinkProducts.html @@ -0,0 +1,29 @@ + \ No newline at end of file diff --git a/client/MenuItems/modalLinkProducts.js b/client/MenuItems/modalLinkProducts.js new file mode 100644 index 0000000..3599091 --- /dev/null +++ b/client/MenuItems/modalLinkProducts.js @@ -0,0 +1,51 @@ +import { M } from '../lib/assets/materialize.js'; +import { Products } from '../../imports/api/products.js'; +import { MenuItems } from '../../imports/api/menuItems'; +import { MenuProdLinks } from '../../imports/api/menuProdLinks.js'; + +Template.modalLinkProducts.onCreated(function() { + this.subscribe("myMenuItems"); + this.subscribe("myProducts"); + this.subscribe("menuProdLinkData"); +}); + +Template.modalLinkProducts.onRendered(function() { + var elems = document.querySelectorAll('.modal'); + var instances = M.Modal.init(elems, {}); + + var elemse = document.querySelectorAll('select'); + var instancese = M.FormSelect.init(elemse, { + dropdownOptions: 4, + }); + + setTimeout(function() { + var instances = M.Modal.init(elems, {}); + var instancese = M.FormSelect.init(elemse, { + dropdownOptions: 4, + }); + }, 250); +}); + +Template.modalLinkProducts.helpers({ + products: function() { + return Products.find({}); + } +}); + +Template.modalLinkProducts.events({ + 'click #saveLink' (event) { + event.preventDefault(); + let menuItemId = Session.get("menuItemId"); + let linkSelect = document.getElementById('prodForMenu'); + let links = M.FormSelect.getInstance(linkSelect).getSelectedValues(); + if (typeof links != undefined && links != [] && links != null) { + Meteor.call("add.menuProdLinks", menuItemId, links, function(err, result) { + if (err) { + console.log(" ERROR adding product links to this menu item: " + err); + } else { + showSnackbar("Products added to Menu Item successfully!", "green"); + } + }); + } + } +}); \ No newline at end of file diff --git a/imports/api/menuProdLinks.js b/imports/api/menuProdLinks.js new file mode 100644 index 0000000..18d833f --- /dev/null +++ b/imports/api/menuProdLinks.js @@ -0,0 +1,44 @@ +import { Meteor } from 'meteor/meteor'; +import { Mongo } from 'meteor/mongo'; +import { check } from 'meteor/check'; +import { Products } from './products'; + +export const MenuProdLinks = new Mongo.Collection('menuProdLinks'); + +MenuProdLinks.allow({ + insert: function(userId, doc){ + // if use id exists, allow insert + return !!userId; + }, +}); + +Meteor.methods({ + 'add.menuProdLinks' (menuItemId, prodNameArray) { + check(menuItemId, String); + check(prodNameArray, [String]); + + if (!this.userId) { + throw new Meteor.Error('You are not allowed to add menu and product links. Make sure you are logged in with valid user credentials.'); + } + + let productObj = {}; + + let prodNameLength = prodNameArray.length; + + for (i=0; i