diff --git a/client/AdminMgmt/CleanUp/cleanUp.html b/client/AdminMgmt/CleanUp/cleanUp.html index e6159a2..d92b810 100644 --- a/client/AdminMgmt/CleanUp/cleanUp.html +++ b/client/AdminMgmt/CleanUp/cleanUp.html @@ -6,7 +6,7 @@
Clean Up List Items - Clean Lists + Clean Lists info
@@ -16,9 +16,9 @@
Clean Up Menus - Clean Menus + Clean Menus info - +
@@ -26,7 +26,7 @@
Clean Up Products - Clean Products + Clean Products info
@@ -36,13 +36,24 @@
Clean Up Tasks - Clean Tasks + Clean Tasks info
+
+
+
+ Clean Up Stores + Clean Stores + info + +
+
+
+ {{> cleanUpModalConfirm}} {{else}}

You appear to have reached this page without having appropriate permissions to view the contents. If you believe this is a mistake, please contact your system admin for assistance.

{{/if}} diff --git a/client/AdminMgmt/CleanUp/cleanUp.js b/client/AdminMgmt/CleanUp/cleanUp.js index 20cb079..0e106b1 100644 --- a/client/AdminMgmt/CleanUp/cleanUp.js +++ b/client/AdminMgmt/CleanUp/cleanUp.js @@ -1,12 +1,24 @@ import { M } from '../../lib/assets/materialize.js'; +import { Lists } from '../../../imports/api/lists.js'; +import { Menus } from '../../../imports/api/menu.js'; +import { TaskItems } from '../../../imports/api/tasks.js'; +import { Products } from '../../../imports/api/products.js'; +import { Stores } from '../../../imports/api/stores.js'; Template.cleanUp.onCreated(function() { - + this.subscribe("allLists"); + this.subscribe("allMenus"); + this.subscribe("allTasks"); + this.subscribe("allProducts"); + this.subscribe("allStores"); }); Template.cleanUp.onRendered(function() { var elems = document.querySelectorAll('.tooltipped'); var instances = M.Tooltip.init(elems, {}); + + var elemsm = document.querySelectorAll('.modal'); + var instancesm = M.Modal.init(elemsm, {}); }); Template.cleanUp.helpers({ @@ -14,5 +26,24 @@ Template.cleanUp.helpers({ }); Template.cleanUp.events({ - + 'click #cleanLists' (event) { + event.preventDefault(); + Session.set("cleanWhat", "Lists"); + }, + 'click #cleanMenus' (event) { + event.preventDefault(); + Session.set("cleanWhat", "Menus"); + }, + 'click #cleanProducts' (event) { + event.preventDefault(); + Session.set("cleanWhat", "Products"); + }, + 'click #cleanStores' (event) { + event.preventDefault(); + Session.set("cleanWhat", "Stores"); + }, + 'click #cleanTasks' (event) { + event.preventDefault(); + Session.set("cleanWhat", "Tasks"); + }, }); \ No newline at end of file diff --git a/client/AdminMgmt/CleanUp/modalConfirm/cleanUpModalConfirm.html b/client/AdminMgmt/CleanUp/modalConfirm/cleanUpModalConfirm.html new file mode 100644 index 0000000..1038efb --- /dev/null +++ b/client/AdminMgmt/CleanUp/modalConfirm/cleanUpModalConfirm.html @@ -0,0 +1,20 @@ + \ No newline at end of file diff --git a/client/AdminMgmt/CleanUp/modalConfirm/cleanUpModalConfirm.js b/client/AdminMgmt/CleanUp/modalConfirm/cleanUpModalConfirm.js new file mode 100644 index 0000000..02f7b39 --- /dev/null +++ b/client/AdminMgmt/CleanUp/modalConfirm/cleanUpModalConfirm.js @@ -0,0 +1,53 @@ +import { M } from '../../../lib/assets/materialize.js'; +import { Lists } from '../../../../imports/api/lists.js'; +import { Menus } from '../../../../imports/api/menu'; +import { TaskItems } from '../../../../imports/api/tasks'; +import { Products } from '../../../../imports/api/products.js'; +import { Stores } from '../../../../imports/api/stores.js'; + +Template.cleanUpModalConfirm.onCreated(function() { + +}); + +Template.cleanUpModalConfirm.onRendered(function () { + +}); + +Template.cleanUpModalConfirm.helpers({ + whatItems: function() { + return Session.get("cleanWhat"); + } +}); + +Template.cleanUpModalConfirm.events({ + 'click #confirmClean' (event) { + let whatItems = Session.get("cleanWhat"); + + switch(whatItems) { + case "Lists": + cleanUp("clean.Lists"); + case "Menus": + cleanUp("clean.Menus"); + case "Products": + // cleanUp("clean.Products"); + case "Stores": + // cleanUp("clean.Stores"); + case "Tasks": + // cleanUp("clean.Tasks"); + default: + break; + } + } +}); + +cleanUp = function(methodName) { + Meteor.call(methodName, function(err, result) { + if (err) { + console.log(" ERROR cleaning lists: " + err) + } else { + showSnackbar("Lists have been cleaned up!", "green"); + let confirmModal = document.getElementById('cleanUpConfirm'); + M.Modal.getInstance(confirmModal).close(); + } + }); +} \ No newline at end of file diff --git a/imports/api/lists.js b/imports/api/lists.js index 14ec348..6b8651d 100644 --- a/imports/api/lists.js +++ b/imports/api/lists.js @@ -65,5 +65,12 @@ Meteor.methods({ completedOn: new Date() } });; - } + }, + 'clean.Lists' () { + if (!this.userId) { + throw new Meteor.Error('You are not allowed to clean up old lists. Make sure you are logged in with valid user credentials.'); + } + + return Lists.remove({ listComplete: true }); + }, }); \ No newline at end of file diff --git a/imports/api/menu.js b/imports/api/menu.js index 341a1d0..7271f23 100644 --- a/imports/api/menu.js +++ b/imports/api/menu.js @@ -1,6 +1,9 @@ import { Meteor } from 'meteor/meteor'; import { Mongo } from 'meteor/mongo'; import { check } from 'meteor/check'; +import { MenuItems } from './menuItems'; +import moment from 'moment'; +import { mark } from '@babel/runtime/regenerator'; export const Menus = new Mongo.Collection('menus'); @@ -73,5 +76,50 @@ Meteor.methods({ menuComplete: false, } }); - } + }, + 'clean.Menus' () { + if (!this.userId) { + throw new Meteor.Error('You are not allowed to clean up old Menus. Make sure you are logged in with valid user credentials.'); + } + + let removeMenuIds = []; + + + // let's find all the menus with menu items that are past their date. + let menuList = Menus.find({ menuComplete: false }).fetch(); + for (i=0; i < menuList.length; i++) { + let removeMenu = true; + let items = MenuItems.find({ menuId: menuList[i]._id }).fetch(); + for (j=0; j < items.length; j++) { + let srvDate = moment(items[j].serveDateActual); + let today = moment(); + let expired = moment(today).isAfter(srvDate); + // console.log("Expired: " + expired); + if (expired != true) { + removeMenu = false; + } + if (j == items.length - 1) { + if (removeMenu == true) { + removeMenuIds.push(menuList[i]._id); + } + } + } + } + + // next let's add the ids of any menus that are marked complete + let markedComplete = Menus.find({ menuComplete: true }).fetch(); + // console.log("---- ---- ----"); + // console.dir(markedComplete); + for (k = 0; k < markedComplete.length; k++) { + let menuId = markedComplete[k]._id; + removeMenuIds.push(menuId); + } + + // console.log(" ----- Need to remove Menus: "); + console.dir(removeMenuIds); + + for (l = 0; l < removeMenuIds.length; l++) { + Menus.remove({ _id: removeMenuIds[l] }); + } + }, }); \ No newline at end of file diff --git a/server/publish.js b/server/publish.js index c645127..6de7726 100644 --- a/server/publish.js +++ b/server/publish.js @@ -122,6 +122,38 @@ Meteor.publish("allTasks", function() { } }); +Meteor.publish("allProducts", function() { + try { + return Products.find({}); + } catch (error) { + console.log(" ERROR pulling the task items: " + error); + } +}); + +Meteor.publish("allMenus", function() { + try { + return Menus.find({}); + } catch (error) { + console.log(" ERROR pulling the task items: " + error); + } +}); + +Meteor.publish("allStores", function() { + try { + return Stores.find({}); + } catch (error) { + console.log(" ERROR pulling the task items: " + error); + } +}); + +Meteor.publish("allLists", function() { + try { + return Lists.find({}); + } catch (error) { + console.log(" ERROR pulling the task items: " + error); + } +}); + Meteor.publish("myTasks", function() { try { return TaskItems.find({ assignedToId: this.userId });