dev work on menu to prod link

This commit is contained in:
Brian McGonagill 2024-07-28 19:42:23 -05:00
parent 01ae220674
commit 9abb198e82
7 changed files with 163 additions and 3 deletions

View file

@ -19,6 +19,10 @@ Template.taskForm.onRendered(function() {
secondaryPlaceholder: '+Task Name', secondaryPlaceholder: '+Task Name',
}); });
setTimeout(function() {
instances = M.FormSelect.init(elems, {});
}, 350);
Session.set("taskNameErr", false); Session.set("taskNameErr", false);
Session.set("taskUserErr", false); Session.set("taskUserErr", false);
Session.set("taskDateErr", false); Session.set("taskDateErr", false);

View file

@ -2,8 +2,15 @@
<div class="row"> <div class="row">
<div class="col s12"> <div class="col s12">
<table> <table>
<thead>
<tr>
<th>Menu Item</th>
<th>Date to Serve</th>
<th>Actions</th>
</tr>
</thead>
{{#each thisMenuItems}} {{#each thisMenuItems}}
<tr class="clickable"> <tr>
<td> <td>
<span> <span>
{{#if $eq itemMade true}} {{#if $eq itemMade true}}
@ -17,12 +24,16 @@
{{serveDate}} {{serveDate}}
</td> </td>
<td> <td>
<i class="material-icons clickable deleteMenuItem right modal-trigger" data-target="modalDelete">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>
</td> </td>
</tr> </tr>
{{/each}} {{/each}}
</table> </table>
<div class="tooltip-content" style="display: none;" id="deleteMenuTip">Delete this menu item</div>
<div class="tooltip-content" style="display: none;" id="linkMenuTip">Link Products that make up this menu item</div>
</div> </div>
</div> </div>
{{> deleteConfirmationModal}} {{> deleteConfirmationModal}}
{{> modalLinkProducts}}
</template> </template>

View file

@ -10,6 +10,14 @@ Template.menuItemsTbl.onCreated(function() {
Template.menuItemsTbl.onRendered(function() { Template.menuItemsTbl.onRendered(function() {
var elems = document.querySelectorAll('.modal'); var elems = document.querySelectorAll('.modal');
var instances = M.Modal.init(elems, {}); 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({ Template.menuItemsTbl.helpers({
@ -26,4 +34,8 @@ Template.menuItemsTbl.events({
Session.set("item", this.itemName); Session.set("item", this.itemName);
Session.set("view", "Menu Items"); Session.set("view", "Menu Items");
}, },
'click .linkToProducts' (event) {
event.preventDefault();
Session.set("menuItemId", this._id);
}
}); });

View file

@ -0,0 +1,29 @@
<template name="modalLinkProducts">
<div id="modalLinkProducts" class="modal">
<div class="modal-content">
<p class="flow-text">Choose Product Items below that are used to make this menu item.</p>
<div class="col s12 input-field outlined" id="prouctsForMenudiv">
<select name="" id="prodForMenu" class="prodForMenu" multiple>
<option value="" disabled>Choose...</option>
{{#each products}}
<option value="{{prodName}}">{{prodName}}</option>
{{/each}}
</select>
</div>
</div>
<br>
<hr>
<div class="modal-footer">
<div class="row">
<div class="col s6">
<a id="cancelLInk" class="btn waves-effect wave-light orange white-text left modal-close">Cancel</a>
</div>
<div class="col s6">
<a id="saveLink" class="btn waves-effect waves-light green white-text right modal-close">Save</a>
</div>
</div>
</div>
</div>
{{> snackbar}}
</template>

View file

@ -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");
}
});
}
}
});

View file

@ -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<prodNameLength; i++) {
let product = Products.findOne({ prodName: prodNameArray[i] });
if (typeof product != 'undefined' && product != null && product != "") {
let prodId = product._id;
MenuProdLinks.insert({
menuItemId: menuItemId,
prodName: prodNameArray[i],
prodId: prodId,
dateCreated: Date(),
createdBy: this.userId
});
} else {
console.log(" ERROR - unable to find a matching product by name: " + prodName[i] + ".");
}
}
}
});

View file

@ -9,6 +9,7 @@ import { MenuItems } from '../imports/api/menuItems.js';
import moment from 'moment'; import moment from 'moment';
import { TaskItems } from '../imports/api/tasks.js'; import { TaskItems } from '../imports/api/tasks.js';
import { UserConfig } from '../imports/api/userConfig.js'; import { UserConfig } from '../imports/api/userConfig.js';
import { MenuProdLinks } from '../imports/api/menuProdLinks.js';
Meteor.publish("SystemConfig", function() { Meteor.publish("SystemConfig", function() {
try { try {
@ -118,4 +119,12 @@ Meteor.publish("rolesAvailable", function() {
} catch (error) { } catch (error) {
console.log(" ERROR publishing roles: " + error); console.log(" ERROR publishing roles: " + error);
} }
}) });
Meteor.publish("menuProdLinkData", function() {
try {
return MenuProdLinks.find({});
} catch (error) {
console.log(" ERROR publishing menu product links: " + error);
}
});