Finished coding the AssetTypes part of the Admin page. Tested adding assets. Did not implement removing them or updating them. Added the start for a page to manage assets.

This commit is contained in:
2022-06-29 00:31:47 -07:00
parent 3c58f3f8da
commit 94c7fb9f7b
5 changed files with 3734 additions and 75 deletions

View File

@@ -15,7 +15,8 @@
Meteor.subscribe('assetTypes');
});
const fixRecords = () => {Meteor.call("admin.fixRecords");}
// Should not be needed now. Did not work well - had a bug somewhere.
// const fixRecords = () => {Meteor.call("admin.fixRecords");}
const siteColumns = [
{
@@ -54,7 +55,6 @@
editedSite.subscribe(site => {dirtySite = Object.assign({name: ""}, site)});
// Load the sites (reactive).
let sites = Sites.find({});
const applySiteChanges = () => {
if(dirtySite._id)
Meteor.call("sites.update", dirtySite._id, dirtySite.name);
@@ -66,6 +66,7 @@
editedSite.set(null);
}
let selectedSite = null;
let students = null;
let staff = null;
$: {
@@ -199,27 +200,43 @@
minWidth: 100,
weight: 1,
cls: "description",
}, {
key: "hasSerial",
title: "Has Serial",
value: v => v.hasSerial,
minWidth: 100,
weight: 1,
cls: "hasSerial",
},
];
const assetTypesActions = {
title: "Actions",
headerWidgets: [
{icon: "add_box", action: () => {editedAssetType.set({name: ""});}, tooltip: "Add a new asset type."}
],
rowWidgets: [
{icon: "add_circle", action: (v) => {editedAssetType.set(v)}},
{icon: "delete", action: (v) => {deleteAssetType(v)}}
],
};
let editedAssetType = writable(null);
const onAssetTypeSelection = (e) => {
}
let dirtyAssetType = null;
// Copy the edited site when ever it changes, set some defaults for a new site object (to make the view happy).
editedAssetType.subscribe(v => {dirtyAssetType = Object.assign({name: ""}, v)});
// Copy the edited value when ever it changes, set some defaults for a new value object (to make the view happy).
editedAssetType.subscribe(v => {dirtyAssetType = Object.assign({name: "", description: ""}, v)});
// Load the sites (reactive).
let assetTypes = AssetTypes.find({});
const deleteAssetType = assetType => {
//TODO:
};
const applyAssetTypeChanges = () => {
if(dirtyAssetType._id)
Meteor.call("assetTypes.update", dirtyAssetType._id, dirtyAssetType.name, dirtyAssetType.description);
else
Meteor.call("assetTypes.add", dirtyAssetType.name, dirtyAssetType.description);
editedAssetType.set(null);
}
const rejectAssetTypeChanges = () => {
editedSite.set(null);
}
</script>
<div class="container">
<h2>Sites</h2>
<GridTable bind:rows={sites} columns="{siteColumns}" actions="{actions}" rowKey="{(v) => {return v._id}}" bind:edited="{editedSite}" on:selection={onSiteSelection}>
{#if dirtySite}
<div class="editorContainer">
@@ -286,21 +303,20 @@
{/if}
<h2>Asset Types</h2>
<GridTable bind:rows={assetTypes} columns="{assetTypesColumns}" actions="{null}" rowKey="{(v) => {return v._id}}" bind:edited="{editedAssetType}" on:selection={onAssetTypeSelection}>
{#if dirtySite}
<GridTable bind:rows={assetTypes} columns="{assetTypesColumns}" actions="{assetTypesActions}" rowKey="{(v) => {return v._id}}" bind:edited="{editedAssetType}" on:selection={onAssetTypeSelection}>
{#if dirtyAssetType}
<div class="editorContainer">
<div style="grid-column: 1/span 1">
<TextField type="text" style="width: 100%" bind:value={dirtySite.name} label="Name">
<HelperText slot="helper">Provide a unique name for the site.</HelperText>
<TextField type="text" style="width: 100%" bind:value={dirtyAssetType.name} label="Name">
<HelperText slot="helper">Provide a unique name for the asset type.</HelperText>
</TextField>
<TextField type="text" style="width: 100%" bind:value={dirtyAssetType.description} label="Description">
<HelperText slot="helper">A detailed description.</HelperText>
</TextField>
</div>
<button type="button" style="grid-column: 2/span 1;" class="button accept-button material-icons material-symbols-outlined" on:click={applySiteChanges}>
check
</button>
<button type="button" style="grid-column: 3/span 1;" class="button reject-button material-icons material-symbols-outlined" on:click={rejectSiteChanges}>
close
</button>
<button type="button" style="grid-column: 2/span 1;" class="button accept-button material-icons material-symbols-outlined" on:click={applyAssetTypeChanges}>check</button>
<button type="button" style="grid-column: 3/span 1;" class="button reject-button material-icons material-symbols-outlined" on:click={rejectAssetTypeChanges}>close</button>
</div>
{/if}
</GridTable>