Added List and Menu clean up.

This commit is contained in:
Brian McGonagill 2024-07-30 16:32:06 -05:00
parent 2f3f82477a
commit e60c32894c
7 changed files with 211 additions and 9 deletions

View file

@ -6,7 +6,7 @@
<div class="card">
<div class="card-content">
<span class="card-title">Clean Up List Items</span>
<a class="btn waves-effect waves-light blue white-text" id="cleanLists">Clean Lists</a>
<a class="btn waves-effect waves-light blue white-text modal-trigger" href="#cleanUpConfirm" id="cleanLists">Clean Lists</a>
<i class="material-icons tooltipped right" data-html="true" data-position="top" data-tooltip-id="tooltip-content">info</i>
<div id="tooltip-content" style="display: none;">To clean up old lists along with related list items, ensure any lists you no longer need or use are marked as 'Complete' by tapping or clicking the checkmark icon on the list entry.</div>
</div>
@ -16,9 +16,9 @@
<div class="card">
<div class="card-content">
<span class="card-title">Clean Up Menus</span>
<a class="btn waves-effect waves-light blue white-text" id="cleanLists">Clean Menus</a>
<a class="btn waves-effect waves-light blue white-text modal-trigger" href="#cleanUpConfirm" id="cleanMenus">Clean Menus</a>
<i class="material-icons tooltipped right" data-html="true" data-position="top" data-tooltip-id="tooltip-menus">info</i>
<div id="tooltip-menus" style="display: none;">This will clean up old Menus and items where all items are past the date, including items that have no date set.</div>
<div id="tooltip-menus" style="display: none;">This will clean up old Menus and items where all Menus where menu items are past the date, including items that have no date set.</div>
</div>
</div>
</div>
@ -26,7 +26,7 @@
<div class="card">
<div class="card-content">
<span class="card-title">Clean Up Products</span>
<a class="btn waves-effect waves-light blue white-text" id="cleanLists">Clean Products</a>
<a class="btn waves-effect waves-light blue white-text" id="cleanProducts">Clean Products</a>
<i class="material-icons tooltipped right" data-html="true" data-position="top" data-tooltip-id="tooltip-products">info</i>
<div id="tooltip-products" style="display: none;">This will help you clean up all products. This task takes a little more user interaction in order to identify duplicate and unique items.</div>
</div>
@ -36,13 +36,24 @@
<div class="card">
<div class="card-content">
<span class="card-title">Clean Up Tasks</span>
<a class="btn waves-effect waves-light blue white-text" id="cleanLists">Clean Tasks</a>
<a class="btn waves-effect waves-light blue white-text" id="cleanTasks">Clean Tasks</a>
<i class="material-icons tooltipped right" data-html="true" data-position="top" data-tooltip-id="tooltip-tasks">info</i>
<div id="tooltip-tasks" style="display: none;">This will clean up all tasks where the date has past, or the task is marked completed. For completed tasks to be cleared, today must also be past the due date on the task.</div>
</div>
</div>
</div>
<div class="col s12 m6 l4">
<div class="card">
<div class="card-content">
<span class="card-title">Clean Up Stores</span>
<a class="btn waves-effect waves-light blue white-text" id="cleanStores">Clean Stores</a>
<i class="material-icons tooltipped right" data-html="true" data-position="top" data-tooltip-id="tooltip-stores">info</i>
<div id="tooltip-stores" style="display: none;">This will allow you to clean up Store entries if needed.</div>
</div>
</div>
</div>
</div>
{{> cleanUpModalConfirm}}
{{else}}
<p class="flow-text">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.</p>
{{/if}}

View file

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

View file

@ -0,0 +1,20 @@
<template name="cleanUpModalConfirm">
<div class="modal" id="cleanUpConfirm">
<div class="modal-content">
<h4>Clean Up {{whatItems}}</h4>
<p class="flow-text">Please click the 'Confirm' button in order to continue with the {{whatItem}} clean up. Note: this action canno be undone once confirmed.</p>
</div>
<div class="modal-footer">
<div class="row">
<div class="col s6">
<a class="left btn waves-effect waves-light orange white-text cancelClean modal-close">Close</a>
</div>
<div class="col s6">
<a class="right btn waves-effect waves-light blue white-text confirmClean" id="confirmClean">Confirm</a>
</div>
</div>
</div>
</div>
{{> snackbar}}
</template>

View file

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

View file

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

View file

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

View file

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