mirror of
https://gitlab.com/bmcgonag/get_my.git
synced 2026-03-27 08:18:50 +00:00
Add list items from linked menu items
This commit is contained in:
parent
91150f03b2
commit
00a99e0393
11 changed files with 203 additions and 5 deletions
|
|
@ -11,7 +11,7 @@
|
||||||
{{itemName}}
|
{{itemName}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</span>
|
</span>
|
||||||
<i class="material-icons clickable deleteListItem right">delete</i>
|
<i class="material-icons clickable deleteListItem right modal-trigger" href="#modalDelete">delete</i>
|
||||||
<i class="material-icons clickable markListItemReceived right">check</i>
|
<i class="material-icons clickable markListItemReceived right">check</i>
|
||||||
</li>
|
</li>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { ListItems } from '../../imports/api/listItems.js';
|
import { ListItems } from '../../imports/api/listItems.js';
|
||||||
|
import { M } from '../lib/assets/materialize.js';
|
||||||
|
|
||||||
Template.listItemsTbl.onCreated(function() {
|
Template.listItemsTbl.onCreated(function() {
|
||||||
this.autorun( () => {
|
this.autorun( () => {
|
||||||
|
|
@ -7,8 +8,9 @@ Template.listItemsTbl.onCreated(function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
Template.listItemsTbl.onRendered(function() {
|
Template.listItemsTbl.onRendered(function() {
|
||||||
// new modal init here
|
var elems = document.querySelectorAll('.modal');
|
||||||
// $('.modal').modal();
|
var instances = M.Modal.init(elems, {});
|
||||||
|
|
||||||
Session.set("showReceivedItems", false);
|
Session.set("showReceivedItems", false);
|
||||||
Session.set("searchVal", "");
|
Session.set("searchVal", "");
|
||||||
});
|
});
|
||||||
|
|
|
||||||
47
client/MenuItems/addProdToListModal.html
Normal file
47
client/MenuItems/addProdToListModal.html
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
<template name="addProdToListModal">
|
||||||
|
<div class="modal" id="addProdToList">
|
||||||
|
<div class="modal-content">
|
||||||
|
<h2>Add Items to List</h2>
|
||||||
|
<form class="row" style="gap: 1em;">
|
||||||
|
<div class="col s12 input-field outlined" id="chooseListDiv">
|
||||||
|
<select name="chooseList" id="chooseList">
|
||||||
|
{{#each setOfLists}}
|
||||||
|
<option value="{{_id}}">{{listName}}</option>
|
||||||
|
{{/each}}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col s12">
|
||||||
|
<ul class="collection with-header">
|
||||||
|
<li class="collection-header">
|
||||||
|
<h4>Products to Add</h4>
|
||||||
|
</li>
|
||||||
|
{{#each productToChoose}}
|
||||||
|
<li class="collection-item" id="{{prodId}}">
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" class="productListing" id="{{prodId}}" />
|
||||||
|
<span class="my-text">{{prodName}}</span>
|
||||||
|
</label>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
{{/each}}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col s12 m6 l6">
|
||||||
|
<a class="left btn waves-effect waves-light orange white-text modal-close">Cancel</a>
|
||||||
|
</div>
|
||||||
|
<div class="col s12 m6 l6">
|
||||||
|
<a class="btn waves-effect waves-light green white-text saveProdsToList" id="saveProdsToList">Save to List</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{> snackbar}}
|
||||||
|
</template>
|
||||||
64
client/MenuItems/addProdToListModal.js
Normal file
64
client/MenuItems/addProdToListModal.js
Normal file
|
|
@ -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");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th>Menu Item</th>
|
<th>Menu Item</th>
|
||||||
<th>Date to Serve</th>
|
<th>Date to Serve</th>
|
||||||
|
<th>Has Product Links</th>
|
||||||
<th>Actions</th>
|
<th>Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
@ -23,6 +24,9 @@
|
||||||
<td>
|
<td>
|
||||||
{{serveDate}}
|
{{serveDate}}
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
{{#if $eq isLinked true}}<a class="waves-effect waves-light blue darken-3 white-text btn addProdsToList modal-trigger" href="#addProdToList">+ Shopping List</a>{{/if}}
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<i class="material-icons tooltipped modal-trigger deleteMenuItem clickable" href="#modalDelete" data-position="top" data-tooltip-id="deleteMenuTip">delete</i>
|
<i class="material-icons tooltipped modal-trigger deleteMenuItem clickable" href="#modalDelete" data-position="top" data-tooltip-id="deleteMenuTip">delete</i>
|
||||||
<i class="material-icons tooltipped modal-trigger linkToProducts clickable" href="#modalLinkProducts" data-position="top" data-tooltip-id="linkMenuTip">link</i>
|
<i class="material-icons tooltipped modal-trigger linkToProducts clickable" href="#modalLinkProducts" data-position="top" data-tooltip-id="linkMenuTip">link</i>
|
||||||
|
|
@ -36,4 +40,5 @@
|
||||||
</div>
|
</div>
|
||||||
{{> deleteConfirmationModal}}
|
{{> deleteConfirmationModal}}
|
||||||
{{> modalLinkProducts}}
|
{{> modalLinkProducts}}
|
||||||
|
{{> addProdToListModal}}
|
||||||
</template>
|
</template>
|
||||||
|
|
@ -37,5 +37,9 @@ Template.menuItemsTbl.events({
|
||||||
'click .linkToProducts' (event) {
|
'click .linkToProducts' (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
Session.set("menuItemId", this._id);
|
Session.set("menuItemId", this._id);
|
||||||
|
},
|
||||||
|
'click .addProdsToList' (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
Session.set("menuItemId", this._id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -42,10 +42,16 @@ Template.modalLinkProducts.events({
|
||||||
Meteor.call("add.menuProdLinks", menuItemId, links, function(err, result) {
|
Meteor.call("add.menuProdLinks", menuItemId, links, function(err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(" ERROR adding product links to this menu item: " + err);
|
console.log(" ERROR adding product links to this menu item: " + err);
|
||||||
|
} else {
|
||||||
|
Meteor.call('update.menuItemLinked', menuItemId, true, function(err, result) {
|
||||||
|
if (err) {
|
||||||
|
console.log(" ERROR adding link exists to menu item: " + err);
|
||||||
} else {
|
} else {
|
||||||
showSnackbar("Products added to Menu Item successfully!", "green");
|
showSnackbar("Products added to Menu Item successfully!", "green");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -25,3 +25,7 @@ strike {
|
||||||
text-decoration-thickness: 3px;
|
text-decoration-thickness: 3px;
|
||||||
text-decoration-color: red;
|
text-decoration-color: red;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.my-text {
|
||||||
|
font-size: 1.3em !important;
|
||||||
|
}
|
||||||
|
|
@ -54,9 +54,39 @@ Meteor.methods({
|
||||||
dateAddedToList: new Date(),
|
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) {
|
'setOrdered.listItem' (itemId) {
|
||||||
check(itemId, String);
|
check(itemId, String);
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,21 @@ Meteor.methods({
|
||||||
addedBy: this.userId,
|
addedBy: this.userId,
|
||||||
itemMade: false,
|
itemMade: false,
|
||||||
dateAddedtoMenu: new Date(),
|
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) {
|
'setMade.menuItem' (itemId) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { Meteor } from 'meteor/meteor';
|
import { Meteor } from 'meteor/meteor';
|
||||||
import { SysConfig } from '../imports/api/systemConfig';
|
import { SysConfig } from '../imports/api/systemConfig';
|
||||||
|
import { MenuItems } from '../imports/api/menuItems';
|
||||||
|
|
||||||
Meteor.startup(() => {
|
Meteor.startup(() => {
|
||||||
// code to run on server at startup
|
// code to run on server at startup
|
||||||
|
|
@ -18,4 +19,24 @@ Meteor.startup(() => {
|
||||||
} else {
|
} else {
|
||||||
console.log("Registration policy already set.");
|
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.");
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue