Added Task Mgmt, and framework for Recipes.

This commit is contained in:
Brian McGonagill 2022-09-05 09:39:54 -05:00
parent 3b9a54daf1
commit 947abfb76f
13 changed files with 430 additions and 1 deletions

View file

@ -11,6 +11,7 @@
<li id="manageCategory" class="collection-item">Category</li>
<li id="manageLocation" class="collection-item">Location</li>
<li id="manageStore" class="collection-item">Store</li>
<li id="taskHome" class="collection-item">Tasks</li>
</ul>
</div>
</div>

View file

@ -1,4 +1,3 @@
Template.mgmtPage.onCreated(function() {
});

View file

@ -0,0 +1,35 @@
<template name="taskForm">
<h4>Tasks</h4>
<div class="row">
<div class="col s12 m6 l4 input-field">
<input type="text" class="taskName" id="taskName" />
<label for="taskName">Task Name</label>
</div>
<div class="col s12 m6 l4 input-field">
<select name="taskUser" id="taskUser" class="taskUser">
<option value="" disabled selected>Assign to user...</option>
{{#each taskUsers}}
<option value="{{username}}">{{username}}</option>
{{/each}}
</select>
</div>
<div class="col s12 m6 l4 input-field">
<input type="text" class="datepicker" id="taskDate" />
<label for="taskDate">Task Date</label>
</div>
</div>
<div class="row">
<div class="col s12 m6 l6">
<p>
<label>
<input type="checkbox" id="hideCompletedTasks" />
<span>Hide Completed</span>
</label>
</p>
</div>
<div class="col s12 m6 l6">
<a class="waves-effect waves-light btn saveTaskMgmt green right">Add</a>
</div>
</div>
{{> snackbar}}
</template>

View file

@ -0,0 +1,79 @@
import { Tasks } from '../../../imports/api/tasks.js';
Template.taskForm.onCreated(function() {
this.subscribe("userList");
this.subscribe("allTasks");
});
Template.taskForm.onRendered(function() {
Meteor.setTimeout(function() {
$('select').formSelect();
}, 100);
$('select').formSelect();
$('.datepicker').datepicker();
Session.set("taskNameErr", false);
Session.set("taskUserErr", false);
Session.set("taskDateErr", false);
Session.set("hideCompletedTasks", true);
});
Template.taskForm.helpers({
taskUsers: function() {
return Meteor.users.find({});
},
username: function() {
return this.profile.fullname;
},
});
Template.taskForm.events({
'click .saveTaskMgmt' (event) {
event.preventDefault();
let taskName = $("#taskName").val();
let taskUser = $("#taskUser").val();
let taskDate = $("#taskDate").val();
let taskUserErr = false;
let taskNameErr = false;
let taskDateErr = false;
console.log("taskUser value: " + taskUser);
if (taskName == null || taskName == "") {
taskNameErr = true;
}
if (taskDate == null || taskDate == "") {
taskDateErr = true;
}
if (taskUser == null || taskUser == "") {
console.log("triggered taskUser error.");
taskUserErr = true;
}
if (taskUserErr == false && taskDateErr == false && taskNameErr == false) {
Meteor.call("add.task", taskName, taskUser, taskDate, function(err, result) {
if (err) {
console.log(" ERROR adding the new task: " + err);
} else {
console.log(" SUCCESS adding the new task.");
$("#taskName").val("");
$("#taskDate").val("");
$("#taskUser").val("");
$('select').formSelect();
}
});
} else {
showSnackbar("ERROR: Missing Required Fields!", "red");
}
},
'click #hideCompletedTasks' (event) {
let hideComp = $("#hideCompletedTasks").prop('checked');
if (hideComp == true) {
Session.set("hideCompletedTasks", true);
} else {
Session.set("hideCompletedTasks", false);
}
}
});

View file

@ -0,0 +1,5 @@
<template name="taskHome">
{{> taskForm}}
<hr>
{{> taskTbl}}
</template>

View file

@ -0,0 +1,38 @@
<template name="taskTbl">
<div class="row">
<div class="col s12">
<table class="highlight striped responsive-table">
<thead>
<tr>
<th>Task Name</th>
<th>Assigned To</th>
<th>Due</th>
<th>Done On</th>
<th>Complete</th>
</tr>
</thead>
<tbody>
{{#each tasks}}
<tr>
<td>{{taskName}}</td>
<td>{{assignedTo}}</td>
<td>{{taskDate}}</td>
<td>{{completeDate}}</td>
<td>
{{#if $eq isComplete true}}
<i class="material-icons green">check</i>
{{/if}}
</td>
<td>
<i class="material-icons clickable deleteTask">delete</i>
<i class="material-icons clickable markTaskComplete">check</i>
</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
</div>
{{> deleteConfirmationModal}}
{{> snackbar}}
</template>

View file

@ -0,0 +1,51 @@
import { TaskItems } from '../../../imports/api/tasks.js';
import moment from 'moment';
Template.taskTbl.onCreated(function() {
this.subscribe("allTasks");
});
Template.taskTbl.onRendered(function() {
Session.set("hideCompletedTasks", false);
});
Template.taskTbl.helpers({
tasks: function() {
let hideComp = Session.get("hideCompletedTasks");
if (hideComp == false) {
return TaskItems.find({});
} else {
return TaskItems.find({ isComplete: false });
}
},
completeDate: function() {
let completedOn = this.completedOn;
if (completedOn != null) {
let compOn = moment(completedOn).format("MMM DD, YYYY");
return compOn;
}
}
});
Template.taskTbl.events({
'click .deleteTask' (event) {
event.preventDefault();
Session.set("deleteId", this._id);
Session.set("method", "delete.task");
Session.set("item", this.taskName);
Session.set("view", "Tasks");
$('#modalDelete').modal('open');
},
'click .markTaskComplete' (event) {
event.preventDefault();
let taskId = this._id;
Meteor.call("markTask.complete", taskId, function(err, result) {
if (err) {
console.log(" ERROR marking task completeL " + err);
showSnackbar("ERROR Marking Task Complete!", "red");
} else {
showSnackbar("Successfully Marked Task Complete!", "green");
}
});
},
});

View file

@ -10,6 +10,7 @@
{{#if currentUser}}
<li><a href="#" id="mylists" class="navBtn">My Lists</a></li>
<li><a href="#" id="mymenus" class="navBtn">My Menus</a></li>
<li><a href="#" id="myTasks" class="navBtn">My Tasks</a></li>
{{#if isInRole 'systemadmin'}}
<li><a href="#" id="manage" class="navBtn">Manage</a></li>
{{/if}}
@ -24,6 +25,7 @@
{{#if currentUser}}
<li><a href="#!" id="mylists" class="navBtn">My Lists</a></li>
<li><a href="#!" id="mymenus" class="navBtn">My Menus</a></li>
<li><a href="#!" id="myTasks" class="navBtn">My Tasks</a></li>
{{#if isInRole 'systemadmin'}}
<li><a href="#!" id="manage" class="navBtn">Manage</a></li>
{{/if}}

View file

@ -0,0 +1,57 @@
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
export const RecipeItems = new Mongo.Collection('recipeitems');
RecipeItems.allow({
insert: function(userId, doc){
// if use id exists, allow insert
return !!userId;
},
});
Meteor.methods({
'add.recipeItem' (recipeId, recipeItemType, recipeItem) {
check(recipeId, String);
check(recipeItemType, String);
check(recipeItem, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to add recipe items. Make sure you are logged in with valid user credentials.');
}
return RecipeItems.insert({
recipeId: recipeId,
recipeItemType: recipeItemType,
recipeItem: recipeItem,
});
},
'edit.recipeItem' (recipeItemId, recipeId, recipeItemType, recipeItem) {
check(recipeItemId, String);
check(recipeId, String);
check(recipeItemType, String);
check(recipeItem, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to edit recipe items. Make sure you are logged in with valid user credentials.');
}
return RecipeItems.update({ _id: recipeItemId }, {
$set: {
recipeId: recipeId,
recipeItemType: recipeItemType,
recipeItem: recipeItem,
}
});
},
'delete.recipeItem' (recipeItemId) {
check(recipeItemId, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to delete recipe items. Make sure you are logged in with valid user credentials.');
}
return RecipeItems.remove({ _id: recipeItemId });
}
});

53
imports/api/recipes.js Normal file
View file

@ -0,0 +1,53 @@
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
export const Recipes = new Mongo.Collection('recipes');
Recipes.allow({
insert: function(userId, doc){
// if use id exists, allow insert
return !!userId;
},
});
Meteor.methods({
'add.recipe' (recipeName) {
check(recipeName, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to add recipes. Make sure you are logged in with valid user credentials.');
}
return Recipes.insert({
recipeName: recipeName,
addedBy: this.userId,
addedOn: new Date(),
});
},
'edit.recipe' (recipeId, recipeName) {
check(recipeId, String);
check(recipeName, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to add recipes. Make sure you are logged in with valid user credentials.');
}
return Recipes.update({ _id: recipeId }, {
$set: {
recipeName: recipeName,
updatedOn: new Date(),
updatedBy: this.userId,
}
});
},
'delete.recipe' (recipeId) {
check(recipeId, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to delete recipes. Make sure you are logged in with valid user credentials.');
}
return Recipes.remove({ _id: recipeId });
}
});

93
imports/api/tasks.js Normal file
View file

@ -0,0 +1,93 @@
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
export const TaskItems = new Mongo.Collection('taskitems');
TaskItems.allow({
insert: function(userId, doc){
// if use id exists, allow insert
return !!userId;
},
});
Meteor.methods({
'add.task' (taskName, assignedTo, taskDate) {
check(taskName, String);
check(assignedTo, String);
check(taskDate, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to add tasks. Make sure you are logged in with valid user credentials.');
}
return TaskItems.insert({
taskName: taskName,
taskDate: taskDate,
assignedTo: assignedTo,
isComplete: false,
completedOn: null,
assignedOn: new Date(),
assignedBy: this.userId,
});
},
'edit.task' (taskId, taskName, assignedTo, taskDate) {
check(taskId, String);
check(taskName, String);
check(assignedTo, String);
check(taskDate, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to edit tasks. Make sure you are logged in with valid user credentials.');
}
return TaskItems.update({ _id: taskId }, {
$set: {
taskName: taskName,
taskDate: taskDate,
assignedTo: assignedTo,
changedOn: new Date(),
changedBy: this.userId,
}
});
},
'delete.task' (taskId) {
check(taskId, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to delete tasks. Make sure you are logged in with valid user credentials.');
}
return TaskItems.remove({ _id: taskId });
},
'markTask.complete' (taskId) {
check(taskId, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to mark tasks complete. Make sure you are logged in with valid user credentials.');
}
return TaskItems.update({ _id: taskId }, {
$set: {
isComplete: true,
completedOn: new Date(),
completedBy: this.userId,
}
});
},
'markTask.notComplete' (taskId) {
check(taskId, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to mark tasks not complete. Make sure you are logged in with valid user credentials.');
}
return TaskItems.update({ _id: taskId }, {
$set: {
isComplete: false,
markedUncomplteOn: new Date(),
markedUncompleteBy: this.userId,
}
});
},
});

View file

@ -109,3 +109,10 @@ FlowRouter.route('/menuItems', {
BlazeLayout.render('MainLayout', { main: 'menuItems' });
}
});
FlowRouter.route('/taskHome', {
name: 'taskHome',
action() {
BlazeLayout.render('MainLayout', { main: 'taskHome' });
}
});

View file

@ -9,6 +9,7 @@ import { ListItems } from '../imports/api/listItems.js';
import { Menus } from '../imports/api/menu.js';
import { MenuItems } from '../imports/api/menuItems.js';
import moment from 'moment';
import { TaskItems } from '../imports/api/tasks.js';
Meteor.publish("SystemConfig", function() {
try {
@ -96,3 +97,11 @@ Meteor.publish("todayMenuItems", function() {
console.log(" ERROR pulling today's menu items: " + error);
}
});
Meteor.publish("allTasks", function() {
try {
return TaskItems.find({});
} catch (error) {
console.log(" ERROR pulling the task items: " + error);
}
});