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-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
|
|
|
});
|
|
|
|
|
let selectedSiteId;
|
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) => {
|
|
|
|
|
let result = Assets.find({assigneeId: person._id}).fetch();
|
|
|
|
|
|
|
|
|
|
for(next of result) {
|
|
|
|
|
next.type = AssetTypes.findOne({_id: next.assetTypeId})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
const unassign = (asset) => {
|
|
|
|
|
unassignAsset = asset;
|
|
|
|
|
condition = asset.condition;
|
|
|
|
|
conditionDetails = asset.conditionDetails;
|
|
|
|
|
// if(confirm("Unassign Asset?")) {
|
|
|
|
|
// Meteor.call("assets.unassign", asset.assetId);
|
|
|
|
|
// }
|
|
|
|
|
openDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let isDialogOpen = false;
|
|
|
|
|
let dialogAsset;
|
|
|
|
|
|
|
|
|
|
const openDialog = () => {
|
|
|
|
|
// assetTypeDialogSelectedIndex = -1;
|
|
|
|
|
isDialogOpen = true;
|
|
|
|
|
}
|
|
|
|
|
const dialogClosed = (e) => {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
case 'cancel':
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-02 12:02:56 -07:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<div class="container">
|
2022-08-16 16:08:12 -07:00
|
|
|
<Dialog bind:open={isDialogOpen} surface$style="width: 850px; max-width: calc(100vw - 32px);"
|
|
|
|
|
on:SMUIDialog:closed={dialogClosed}>
|
|
|
|
|
<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>
|
|
|
|
|
|
|
|
|
|
<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}
|
|
|
|
|
Type: {asset.type.name}<br/>
|
|
|
|
|
AssetId: {asset.assetId}<br/>
|
|
|
|
|
Serial: {asset.serial}<br/>
|
2022-08-16 16:08:12 -07:00
|
|
|
<Button variant="raised" touch on:click={() => {unassign(asset)}}>
|
|
|
|
|
<Label style="color: white">Unassign</Label>
|
|
|
|
|
</Button>
|
2022-08-16 07:39:15 -07:00
|
|
|
{/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/>
|
2022-08-16 16:08:12 -07:00
|
|
|
<Button variant="raised" touch on:click={() => {unassign(asset)}}>
|
|
|
|
|
<Label style="color: white">Unassign</Label>
|
|
|
|
|
</Button>
|
2022-08-16 07:39:15 -07:00
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
</li>
|
|
|
|
|
{/each}
|
|
|
|
|
</ul>
|
|
|
|
|
{/if}
|
2022-08-02 12:02:56 -07:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
|
|
|
|
|
</style>
|