Just changes.
This commit is contained in:
parent
5ba618f471
commit
8bd3fb1853
8 changed files with 214 additions and 13 deletions
|
|
@ -41,6 +41,9 @@
|
|||
<div>
|
||||
<button class="locationTypes navSetup" id="locationTypes">Location Types</button>
|
||||
</div>
|
||||
<div>
|
||||
<button class="locaions navSetup" id="locations">Locations</button>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="grid">
|
||||
<div>
|
||||
<button class="secondary" id="importLocationTypes">Import from CSV</button>
|
||||
</div>
|
||||
<div>
|
||||
<button class="primary right" id="saveLocationType">Save</button>
|
||||
</div>
|
||||
|
|
|
|||
14
client/Locations/locationInfo.html
Normal file
14
client/Locations/locationInfo.html
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<template name="locationInfo">
|
||||
{{#each parentLocations}}
|
||||
<details>
|
||||
<summary role="button" class="outline topLevel" id="{{_id}}">{{locationName}}</summary>
|
||||
<div>
|
||||
{{#each childLocation}}
|
||||
<details>
|
||||
<summary role="button" class="innerLevel" id="{{_id}}">{{locationName}}</summary>
|
||||
</details>
|
||||
{{/each}}
|
||||
</div>
|
||||
</details>
|
||||
{{/each}}
|
||||
</template>
|
||||
33
client/Locations/locationInfo.js
Normal file
33
client/Locations/locationInfo.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { Roles } from 'meteor/roles';
|
||||
import { FlowRouter } from 'meteor/ostrio:flow-router-extra';
|
||||
import { Locations } from '../../imports/api/locations.js';
|
||||
import { LocationTypes } from '../../imports/api/locationTypes.js';
|
||||
import _classCheckPrivateStaticFieldDescriptor from '@babel/runtime/helpers/classCheckPrivateStaticFieldDescriptor';
|
||||
|
||||
Template.locationInfo.onCreated(function () {
|
||||
this.subscribe("LocationTypes");
|
||||
this.subscribe("Locations");
|
||||
});
|
||||
|
||||
Template.locationInfo.onRendered(function () {
|
||||
|
||||
});
|
||||
|
||||
Template.locationInfo.helpers({
|
||||
parentLocations: function () {
|
||||
return Locations.find({ isChild: false });
|
||||
},
|
||||
childLocation: function () {
|
||||
let parId = Session.get("parentId");
|
||||
console.log("Child Loc: " + parId);
|
||||
return Locations.find({ parentId: parId });
|
||||
},
|
||||
});
|
||||
|
||||
Template.locationInfo.events({
|
||||
'click .topLevel'(e) {
|
||||
let parentId = e.currentTarget.id;
|
||||
console.log("Parent ID: " + parentId);
|
||||
Session.set("parentId", parentId);
|
||||
},
|
||||
});
|
||||
|
|
@ -1,4 +1,55 @@
|
|||
<template name="locations">
|
||||
<h1>Locations</h1>
|
||||
|
||||
<p>You can build out your storage structure heere. Setting a location as a 'child' will prompt you to select the 'parent' location.</p>
|
||||
<hr>
|
||||
<div class="grid">
|
||||
<div>
|
||||
<label for="lcationName">Location Name *</label>
|
||||
<input type="text" class="locationName" id="locationName" required />
|
||||
</div>
|
||||
<div>
|
||||
<label for="locationDesc">Description</label>
|
||||
<input type="text" class="locationDesc" id="locationDesc" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid">
|
||||
<div>
|
||||
<label for="locationType">Location Type *</label>
|
||||
<select name="locationType" id="locationType" class="locationType">
|
||||
<option value="" disabled selected>Choose...</option>
|
||||
{{#each locTypes}}
|
||||
<option value="{{locationTypeName}} | {{_id}}">{{locationTypeName}}</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid">
|
||||
<div>
|
||||
<label for="locationIsChild">
|
||||
<input type="checkbox" class="locationIsChild" id="locationIsChild">
|
||||
Child Location
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid">
|
||||
{{#if $eq isChild true}}
|
||||
<div>
|
||||
<label for="parentLocation">Parent Location *</label>
|
||||
<select name="parentLocation" id="parentLocation" required>
|
||||
<option value="" disabled selected>Choose...</option>
|
||||
{{#each locations}}
|
||||
<option value="{{locationNmae}} | {{_id}}">{{locationName}}</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
<div class="grid">
|
||||
<div>
|
||||
<button class="primary saveLocation right" id="saveLocation">Save</button>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
{{> locationInfo}}
|
||||
{{> snackbar}}
|
||||
</template>
|
||||
|
|
@ -1,19 +1,92 @@
|
|||
import { Roles } from 'meteor/roles';
|
||||
import { FlowRouter } from 'meteor/ostrio:flow-router-extra';
|
||||
// import { Locations } from '../../imports/api/locations.js';
|
||||
|
||||
Template.locations.onCreated(function() {
|
||||
import { Locations } from '../../imports/api/locations.js';
|
||||
import { LocationTypes } from '../../imports/api/locationTypes.js';
|
||||
|
||||
Template.locations.onCreated(function () {
|
||||
this.subscribe("LocationTypes");
|
||||
this.subscribe("Locations");
|
||||
});
|
||||
|
||||
Template.locations.onRendered(function() {
|
||||
|
||||
Template.locations.onRendered(function () {
|
||||
Session.set("isChild", false);
|
||||
});
|
||||
|
||||
Template.locations.helpers({
|
||||
|
||||
isChild: function () {
|
||||
return Session.get("isChild");
|
||||
},
|
||||
locations: function () {
|
||||
return Locations.find({});
|
||||
},
|
||||
locTypes: function () {
|
||||
return LocationTypes.find({});
|
||||
}
|
||||
});
|
||||
|
||||
Template.locations.events({
|
||||
'change #locationIsChild'(event) {
|
||||
console.log("Clicked.");
|
||||
let isChild = $("#locationIsChild").prop('checked');
|
||||
if (isChild) {
|
||||
Session.set("isChild", true);
|
||||
} else {
|
||||
Session.set("isChild", false);
|
||||
}
|
||||
},
|
||||
'click #saveLocation'(event) {
|
||||
let locName = $("#locationName").val();
|
||||
let locDesc = $("#locationDesc").val();
|
||||
let locType = $("#locationType").val();
|
||||
let isChild = $("#locationIsChild").prop("checked");
|
||||
let parentLocation = $("#parentLocation").val();
|
||||
|
||||
let parentInfo = [];
|
||||
let parentName = "";
|
||||
let parentId = "";
|
||||
|
||||
let locTypeParts = locType.split(' | ');
|
||||
let locTypeName = locTypeParts[0];
|
||||
let locTypeId = locTypeParts[1];
|
||||
|
||||
if (isChild == true) {
|
||||
// split the parent location name details
|
||||
if (parentLocation == "" || parentLocation == null) {
|
||||
showSnackbar("Parent Location is Required!", "red");
|
||||
return;
|
||||
} else {
|
||||
parentInfo = parentLocation.split(' | ');
|
||||
parentName = parentInfo[0];
|
||||
parentId = parentInfo[1];
|
||||
}
|
||||
}
|
||||
|
||||
if (locName == null || locName == "") {
|
||||
showSnackbar("Location Name is Required!", "red");
|
||||
return;
|
||||
} else if (locType == "" || locType == null) {
|
||||
showSnackbar("Location Type is Required!", "red");
|
||||
return;
|
||||
} else {
|
||||
let addLocation = async () => {
|
||||
try {
|
||||
const result = await Meteor.callAsync('add.location', locName, locDesc, locTypeName, locTypeId, isChild, parentName, parentId);
|
||||
if (!result) {
|
||||
showSnackbar("Could not add location!", "red");
|
||||
return;
|
||||
} else {
|
||||
showSnackbar("Location Successfuly Added!", "green");
|
||||
$("#locationName").val("");
|
||||
$("#locationDesc").val("");
|
||||
$("#locationType").val("");
|
||||
$("#isChild").prop('checked', false);
|
||||
$("#parentLocation").val("");
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
addLocation();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -12,5 +12,29 @@ Locations.allow({
|
|||
});
|
||||
|
||||
Meteor.methods({
|
||||
async 'add.location' (locName, locDesc, locTypeName, locTypeId, isChild, parentName, parentId) {
|
||||
check(locName, String);
|
||||
check(locDesc, String);
|
||||
check(locTypeName, String);
|
||||
check(locTypeId, String);
|
||||
check(isChild, Boolean);
|
||||
check(parentName, String);
|
||||
check(parentId, String);
|
||||
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('You are not allowed to add locations. Make sure you are logged in with valid user credentials.');
|
||||
}
|
||||
|
||||
return await Locations.insertAsync({
|
||||
locationName: locName,
|
||||
locationDesc: locDesc,
|
||||
locationTypeName: locTypeName,
|
||||
locationTypeId: locTypeId,
|
||||
isChild: isChild,
|
||||
parentName: parentName,
|
||||
parentId: parentId,
|
||||
addedOn: new Date(),
|
||||
addedBy: this.userId,
|
||||
});
|
||||
},
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue