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

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