Added the ability to create and edit students and staff. Still cannot delete.
This commit is contained in:
@@ -17,9 +17,14 @@ if (Meteor.isServer) {
|
||||
});
|
||||
}
|
||||
Meteor.methods({
|
||||
'staff.add'(firstName, lastName, email, siteId) {
|
||||
'staff.add'(id, firstName, lastName, email, siteId) {
|
||||
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) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import { check } from 'meteor/check';
|
||||
import {Sites} from "./sites";
|
||||
import { Roles } from 'meteor/alanning:roles';
|
||||
import {parse} from 'csv-parse';
|
||||
import {Staff} from "/imports/api/staff";
|
||||
|
||||
// console.log("Setting Up Students...")
|
||||
|
||||
@@ -19,6 +20,21 @@ if (Meteor.isServer) {
|
||||
});
|
||||
|
||||
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'() {
|
||||
return Students.rawCollection().distinct('grade', {});
|
||||
},
|
||||
|
||||
@@ -104,15 +104,17 @@
|
||||
}
|
||||
let dirtyStaff;
|
||||
// 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 => {
|
||||
//TODO:
|
||||
//TODO: We must first ensure we have no assets assigned to the staff member.
|
||||
};
|
||||
const applyStaffChanges = () => {
|
||||
if(dirtyStaff._id)
|
||||
Meteor.call("staff.update", dirtyStaff);
|
||||
else
|
||||
Meteor.call("staff.add", dirtyStaff);
|
||||
if(dirtyStaff._id) {
|
||||
Meteor.call("staff.update", dirtyStaff._id, dirtyStaff.id, dirtyStaff.firstName, dirtyStaff.lastName, dirtyStaff.email, dirtyStaff.siteId);
|
||||
}
|
||||
else {
|
||||
Meteor.call("staff.add", dirtyStaff.id, dirtyStaff.firstName, dirtyStaff.lastName, dirtyStaff.email, dirtyStaff.siteId);
|
||||
}
|
||||
editedStaff.set(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}>
|
||||
{#if dirtyStaff}
|
||||
<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">
|
||||
<TextField type="text" style="width: 100%" bind:value={dirtyStaff.email} label="Email">
|
||||
</TextField>
|
||||
@@ -157,6 +163,13 @@
|
||||
<TextField type="text" style="width: 100%" bind:value={dirtyStaff.lastName} label="Last Name">
|
||||
</TextField>
|
||||
</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}>
|
||||
check
|
||||
|
||||
@@ -58,6 +58,13 @@
|
||||
|
||||
const studentColumns = [
|
||||
{
|
||||
key: "id",
|
||||
title: "ID",
|
||||
value: v => v.id,
|
||||
minWidth: 100,
|
||||
weight: 1,
|
||||
cls: "id",
|
||||
}, {
|
||||
key: "email",
|
||||
title: "Email",
|
||||
value: v => v.email,
|
||||
@@ -80,9 +87,9 @@
|
||||
cls: "lastName",
|
||||
}, {
|
||||
key: "grade",
|
||||
title: "Grade",
|
||||
title: "GRD",
|
||||
value: v => v.grade,
|
||||
minWidth: 100,
|
||||
minWidth: 50,
|
||||
weight: 1,
|
||||
cls: "grade",
|
||||
},
|
||||
@@ -103,15 +110,15 @@
|
||||
}
|
||||
let dirtyStudent;
|
||||
// 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 => {
|
||||
//TODO:
|
||||
//TODO: Need to ensure no assets are assigned to the student first.
|
||||
};
|
||||
const applyStudentChanges = () => {
|
||||
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
|
||||
Meteor.call("students.add", dirtyStudent);
|
||||
Meteor.call("students.add", dirtyStudent.id, dirtyStudent.firstName, dirtyStudent.lastName, dirtyStudent.email, dirtyStudent.siteId, dirtyStudent.grade);
|
||||
editedStudent.set(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}>
|
||||
{#if dirtyStudent}
|
||||
<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">
|
||||
<TextField type="text" style="width: 100%" bind:value={dirtyStudent.email} label="Email">
|
||||
</TextField>
|
||||
@@ -159,6 +170,13 @@
|
||||
<TextField type="text" style="width: 100%" bind:value={dirtyStudent.grade} label="Grade">
|
||||
</TextField>
|
||||
</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}>
|
||||
check
|
||||
|
||||
Reference in New Issue
Block a user