mirror of
https://gitlab.com/bmcgonag/get_my.git
synced 2026-03-27 00:08:49 +00:00
Merge branch 'dev' into 'main'
Updaated Products to have multiple associated stores. See merge request bmcgonag/get_my!5
This commit is contained in:
commit
31e7bdbe0a
4 changed files with 56 additions and 96 deletions
|
|
@ -14,16 +14,17 @@
|
||||||
<input type="text" class="prodName" style="{{#if $eq prodNameErr true}}border: 2px solid red;{{/if}}" id="prodName" />
|
<input type="text" class="prodName" style="{{#if $eq prodNameErr true}}border: 2px solid red;{{/if}}" id="prodName" />
|
||||||
<label for="prodName">Name*</label>
|
<label for="prodName">Name*</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="col s12 m6 l6 input-field outlined">
|
<div class="col s12 m4 l4 input-field outlined">
|
||||||
<select name="prodStore" id="prodStore">
|
<select name="prodStore" id="prodStore" multiple>
|
||||||
<option value="" disabled selected></option>
|
|
||||||
<option id="addNewStore" value="addNewStore" class="modal-trigger" data-target="modalStore">+ Add New Store</option>
|
|
||||||
{{#each stores}}
|
{{#each stores}}
|
||||||
<option value="{{storeName}}">{{storeName}}</option>
|
<option value="{{storeName}}">{{storeName}}</option>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</select>
|
</select>
|
||||||
<label for="prodStore">Store</label>
|
<label for="prodStore">Store</label>
|
||||||
</div>
|
</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">
|
<div class="col s12 m12 l12">
|
||||||
{{#if $eq prodEditMode false}}
|
{{#if $eq prodEditMode false}}
|
||||||
<a class="waves-effect waves-light btn saveProdMgmt green white-text right">Add</a>
|
<a class="waves-effect waves-light btn saveProdMgmt green white-text right">Add</a>
|
||||||
|
|
|
||||||
|
|
@ -32,36 +32,12 @@ Template.prodMgmtForm.helpers({
|
||||||
});
|
});
|
||||||
|
|
||||||
Template.prodMgmtForm.events({
|
Template.prodMgmtForm.events({
|
||||||
'click .saveProdMgmt' (event) {
|
'click .saveProdMgmt, click .editProdMgmt' (event) {
|
||||||
event.preventDefault();
|
|
||||||
let name = $("#prodName").val();
|
let name = $("#prodName").val();
|
||||||
let store = $("#prodStore").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 prodId = Session.get("prodEditId");
|
||||||
let store = $("#prodStore").val();
|
let prodEditMode = Session.get("prodEditMode");
|
||||||
|
|
||||||
if (store == null) {
|
if (store == null) {
|
||||||
store = "";
|
store = "";
|
||||||
|
|
@ -71,71 +47,27 @@ Template.prodMgmtForm.events({
|
||||||
Session.set("prodNameRed", true);
|
Session.set("prodNameRed", true);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
Meteor.call('edit.product', prodId, name, store, function(err, result) {
|
if (prodEditMode == true) {
|
||||||
if (err) {
|
Meteor.call('edit.product', prodId, name, store, function(err, result) {
|
||||||
// console.log(" ERROR: can't add product: " + err);
|
if (err) {
|
||||||
} else {
|
console.log(" ERROR: can't add product: " + err);
|
||||||
$("#prodName").val("");
|
} else {
|
||||||
Session.set("prodEditMode", false);
|
$("#prodName").val("");
|
||||||
showSnackbar("Product Edited Successfully!", "green");
|
showSnackbar("Successfully Edited Product!", "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;
|
|
||||||
} else {
|
} else {
|
||||||
if (prodEditMode == true) {
|
Meteor.call('add.product', name, store, function(err, result) {
|
||||||
Meteor.call('edit.product', prodId, name, store, function(err, result) {
|
if (err) {
|
||||||
if (err) {
|
console.log(" ERROR: can't add product: " + err);
|
||||||
console.log(" ERROR: can't add product: " + err);
|
} else {
|
||||||
} else {
|
$("#prodName").val("");
|
||||||
$("#prodName").val("");
|
showSnackbar("Product Added Succssfully!", "green");
|
||||||
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");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'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) {
|
'click #showNoStoreSet' (event) {
|
||||||
let noStoreSet = $("#showNoStoreSet").prop('checked');
|
let noStoreSet = $("#showNoStoreSet").prop('checked');
|
||||||
console.log("Clicked: " + noStoreSet);
|
console.log("Clicked: " + noStoreSet);
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ Products.allow({
|
||||||
Meteor.methods({
|
Meteor.methods({
|
||||||
'add.product' (prodName, prodStore) {
|
'add.product' (prodName, prodStore) {
|
||||||
check(prodName, String);
|
check(prodName, String);
|
||||||
check(prodStore, String);
|
check(prodStore, [String]);
|
||||||
|
|
||||||
if (!this.userId) {
|
if (!this.userId) {
|
||||||
throw new Meteor.Error('You are not allowed to add products. Make sure you are logged in with valid user credentials.');
|
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) {
|
'edit.product' (prodId, prodName, prodStore) {
|
||||||
check(prodId, String);
|
check(prodId, String);
|
||||||
check(prodName, String);
|
check(prodName, String);
|
||||||
check(prodStore, String);
|
check(prodStore, [String]);
|
||||||
|
|
||||||
if (!this.userId) {
|
if (!this.userId) {
|
||||||
throw new Meteor.Error('You are not allowed to edit products. Make sure you are logged in with valid user credentials.');
|
throw new Meteor.Error('You are not allowed to edit products. Make sure you are logged in with valid user credentials.');
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { Meteor } from 'meteor/meteor';
|
import { Meteor } from 'meteor/meteor';
|
||||||
import { SysConfig } from '../imports/api/systemConfig';
|
import { SysConfig } from '../imports/api/systemConfig';
|
||||||
import { MenuItems } from '../imports/api/menuItems';
|
import { MenuItems } from '../imports/api/menuItems';
|
||||||
|
import { Products } from '../imports/api/products.js';
|
||||||
|
|
||||||
Meteor.startup(() => {
|
Meteor.startup(() => {
|
||||||
// code to run on server at 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)
|
// check if the isLInked item exists on menuitems, and if not, add it (data cleanup task)
|
||||||
let itemInfoNoLink = MenuItems.find({ isLinked: { $exists: false } }).fetch();
|
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) {
|
if (itemInfoNoLink.length > 0) {
|
||||||
// console.log("found items with isLinked not set.");
|
// console.log("found items with isLinked not set.");
|
||||||
// console.dir(itemInfoNoLink);
|
// console.dir(itemInfoNoLink);
|
||||||
|
|
@ -36,7 +37,33 @@ Meteor.startup(() => {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// this will show if all items are found to have isLInked set.
|
// 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,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue