Merged the AssetAssignment collection with the Asset collection; Updated views for assigning assets; Added view to find asset assignments by assetId.

This commit is contained in:
2022-08-14 17:07:14 -07:00
parent f3b1b38e82
commit cf51200393
13 changed files with 3897 additions and 53 deletions

View File

@@ -5,12 +5,13 @@
import Sites from "/imports/ui/Admin/Sites.svelte";
import Students from "/imports/ui/Admin/Students.svelte";
import Staff from "/imports/ui/Admin/Staff.svelte";
import Functions from "/imports/ui/Admin/Functions.svelte";
let activeTab = "Sites";
</script>
<div class="container">
<TabBar tabs={['Sites','Students','Staff','Asset Types']} minWidth let:tab bind:active={activeTab}>
<TabBar tabs={['Sites','Students','Staff','Asset Types', 'Functions']} minWidth let:tab bind:active={activeTab}>
<Tab {tab}>
<Label>{tab}</Label>
</Tab>
@@ -23,6 +24,8 @@
<Staff></Staff>
{:else if activeTab === 'Asset Types'}
<AssetTypes></AssetTypes>
{:else if activeTab === 'Functions'}
<Functions></Functions>
{/if}
</div>

View File

@@ -0,0 +1,16 @@
<script>
import Button, { Label } from '@smui/button';
const fixAssetAssignments = () => {
Meteor.call('assets.fixAssetAssignments');
}
</script>
<div class="container">
<Button variant="raised" touch on:click={fixAssetAssignments}>
<Label style="color: white">Fix Assignments</Label>
</Button>
</div>
<style>
</style>

View File

@@ -7,7 +7,8 @@
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 Assignments from "/imports/ui/Assets/Assignments.svelte";
import AssignmentByAssignee from "/imports/ui/Assets/AssignmentByAssignee.svelte";
import AssignmentByAsset from "/imports/ui/Assets/AssignmentByAsset.svelte";
let canManageLaptops = false;
let isAdmin = false;
@@ -23,7 +24,8 @@
let tabs = [];
if(canManageLaptops) {
tabs.push({id: 'listAssignments', label: 'Assignment List'});
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) {
@@ -45,8 +47,10 @@
<AddAssets></AddAssets>
{:else if activeTab && activeTab.id === 'assignAssets'}
<AssignAssets></AssignAssets>
{:else if activeTab && activeTab.id === 'listAssignments'}
<Assignments></Assignments>
{:else if activeTab && activeTab.id === 'listAssignmentsByAssignee'}
<AssignmentByAssignee></AssignmentByAssignee>
{:else if activeTab && activeTab.id === 'listAssignmentsByAsset'}
<AssignmentByAsset></AssignmentByAsset>
{/if}
</div>

View File

@@ -57,9 +57,16 @@
const createAssignment = () => {
if(assetId && assetId.length && selectedAssignee) {
Meteor.call("AssetAssignments.add", assetId, selectedCategory === 'Student' ? "Student" : "Staff", selectedAssignee._id)
// TODO: Set focus to the asset ID field.
assetId = "";
Meteor.call("assets.assign", assetId, selectedCategory === 'Student' ? "Student" : "Staff", selectedAssignee._id, (err, result) => {
if(err) {
console.error(err);
//TODO: Display an error!
}
else {
// TODO: Set focus to the asset ID field.
assetId = "";
}
});
}
}
</script>

View File

@@ -0,0 +1,84 @@
<script>
import {Meteor} from "meteor/meteor";
import {onMount} from "svelte";
import TextField from '@smui/textfield';
import {Staff} from "/imports/api/staff";
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 {Students} from "/imports/api/students";
import {AssetTypes} from "/imports/api/asset-types";
onMount(async () => {
Meteor.subscribe('assets');
Meteor.subscribe('students');
Meteor.subscribe('staff');
Meteor.subscribe('assetTypes');
});
let searchText = "";
let foundAsset;
let selectedResult;
let foundAssignee;
let foundAssetType;
$: {
selectedResult = null;
if(searchText) {
foundAsset = Assets.findOne({assetId: searchText});
}
else {
foundAsset = undefined;
}
}
$: {
if(foundAsset) {
foundAssetType = AssetTypes.findOne({_id: foundAsset.assetTypeId});
if(foundAsset.assigneeType === 'Student') {
foundAssignee = Students.findOne({_id: foundAsset.assigneeId});
}
else {
foundAssignee = Staff.findOne({_id: foundAsset.assigneeId});
}
}
else {
foundAssetType = undefined;
foundAssignee = undefined;
}
}
const formatDate = (date) => {
return date.toLocaleDateString('en-us', {weekday: 'long', year: 'numeric', month: 'short', day: 'numeric'});
}
</script>
<div class="container">
<h1 style="display: block">Asset Assignments</h1>
<Paper>
<LayoutGrid>
<Cell span="{6}">
<TextField type="text" bind:value={searchText} label="Asset ID"></TextField>
</Cell>
</LayoutGrid>
</Paper>
{#if foundAsset}
<div>Asset ID: {foundAsset.assetId}</div>
{#if foundAssetType}
<div>{foundAssetType.name}</div>
{/if}
{#if foundAssignee}
<div>Assigned on: {formatDate(foundAsset.assignmentDate)}</div>
<div>Assigned to: {foundAssignee.firstName} {foundAssignee.lastName}
{#if foundAssignee.grade} ~ {foundAssignee.grade} {/if}({foundAssignee.email})</div>
{/if}
{/if}
</div>
<style>
</style>