Reorganized assignment UI. Added searching by person.

This commit is contained in:
2022-08-16 07:39:15 -07:00
parent 571f3da1d6
commit 1501a36801
9 changed files with 3816 additions and 198 deletions

View File

@@ -3,6 +3,9 @@ import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check'; import { check } from 'meteor/check';
import { MongoClient } from 'mongodb'; import { MongoClient } from 'mongodb';
import {Assets} from "/imports/api/assets"; import {Assets} from "/imports/api/assets";
import {Students} from "/imports/api/students";
import {Staff} from "/imports/api/staff";
import {AssetTypes} from "/imports/api/asset-types";
//import {Roles} from 'alanning/roles'; //import {Roles} from 'alanning/roles';
// console.log("Setting Up Data Collection...") // console.log("Setting Up Data Collection...")
@@ -81,13 +84,34 @@ if (Meteor.isServer) {
} }
if(query) { if(query) {
console.log("Collecting Chromebook Data: "); // console.log("Collecting Chromebook Data: ");
console.log(query); // console.log(query);
//Sort by the last time the record was updated from most to least recent. //Sort by the last time the record was updated from most to least recent.
let result = Meteor.Records.find(query, {sort: {endTime: -1}}).fetch(); let result = Meteor.Records.find(query, {sort: {endTime: -1}}).fetch();
// console.log("Found: "); // console.log("Found: ");
// console.log(result); // console.log(result);
//Add some additional data to the records.
for (let next of result) {
if (next.serial) {
next.asset = Assets.findOne({serial: next.serial});
}
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})
}
}
}
return result; return result;
} else return null; } else return null;

View File

@@ -12,7 +12,8 @@ export const Staff = new Mongo.Collection('staff');
if (Meteor.isServer) { if (Meteor.isServer) {
// This code only runs on the server // This code only runs on the server
Meteor.publish('staff', function(siteId) { Meteor.publish('staff', function(siteId) {
return Staff.find({siteId}); if(siteId) check(siteId, String);
return siteId ? Staff.find({siteId}) : Staff.find({});
}); });
} }
Meteor.methods({ Meteor.methods({

View File

@@ -14,7 +14,8 @@ if (Meteor.isServer) {
// This code only runs on the server // This code only runs on the server
Meteor.publish('students', function(siteId) { Meteor.publish('students', function(siteId) {
return Students.find({siteId}); if(siteId) check(siteId, String);
return siteId ? Students.find({siteId}) : Students.find({});
}); });
Meteor.methods({ Meteor.methods({

View File

@@ -9,12 +9,14 @@
import Admin from './Admin.svelte'; import Admin from './Admin.svelte';
import Announcer from './Announcer.svelte'; import Announcer from './Announcer.svelte';
import Assets from "./Assets.svelte"; import Assets from "./Assets.svelte";
import Assignments from "/imports/ui/Assignments.svelte";
// When the URL changes, run the code... in this case to scroll to the top. // When the URL changes, run the code... in this case to scroll to the top.
router.subscribe(_ => window.scrollTo(0, 0)); router.subscribe(_ => window.scrollTo(0, 0));
let canManageLaptops = false; let canManageLaptops = false;
let isAdmin = false; let isAdmin = false;
let currentUser
$: currentUser = useTracker(() => Meteor.user()); $: currentUser = useTracker(() => Meteor.user());
Tracker.autorun(() => { Tracker.autorun(() => {
@@ -62,11 +64,10 @@
<a href="/">Home</a> <a href="/">Home</a>
{#if canManageLaptops} {#if canManageLaptops}
<a href="/chromebooks">Chromebooks</a> <a href="/chromebooks">Chromebooks</a>
{/if} <a href="/assignments">Assignments</a>
{#if canManageLaptops}
<a href="/assets">Assets</a>
{/if} {/if}
{#if isAdmin} {#if isAdmin}
<a href="/assets">Assets</a>
<a href="/users">Users</a> <a href="/users">Users</a>
<a href="/admin">Admin</a> <a href="/admin">Admin</a>
{/if} {/if}
@@ -81,8 +82,13 @@
</div> </div>
</div> </div>
</Route> </Route>
<Route path="/assets"> <Route path="/assignments">
{#if canManageLaptops} {#if canManageLaptops}
<Assignments/>
{/if}
</Route>
<Route path="/assets">
{#if isAdmin}
<Assets/> <Assets/>
{/if} {/if}
</Route> </Route>

View File

@@ -2,16 +2,13 @@
import Tab, { Label } from '@smui/tab'; import Tab, { Label } from '@smui/tab';
import TabBar from '@smui/tab-bar'; import TabBar from '@smui/tab-bar';
import {Meteor} from "meteor/meteor"; import {Meteor} from "meteor/meteor";
import {onMount} from "svelte";
import AssetList from "/imports/ui/Assets/AssetList.svelte"; import AssetList from "/imports/ui/Assets/AssetList.svelte";
import AddAssets from "/imports/ui/Assets/AddAssets.svelte"; import AddAssets from "/imports/ui/Assets/AddAssets.svelte";
import {useTracker} from "meteor/rdb:svelte-meteor-data"; import {useTracker} from "meteor/rdb:svelte-meteor-data";
import AssignAssets from "/imports/ui/Assets/AssignAssets.svelte";
import AssignmentByAssignee from "/imports/ui/Assets/AssignmentByAssignee.svelte";
import AssignmentByAsset from "/imports/ui/Assets/AssignmentByAsset.svelte";
let canManageLaptops = false; let canManageLaptops = false;
let isAdmin = false; let isAdmin = false;
let currentUser
$: currentUser = useTracker(() => Meteor.user()); $: currentUser = useTracker(() => Meteor.user());
Tracker.autorun(() => { Tracker.autorun(() => {
@@ -23,11 +20,6 @@
let tabs = []; let tabs = [];
if(canManageLaptops) {
tabs.push({id: 'listAssignmentsByAssignee', label: 'Assignments By Assignee'});
tabs.push({id: 'listAssignmentsByAsset', label: 'Assignments By Asset'});
tabs.push({id: 'assignAssets', label: 'Assign Assets'});
}
if(isAdmin) { if(isAdmin) {
tabs.push({id: 'listAssets', label: 'Asset List'}); tabs.push({id: 'listAssets', label: 'Asset List'});
tabs.push({id: 'addAssets', label: 'Add Assets'}); tabs.push({id: 'addAssets', label: 'Add Assets'});
@@ -45,12 +37,6 @@
<AssetList></AssetList> <AssetList></AssetList>
{:else if activeTab && activeTab.id === 'addAssets'} {:else if activeTab && activeTab.id === 'addAssets'}
<AddAssets></AddAssets> <AddAssets></AddAssets>
{:else if activeTab && activeTab.id === 'assignAssets'}
<AssignAssets></AssignAssets>
{:else if activeTab && activeTab.id === 'listAssignmentsByAssignee'}
<AssignmentByAssignee></AssignmentByAssignee>
{:else if activeTab && activeTab.id === 'listAssignmentsByAsset'}
<AssignmentByAsset></AssignmentByAsset>
{/if} {/if}
</div> </div>

View File

@@ -0,0 +1,51 @@
<script>
import Tab, { Label } from '@smui/tab';
import TabBar from '@smui/tab-bar';
import {Meteor} from "meteor/meteor";
import {useTracker} from "meteor/rdb:svelte-meteor-data";
import AssignAssets from "/imports/ui/Assignments/AssignAssets.svelte";
import AssignmentByAssignee from "/imports/ui/Assignments/AssignmentByAssignee.svelte";
import AssignmentByAsset from "/imports/ui/Assignments/AssignmentByAsset.svelte";
import AssignmentByPerson from "/imports/ui/Assignments/AssignmentByPerson.svelte";
let canManageLaptops = false;
let isAdmin = false;
$: currentUser = useTracker(() => Meteor.user());
Tracker.autorun(() => {
// For some reason currentUser is always null here, and is not reactive (user changes and this does not get re-called).
let user = Meteor.user();
canManageLaptops = user && Roles.userIsInRole(user._id, 'laptop-management', 'global');
isAdmin = user && Roles.userIsInRole(user._id, 'admin', 'global');
});
let tabs = [];
if(canManageLaptops) {
// tabs.push({id: 'listAssignmentsByAssignee', label: 'Assignments By Assignee'});
tabs.push({id: 'listAssignmentsByPerson', label: 'By Person'});
tabs.push({id: 'listAssignmentsByAsset', label: 'By Asset'});
tabs.push({id: 'assignAssets', label: 'Assign Assets'});
}
let activeTab = tabs[0];
</script>
<div class="container">
<TabBar tabs={tabs} minWidth let:tab bind:active={activeTab}>
<Tab {tab}>
<Label>{tab.label}</Label>
</Tab>
</TabBar>
{#if activeTab && activeTab.id === 'assignAssets'}
<AssignAssets></AssignAssets>
{:else if activeTab && activeTab.id === 'listAssignmentsByAssignee'}
<AssignmentByAssignee></AssignmentByAssignee>
{:else if activeTab && activeTab.id === 'listAssignmentsByPerson'}
<AssignmentByPerson></AssignmentByPerson>
{:else if activeTab && activeTab.id === 'listAssignmentsByAsset'}
<AssignmentByAsset></AssignmentByAsset>
{/if}
</div>
<style>
</style>

View File

@@ -9,97 +9,49 @@
import List, {Item, Graphic, Meta, Text, PrimaryText, SecondaryText} from '@smui/list'; import List, {Item, Graphic, Meta, Text, PrimaryText, SecondaryText} from '@smui/list';
import Paper from '@smui/paper'; import Paper from '@smui/paper';
import LayoutGrid, {Cell} from '@smui/layout-grid'; import LayoutGrid, {Cell} from '@smui/layout-grid';
import {Assets} from "/imports/api/assets";
import {AssetTypes} from "/imports/api/asset-types";
let grades = ['Staff', 'All Grades'];
onMount(async () => { onMount(async () => {
Meteor.subscribe('sites'); Meteor.subscribe('students');
Meteor.call('students.getPossibleGrades', (err, result) => { Meteor.subscribe('staff');
if(err) console.log(err); Meteor.subscribe('assets');
else { Meteor.subscribe('assetTypes');
grades = ['Staff', 'All Grades', ...result];
}
});
}); });
// Load the sites (reactive).
let sites = Sites.find({});
let selectedSiteId; let selectedSiteId;
let categories = ['Asset ID', 'Email', 'First Name', 'Last Name']; let categories = ['Email', 'First Name', 'Last Name'];
let selectedCategory = 'Email'; let selectedCategory = 'Email';
let selectedGrade = 'All Grades';
let searchText = ""; let searchText = "";
let searchResults; let staffSearchResults;
let selectedResult; let studentSearchResults;
$: { $: {
console.log("Site ID") if(searchText && searchText.length > 1) {
console.log(selectedSiteId) let query = {};
if(selectedSiteId) { if (selectedCategory === 'Email') {
Meteor.subscribe('students', selectedSiteId); query.email = {$regex: searchText, $options: 'i'};
Meteor.subscribe('staff', selectedSiteId); } else if (selectedCategory === 'First Name') {
} query.firstName = {$regex: searchText, $options: 'i'};
} else {
query.lastName = {$regex: searchText, $options: 'i'};
}
staffSearchResults = Staff.find(query);
studentSearchResults = Students.find(query);
}
else {
staffSearchResults = undefined;
studentSearchResults = undefined;
}
} }
$: { const assignedAssets = (person) => {
selectedResult = null; let result = Assets.find({assigneeId: person._id}).fetch();
console.log("Starting search")
for(next of result) {
// Require at least two characters in the search field before we start filtering. next.type = AssetTypes.findOne({_id: next.assetTypeId})
if(selectedSiteId && selectedGrade && selectedCategory) { }
let query = {};
let queryType = (selectedGrade === "Staff") ? 1 : 0; return result;
if(searchText && searchText.length > 0) {
if (selectedCategory === 'Email') {
query.email = {$regex: searchText, $options: 'i'};
} else if( selectedCategory === 'Asset ID') {
//Do not do anything yet...
} else if (selectedCategory === 'First Name') {
query.firstName = {$regex: searchText, $options: 'i'};
} else {
query.lastName = {$regex: searchText, $options: 'i'};
}
}
if(selectedCategory === 'Asset ID') {
Meteor.call('AssetAssignments.getOne', searchText, (err, result) => {
if(err) {
console.error(err);
}
else {
if(result && result.assigneeType && result.assigneeId) {
if (result.assigneeType === 'Staff') {
query._id = result.assigneeId;
queryType = 1;
} else if (result.assigneeType === 'Student') {
query._id = result.assigneeId;
queryType = 0;
} else {
console.error("Invalid AssigneeType");
}
}
else {
console.error('Invalid result from AssetAssignments.getOne');
}
}
});
}
if(queryType === 1) {
searchResults = Staff.find(query);
}
else {
if(selectedGrade !== 'All Grades') {
query.grade = selectedGrade;
}
// console.log("Searching")
// console.log(query)
searchResults = Students.find(query);
}
}
else {
searchResults = undefined;
}
} }
</script> </script>
@@ -108,20 +60,6 @@
<Paper> <Paper>
<LayoutGrid> <LayoutGrid>
<Cell span="{6}">
<Select bind:value={selectedSiteId} label="Site">
{#each $sites as site}
<Option value={site._id}>{site.name}</Option>
{/each}
</Select>
</Cell>
<Cell span="{6}">
<Select bind:value={selectedGrade} label="Grade">
{#each grades as grade}
<Option value={grade}>{grade}</Option>
{/each}
</Select>
</Cell>
<Cell span="{6}"> <Cell span="{6}">
<Select bind:value={selectedCategory} label="Category"> <Select bind:value={selectedCategory} label="Category">
{#each categories as category} {#each categories as category}
@@ -143,18 +81,38 @@
<!-- <Label style="color: white">Create</Label>--> <!-- <Label style="color: white">Create</Label>-->
<!-- </Button>--> <!-- </Button>-->
</div> </div>
<List twoLine singleSelection> {#if staffSearchResults}
{#if searchResults} <ul>
{#each $searchResults as result} {#each $staffSearchResults as next}
<Item selected={selectedResult === result}> <li>
<Text> {next.firstName} {next.lastName} ({next.email})
<PrimaryText>{result.firstName} {result.lastName}</PrimaryText> <div style="margin-left: 2rem">
<SecondaryText>{result.email} {result.grade ? '(' + result.grade + ')' : ""}</SecondaryText> {#each (assignedAssets(next)) as asset}
</Text> Type: {asset.type.name}<br/>
</Item> AssetId: {asset.assetId}<br/>
{/each} Serial: {asset.serial}<br/>
{/if} {/each}
</List> </div>
</li>
{/each}
</ul>
{/if}
{#if studentSearchResults}
<ul>
{#each $studentSearchResults as next}
<li>
{next.firstName} {next.lastName} ~ {next.grade} ({next.email})
<div style="margin-left: 2rem">
{#each (assignedAssets(next)) as asset}
Type: {asset.type.name}<br/>
AssetId: {asset.assetId}<br/>
Serial: {asset.serial}<br/>
{/each}
</div>
</li>
{/each}
</ul>
{/if}
</div> </div>
<style> <style>

View File

@@ -14,6 +14,7 @@
import {Students} from "/imports/api/students"; import {Students} from "/imports/api/students";
import {Staff} from "/imports/api/staff"; import {Staff} from "/imports/api/staff";
import {AssetTypes} from "/imports/api/asset-types"; import {AssetTypes} from "/imports/api/asset-types";
import {Assets} from "/imports/api/assets";
let serialInput = null; let serialInput = null;
let emailInput = null; let emailInput = null;
@@ -104,7 +105,7 @@
}); });
let chromebookData = null; let chromebookData = null;
$: { $: {
if(deviceId || serial || email || date) { if(deviceId || assetId || serial || email || date) {
let params = {}; let params = {};
if(deviceId) params.deviceId = deviceId; if(deviceId) params.deviceId = deviceId;
@@ -121,25 +122,6 @@
if (error) { if (error) {
console.error(error); console.error(error);
} else { } 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; chromebookData = result;
} }
}); });
@@ -148,6 +130,8 @@
chromebookData = null; chromebookData = null;
} }
} }
</script> </script>
<Route path="/" let:meta> <Route path="/" let:meta>
@@ -158,18 +142,19 @@
{#each chromebookData as data} {#each chromebookData as data}
<li> <li>
{#if data.person} {#if data.person}
{data.person.firstName} {data.person.lastName} (<a href="/chromebooks?email={encodeURIComponent(data.email)}">{data.email}</a>)<br/> User: {data.person.firstName} {data.person.lastName} {#if data.person.grade} ~ {data.person.grade}{/if} (<a href="/chromebooks?email={encodeURIComponent(data.email)}">{data.email}</a>)<br/>
{:else} {:else}
<a href="/chromebooks?email={encodeURIComponent(data.email)}">{data.email}</a><br/> User: <a href="/chromebooks?email={encodeURIComponent(data.email)}">{data.email}</a><br/>
{/if} {/if}
<a href="/chromebooks?deviceId={encodeURIComponent(data.deviceId)}">{data.deviceId}</a><br/> Device ID: <a href="/chromebooks?deviceId={encodeURIComponent(data.deviceId)}">{data.deviceId}</a><br/>
<a href="/chromebooks?serial={encodeURIComponent(data.serial)}">{data.serial}</a><br/> Serial: <a href="/chromebooks?serial={encodeURIComponent(data.serial)}">{data.serial}</a><br/>
{#if data.asset}Asset ID: <a href="/chromebooks?assetId={encodeURIComponent(data.assetId)}">{data.asset.assetId}</a><br/>{/if}
{new Date(data.startTime).toLocaleDateString("en-US") + "-" + new Date(data.endTime).toLocaleDateString("en-US")} {new Date(data.startTime).toLocaleDateString("en-US") + "-" + new Date(data.endTime).toLocaleDateString("en-US")}
{#if data.assetType} {#if data.assetType}
<br/>Asset Type: {data.assetType.name} <br/>Asset Type: {data.assetType.name}
{/if} {/if}
{#if data.assignedTo} {#if data.assignedTo}
<br/>Currently assigned to: {next.assignedTo.firstName} {next.assignedTo.lastName} ({next.assignedTo.email}) <br/>Currently assigned to: {data.assignedTo.firstName} {data.assignedTo.lastName} {#if data.assignedTo.grade} ~ {data.assignedTo.grade}{/if} ({data.assignedTo.email})
{/if} {/if}
</li> </li>
{/each} {/each}

3690
package-lock.json generated

File diff suppressed because it is too large Load Diff