Merge branch 'dev' into 'main'

Updaated Products to have multiple associated stores.

See merge request bmcgonag/get_my!5
This commit is contained in:
Brian McGonagill 2024-08-13 15:51:43 +00:00
commit 31e7bdbe0a
4 changed files with 56 additions and 96 deletions

View file

@ -14,16 +14,17 @@
<input type="text" class="prodName" style="{{#if $eq prodNameErr true}}border: 2px solid red;{{/if}}" id="prodName" />
<label for="prodName">Name*</label>
</div>
<div class="col s12 m6 l6 input-field outlined">
<select name="prodStore" id="prodStore">
<option value="" disabled selected></option>
<option id="addNewStore" value="addNewStore" class="modal-trigger" data-target="modalStore">+ Add New Store</option>
<div class="col s12 m4 l4 input-field outlined">
<select name="prodStore" id="prodStore" multiple>
{{#each stores}}
<option value="{{storeName}}">{{storeName}}</option>
{{/each}}
</select>
<label for="prodStore">Store</label>
</div>
<div class="col s12 m2 l2">
<a class="btn waves-light waves-effect blue white-text modal-trigger" id="addNewStore" href="#modalStore">+ Add Store</a>
</div>
<div class="col s12 m12 l12">
{{#if $eq prodEditMode false}}
<a class="waves-effect waves-light btn saveProdMgmt green white-text right">Add</a>

View file

@ -32,36 +32,12 @@ Template.prodMgmtForm.helpers({
});
Template.prodMgmtForm.events({
'click .saveProdMgmt' (event) {
event.preventDefault();
'click .saveProdMgmt, click .editProdMgmt' (event) {
let name = $("#prodName").val();
let store = $("#prodStore").val();
if (store == null) {
store = "";
}
if (name == "" || name == null) {
Session.set("prodNameRed", true);
return;
} else {
Meteor.call('add.product', name, store, function(err, result) {
if (err) {
console.log(" ERROR: can't add product: " + err);
} else {
$("#prodName").val("");
let elemse = document.querySelectorAll('select');
let instancese = M.FormSelect.init(elemse, {});
showSnackbar("Succesffuly Added Product!", "green");
}
});
}
},
'click .editProdMgmt' (event) {
event.preventDefault();
let name = $("#prodName").val();
let prodId = Session.get("prodEditId");
let store = $("#prodStore").val();
let prodEditMode = Session.get("prodEditMode");
if (store == null) {
store = "";
@ -71,71 +47,27 @@ Template.prodMgmtForm.events({
Session.set("prodNameRed", true);
return;
} else {
Meteor.call('edit.product', prodId, name, store, function(err, result) {
if (err) {
// console.log(" ERROR: can't add product: " + err);
} else {
$("#prodName").val("");
Session.set("prodEditMode", false);
showSnackbar("Product Edited Successfully!", "green");
}
});
}
},
'keypress form.prodInputForm' (event) {
// event.preventDefault();
if (event.which === 13) {
let name = $("#prodName").val();
let store = $("#prodStore").val();
let prodId = Session.get("prodEditId");
let prodEditMode = Session.get("prodEditMode");
// console.log(" ---- got the submit event for products.");
if (store == null) {
store = "";
}
if (name == "" || name == null) {
Session.set("prodNameRed", true);
return;
if (prodEditMode == true) {
Meteor.call('edit.product', prodId, name, store, function(err, result) {
if (err) {
console.log(" ERROR: can't add product: " + err);
} else {
$("#prodName").val("");
showSnackbar("Successfully Edited Product!", "green");
}
});
} else {
if (prodEditMode == true) {
Meteor.call('edit.product', prodId, name, store, function(err, result) {
if (err) {
console.log(" ERROR: can't add product: " + err);
} else {
$("#prodName").val("");
showSnackbar("Successfully Edited Product!", "green");
}
});
} else {
Meteor.call('add.product', name, store, function(err, result) {
if (err) {
console.log(" ERROR: can't add product: " + err);
} else {
$("#prodName").val("");
showSnackbar("Product Added Succssfully!", "green");
}
});
}
Meteor.call('add.product', name, store, function(err, result) {
if (err) {
console.log(" ERROR: can't add product: " + err);
} else {
$("#prodName").val("");
showSnackbar("Product Added Succssfully!", "green");
}
});
}
}
},
'change #prodStore' (event) {
// event.preventDefault();
console.log("detected event");
let val = $("#prodStore").val();
console.log("Value detected: " + val);
if (val == "addNewStore") {
console.log("got the request for modal.");
$("#prodStore").val("");
// open modal to add a new store
let elemmm = document.getElementById('modalStore');
let storeModal = M.Modal.getInstance(elemmm);
storeModal.open();
}
},
'click #showNoStoreSet' (event) {
let noStoreSet = $("#showNoStoreSet").prop('checked');
console.log("Clicked: " + noStoreSet);

View file

@ -14,7 +14,7 @@ Products.allow({
Meteor.methods({
'add.product' (prodName, prodStore) {
check(prodName, String);
check(prodStore, String);
check(prodStore, [String]);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to add products. Make sure you are logged in with valid user credentials.');
@ -29,7 +29,7 @@ Meteor.methods({
'edit.product' (prodId, prodName, prodStore) {
check(prodId, String);
check(prodName, String);
check(prodStore, String);
check(prodStore, [String]);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to edit products. Make sure you are logged in with valid user credentials.');

View file

@ -1,6 +1,7 @@
import { Meteor } from 'meteor/meteor';
import { SysConfig } from '../imports/api/systemConfig';
import { MenuItems } from '../imports/api/menuItems';
import { Products } from '../imports/api/products.js';
Meteor.startup(() => {
// code to run on server at startup
@ -22,7 +23,7 @@ Meteor.startup(() => {
// 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);
// 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);
@ -36,7 +37,33 @@ Meteor.startup(() => {
}
} else {
// this will show if all items are found to have isLInked set.
// console.log("No itesm with isLinked not 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;
prodStoreArray.push(prodStore);
// console.dir(prodStoreArray);
Products.update({ _id: prodInfo[j]._id }, {
$set: {
prodStore: prodStoreArray,
}
});
}
}
});