Added new models. Major changes to the table widget. Still has problems with the editing in the table widget.
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import "./users.js";
|
||||
import "./data-collection.js";
|
||||
import "./admin.js";
|
||||
import "./students.js";
|
||||
import "./rooms.js";
|
||||
import "./sites.js";
|
||||
|
||||
24
imports/api/rooms.js
Normal file
24
imports/api/rooms.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import {Mongo} from "meteor/mongo";
|
||||
import {Meteor} from "meteor/meteor";
|
||||
|
||||
export const Rooms = new Mongo.Collection('rooms');
|
||||
|
||||
if (Meteor.isServer) {
|
||||
// This code only runs on the server
|
||||
Meteor.publish('rooms', function(siteId) {
|
||||
return Rooms.find({siteId});
|
||||
});
|
||||
}
|
||||
Meteor.methods({
|
||||
'rooms.add'(name, siteId) {
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
Rooms.insert({name, siteId});
|
||||
}
|
||||
},
|
||||
'rooms.remove'(_id) {
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
//TODO: Need to first verify there are no checked out assets to the room.
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
37
imports/api/sites.js
Normal file
37
imports/api/sites.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import {Mongo} from "meteor/mongo";
|
||||
import {Meteor} from "meteor/meteor";
|
||||
import {Students} from "./students";
|
||||
import {Rooms} from "./rooms";
|
||||
|
||||
export const Sites = new Mongo.Collection('sites');
|
||||
|
||||
if (Meteor.isServer) {
|
||||
// This code only runs on the server
|
||||
Meteor.publish('sites', function() {
|
||||
return Sites.find({});
|
||||
});
|
||||
}
|
||||
Meteor.methods({
|
||||
'sites.update'(_id, name) {
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
Sites.update({_id}, {$set: {name}});
|
||||
}
|
||||
},
|
||||
'sites.add'(name) {
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
Sites.insert({name});
|
||||
}
|
||||
},
|
||||
'sites.remove'(_id) {
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
let site = Sites.find({_id});
|
||||
|
||||
if(site) {
|
||||
//Clear any site references in student/room entries.
|
||||
Students.update({siteId: _id}, {$unset: {siteId: 1}});
|
||||
Rooms.update({siteId: _id}, {$unset: {siteId: 1}});
|
||||
Sites.remove({_id});
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
66
imports/api/students.js
Normal file
66
imports/api/students.js
Normal file
@@ -0,0 +1,66 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
import { check } from 'meteor/check';
|
||||
import {Sites} from "./sites";
|
||||
|
||||
export const Students = new Mongo.Collection('students');
|
||||
|
||||
if (Meteor.isServer) {
|
||||
// This code only runs on the server
|
||||
Meteor.publish('students', function(siteId) {
|
||||
return Students.find({siteId});
|
||||
});
|
||||
}
|
||||
|
||||
Meteor.methods({
|
||||
/**
|
||||
* Expects the CSV string to contain comma delimited data in the form:
|
||||
* email, student ID, first name, last name, grade, first name alias, last name alias
|
||||
*
|
||||
* The query in Aeries is: `LIST STU SEM ID FN LN GR FNA LNA`.
|
||||
* The query in SQL is: `SELECT [STU].[SEM] AS [StuEmail], [STU].[ID] AS [Student ID], STU.FN AS [First Name], STU.LN AS [Last Name], [STU].[GR] AS [Grade], [STU].[FNA] AS [First Name Alias], [STU].[LNA] AS [Last Name Alias] FROM (SELECT [STU].* FROM STU WHERE [STU].DEL = 0) STU WHERE ( [STU].SC = 5) ORDER BY [STU].[LN], [STU].[FN];`.
|
||||
* Run the query in Aeries as a `Report`, select TXT, and upload here.
|
||||
*
|
||||
* Aeries adds a header per 'page' of data (I think 35 entries per page).
|
||||
* Example:
|
||||
* Anderson Valley Jr/Sr High School,6/11/2022
|
||||
* 2021-2022,Page 1
|
||||
* StuEmail,Student ID,First Name,Last Name,Grade,First Name Alias,Last Name Alias
|
||||
*/
|
||||
'students.loadCsv'(csv, siteId) {
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
check(csv, String);
|
||||
check(siteId, String);
|
||||
|
||||
let site = Sites.find({_id: siteId});
|
||||
|
||||
if(site) {
|
||||
let lines = csv.split(/\r?\n/);
|
||||
let pageHeader = lines[0];
|
||||
let skip;
|
||||
|
||||
for (const line of lines) {
|
||||
if (skip > 0) skip--;
|
||||
else if (line === pageHeader) {
|
||||
skip = 2;
|
||||
} else {
|
||||
let values = line.split(/\s*,\s*/);
|
||||
let email = values[0];
|
||||
let id = values[1];
|
||||
let firstName = values[2];
|
||||
let lastName = values[3];
|
||||
let grade = values[4];
|
||||
let firstNameAlias = values[5];
|
||||
let lastNameAlias = values[6];
|
||||
let student = {email, id, firstName, lastName, grade, firstNameAlias, lastNameAlias};
|
||||
|
||||
console.log(student);
|
||||
|
||||
//TODO: Find existing student. Update student, and move them to the new site.
|
||||
//TODO: Create student if none exists.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user