Fixing clean Up and added option to show which products arent used in a list

This commit is contained in:
Brian McGonagill 2025-08-09 07:21:46 -05:00
parent c6c5951d16
commit 680f7c614d
6 changed files with 71 additions and 10 deletions

View file

@ -29,7 +29,7 @@ Template.cleanUpModalConfirm.events({
case "Menus":
cleanUp("clean.Menus", whatItems);
case "Products":
// cleanUp("clean.Products", whatItems);
cleanUp("clean.Products", whatItems);
case "Stores":
// cleanUp("clean.Stores", whatItems);
case "Tasks":
@ -43,7 +43,7 @@ Template.cleanUpModalConfirm.events({
cleanUp = async function(methodName, whatItems) {
let result = Meteor.callAsync(methodName);
if (!result) {
console.log(" ERROR cleaning " + whatItems + ": " + err);
console.log(" ERROR cleaning " + whatItems);
} else {
showSnackbar(whatItems + " have been cleaned up!", "green");
let confirmModal = document.getElementById('cleanUpConfirm');
@ -51,6 +51,15 @@ cleanUp = async function(methodName, whatItems) {
}
}
cleanProducts = async function(methodName, whatItems) {
let result = await Meteor.call(methodName, whatItems);
if (!result) {
console.log(" ERROR cleaning " + whatItems);
} else {
showSnackbar(whatItems + " have been cleaned up.", "green");
}
}
cleanTasks = async function(methodName, whatItems) {
let timeFrame = Session.get("overdueVal");
let result = await Meteor.call(methodName, timeFrame);

View file

@ -2,14 +2,22 @@
<h4>Product Management</h4>
{{#if Template.subscriptionsReady}}
<form action="submit" class="row prodInputForm" style="gap: 1em;">
<div class="col s12">
<p>
<label>
<input type="checkbox" id="showNoStoreSet" />
<span>Show Products without Store Assigned</span>
</label>
</p>
</div>
<div class="col s12">
<p>
<label>
<input type="checkbox" id="showNoStoreSet" />
<span>Show Products without Store Assigned</span>
</label>
</p>
</div>
<div class="col s12">
<p>
<label>
<input type="checkbox" id="showNoList" />
<span>Show Products Never Used in a List</span>
</label>
</p>
</div>
<div class="col s12 m6 l6 input-field outlined">
<input type="text" class="prodName" style="{{#if $eq prodNameErr true}}border: 2px solid red;{{/if}}" id="prodName" />
<label for="prodName">Name*</label>

View file

@ -60,6 +60,14 @@ Template.prodMgmtForm.events({
Session.set("noStoreSet", false);
}
},
'click #showNoList' (event) {
let notUsedInList = $("#showNoList").prop('checked');
if (notUsedInList == true) {
Session.set("noListUsed", true);
} else {
Session.set("noListUsed", false);
}
},
'submit .prodInputForm' (event) {
},

View file

@ -1,14 +1,17 @@
import { Products } from '../../../imports/api/products.js';
import { ListItems } from '../../../imports/api/listItems.js';
import { M } from '../../lib/assets/materialize.js';
Template.prodMgmtTbl.onCreated(function() {
this.subscribe("myProducts");
this.subscribe("allListItems");
});
Template.prodMgmtTbl.onRendered(function() {
Session.set("searchProds", false);
Session.set("searchStore", false);
Session.set("noStoreSet", false);
Session.set("noListUsed", false);
});
Template.prodMgmtTbl.helpers({
@ -16,6 +19,7 @@ Template.prodMgmtTbl.helpers({
let searchProd = Session.get("searchProds");
let searchStore = Session.get("searchStore");
let noStoreSet = Session.get("noStoreSet");
let noListUsed = Session.get("noListUsed");
if (searchProd == true) {
let searchVal = Session.get("searchVal");
@ -33,6 +37,20 @@ Template.prodMgmtTbl.helpers({
}
} else if (noStoreSet == true) {
return Products.find({ prodStore: '' }, { sort: { prodName: 1 }});
} else if (noListUsed == true) {
let i;
let idList = [];
let idsInLists = ListItems.find({}).fetch();
for (i=0; i < idsInLists.length; i++) {
// console.log(idsInList[i]);
idList.push(idsInLists[i].prodId);
}
if (i > idsInLists.length - 1) {
console.dir(idList);
let noProdsNot = Products.find({ _id: { $nin: idList }}).count();
console.log(noProdsNot);
return Products.find({ _id: { $nin: idList }}, { sort: { prodName: 1 }});
}
} else {
return Products.find({}, { sort: { prodName: 1 }});
}

View file

@ -63,5 +63,15 @@ Meteor.methods({
}
return await Products.removeAsync({ _id: prodId });
},
async 'clean.Products' () {
if (!this.userId) {
throw new Meteor.Error('You are not allowed to delete products. Make sure you are logged in with valid user credentials.');
}
// first we need to find potential duplicate products
// next we need to see which of those are on incomplete lists
// Then we'll update those to use the main products ID instead
// finally we'll delete the duplicates
}
});

View file

@ -96,6 +96,14 @@ Meteor.publish("myListItems", function(listId) {
}
});
Meteor.publish("allListItems", function() {
try {
return ListItems.find({});
} catch (error) {
console.log(" ERROR pulling all list items.");
}
});
Meteor.publish("myStoreListItems", function(listId) {
try {
let stores = Store.find({});