diff --git a/client/AdminMgmt/CleanUp/modalConfirm/cleanUpModalConfirm.js b/client/AdminMgmt/CleanUp/modalConfirm/cleanUpModalConfirm.js index 247da06..19245ea 100644 --- a/client/AdminMgmt/CleanUp/modalConfirm/cleanUpModalConfirm.js +++ b/client/AdminMgmt/CleanUp/modalConfirm/cleanUpModalConfirm.js @@ -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); diff --git a/client/AdminMgmt/ProductMgmt/prodMgmtForm.html b/client/AdminMgmt/ProductMgmt/prodMgmtForm.html index 357b19c..3a6ff9c 100644 --- a/client/AdminMgmt/ProductMgmt/prodMgmtForm.html +++ b/client/AdminMgmt/ProductMgmt/prodMgmtForm.html @@ -2,14 +2,22 @@

Product Management

{{#if Template.subscriptionsReady}}
-
-

- -

-
+
+

+ +

+
+
+

+ +

+
diff --git a/client/AdminMgmt/ProductMgmt/prodMgmtForm.js b/client/AdminMgmt/ProductMgmt/prodMgmtForm.js index cb5fc18..f0c2a2d 100644 --- a/client/AdminMgmt/ProductMgmt/prodMgmtForm.js +++ b/client/AdminMgmt/ProductMgmt/prodMgmtForm.js @@ -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) { }, diff --git a/client/AdminMgmt/ProductMgmt/prodMgmtTbl.js b/client/AdminMgmt/ProductMgmt/prodMgmtTbl.js index cf49c52..48dfee1 100644 --- a/client/AdminMgmt/ProductMgmt/prodMgmtTbl.js +++ b/client/AdminMgmt/ProductMgmt/prodMgmtTbl.js @@ -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 }}); } diff --git a/imports/api/products.js b/imports/api/products.js index b8d5056..35e8206 100644 --- a/imports/api/products.js +++ b/imports/api/products.js @@ -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 } }); diff --git a/server/publish.js b/server/publish.js index c0f8072..61750dd 100644 --- a/server/publish.js +++ b/server/publish.js @@ -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({});