Added the ability to create and edit students and staff. Still cannot delete.

This commit is contained in:
2022-08-21 11:13:19 -07:00
parent 8d4b72c581
commit 23838990d4
4 changed files with 66 additions and 14 deletions

View File

@@ -17,9 +17,14 @@ if (Meteor.isServer) {
}); });
} }
Meteor.methods({ Meteor.methods({
'staff.add'(firstName, lastName, email, siteId) { 'staff.add'(id, firstName, lastName, email, siteId) {
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) { if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
Staff.insert({firstName, lastName, email, siteId}); Staff.insert({id, firstName, lastName, email, siteId});
}
},
'staff.update'(_id, id, firstName, lastName, email, siteId) {
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
Staff.update({_id}, {$set: {id, firstName, lastName, email, siteId}});
} }
}, },
'staff.remove'(_id) { 'staff.remove'(_id) {

View File

@@ -4,6 +4,7 @@ import { check } from 'meteor/check';
import {Sites} from "./sites"; import {Sites} from "./sites";
import { Roles } from 'meteor/alanning:roles'; import { Roles } from 'meteor/alanning:roles';
import {parse} from 'csv-parse'; import {parse} from 'csv-parse';
import {Staff} from "/imports/api/staff";
// console.log("Setting Up Students...") // console.log("Setting Up Students...")
@@ -19,6 +20,21 @@ if (Meteor.isServer) {
}); });
Meteor.methods({ Meteor.methods({
'students.add'(id, firstName, lastName, email, siteId, grade) {
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
Students.insert({id, firstName, lastName, email, siteId, grade});
}
},
'students.update'(_id, id, firstName, lastName, email, siteId, grade) {
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
Students.update({_id}, {$set: {id, firstName, lastName, email, siteId, grade}});
}
},
'students.remove'(_id) {
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
//TODO: Need to first verify there are no checked out assets to the staff member.
}
},
'students.getPossibleGrades'() { 'students.getPossibleGrades'() {
return Students.rawCollection().distinct('grade', {}); return Students.rawCollection().distinct('grade', {});
}, },

View File

@@ -104,15 +104,17 @@
} }
let dirtyStaff; let dirtyStaff;
// Copy the edited value when ever it changes, set some defaults for a new value object (to make the view happy). // Copy the edited value when ever it changes, set some defaults for a new value object (to make the view happy).
editedStaff.subscribe(v => {dirtyStaff = Object.assign({email: "", firstName: "", lastName: ""}, v)}); editedStaff.subscribe(v => {dirtyStaff = Object.assign({id: "", email: "", firstName: "", lastName: "", siteId: selectedSiteId}, v)});
const deleteStaff = staff => { const deleteStaff = staff => {
//TODO: //TODO: We must first ensure we have no assets assigned to the staff member.
}; };
const applyStaffChanges = () => { const applyStaffChanges = () => {
if(dirtyStaff._id) if(dirtyStaff._id) {
Meteor.call("staff.update", dirtyStaff); Meteor.call("staff.update", dirtyStaff._id, dirtyStaff.id, dirtyStaff.firstName, dirtyStaff.lastName, dirtyStaff.email, dirtyStaff.siteId);
else }
Meteor.call("staff.add", dirtyStaff); else {
Meteor.call("staff.add", dirtyStaff.id, dirtyStaff.firstName, dirtyStaff.lastName, dirtyStaff.email, dirtyStaff.siteId);
}
editedStaff.set(null); editedStaff.set(null);
dirtyStaff = null; dirtyStaff = null;
} }
@@ -145,6 +147,10 @@
<GridTable bind:rows={staff} columns="{staffColumns}" actions="{staffActions}" rowKey="{(v) => {return v._id}}" bind:edited="{editedStaff}" on:selection={onStaffSelection}> <GridTable bind:rows={staff} columns="{staffColumns}" actions="{staffActions}" rowKey="{(v) => {return v._id}}" bind:edited="{editedStaff}" on:selection={onStaffSelection}>
{#if dirtyStaff} {#if dirtyStaff}
<div class="editorContainer"> <div class="editorContainer">
<div style="grid-column: 1/span 1">
<TextField type="number" style="width: 100%" bind:value={dirtyStaff.id} label="ID">
</TextField>
</div>
<div style="grid-column: 1/span 1"> <div style="grid-column: 1/span 1">
<TextField type="text" style="width: 100%" bind:value={dirtyStaff.email} label="Email"> <TextField type="text" style="width: 100%" bind:value={dirtyStaff.email} label="Email">
</TextField> </TextField>
@@ -157,6 +163,13 @@
<TextField type="text" style="width: 100%" bind:value={dirtyStaff.lastName} label="Last Name"> <TextField type="text" style="width: 100%" bind:value={dirtyStaff.lastName} label="Last Name">
</TextField> </TextField>
</div> </div>
<div style="grid-column: 1/span 1">
<Select bind:value={dirtyStaff.siteId} label="Site">
{#each $sites as site}
<Option value={site._id}>{site.name}</Option>
{/each}
</Select>
</div>
<button type="button" style="grid-column: 2/span 1;" class="button accept-button material-icons material-symbols-outlined" on:click={applyStaffChanges}> <button type="button" style="grid-column: 2/span 1;" class="button accept-button material-icons material-symbols-outlined" on:click={applyStaffChanges}>
check check

View File

@@ -58,6 +58,13 @@
const studentColumns = [ const studentColumns = [
{ {
key: "id",
title: "ID",
value: v => v.id,
minWidth: 100,
weight: 1,
cls: "id",
}, {
key: "email", key: "email",
title: "Email", title: "Email",
value: v => v.email, value: v => v.email,
@@ -80,9 +87,9 @@
cls: "lastName", cls: "lastName",
}, { }, {
key: "grade", key: "grade",
title: "Grade", title: "GRD",
value: v => v.grade, value: v => v.grade,
minWidth: 100, minWidth: 50,
weight: 1, weight: 1,
cls: "grade", cls: "grade",
}, },
@@ -103,15 +110,15 @@
} }
let dirtyStudent; let dirtyStudent;
// Copy the edited value when ever it changes, set some defaults for a new value object (to make the view happy). // Copy the edited value when ever it changes, set some defaults for a new value object (to make the view happy).
editedStudent.subscribe(v => {dirtyStudent = Object.assign({email: "", firstName: "", lastName: "", grade: ""}, v)}); editedStudent.subscribe(v => {dirtyStudent = Object.assign({id: "", email: "", firstName: "", lastName: "", grade: "", siteId: selectedSiteId}, v)});
const deleteStudent = student => { const deleteStudent = student => {
//TODO: //TODO: Need to ensure no assets are assigned to the student first.
}; };
const applyStudentChanges = () => { const applyStudentChanges = () => {
if(dirtyStudent._id) if(dirtyStudent._id)
Meteor.call("students.update", dirtyStudent); Meteor.call("students.update", dirtyStudent._id, dirtyStudent.id, dirtyStudent.firstName, dirtyStudent.lastName, dirtyStudent.email, dirtyStudent.siteId, dirtyStudent.grade);
else else
Meteor.call("students.add", dirtyStudent); Meteor.call("students.add", dirtyStudent.id, dirtyStudent.firstName, dirtyStudent.lastName, dirtyStudent.email, dirtyStudent.siteId, dirtyStudent.grade);
editedStudent.set(null); editedStudent.set(null);
dirtyStudent = null; dirtyStudent = null;
} }
@@ -143,6 +150,10 @@
<GridTable bind:rows={students} columns="{studentColumns}" actions="{studentsActions}" rowKey="{(v) => {return v._id}}" bind:edited="{editedStudent}" on:selection={onStudentSelection}> <GridTable bind:rows={students} columns="{studentColumns}" actions="{studentsActions}" rowKey="{(v) => {return v._id}}" bind:edited="{editedStudent}" on:selection={onStudentSelection}>
{#if dirtyStudent} {#if dirtyStudent}
<div class="editorContainer"> <div class="editorContainer">
<div style="grid-column: 1/span 1">
<TextField type="number" style="width: 100%" bind:value={dirtyStudent.id} label="Student ID">
</TextField>
</div>
<div style="grid-column: 1/span 1"> <div style="grid-column: 1/span 1">
<TextField type="text" style="width: 100%" bind:value={dirtyStudent.email} label="Email"> <TextField type="text" style="width: 100%" bind:value={dirtyStudent.email} label="Email">
</TextField> </TextField>
@@ -159,6 +170,13 @@
<TextField type="text" style="width: 100%" bind:value={dirtyStudent.grade} label="Grade"> <TextField type="text" style="width: 100%" bind:value={dirtyStudent.grade} label="Grade">
</TextField> </TextField>
</div> </div>
<div style="grid-column: 1/span 1">
<Select bind:value={dirtyStudent.siteId} label="Site">
{#each $sites as site}
<Option value={site._id}>{site.name}</Option>
{/each}
</Select>
</div>
<button type="button" style="grid-column: 2/span 1;" class="button accept-button material-icons material-symbols-outlined" on:click={applyStudentChanges}> <button type="button" style="grid-column: 2/span 1;" class="button accept-button material-icons material-symbols-outlined" on:click={applyStudentChanges}>
check check