2022-08-02 12:02:56 -07:00
|
|
|
<script>
|
|
|
|
|
import {Meteor} from "meteor/meteor";
|
|
|
|
|
import {onMount} from "svelte";
|
|
|
|
|
import {Sites} from "../../api/sites";
|
|
|
|
|
import TextField from '@smui/textfield';
|
|
|
|
|
import {Students} from "../../api/students";
|
|
|
|
|
import Select, { Option } from '@smui/select';
|
|
|
|
|
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';
|
2022-08-16 07:39:15 -07:00
|
|
|
import {Assets} from "/imports/api/assets";
|
|
|
|
|
import {AssetTypes} from "/imports/api/asset-types";
|
2022-08-16 16:08:12 -07:00
|
|
|
import Button, { Label } from '@smui/button';
|
|
|
|
|
import Dialog, { Title, Content, Actions } from '@smui/dialog';
|
2022-08-20 22:51:54 -07:00
|
|
|
import AssignmentByPersonAssets from "/imports/ui/Assignments/AssignmentByPersonAssets.svelte";
|
2022-08-02 12:02:56 -07:00
|
|
|
|
|
|
|
|
onMount(async () => {
|
2022-08-16 07:39:15 -07:00
|
|
|
Meteor.subscribe('students');
|
|
|
|
|
Meteor.subscribe('staff');
|
|
|
|
|
Meteor.subscribe('assets');
|
|
|
|
|
Meteor.subscribe('assetTypes');
|
2022-08-02 12:02:56 -07:00
|
|
|
});
|
2022-08-16 07:39:15 -07:00
|
|
|
let categories = ['Email', 'First Name', 'Last Name'];
|
2022-08-02 12:02:56 -07:00
|
|
|
let selectedCategory = 'Email';
|
|
|
|
|
let searchText = "";
|
2022-08-16 07:39:15 -07:00
|
|
|
let staffSearchResults;
|
|
|
|
|
let studentSearchResults;
|
2022-08-02 12:02:56 -07:00
|
|
|
|
|
|
|
|
$: {
|
2022-08-16 07:39:15 -07:00
|
|
|
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;
|
|
|
|
|
}
|
2022-08-02 12:02:56 -07:00
|
|
|
}
|
2022-08-16 07:39:15 -07:00
|
|
|
|
|
|
|
|
const assignedAssets = (person) => {
|
2022-08-20 22:51:54 -07:00
|
|
|
let result = Assets.find({assigneeId: person._id}).fetch();
|
|
|
|
|
|
|
|
|
|
for (next of result) {
|
|
|
|
|
next.type = AssetTypes.findOne({_id: next.assetTypeId})
|
2022-08-16 07:39:15 -07:00
|
|
|
}
|
2022-08-20 22:51:54 -07:00
|
|
|
|
|
|
|
|
return result;
|
2022-08-02 12:02:56 -07:00
|
|
|
}
|
2022-08-16 16:08:12 -07:00
|
|
|
|
|
|
|
|
let conditions = ['New', 'Like New', 'Good', 'Okay', 'Damaged'];
|
|
|
|
|
let condition = "New";
|
|
|
|
|
let conditionDetails = "";
|
|
|
|
|
let comment = "";
|
|
|
|
|
let unassignAsset;
|
2022-08-20 22:51:54 -07:00
|
|
|
let isUnassignDialogOpen = false;
|
2022-08-16 16:08:12 -07:00
|
|
|
|
|
|
|
|
const unassign = (asset) => {
|
|
|
|
|
unassignAsset = asset;
|
2022-08-20 22:51:54 -07:00
|
|
|
comment = "";
|
2022-08-16 16:08:12 -07:00
|
|
|
condition = asset.condition;
|
|
|
|
|
conditionDetails = asset.conditionDetails;
|
2022-08-20 22:51:54 -07:00
|
|
|
isUnassignDialogOpen = true;
|
2022-08-16 16:08:12 -07:00
|
|
|
}
|
2022-08-20 22:51:54 -07:00
|
|
|
const unassignDialogClosed = (e) => {
|
2022-08-16 16:08:12 -07:00
|
|
|
switch (e.detail.action) {
|
|
|
|
|
case 'unassign':
|
|
|
|
|
if(unassignAsset && unassignAsset.assetId) {
|
|
|
|
|
Meteor.call("assets.unassign", unassignAsset.assetId, comment, condition, conditionDetails, (err, result) => {
|
|
|
|
|
if(err) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
//TODO: Display an error!
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// TODO: Set focus to the asset ID field.
|
|
|
|
|
unassignAsset = undefined;
|
2022-08-20 22:51:54 -07:00
|
|
|
//Force a refresh. Should not be necessary, but I cannot seem to get the Reactive UI to work.
|
|
|
|
|
let x = searchText;
|
|
|
|
|
searchText = "";
|
|
|
|
|
searchText = x;
|
2022-08-16 16:08:12 -07:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
case 'cancel':
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-20 22:51:54 -07:00
|
|
|
|
|
|
|
|
let isAssignDialogOpen = false;
|
|
|
|
|
let assetId = "";
|
|
|
|
|
let foundAsset = undefined;
|
|
|
|
|
|
|
|
|
|
$: {
|
|
|
|
|
if(assetId && assetId.length > 0) {
|
|
|
|
|
foundAsset = Assets.findOne({assetId: assetId});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let assignDialogPersonId;
|
|
|
|
|
let assignDialogPersonType;
|
|
|
|
|
let assignDialogCondition = "Good";
|
|
|
|
|
let assignDialogConditionDetails = "";
|
|
|
|
|
let showAssetIdField = false;
|
|
|
|
|
|
|
|
|
|
const assignAssets = (personId, personType) => {
|
|
|
|
|
assignDialogPersonType = personType;
|
|
|
|
|
assignDialogPersonId = personId;
|
|
|
|
|
assignDialogCondition = foundAsset.condition ? foundAsset.condition : "Good";
|
|
|
|
|
assignDialogConditionDetails = foundAsset.conditionDetails ? foundAsset.conditionDetails : "";
|
|
|
|
|
isAssignDialogOpen = true;
|
|
|
|
|
}
|
|
|
|
|
const assignDialogClosed = (e) => {
|
|
|
|
|
switch (e.detail.action) {
|
|
|
|
|
case 'assign':
|
|
|
|
|
if(foundAsset && foundAsset.assetId) {
|
|
|
|
|
Meteor.call("assets.assign", foundAsset.assetId, assignDialogPersonType, assignDialogPersonId, assignDialogCondition, assignDialogConditionDetails, (err, result) => {
|
|
|
|
|
if(err) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
//TODO: Display an error!
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
foundAsset = undefined;
|
|
|
|
|
assetId = "";
|
|
|
|
|
searchText = searchText;
|
|
|
|
|
|
|
|
|
|
//Force a refresh. Should not be necessary, but I cannot seem to get the Reactive UI to work.
|
|
|
|
|
let x = searchText;
|
|
|
|
|
searchText = "";
|
|
|
|
|
searchText = x;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
case 'cancel':
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-02 12:02:56 -07:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<div class="container">
|
2022-08-20 22:51:54 -07:00
|
|
|
<Dialog bind:open={isUnassignDialogOpen} surface$style="width: 850px; max-width: calc(100vw - 32px);"
|
|
|
|
|
on:SMUIDialog:closed={unassignDialogClosed}>
|
2022-08-16 16:08:12 -07:00
|
|
|
<Title id="large-scroll-title">Report Asset Condition</Title>
|
|
|
|
|
<Content id="large-scroll-content">
|
|
|
|
|
<Select bind:value={condition} label="Condition">
|
|
|
|
|
{#each conditions as next}
|
|
|
|
|
<Option value={next}>{next}</Option>
|
|
|
|
|
{/each}
|
|
|
|
|
</Select>
|
|
|
|
|
<div style="grid-column: 1/span 1">
|
|
|
|
|
<TextField type="text" style="width: 100%; margin-top: 1rem" bind:value={comment} label="Comment"></TextField>
|
|
|
|
|
</div>
|
|
|
|
|
<div style="grid-column: 1/span 1">
|
|
|
|
|
<TextField textarea style="width: 100%; height: 20rem; margin-top: 1rem" helperLine$style="width: 100%" bind:value={conditionDetails} label="Condition Details">
|
|
|
|
|
</TextField>
|
|
|
|
|
</div>
|
|
|
|
|
</Content>
|
|
|
|
|
<Actions>
|
|
|
|
|
<Button action="unassign" default>
|
|
|
|
|
<Label>Ok</Label>
|
|
|
|
|
</Button>
|
|
|
|
|
<Button action="cancel">
|
|
|
|
|
<Label>Cancel</Label>
|
|
|
|
|
</Button>
|
|
|
|
|
</Actions>
|
|
|
|
|
</Dialog>
|
|
|
|
|
|
2022-08-20 22:51:54 -07:00
|
|
|
<Dialog bind:open={isAssignDialogOpen} surface$style="width: 850px; max-width: calc(100vw - 32px);"
|
|
|
|
|
on:SMUIDialog:closed={assignDialogClosed}>
|
|
|
|
|
<Title id="large-scroll-title">Assign Asset</Title>
|
|
|
|
|
<Content id="large-scroll-content">
|
|
|
|
|
<Select bind:value={assignDialogCondition} label="Condition">
|
|
|
|
|
{#each conditions as next}
|
|
|
|
|
<Option value={next}>{next}</Option>
|
|
|
|
|
{/each}
|
|
|
|
|
</Select>
|
|
|
|
|
<div style="grid-column: 1/span 1">
|
|
|
|
|
<TextField textarea style="width: 100%; height: 20rem; margin-top: 1rem" helperLine$style="width: 100%" bind:value={assignDialogConditionDetails} label="Condition Details">
|
|
|
|
|
</TextField>
|
|
|
|
|
</div>
|
|
|
|
|
</Content>
|
|
|
|
|
<Actions>
|
|
|
|
|
<Button action="assign" default>
|
|
|
|
|
<Label>Assign</Label>
|
|
|
|
|
</Button>
|
|
|
|
|
<Button action="cancel">
|
|
|
|
|
<Label>Cancel</Label>
|
|
|
|
|
</Button>
|
|
|
|
|
</Actions>
|
|
|
|
|
</Dialog>
|
|
|
|
|
|
2022-08-16 16:08:12 -07:00
|
|
|
<h1 style="display: block">Asset Assignments By Student/Staff</h1>
|
2022-08-02 12:02:56 -07:00
|
|
|
|
|
|
|
|
<Paper>
|
|
|
|
|
<LayoutGrid>
|
|
|
|
|
<Cell span="{6}">
|
|
|
|
|
<Select bind:value={selectedCategory} label="Category">
|
|
|
|
|
{#each categories as category}
|
|
|
|
|
<Option value={category}>{category}</Option>
|
|
|
|
|
{/each}
|
|
|
|
|
</Select>
|
|
|
|
|
</Cell>
|
|
|
|
|
<Cell span="{6}">
|
|
|
|
|
<TextField type="text" bind:value={searchText} label="Search"></TextField>
|
|
|
|
|
</Cell>
|
|
|
|
|
</LayoutGrid>
|
|
|
|
|
</Paper>
|
|
|
|
|
|
|
|
|
|
<div style="width: 100%; display: flex; flex-direction: row; flex-wrap: nowrap; justify-content: flex-start; align-items: flex-end; align-content: stretch; column-gap: 2rem;">
|
|
|
|
|
<!-- <TextField bind:this={assetIdWidget} style="flex-grow: 999;" type="text" bind:value={assetId} label="Asset ID">-->
|
|
|
|
|
|
|
|
|
|
<!-- </TextField>-->
|
|
|
|
|
<!-- <Button variant="raised" color="secondary" on:click={createAssignment()} disabled={!assetId || assetId.length === 0 || !selectedAssignee}>-->
|
|
|
|
|
<!-- <Label style="color: white">Create</Label>-->
|
|
|
|
|
<!-- </Button>-->
|
|
|
|
|
</div>
|
2022-08-16 07:39:15 -07:00
|
|
|
{#if staffSearchResults}
|
|
|
|
|
<ul>
|
|
|
|
|
{#each $staffSearchResults as next}
|
|
|
|
|
<li>
|
|
|
|
|
{next.firstName} {next.lastName} ({next.email})
|
|
|
|
|
<div style="margin-left: 2rem">
|
|
|
|
|
{#each (assignedAssets(next)) as asset}
|
2022-08-20 22:51:54 -07:00
|
|
|
<div class="asset">
|
|
|
|
|
Type: {asset.type.name}<br/>
|
|
|
|
|
AssetId: {asset.assetId}<br/>
|
|
|
|
|
Serial: {asset.serial}<br/>
|
|
|
|
|
<Button variant="raised" color="secondary" touch on:click={() => {unassign(asset)}}>
|
|
|
|
|
<Label style="color: white">Unassign</Label>
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
2022-08-16 07:39:15 -07:00
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
</li>
|
|
|
|
|
{/each}
|
|
|
|
|
</ul>
|
|
|
|
|
{/if}
|
2022-08-20 22:51:54 -07:00
|
|
|
{#if $studentSearchResults}
|
2022-08-16 07:39:15 -07:00
|
|
|
<ul>
|
|
|
|
|
{#each $studentSearchResults as next}
|
|
|
|
|
<li>
|
2022-08-20 22:51:54 -07:00
|
|
|
{next.firstName} {next.lastName} ~ {next.grade} ({next.email})
|
|
|
|
|
<Button style="margin-left: 3rem" color="primary" on:click={() => {showAssetIdField = !showAssetIdField;}}>
|
|
|
|
|
<span class="material-symbols-outlined material-icons">add</span>
|
|
|
|
|
</Button>
|
2022-08-16 07:39:15 -07:00
|
|
|
<div style="margin-left: 2rem">
|
2022-08-20 22:51:54 -07:00
|
|
|
<!-- style="visibility: {showAssetIdField ? 'visible' : 'hidden'}"-->
|
|
|
|
|
<div class='asset'>
|
|
|
|
|
<TextField type="text" bind:value={assetId} label="Asset ID"></TextField>
|
|
|
|
|
{#if foundAsset}
|
|
|
|
|
<div>Asset ID: {foundAsset.assetId}</div>
|
|
|
|
|
<div>Serial: {foundAsset.serial}</div>
|
|
|
|
|
{/if}
|
|
|
|
|
<Button style="display: block" variant="raised" color="secondary" touch disabled="{!foundAsset || foundAsset.assigneeId !== undefined}" on:click={() => {assignAssets(next._id,'Student')}}>
|
|
|
|
|
<Label style="color: white">Assign</Label>
|
2022-08-16 16:08:12 -07:00
|
|
|
</Button>
|
2022-08-20 22:51:54 -07:00
|
|
|
</div>
|
|
|
|
|
<!-- person="{next}" bind:person={next}-->
|
|
|
|
|
<!-- <AssignmentByPersonAssets person="{next}" on:unassign={(e) => {unassign(e.detail)}}/>-->
|
|
|
|
|
{#each assignedAssets(next) as asset}
|
|
|
|
|
<div class="asset">
|
|
|
|
|
Type: {asset.type.name}<br/>
|
|
|
|
|
AssetId: {asset.assetId}<br/>
|
|
|
|
|
Serial: {asset.serial}<br/>
|
|
|
|
|
<Button variant="raised" color="secondary" touch on:click={() => {unassign(asset)}}>
|
|
|
|
|
<Label style="color: white">Unassign</Label>
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
2022-08-16 07:39:15 -07:00
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
</li>
|
|
|
|
|
{/each}
|
|
|
|
|
</ul>
|
|
|
|
|
{/if}
|
2022-08-02 12:02:56 -07:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<style>
|
2022-08-20 22:51:54 -07:00
|
|
|
.asset:nth-child(even) {
|
|
|
|
|
background: #DDD;
|
|
|
|
|
}
|
|
|
|
|
.asset:nth-child(odd) {
|
|
|
|
|
background: #D8D0D3;
|
|
|
|
|
}
|
2022-08-02 12:02:56 -07:00
|
|
|
</style>
|