Added assignment history and unassignment feature (not yet tested).
This commit is contained in:
14
imports/api/asset-assignment-history.js
Normal file
14
imports/api/asset-assignment-history.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import {Mongo} from "meteor/mongo";
|
||||||
|
|
||||||
|
export const AssetAssignmentHistory = new Mongo.Collection('assetAssignmentHistory');
|
||||||
|
|
||||||
|
/*
|
||||||
|
Maintains a historical record of asset assignments.
|
||||||
|
assetId: The asset's assigned ID (not a MongoID).
|
||||||
|
assigneeType: One of 'Student' or 'Staff'.
|
||||||
|
assigneeId: The MongoID of the student or staff the asset was assigned to.
|
||||||
|
startDate: The date/time of the assignment.
|
||||||
|
endDate: The date/time of the unassignment.
|
||||||
|
startCondition: TODO
|
||||||
|
endCondition: TODO
|
||||||
|
*/
|
||||||
@@ -5,6 +5,7 @@ import { Roles } from 'meteor/alanning:roles';
|
|||||||
//import SimpleSchema from "simpl-schema";
|
//import SimpleSchema from "simpl-schema";
|
||||||
import {AssetTypes} from "./asset-types";
|
import {AssetTypes} from "./asset-types";
|
||||||
import {AssetAssignments} from "/imports/api/asset-assignments";
|
import {AssetAssignments} from "/imports/api/asset-assignments";
|
||||||
|
import {AssetAssignmentHistory} from "/imports/api/asset-assignment-history";
|
||||||
|
|
||||||
// console.log("Setting Up Assets...")
|
// console.log("Setting Up Assets...")
|
||||||
|
|
||||||
@@ -91,6 +92,7 @@ Meteor.methods({
|
|||||||
Assets.insert({assetTypeId, assetId});
|
Assets.insert({assetTypeId, assetId});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else throw new Meteor.Error("User Permission Error");
|
||||||
},
|
},
|
||||||
'assets.update'(_id, assetId, serial) {
|
'assets.update'(_id, assetId, serial) {
|
||||||
check(_id, String);
|
check(_id, String);
|
||||||
@@ -101,6 +103,7 @@ Meteor.methods({
|
|||||||
//TODO: Need to first verify there are no checked out assets to the staff member.
|
//TODO: Need to first verify there are no checked out assets to the staff member.
|
||||||
Assets.update({_id}, {$set: {assetId, serial}});
|
Assets.update({_id}, {$set: {assetId, serial}});
|
||||||
}
|
}
|
||||||
|
else throw new Meteor.Error("User Permission Error");
|
||||||
},
|
},
|
||||||
'assets.remove'(_id) {
|
'assets.remove'(_id) {
|
||||||
check(_id, String);
|
check(_id, String);
|
||||||
@@ -109,6 +112,7 @@ Meteor.methods({
|
|||||||
//TODO: Ensure we have not assigned this asset??? Not sure if we should require unassigning first.
|
//TODO: Ensure we have not assigned this asset??? Not sure if we should require unassigning first.
|
||||||
Assets.remove({_id});
|
Assets.remove({_id});
|
||||||
}
|
}
|
||||||
|
else throw new Meteor.Error("User Permission Error");
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Assigns the asset to the assignee. The assignee should either be a Student or Staff member.
|
* Assigns the asset to the assignee. The assignee should either be a Student or Staff member.
|
||||||
@@ -129,8 +133,9 @@ Meteor.methods({
|
|||||||
// Should never happen.
|
// Should never happen.
|
||||||
console.error("Error: Received incorrect assignee type in adding an assignment.");
|
console.error("Error: Received incorrect assignee type in adding an assignment.");
|
||||||
console.error(assigneeType);
|
console.error(assigneeType);
|
||||||
|
throw new Meteor.Error("Error: Received incorrect assignee type in adding an assignment.");
|
||||||
}
|
}
|
||||||
else if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
else if(Roles.userIsInRole(Meteor.userId(), "laptop-management", {anyScope:true})) {
|
||||||
let asset = Assets.findOne({assetId});
|
let asset = Assets.findOne({assetId});
|
||||||
|
|
||||||
if(asset) {
|
if(asset) {
|
||||||
@@ -147,6 +152,7 @@ Meteor.methods({
|
|||||||
console.error("Could not find the asset: " + assetId)
|
console.error("Could not find the asset: " + assetId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else throw new Meteor.Error("User Permission Error");
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Removes an assignment for the asset.
|
* Removes an assignment for the asset.
|
||||||
@@ -160,37 +166,53 @@ Meteor.methods({
|
|||||||
|
|
||||||
if(!date) date = new Date();
|
if(!date) date = new Date();
|
||||||
|
|
||||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
if(Roles.userIsInRole(Meteor.userId(), "laptop-management", {anyScope:true})) {
|
||||||
|
let asset = Assets.findOne({assetId});
|
||||||
|
|
||||||
|
if(asset) {
|
||||||
|
try {
|
||||||
|
AssetAssignmentHistory.insert({assetId, assigneeType: asset.assigneeType, assigneeId: asset.assigneeId, startDate: asset.assignmentDate, endDate: date});
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
Assets.update({assetId}, {$unset: {assigneeType, assigneeId, assignmentDate}});
|
Assets.update({assetId}, {$unset: {assigneeType, assigneeId, assignmentDate}});
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
console.error("Could not find the asset: " + assetId);
|
||||||
|
throw new Meteor.Error("Could not find the asset: " + assetId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else throw new Meteor.Error("User Permission Error");
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* A fix to remove the AssetAssignment collection and merge it with the Asset collection.
|
* A fix to remove the AssetAssignment collection and merge it with the Asset collection.
|
||||||
*/
|
*/
|
||||||
'assets.fixAssetAssignments'() {
|
'assets.fixAssetAssignments'() {
|
||||||
let assignmentDate = new Date();
|
// Removed this since it should no longer be relevant.
|
||||||
//This function just removes the need for the asset-assignments collection and merges it with assets.
|
|
||||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
|
||||||
let assets = Assets.find({}).fetch();
|
|
||||||
let assetAssignments = AssetAssignments.find({}).fetch();
|
|
||||||
|
|
||||||
let assetMap = assets.reduce((map, obj) => {
|
// let assignmentDate = new Date();
|
||||||
map[obj.assetId] = obj;
|
// //This function just removes the need for the asset-assignments collection and merges it with assets.
|
||||||
return map;
|
// if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||||
}, {});
|
// let assets = Assets.find({}).fetch();
|
||||||
|
// let assetAssignments = AssetAssignments.find({}).fetch();
|
||||||
console.log(assetMap);
|
//
|
||||||
console.log("");
|
// let assetMap = assets.reduce((map, obj) => {
|
||||||
|
// map[obj.assetId] = obj;
|
||||||
for(let next of assetAssignments) {
|
// return map;
|
||||||
console.log(next);
|
// }, {});
|
||||||
let asset = assetMap[next.assetId];
|
//
|
||||||
console.log("Updating " + asset.assetId + " to be assigned to " + next.assigneeType + ": " + next.assigneeId);
|
// console.log(assetMap);
|
||||||
let c = Assets.update({assetId: asset.assetId}, {$set: {assigneeType: next.assigneeType, assigneeId: next.assigneeId, assignmentDate}});
|
// console.log("");
|
||||||
console.log("Updated " + c + " Assets");
|
//
|
||||||
console.log(Assets.findOne({assetId: asset.assetId}));
|
// for(let next of assetAssignments) {
|
||||||
}
|
// console.log(next);
|
||||||
}
|
// let asset = assetMap[next.assetId];
|
||||||
|
// console.log("Updating " + asset.assetId + " to be assigned to " + next.assigneeType + ": " + next.assigneeId);
|
||||||
|
// let c = Assets.update({assetId: asset.assetId}, {$set: {assigneeType: next.assigneeType, assigneeId: next.assigneeId, assignmentDate}});
|
||||||
|
// console.log("Updated " + c + " Assets");
|
||||||
|
// console.log(Assets.findOne({assetId: asset.assetId}));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -7,5 +7,6 @@ import "./sites.js";
|
|||||||
import "./asset-types.js";
|
import "./asset-types.js";
|
||||||
import "./assets.js";
|
import "./assets.js";
|
||||||
import "./asset-assignments.js";
|
import "./asset-assignments.js";
|
||||||
|
import "./asset-assignment-history.js";
|
||||||
|
|
||||||
// console.log("Finished setting up server side models.");
|
// console.log("Finished setting up server side models.");
|
||||||
@@ -9,6 +9,8 @@
|
|||||||
import {Assets} from "/imports/api/assets";
|
import {Assets} from "/imports/api/assets";
|
||||||
import {Students} from "/imports/api/students";
|
import {Students} from "/imports/api/students";
|
||||||
import {AssetTypes} from "/imports/api/asset-types";
|
import {AssetTypes} from "/imports/api/asset-types";
|
||||||
|
import Button, { Label } from '@smui/button';
|
||||||
|
import Dialog, { Title, Content, Actions } from '@smui/dialog';
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
Meteor.subscribe('assets');
|
Meteor.subscribe('assets');
|
||||||
@@ -53,6 +55,11 @@
|
|||||||
const formatDate = (date) => {
|
const formatDate = (date) => {
|
||||||
return date.toLocaleDateString('en-us', {weekday: 'long', year: 'numeric', month: 'short', day: 'numeric'});
|
return date.toLocaleDateString('en-us', {weekday: 'long', year: 'numeric', month: 'short', day: 'numeric'});
|
||||||
}
|
}
|
||||||
|
const unassign = () => {
|
||||||
|
if(confirm("Unassign Asset?")) {
|
||||||
|
Meteor.call("assets.unassign", foundAsset.assetId);
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
@@ -75,8 +82,26 @@
|
|||||||
<div>Assigned on: {formatDate(foundAsset.assignmentDate)}</div>
|
<div>Assigned on: {formatDate(foundAsset.assignmentDate)}</div>
|
||||||
<div>Assigned to: {foundAssignee.firstName} {foundAssignee.lastName}
|
<div>Assigned to: {foundAssignee.firstName} {foundAssignee.lastName}
|
||||||
{#if foundAssignee.grade} ~ {foundAssignee.grade} {/if}({foundAssignee.email})</div>
|
{#if foundAssignee.grade} ~ {foundAssignee.grade} {/if}({foundAssignee.email})</div>
|
||||||
|
|
||||||
|
<Button variant="raised" touch on:click={unassign}>
|
||||||
|
<Label style="color: white">Unassign</Label>
|
||||||
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
<!-- <Dialog bind:open={showDialog} aria-labelledby="Confirm" aria-describedby="Unassign Confirmation">-->
|
||||||
|
<!-- <!– Title cannot contain leading whitespace due to mdc-typography-baseline-top() –>-->
|
||||||
|
<!-- <Title id="simple-title">Unassign Asset?</Title>-->
|
||||||
|
<!-- <Content id="simple-content"></Content>-->
|
||||||
|
<!-- <Actions>-->
|
||||||
|
<!-- <Button on:click={() => (clicked = 'No')}>-->
|
||||||
|
<!-- <Label>No</Label>-->
|
||||||
|
<!-- </Button>-->
|
||||||
|
<!-- <Button on:click={() => (clicked = 'Yes')}>-->
|
||||||
|
<!-- <Label>Yes</Label>-->
|
||||||
|
<!-- </Button>-->
|
||||||
|
<!-- </Actions>-->
|
||||||
|
<!-- </Dialog>-->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
Reference in New Issue
Block a user