From 195d93fd20a897b877fb72b9977ea2d9a44e31ad Mon Sep 17 00:00:00 2001 From: "DESKTOP-C9V2M01\\Zeeri" Date: Fri, 22 Jul 2022 00:14:45 -0700 Subject: [PATCH] Fixed bug in Admin page; Finished asset data entry page. --- imports/api/assets.js | 8 ++++++-- imports/ui/Admin.svelte | 12 +++++------ imports/ui/Assets/AssetDataEntry.svelte | 27 +++++++++++++++++++++---- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/imports/api/assets.js b/imports/api/assets.js index 8a57ed2..3beb9e9 100644 --- a/imports/api/assets.js +++ b/imports/api/assets.js @@ -57,8 +57,12 @@ Meteor.methods({ if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) { let assetType = AssetTypes.findOne({assetTypeId}); - - if(serial) { + + if(Assets.findOne({assetId})) { + //return {error: true, errorType: 'duplicateAssetId'} + throw new Meteor.Error("duplicateAssetId", "Cannot use the same asset ID twice.") + } + else if(serial) { Assets.insert({assetTypeId, assetId, serial}); } else { diff --git a/imports/ui/Admin.svelte b/imports/ui/Admin.svelte index 14d774c..183ea5a 100644 --- a/imports/ui/Admin.svelte +++ b/imports/ui/Admin.svelte @@ -50,9 +50,9 @@ }; // Create a holder for the site being edited. This allows us to clear the editor when the user finishes, and allows the table or parent view to setup the editor. let editedSite = writable(null); - let dirtySite = null; + let dirtySite; // Copy the edited site when ever it changes, set some defaults for a new site object (to make the view happy). - editedSite.subscribe(site => {dirtySite = Object.assign({}, site)}); + editedSite.subscribe(site => {dirtySite = Object.assign({name:""}, site)}); // Load the sites (reactive). let sites = Sites.find({}); const applySiteChanges = () => { @@ -61,6 +61,7 @@ else Meteor.call("sites.add", dirtySite.name); editedSite.set(null); + dirtySite = null; } const rejectSiteChanges = () => { editedSite.set(null); @@ -215,7 +216,7 @@ let editedAssetType = writable(null); const onAssetTypeSelection = (e) => { } - let dirtyAssetType = null; + let dirtyAssetType; // 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). @@ -229,6 +230,7 @@ else Meteor.call("assetTypes.add", dirtyAssetType.name, dirtyAssetType.description); editedAssetType.set(null); + dirtyAssetType = null; } const rejectAssetTypeChanges = () => { editedSite.set(null); @@ -320,10 +322,6 @@ {/if} - - - -