2022-07-12 11:26:36 -07:00
|
|
|
<script>
|
|
|
|
|
import {Meteor} from "meteor/meteor";
|
|
|
|
|
import {onMount} from "svelte";
|
|
|
|
|
import {writable} from "svelte/store";
|
2022-07-13 17:40:38 -07:00
|
|
|
import Select, {Option} from '@smui/select';
|
|
|
|
|
import Dialog, {Title, Content, Actions} from '@smui/dialog';
|
|
|
|
|
import Button, {Label} from '@smui/button';
|
|
|
|
|
import List, {Item, Text, PrimaryText, SecondaryText} from '@smui/list';
|
2022-07-12 11:26:36 -07:00
|
|
|
import TextField from '@smui/textfield';
|
|
|
|
|
import u from 'umbrellajs';
|
|
|
|
|
import {AssetTypes} from "/imports/api/asset-types";
|
2022-08-08 22:15:55 -07:00
|
|
|
import Paper from '@smui/paper';
|
2022-07-12 11:26:36 -07:00
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
|
Meteor.subscribe('assetTypes');
|
|
|
|
|
Meteor.subscribe('assets');
|
|
|
|
|
});
|
|
|
|
|
let assetTypes;
|
|
|
|
|
//$m: assetTypes = AssetTypes.find({}).fetch();
|
|
|
|
|
//$: assetTypes = useTracker(() => AssetTypes.find({}).fetch());
|
2022-08-08 22:15:55 -07:00
|
|
|
$: assetTypes = AssetTypes.find({}, {sort: {year: -1}});
|
2022-07-12 11:26:36 -07:00
|
|
|
let selectedAssetTypes = [];
|
|
|
|
|
|
|
|
|
|
let selectedType = null;
|
|
|
|
|
const selectAssetType = (assetType) => {
|
|
|
|
|
selectedType = assetType;
|
|
|
|
|
}
|
|
|
|
|
const showAddAssetType = () => {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
let openAddAssetTypeButton;
|
|
|
|
|
let isOpen_AddAssetType = false;
|
|
|
|
|
const openAddAssetType = () => {
|
|
|
|
|
isOpen_AddAssetType = !isOpen_AddAssetType;
|
|
|
|
|
//openAddAssetTypeButton.innerHTML = isOpen_AddAssetType ? "close" : "add";
|
2022-07-13 17:40:38 -07:00
|
|
|
|
|
|
|
|
if (isOpen_AddAssetType) {
|
2022-07-12 11:26:36 -07:00
|
|
|
openAddAssetTypeButton.classList.add("reject-button");
|
2022-07-13 17:40:38 -07:00
|
|
|
} else {
|
2022-07-12 11:26:36 -07:00
|
|
|
openAddAssetTypeButton.classList.remove("reject-button");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let selectedAddAssetType = null;
|
2022-07-13 17:40:38 -07:00
|
|
|
|
2022-07-12 11:26:36 -07:00
|
|
|
let openDialog = false;
|
|
|
|
|
let assetTypeDialogSelectedIndex;
|
|
|
|
|
let assetTypeDialogSelectedValue;
|
|
|
|
|
const openAssetTypesDialog = () => {
|
|
|
|
|
assetTypeDialogSelectedIndex = -1;
|
|
|
|
|
openDialog = true;
|
|
|
|
|
}
|
|
|
|
|
const dialogClosed = (e) => {
|
2022-07-13 17:40:38 -07:00
|
|
|
switch (e.detail.action) {
|
2022-07-12 11:26:36 -07:00
|
|
|
case 'accept':
|
2022-07-13 17:40:38 -07:00
|
|
|
if (!selectedAssetTypes.some(e => e._id === assetTypeDialogSelectedValue._id)) {
|
2022-07-12 11:26:36 -07:00
|
|
|
selectedAssetTypes = [...selectedAssetTypes, assetTypeDialogSelectedValue];
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
case 'cancel':
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let assetId = "";
|
|
|
|
|
let serial = "";
|
|
|
|
|
const addAsset = () => {
|
2022-07-22 00:14:45 -07:00
|
|
|
if(selectedAssetType && selectedAssetType._id && assetId) {
|
|
|
|
|
let result = Meteor.call("assets.add", selectedAssetType._id, assetId, serial, (err, res) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
if (err.error === 'duplicateAssetId')
|
|
|
|
|
alert("The asset ID `" + assetId + "` has already been used.");
|
|
|
|
|
else
|
|
|
|
|
alert(err);
|
|
|
|
|
} else {
|
|
|
|
|
assetId = "";
|
|
|
|
|
serial = "";
|
|
|
|
|
document.getElementById('assetIdField').focus();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if(!selectedAssetType) {
|
|
|
|
|
alert("Must select an asset type.");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
alert("Must provide an Asset Id.");
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-12 11:26:36 -07:00
|
|
|
}
|
|
|
|
|
let selectedAssetType = null;
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<div class="listContainer">
|
2022-07-13 17:40:38 -07:00
|
|
|
<Dialog bind:open={openDialog} surface$style="width: 850px; max-width: calc(100vw - 32px);"
|
|
|
|
|
on:SMUIDialog:closed={dialogClosed}>
|
2022-07-12 11:26:36 -07:00
|
|
|
<Title id="large-scroll-title">Asset Types</Title>
|
|
|
|
|
<Content id="large-scroll-content">
|
|
|
|
|
<List class="assetTypesList" twoLine singleSelection bind:selectedIndex={assetTypeDialogSelectedIndex}>
|
|
|
|
|
{#each $assetTypes as type}
|
2022-07-13 17:40:38 -07:00
|
|
|
<Item on:SMUI:action={() => (assetTypeDialogSelectedValue = type)}
|
|
|
|
|
selected={assetTypeDialogSelectedValue === type}>
|
2022-07-12 11:26:36 -07:00
|
|
|
<Text>
|
|
|
|
|
<PrimaryText>{type.name}</PrimaryText>
|
|
|
|
|
<SecondaryText>{type.description}</SecondaryText>
|
|
|
|
|
</Text>
|
|
|
|
|
</Item>
|
|
|
|
|
{/each}
|
|
|
|
|
</List>
|
|
|
|
|
</Content>
|
|
|
|
|
<Actions>
|
|
|
|
|
<Button action="accept" default>
|
|
|
|
|
<Label>Ok</Label>
|
|
|
|
|
</Button>
|
|
|
|
|
<Button action="cancel">
|
|
|
|
|
<Label>Cancel</Label>
|
|
|
|
|
</Button>
|
|
|
|
|
</Actions>
|
|
|
|
|
</Dialog>
|
2022-07-13 17:40:38 -07:00
|
|
|
|
2022-08-08 22:15:55 -07:00
|
|
|
<h3 style="display: block">Asset Types</h3>
|
2022-07-13 17:40:38 -07:00
|
|
|
<Button class="addBtn" on:click={openAssetTypesDialog}>
|
|
|
|
|
<Label>Add...</Label>
|
|
|
|
|
</Button>
|
2022-08-08 22:15:55 -07:00
|
|
|
<Paper>
|
|
|
|
|
<List class="assetTypeList" singleSelection dense>
|
|
|
|
|
{#each selectedAssetTypes as type}
|
|
|
|
|
<Item on:SMUI:action={() => (selectedAssetType = type)} selected={selectedAssetType === type}>
|
|
|
|
|
<Text>{type.name}</Text>
|
|
|
|
|
</Item>
|
|
|
|
|
{/each}
|
|
|
|
|
</List>
|
|
|
|
|
</Paper>
|
2022-07-13 17:40:38 -07:00
|
|
|
<div style="grid-column: 1/span 1">
|
2022-07-22 00:14:45 -07:00
|
|
|
<TextField id="assetIdField" type="text" style="width: 100%" bind:value={assetId} label="AssetId">
|
2022-07-13 17:40:38 -07:00
|
|
|
</TextField>
|
|
|
|
|
</div>
|
|
|
|
|
<div style="grid-column: 1/span 1">
|
|
|
|
|
<TextField type="text" style="width: 100%" bind:value={serial} label="Serial">
|
|
|
|
|
</TextField>
|
|
|
|
|
</div>
|
2022-07-21 09:01:47 -07:00
|
|
|
<div style="text-align: right; margin-top: 2rem">
|
2022-07-13 17:40:38 -07:00
|
|
|
<Button on:click={addAsset} variant="raised">Add</Button>
|
2022-07-12 11:26:36 -07:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<style>
|
2022-07-13 17:40:38 -07:00
|
|
|
.columnContainer {
|
|
|
|
|
display: grid;
|
|
|
|
|
grid-template-columns: minmax(20rem, 1fr) minmax(20rem, 1fr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
:global(.addBtn) {
|
2022-08-08 22:15:55 -07:00
|
|
|
/*margin-left: 4rem;*/
|
2022-07-13 17:40:38 -07:00
|
|
|
}
|
|
|
|
|
|
2022-07-12 11:26:36 -07:00
|
|
|
:global(.assetTypeList) {
|
2022-07-13 17:40:38 -07:00
|
|
|
--mdc-ripple-color: blue;
|
2022-07-12 11:26:36 -07:00
|
|
|
--mdc-ripple-selected-opacity: 0.2;
|
|
|
|
|
}
|
2022-07-21 09:01:47 -07:00
|
|
|
:global(.assetTypesList) {
|
|
|
|
|
--mdc-ripple-selected-opacity: 0.2;
|
|
|
|
|
}
|
2022-07-13 17:40:38 -07:00
|
|
|
|
2022-07-12 11:26:36 -07:00
|
|
|
div.listContainer h2 {
|
|
|
|
|
margin: 0;
|
|
|
|
|
}
|
2022-07-13 17:40:38 -07:00
|
|
|
|
2022-07-12 11:26:36 -07:00
|
|
|
.listItem:nth-child(even) {
|
|
|
|
|
/*background: #f6f6f6;*/
|
|
|
|
|
background: white;
|
|
|
|
|
}
|
2022-07-13 17:40:38 -07:00
|
|
|
|
2022-07-12 11:26:36 -07:00
|
|
|
.listItem {
|
|
|
|
|
margin: 4px 0;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
user-select: none;
|
2022-07-13 17:40:38 -07:00
|
|
|
padding-bottom: 1rem;
|
|
|
|
|
padding-top: 0.4rem;
|
2022-07-12 11:26:36 -07:00
|
|
|
border-bottom: 1px solid gray;
|
|
|
|
|
}
|
2022-07-13 17:40:38 -07:00
|
|
|
|
2022-07-12 11:26:36 -07:00
|
|
|
.listItem:last-child {
|
|
|
|
|
border: 0;
|
|
|
|
|
}
|
2022-07-13 17:40:38 -07:00
|
|
|
|
2022-07-12 11:26:36 -07:00
|
|
|
.listItem.selected {
|
|
|
|
|
background-color: rgba(255, 255, 0, 0.38);
|
|
|
|
|
}
|
|
|
|
|
</style>
|