Reorganized assignment UI. Added searching by person.
This commit is contained in:
@@ -3,6 +3,9 @@ import { Mongo } from 'meteor/mongo';
|
||||
import { check } from 'meteor/check';
|
||||
import { MongoClient } from 'mongodb';
|
||||
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';
|
||||
|
||||
// console.log("Setting Up Data Collection...")
|
||||
@@ -81,13 +84,34 @@ if (Meteor.isServer) {
|
||||
}
|
||||
|
||||
if(query) {
|
||||
console.log("Collecting Chromebook Data: ");
|
||||
console.log(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);
|
||||
|
||||
//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;
|
||||
} else return null;
|
||||
|
||||
@@ -12,7 +12,8 @@ export const Staff = new Mongo.Collection('staff');
|
||||
if (Meteor.isServer) {
|
||||
// This code only runs on the server
|
||||
Meteor.publish('staff', function(siteId) {
|
||||
return Staff.find({siteId});
|
||||
if(siteId) check(siteId, String);
|
||||
return siteId ? Staff.find({siteId}) : Staff.find({});
|
||||
});
|
||||
}
|
||||
Meteor.methods({
|
||||
|
||||
@@ -14,7 +14,8 @@ if (Meteor.isServer) {
|
||||
|
||||
// This code only runs on the server
|
||||
Meteor.publish('students', function(siteId) {
|
||||
return Students.find({siteId});
|
||||
if(siteId) check(siteId, String);
|
||||
return siteId ? Students.find({siteId}) : Students.find({});
|
||||
});
|
||||
|
||||
Meteor.methods({
|
||||
|
||||
@@ -9,12 +9,14 @@
|
||||
import Admin from './Admin.svelte';
|
||||
import Announcer from './Announcer.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.
|
||||
router.subscribe(_ => window.scrollTo(0, 0));
|
||||
|
||||
let canManageLaptops = false;
|
||||
let isAdmin = false;
|
||||
let currentUser
|
||||
$: currentUser = useTracker(() => Meteor.user());
|
||||
|
||||
Tracker.autorun(() => {
|
||||
@@ -62,11 +64,10 @@
|
||||
<a href="/">Home</a>
|
||||
{#if canManageLaptops}
|
||||
<a href="/chromebooks">Chromebooks</a>
|
||||
{/if}
|
||||
{#if canManageLaptops}
|
||||
<a href="/assets">Assets</a>
|
||||
<a href="/assignments">Assignments</a>
|
||||
{/if}
|
||||
{#if isAdmin}
|
||||
<a href="/assets">Assets</a>
|
||||
<a href="/users">Users</a>
|
||||
<a href="/admin">Admin</a>
|
||||
{/if}
|
||||
@@ -81,8 +82,13 @@
|
||||
</div>
|
||||
</div>
|
||||
</Route>
|
||||
<Route path="/assets">
|
||||
<Route path="/assignments">
|
||||
{#if canManageLaptops}
|
||||
<Assignments/>
|
||||
{/if}
|
||||
</Route>
|
||||
<Route path="/assets">
|
||||
{#if isAdmin}
|
||||
<Assets/>
|
||||
{/if}
|
||||
</Route>
|
||||
|
||||
@@ -2,16 +2,13 @@
|
||||
import Tab, { Label } from '@smui/tab';
|
||||
import TabBar from '@smui/tab-bar';
|
||||
import {Meteor} from "meteor/meteor";
|
||||
import {onMount} from "svelte";
|
||||
import AssetList from "/imports/ui/Assets/AssetList.svelte";
|
||||
import AddAssets from "/imports/ui/Assets/AddAssets.svelte";
|
||||
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 isAdmin = false;
|
||||
let currentUser
|
||||
$: currentUser = useTracker(() => Meteor.user());
|
||||
|
||||
Tracker.autorun(() => {
|
||||
@@ -23,11 +20,6 @@
|
||||
|
||||
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) {
|
||||
tabs.push({id: 'listAssets', label: 'Asset List'});
|
||||
tabs.push({id: 'addAssets', label: 'Add Assets'});
|
||||
@@ -45,12 +37,6 @@
|
||||
<AssetList></AssetList>
|
||||
{:else if activeTab && activeTab.id === '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}
|
||||
</div>
|
||||
|
||||
|
||||
@@ -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>
|
||||
@@ -9,97 +9,49 @@
|
||||
import List, {Item, Graphic, Meta, Text, PrimaryText, SecondaryText} from '@smui/list';
|
||||
import Paper from '@smui/paper';
|
||||
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 () => {
|
||||
Meteor.subscribe('sites');
|
||||
Meteor.call('students.getPossibleGrades', (err, result) => {
|
||||
if(err) console.log(err);
|
||||
else {
|
||||
grades = ['Staff', 'All Grades', ...result];
|
||||
}
|
||||
});
|
||||
Meteor.subscribe('students');
|
||||
Meteor.subscribe('staff');
|
||||
Meteor.subscribe('assets');
|
||||
Meteor.subscribe('assetTypes');
|
||||
});
|
||||
// Load the sites (reactive).
|
||||
let sites = Sites.find({});
|
||||
let selectedSiteId;
|
||||
let categories = ['Asset ID', 'Email', 'First Name', 'Last Name'];
|
||||
let categories = ['Email', 'First Name', 'Last Name'];
|
||||
let selectedCategory = 'Email';
|
||||
let selectedGrade = 'All Grades';
|
||||
let searchText = "";
|
||||
let searchResults;
|
||||
let selectedResult;
|
||||
let staffSearchResults;
|
||||
let studentSearchResults;
|
||||
|
||||
$: {
|
||||
console.log("Site ID")
|
||||
console.log(selectedSiteId)
|
||||
if(selectedSiteId) {
|
||||
Meteor.subscribe('students', selectedSiteId);
|
||||
Meteor.subscribe('staff', selectedSiteId);
|
||||
}
|
||||
if(searchText && searchText.length > 1) {
|
||||
let query = {};
|
||||
if (selectedCategory === 'Email') {
|
||||
query.email = {$regex: searchText, $options: 'i'};
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
||||
$: {
|
||||
selectedResult = null;
|
||||
console.log("Starting search")
|
||||
|
||||
// Require at least two characters in the search field before we start filtering.
|
||||
if(selectedSiteId && selectedGrade && selectedCategory) {
|
||||
let query = {};
|
||||
let queryType = (selectedGrade === "Staff") ? 1 : 0;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
const assignedAssets = (person) => {
|
||||
let result = Assets.find({assigneeId: person._id}).fetch();
|
||||
|
||||
for(next of result) {
|
||||
next.type = AssetTypes.findOne({_id: next.assetTypeId})
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -108,20 +60,6 @@
|
||||
|
||||
<Paper>
|
||||
<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}">
|
||||
<Select bind:value={selectedCategory} label="Category">
|
||||
{#each categories as category}
|
||||
@@ -143,18 +81,38 @@
|
||||
<!-- <Label style="color: white">Create</Label>-->
|
||||
<!-- </Button>-->
|
||||
</div>
|
||||
<List twoLine singleSelection>
|
||||
{#if searchResults}
|
||||
{#each $searchResults as result}
|
||||
<Item selected={selectedResult === result}>
|
||||
<Text>
|
||||
<PrimaryText>{result.firstName} {result.lastName}</PrimaryText>
|
||||
<SecondaryText>{result.email} {result.grade ? '(' + result.grade + ')' : ""}</SecondaryText>
|
||||
</Text>
|
||||
</Item>
|
||||
{/each}
|
||||
{/if}
|
||||
</List>
|
||||
{#if staffSearchResults}
|
||||
<ul>
|
||||
{#each $staffSearchResults as next}
|
||||
<li>
|
||||
{next.firstName} {next.lastName} ({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}
|
||||
{#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>
|
||||
|
||||
<style>
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
import {Students} from "/imports/api/students";
|
||||
import {Staff} from "/imports/api/staff";
|
||||
import {AssetTypes} from "/imports/api/asset-types";
|
||||
import {Assets} from "/imports/api/assets";
|
||||
|
||||
let serialInput = null;
|
||||
let emailInput = null;
|
||||
@@ -104,7 +105,7 @@
|
||||
});
|
||||
let chromebookData = null;
|
||||
$: {
|
||||
if(deviceId || serial || email || date) {
|
||||
if(deviceId || assetId || serial || email || date) {
|
||||
let params = {};
|
||||
|
||||
if(deviceId) params.deviceId = deviceId;
|
||||
@@ -121,25 +122,6 @@
|
||||
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;
|
||||
}
|
||||
});
|
||||
@@ -148,6 +130,8 @@
|
||||
chromebookData = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<Route path="/" let:meta>
|
||||
@@ -158,18 +142,19 @@
|
||||
{#each chromebookData as data}
|
||||
<li>
|
||||
{#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}
|
||||
<a href="/chromebooks?email={encodeURIComponent(data.email)}">{data.email}</a><br/>
|
||||
User: <a href="/chromebooks?email={encodeURIComponent(data.email)}">{data.email}</a><br/>
|
||||
{/if}
|
||||
<a href="/chromebooks?deviceId={encodeURIComponent(data.deviceId)}">{data.deviceId}</a><br/>
|
||||
<a href="/chromebooks?serial={encodeURIComponent(data.serial)}">{data.serial}</a><br/>
|
||||
Device ID: <a href="/chromebooks?deviceId={encodeURIComponent(data.deviceId)}">{data.deviceId}</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")}
|
||||
{#if data.assetType}
|
||||
<br/>Asset Type: {data.assetType.name}
|
||||
{/if}
|
||||
{#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}
|
||||
</li>
|
||||
{/each}
|
||||
|
||||
Reference in New Issue
Block a user