Added filtering to the Store column in Product management

This commit is contained in:
Brian McGonagill 2024-07-26 11:58:03 -05:00
parent c4123ce6da
commit de1ca5bace
2 changed files with 46 additions and 6 deletions

View file

@ -13,7 +13,15 @@
</div>
{{/if}}
</th>
<th>Store</th>
<th>
{{#if $eq searchStore false}}
Store <i class="material-icons clickable right" id="filterStore">search</i>
{{else}}
<div style="width: 100%;">
<input type="text" class="searchStore" id="searchStore" style="width: 85%;" /> <i class="material-icons clickable" id="closeStoreFilter">close</i>
</div>
{{/if}}
</th>
<th>Actions</th>
</tr>
</thead>

View file

@ -7,20 +7,38 @@ Template.prodMgmtTbl.onCreated(function() {
Template.prodMgmtTbl.onRendered(function() {
Session.set("searchProds", false);
Session.set("searchStore", false);
});
Template.prodMgmtTbl.helpers({
products: function() {
let searchVal = Session.get("searchVal");
if (typeof searchVal == 'undefined' || searchVal.length == 0) {
return Products.find({});
let searchProd = Session.get("searchProds");
let searchStore = Session.get("searchStore");
if (searchProd == true) {
let searchVal = Session.get("searchVal");
if (typeof searchVal == 'undefined' || searchVal.length == 0) {
return Products.find({});
} else {
return Products.find({ prodName: { $regex: searchVal + '.*', $options: 'i' } });
}
} else if (searchStore == true) {
let searchVal = Session.get("searchStoreVal");
if (typeof searchVal == 'undefined' || searchVal.length == 0) {
return Products.find({});
} else {
return Products.find({ prodStore: { $regex: searchVal + '.*', $options: 'i' } });
}
} else {
return Products.find({ prodName: { $regex: searchVal + '.*', $options: 'i' } });
return Products.find({});
}
},
searchProd: function() {
return Session.get("searchProds");
}
},
searchStore: function() {
return Session.get("searchStore");
},
});
Template.prodMgmtTbl.events({
@ -53,5 +71,19 @@ Template.prodMgmtTbl.events({
let searchVal = $("#searchProds").val();
Session.set("searchVal", searchVal);
}
},
'click #filterStore' (event) {
event.preventDefault();
Session.set("searchStore", true);
},
'click #closeStoreFilter' (event) {
event.preventDefault();
Session.set("searchStore", false);
},
'keyup #searchStore' (event) {
if (event.which !== 13) {
let searchVal = $("#searchStore").val();
Session.set("searchStoreVal", searchVal);
}
}
});