diff --git a/client/ListItems/listItemsTbl.html b/client/ListItems/listItemsTbl.html
index de728f8..cd2d486 100644
--- a/client/ListItems/listItemsTbl.html
+++ b/client/ListItems/listItemsTbl.html
@@ -11,7 +11,7 @@
{{itemName}}
{{/if}}
- delete
+ delete
check
{{/each}}
diff --git a/client/ListItems/listItemsTbl.js b/client/ListItems/listItemsTbl.js
index ee70b7c..4cc47a1 100644
--- a/client/ListItems/listItemsTbl.js
+++ b/client/ListItems/listItemsTbl.js
@@ -1,4 +1,5 @@
import { ListItems } from '../../imports/api/listItems.js';
+import { M } from '../lib/assets/materialize.js';
Template.listItemsTbl.onCreated(function() {
this.autorun( () => {
@@ -7,8 +8,9 @@ Template.listItemsTbl.onCreated(function() {
});
Template.listItemsTbl.onRendered(function() {
- // new modal init here
- // $('.modal').modal();
+ var elems = document.querySelectorAll('.modal');
+ var instances = M.Modal.init(elems, {});
+
Session.set("showReceivedItems", false);
Session.set("searchVal", "");
});
diff --git a/client/MenuItems/addProdToListModal.html b/client/MenuItems/addProdToListModal.html
new file mode 100644
index 0000000..c5b7029
--- /dev/null
+++ b/client/MenuItems/addProdToListModal.html
@@ -0,0 +1,47 @@
+
+
+ {{> snackbar}}
+
\ No newline at end of file
diff --git a/client/MenuItems/addProdToListModal.js b/client/MenuItems/addProdToListModal.js
new file mode 100644
index 0000000..1b58f17
--- /dev/null
+++ b/client/MenuItems/addProdToListModal.js
@@ -0,0 +1,64 @@
+import { M } from '../lib/assets/materialize.js';
+import { MenuProdLinks } from '../../imports/api/menuProdLinks';
+import { Products } from '../../imports/api/products.js';
+import { Lists } from '../../imports/api/lists.js';
+import { ListItems } from '../../imports/api/listItems';
+
+Template.addProdToListModal.onCreated(function() {
+ this.subscribe("myProducts");
+ this.subscribe("myLists");
+ this.subscribe("myListItems");
+ this.subscribe("menuProdLinkData");
+});
+
+Template.addProdToListModal.onRendered(function() {
+ var elems = document.querySelectorAll('select');
+ var instances = M.FormSelect.init(elems, {});
+
+ Session.set("itemsSelected", []);
+});
+
+Template.addProdToListModal.helpers({
+ assocProds: function() {
+ let menuItemId = Session.get("menuItemId");
+ let assocProds = MenuProdLinks.find({ menuItemId: menuItemId });
+ if (typeof assocProds != 'undefined' && assocProds != '' && assocProds != null) {
+ return assocProds;
+ }
+ },
+ setOfLists: function() {
+ return Lists.find({});
+ },
+ productToChoose: function() {
+ let prodLinkLIst = MenuProdLinks.find({ menuId: Session.get("menuItemId")});
+ if (typeof prodLinkLIst != 'undefined' && prodLinkLIst != "" && prodLinkLIst != null) {
+ return prodLinkLIst;
+ }
+ },
+});
+
+Template.addProdToListModal.events({
+ 'click .productListing' (event) {
+ let itemId = event.currentTarget.id;
+ let selected = Session.get("itemsSelected");
+ console.log("Item clicked: " + itemId);
+ selected.push(itemId);
+ console.dir(selected);
+ Session.set("itemsSelected", selected);
+ },
+ 'click #saveProdsToList' (event) {
+ event.preventDefault();
+ let selectedItems = Session.get("itemsSelected");
+ let listId = $("#chooseList").val();
+ // console.log(" calling meteor method with items: ");
+ // console.dir(selectedItems);
+ // console.log(" and list id: "+ listId);
+ Meteor.call('add.itemsFromMenuItem', selectedItems, listId, function(err, result) {
+ if (err) {
+ console.log(" ERROR adding menu components to list: " + err);
+ } else {
+ showSnackbar("Items Added to List!", "green");
+ }
+ });
+ }
+});
\ No newline at end of file
diff --git a/client/MenuItems/menuItemsTbl.html b/client/MenuItems/menuItemsTbl.html
index d3d6e5e..ee1da76 100644
--- a/client/MenuItems/menuItemsTbl.html
+++ b/client/MenuItems/menuItemsTbl.html
@@ -6,6 +6,7 @@
| Menu Item |
Date to Serve |
+ Has Product Links |
Actions |
@@ -23,6 +24,9 @@
{{serveDate}}
|
+
+ {{#if $eq isLinked true}}+ Shopping List{{/if}}
+ |
link
@@ -36,4 +40,5 @@
{{> deleteConfirmationModal}}
{{> modalLinkProducts}}
+ {{> addProdToListModal}}
\ No newline at end of file
diff --git a/client/MenuItems/menuItemsTbl.js b/client/MenuItems/menuItemsTbl.js
index b96791c..2347b7f 100644
--- a/client/MenuItems/menuItemsTbl.js
+++ b/client/MenuItems/menuItemsTbl.js
@@ -37,5 +37,9 @@ Template.menuItemsTbl.events({
'click .linkToProducts' (event) {
event.preventDefault();
Session.set("menuItemId", this._id);
+ },
+ 'click .addProdsToList' (event) {
+ event.preventDefault();
+ Session.set("menuItemId", this._id);
}
});
\ No newline at end of file
diff --git a/client/MenuItems/modalLinkProducts.js b/client/MenuItems/modalLinkProducts.js
index 3599091..a367e55 100644
--- a/client/MenuItems/modalLinkProducts.js
+++ b/client/MenuItems/modalLinkProducts.js
@@ -43,7 +43,13 @@ Template.modalLinkProducts.events({
if (err) {
console.log(" ERROR adding product links to this menu item: " + err);
} else {
- showSnackbar("Products added to Menu Item successfully!", "green");
+ Meteor.call('update.menuItemLinked', menuItemId, true, function(err, result) {
+ if (err) {
+ console.log(" ERROR adding link exists to menu item: " + err);
+ } else {
+ showSnackbar("Products added to Menu Item successfully!", "green");
+ }
+ });
}
});
}
diff --git a/client/main.css b/client/main.css
index 84f632d..4eed2dc 100644
--- a/client/main.css
+++ b/client/main.css
@@ -24,4 +24,8 @@ li.collection-item:active {
strike {
text-decoration-thickness: 3px;
text-decoration-color: red;
+}
+
+.my-text {
+ font-size: 1.3em !important;
}
\ No newline at end of file
diff --git a/imports/api/listItems.js b/imports/api/listItems.js
index 3eac732..e83b9f3 100644
--- a/imports/api/listItems.js
+++ b/imports/api/listItems.js
@@ -54,9 +54,39 @@ Meteor.methods({
dateAddedToList: new Date(),
});
}
+ },
+ 'add.itemsFromMenuItem' (itemIds, listId) {
+ check(itemIds, [String]);
+ check(listId, String);
+ if (!this.userId) {
+ throw new Meteor.Error('You are not allowed to add items from a menu. Make sure you are logged in with valid user credentials.');
+ }
-
+ console.dir(itemIds);
+
+ for (i=0; i < itemIds.length; i++) {
+ // let's check and make sure the product isn't already on the list
+ let onList = ListItems.find({ listId: listId, prodId: itemIds[i] }).count();
+ console.log("Number On List: " + onList);
+ if (onList == 0) {
+ // now pull the product
+ let prodInfo = Products.findOne({ _id: itemIds[i] });
+ ListItems.insert({
+ itemName: prodInfo.prodName,
+ listId: listId,
+ prodId: prodInfo._id,
+ addedBy: this.userId,
+ itemStore: prodInfo.prodStore,
+ itemOrdered: false,
+ itemReceived: false,
+ dateAddedToList: new Date(),
+ });
+ } else {
+ // product exists on list, move on to next
+ console.log("Product Exists on Selected List.");
+ }
+ }
},
'setOrdered.listItem' (itemId) {
check(itemId, String);
diff --git a/imports/api/menuItems.js b/imports/api/menuItems.js
index 7a5209d..e0b0851 100644
--- a/imports/api/menuItems.js
+++ b/imports/api/menuItems.js
@@ -31,6 +31,21 @@ Meteor.methods({
addedBy: this.userId,
itemMade: false,
dateAddedtoMenu: new Date(),
+ isLinked: false,
+ });
+ },
+ 'update.menuItemLinked' (itemId, isLinked) {
+ check(itemId, String);
+ check(isLinked, Boolean);
+
+ if (!this.userId) {
+ throw new Meteor.Error('You are not allowed to set this menu item as linked to products. Make sure you are logged in with valid user credentials.');
+ }
+
+ return MenuItems.update({ _id: itemId }, {
+ $set: {
+ isLinked: isLinked,
+ }
});
},
'setMade.menuItem' (itemId) {
diff --git a/server/main.js b/server/main.js
index 3cc4490..524eb75 100644
--- a/server/main.js
+++ b/server/main.js
@@ -1,5 +1,6 @@
import { Meteor } from 'meteor/meteor';
import { SysConfig } from '../imports/api/systemConfig';
+import { MenuItems } from '../imports/api/menuItems';
Meteor.startup(() => {
// code to run on server at startup
@@ -18,4 +19,24 @@ Meteor.startup(() => {
} else {
console.log("Registration policy already set.");
}
+
+ // 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,
+ }
+ });
+ }
+ } else {
+ // this will show if all items are found to have isLInked set.
+ console.log("No itesm with isLinked not set.");
+ }
+
});
|