From d09826dc5193f46431347c578616ba49cd11123c Mon Sep 17 00:00:00 2001 From: Wynne Crisman Date: Mon, 15 Aug 2022 16:18:01 -0700 Subject: [PATCH] Added information to the chromebook data. --- imports/api/data-collection.js | 47 +++++++++++++++++++++----------- imports/ui/App.svelte | 4 +-- imports/ui/Chromebooks.svelte | 49 +++++++++++++++++++++++++++++++--- 3 files changed, 78 insertions(+), 22 deletions(-) diff --git a/imports/api/data-collection.js b/imports/api/data-collection.js index 7d4f058..cf4e672 100644 --- a/imports/api/data-collection.js +++ b/imports/api/data-collection.js @@ -43,6 +43,16 @@ if (Meteor.isServer) { if(Roles.userIsInRole(Meteor.userId(), "laptop-management", {anyScope:true})) { let query = {}; + // For asset ID's, we need to get the serial from the asset collection first. + if(params.assetId) { + let asset = Assets.findOne({assetId : params.assetId}); + + if(asset) { + params.serial = asset.serial; + params.regex = false; + } + } + if (params.deviceId) query.deviceId = params.regex ? { $regex: params.deviceId, $options: "i" @@ -51,14 +61,14 @@ if (Meteor.isServer) { $regex: params.serial, $options: "i" } : params.serial; - else if (params.assetId) { - let asset = Assets.findOne({assetId: params.assetId}); - - if(asset.serial) { - // An exact search. - query.serial = asset.serial; - } - } + // else if (params.assetId) { + // let asset = Assets.findOne({assetId: params.assetId}); + // + // if(asset.serial) { + // // An exact search. + // query.serial = asset.serial; + // } + // } else if (params.email) query.email = params.regex ? { $regex: params.email, $options: "i" @@ -66,18 +76,23 @@ if (Meteor.isServer) { else if (params.date) { //Assume that date is a number. Finds all Chromebook Data with the last check in time greater than or equal to the given date. query.endTime = {'$gte': params.date} } + else { + query = undefined; + } - console.log("Collecting Chromebook Data: "); - console.log(query); + if(query) { + console.log("Collecting Chromebook Data: "); + console.log(query); - //Sort by the last time the record was updated from most to least recent. - let result = Meteor.Records.find(query, {sort: {endTime: -1}}).fetch(); - // console.log("Found: "); - // console.log(result); + //Sort by the last time the record was updated from most to least recent. + let result = Meteor.Records.find(query, {sort: {endTime: -1}}).fetch(); + // console.log("Found: "); + // console.log(result); - return result; + return result; + } else return null; } - else {return null;} + else return null; } // 'tasks.setChecked'(taskId, setChecked) { // check(taskId, String); diff --git a/imports/ui/App.svelte b/imports/ui/App.svelte index a73ca93..79b5626 100644 --- a/imports/ui/App.svelte +++ b/imports/ui/App.svelte @@ -64,10 +64,10 @@ Chromebooks {/if} {#if canManageLaptops} - Users Assets {/if} {#if isAdmin} + Users Admin {/if} @@ -82,7 +82,7 @@ - {#if isAdmin} + {#if canManageLaptops} {/if} diff --git a/imports/ui/Chromebooks.svelte b/imports/ui/Chromebooks.svelte index aa70546..62405ed 100644 --- a/imports/ui/Chromebooks.svelte +++ b/imports/ui/Chromebooks.svelte @@ -10,17 +10,28 @@ import DateInput from "./DateInput.svelte"; import Button, { Label } from '@smui/button'; import IconButton from '@smui/icon-button'; + import {onMount} from "svelte"; + import {Students} from "/imports/api/students"; + import {Staff} from "/imports/api/staff"; + import {AssetTypes} from "/imports/api/asset-types"; let serialInput = null; let emailInput = null; let dateInput = null; let assetIdInput = null; + onMount(async () => { + Meteor.subscribe('assets'); + Meteor.subscribe('students'); + Meteor.subscribe('staff'); + Meteor.subscribe('assetTypes'); + }); + function serialSearch() { router.goto("/chromebooks?serial=" + encodeURIComponent(serialInput) + "®ex=true"); } function assetIdSearch() { - router.goto("/chromebooks?assetId=" + encodeURIComponent(assetIdInput) + "®ex=true"); + router.goto("/chromebooks?assetId=" + encodeURIComponent(assetIdInput.toUpperCase()) + "®ex=false"); } function emailSearch() { router.goto("/chromebooks?email=" + encodeURIComponent(emailInput) + "®ex=true"); @@ -104,12 +115,31 @@ if(!date && regex) params.regex = true; - console.log("Calling DataCollection.chromebookData") - console.log(params); + // console.log("Calling DataCollection.chromebookData") + // console.log(params); Meteor.call("DataCollection.chromebookData", params, (error, result) => { if (error) { console.error(error); } else { + for(let next of result) { + if(next.assetId) { + next.asset = Assets.findOne({assetId: next.assetId}); + } + if(next.email) { + next.person = Students.findOne({email: next.email}); + + if(!next.person) next.person = Staff.findOne({email: next.email}); + } + + if(next.asset) { + next.assetType = AssetTypes.findOne({_id: next.asset.assetType}) + + if(next.asset.assigneeId) { + next.assignedTo = next.asset.assigneeType === "Student" ? Students.findOne({_id: next.asset.assigneeId}) : Staff.findOne({_id: next.asset.assigneeId}) + } + } + } + chromebookData = result; } }); @@ -126,10 +156,21 @@