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:
@@ -22,13 +22,7 @@ const AssetTypesSchema = new SimpleSchema({
|
||||
label: "Description",
|
||||
optional: true,
|
||||
trim: true,
|
||||
defaultValue: ""
|
||||
},
|
||||
hasSerial: {
|
||||
type: Boolean,
|
||||
label: "Is a serial number available for all instances?",
|
||||
optional: false,
|
||||
defaultValue: false
|
||||
defaultValue: "",
|
||||
},
|
||||
});
|
||||
|
||||
@@ -37,9 +31,9 @@ AssetTypes.attachSchema(AssetTypesSchema);
|
||||
|
||||
if (Meteor.isServer) {
|
||||
// Drop any old indexes we no longer will use. Create indexes we need.
|
||||
try {AssetTypes._dropIndex("name")} catch(e) {}
|
||||
try {AssetTypes._dropIndex("External ID")} catch(e) {}
|
||||
//AssetTypes.createIndex({name: "text"}, {name: "name", unique: false});
|
||||
AssetTypes.createIndex({id: 1}, {name: "External ID", unique: true});
|
||||
//AssetTypes.createIndex({id: 1}, {name: "External ID", unique: true});
|
||||
|
||||
//Debug: Show all indexes.
|
||||
// AssetTypes.rawCollection().indexes((err, indexes) => {
|
||||
@@ -52,20 +46,28 @@ if (Meteor.isServer) {
|
||||
});
|
||||
}
|
||||
Meteor.methods({
|
||||
'assetTypes.add'(name, description, hasSerial) {
|
||||
'assetTypes.add'(name, description) {
|
||||
check(name, String);
|
||||
check(description, String);
|
||||
check(hasSerial, Boolean);
|
||||
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
AssetTypes.insert({name, description, hasSerial});
|
||||
AssetTypes.insert({name, description});
|
||||
}
|
||||
},
|
||||
'assetTypes.update'(_id, name, description) {
|
||||
check(_id, String);
|
||||
check(name, String);
|
||||
check(description, String);
|
||||
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
AssetTypes.update({_id}, {$set: {name, description}});
|
||||
}
|
||||
},
|
||||
'assetTypes.remove'(_id) {
|
||||
check(_id, String);
|
||||
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
//TODO: Need to first verify there are no checked out assets to the staff member.
|
||||
//TODO: Need to either remove all assets of this type, or change their type.
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
import Users from './Users.svelte';
|
||||
import Admin from './Admin.svelte';
|
||||
import Announcer from './Announcer.svelte';
|
||||
import Assets from "./Assets.svelte";
|
||||
|
||||
// When the URL changes, run the code... in this case to scroll to the top.
|
||||
router.subscribe(_ => window.scrollTo(0, 0));
|
||||
@@ -66,6 +67,7 @@
|
||||
<a href="/users">Users</a>
|
||||
{/if}
|
||||
{#if isAdmin}
|
||||
<a href="/assets">Assets</a>
|
||||
<a href="/admin">Admin</a>
|
||||
{/if}
|
||||
</nav>
|
||||
@@ -79,6 +81,11 @@
|
||||
</div>
|
||||
</div>
|
||||
</Route>
|
||||
<Route path="/assets">
|
||||
{#if isAdmin}
|
||||
<Assets/>
|
||||
{/if}
|
||||
</Route>
|
||||
<Route path="/admin">
|
||||
{#if isAdmin}
|
||||
<Admin/>
|
||||
|
||||
20
imports/ui/Assets.svelte
Normal file
20
imports/ui/Assets.svelte
Normal file
@@ -0,0 +1,20 @@
|
||||
<script>
|
||||
import {Meteor} from "meteor/meteor";
|
||||
import {onMount} from "svelte";
|
||||
import {writable} from "svelte/store";
|
||||
import TextField from '@smui/textfield';
|
||||
import HelperText from '@smui/textfield/helper-text';
|
||||
import {AssetTypes} from "../api/asset-types";
|
||||
import {Assets} from "../api/assets";
|
||||
|
||||
onMount(async () => {
|
||||
Meteor.subscribe('assetTypes');
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="container">
|
||||
</div>
|
||||
|
||||
<style>
|
||||
|
||||
</style>
|
||||
3694
package-lock.json
generated
3694
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user