Skip to content

Commit

Permalink
#closes #47
Browse files Browse the repository at this point in the history
  • Loading branch information
VanCoding committed Aug 16, 2015
1 parent 3fca9b0 commit 5030603
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 139 deletions.
6 changes: 1 addition & 5 deletions lib/routes/equipment/items/get.js
Expand Up @@ -34,9 +34,6 @@ module.exports = function(req,res){
query["contents."+type+".ids"] = id;
console.log(query);
req.app.db.collection("equipment").findOne(query,{type:true,id:true},cb);
},
function(cb){
req.app.db.collection("equipmenttypes").findOne({_id:type},{manufacturer:true},cb);
}
],function(err,data){
if(err) return res.fail();
Expand All @@ -48,7 +45,6 @@ module.exports = function(req,res){
var logs = data[1];
var location = data[2];
var container = data[3]
var manufacturer = data[4].manufacturer;

req.app.db.collection("equipmenttypes").find({_id:{$in:types}},{name:true}).toArray(function(err,types){
if(err) return res.fail();
Expand All @@ -60,7 +56,7 @@ module.exports = function(req,res){
if(container) container.name = types[container.type].name;

res.writeHead(200,"OK",{"Content-Type":"application/json"});
res.end(JSON.stringify({item:item,logs:logs,location:location,container:container,manufacturer:manufacturer}));
res.end(JSON.stringify({item:item,logs:logs,location:location,container:container}));
});
});
}
1 change: 0 additions & 1 deletion lib/routes/equipment/types/find.js
Expand Up @@ -16,7 +16,6 @@ module.exports = function(req,res){
if(needed.length){
query.$and = needed;
}
console.log(JSON.stringify(query,null,"\t"));
}
req.app.db.collection("equipmenttypes").find(query,{_id:true,name:true,manufacturer:true,category:true,count:true,weight:true,height:true,width:true,length:true}).toArray(function(err,items){
if(err) return res.fail(err);
Expand Down
3 changes: 1 addition & 2 deletions lib/routes/equipment/types/get.js
Expand Up @@ -22,14 +22,13 @@ module.exports = function(req,res){
contents:true
},function(err,item){
if(err || item == null) return cb(err||new Error("Equipmenttype not found"));
if(item.contents && item.contents.length){
if(item.contents instanceof Array){
req.app.db.collection("equipmenttypes").find({_id:{$in:item.contents}},{name:true}).toArray(function(err,types){
if(err) return cb(err);
item.contents = types;
cb(null,item);
})
}else{
item.contents = [];
cb(null,item);
}
})
Expand Down
13 changes: 4 additions & 9 deletions lib/routes/projects/checkins/get.js
Expand Up @@ -8,10 +8,7 @@ module.exports = function(req,res){
var projectid = mongo.ObjectID(req.params.project);
async.parallel([
function(cb){
req.app.db.collection("equipmentcategories").find({},{name:true}).toArray(cb)
},
function(cb){
req.app.db.collection("equipmenttypes").find({},{name:true,category:true,hasItems:true}).toArray(cb);
req.app.db.collection("equipmenttypes").find({},{name:true,hasItems:true,contents:true}).toArray(cb);
},
function(cb){
req.app.db.collection("projects").findOne({_id:projectid},{balance:true},cb)
Expand All @@ -22,10 +19,9 @@ module.exports = function(req,res){
}
],function(err,results){
if(err) return res.fail();
var categories = util.createIndex(results[0],"_id");
var types = util.createIndex(results[1],"_id");
var balance = results[2].balance;
var checkin = results[3];
var types = util.createIndex(results[0],"_id");
var balance = results[1].balance;
var checkin = results[2];
var items;
var history = [];

Expand Down Expand Up @@ -56,7 +52,6 @@ module.exports = function(req,res){
}
res.writeHead(200,"OK",{"Content-Type":"application/json"});
res.end(JSON.stringify({
categories:categories,
types:types,
history:history
}));
Expand Down
58 changes: 32 additions & 26 deletions lib/views/checkin.jade
Expand Up @@ -91,7 +91,7 @@ mixin renderCaseEntry(entry,level)
-var parentscanreceiver = this.scanreceiver;
if entry.items
each contents,item in entry.items
- this.scanreceiver = {parent:parentscanreceiver,contents:contents}
- this.scanreceiver = {parent:parentscanreceiver,contents:contents, entry:entry}
div(style="paddingLeft:"+(level*20)+"px")
= this.props.data.types[entry.type].name
b= " #"+item
Expand Down Expand Up @@ -155,7 +155,7 @@ script.
exports.startScan = function(type){
return function(){
this.refs.scanbutton.scan();
this.refs.scanbutton.onEquipmenttypeChanged(type);
this.refs.scanbutton.onEquipmenttypeChanged(type,[{value:type,label:this.props.data.types[type].name}]);
}.bind(this)
}

Expand All @@ -182,21 +182,30 @@ script.
}

exports.insertOrClose = function(entry,receiver){
var itemId = Object.keys(entry.items)[0];
var item = entry.items[itemId];
while(receiver != null){
for(var i = 0; i < receiver.contents.length; i++){
if(receiver.contents[i].type == entry.type){
receiver.contents[i].count ++;
receiver.contents[i].items[Object.keys(entry.items)[0]] = entry.items[Object.keys(entry.items)[0]];
receiver.contents[i].items[itemId] = item;
//reorder this item to the end
receiver.contents.push(receiver.contents.splice(i,1)[0]);
this.update();
return;
}
}
var type = this.props.data.types[receiver.entry.type];
if(type.contents == "*"){
receiver.contents.push(entry);
this.update();
return;
}
receiver = receiver.parent;
}
if(this.props.entry) this.finishEntry();
this.props.entry = entry;
if(!entry.items[Object.keys(entry.items)[0]].length){
if(!entry.items[itemId].length && this.props.data.types[entry.type].contents != "*"){
this.finishEntry();
}else{
this.update();
Expand All @@ -215,31 +224,28 @@ script.
}

exports.getEntryContents = function(entry,item,cb){
async.parallel([
function(cb){
client.getEquipment(entry.type,item,cb)
},
function(cb){
client.getEquipmentType(entry.type,cb)
}
],function(err,results){
client.getEquipment(entry.type,item,function(err,data){

var item = data.item;

if(err) return cb(err);
var item = results[0].item;
var type = results[1];

var type = this.props.data.types[entry.type];

var entries = [];
for(var i = 0; i < type.contents.length; i++){
var t = type.contents[i]._id;
var subentry = {
supplier:entry.supplier,
type:t,
count:item.contents[t]?item.contents[t].count:0
};
if(this.props.data.types[t].hasItems){
subentry.items = {};
subentry.count = 0;
if(type.contents instanceof Array){
for(var i = 0; i < type.contents.length; i++){
var t = type.contents[i]._id;
var subentry = {
supplier:entry.supplier,
type:t,
count:item.contents[t]?item.contents[t].count:0
};
if(this.props.data.types[t].hasItems){
subentry.items = {};
subentry.count = 0;
}
entries.push(subentry);
}
entries.push(subentry);
}
if(!entry.items) entry.items = {};
entry.items[item.id] = entries;
Expand Down
2 changes: 1 addition & 1 deletion lib/views/checkout.jade
Expand Up @@ -134,7 +134,7 @@ script.
exports.startScan = function(type){
return function(){
this.refs.scanbutton.scan();
this.refs.scanbutton.onEquipmenttypeChanged(type);
this.refs.scanbutton.onEquipmenttypeChanged(type,[{value:type,label:this.props.data.types[type].name}]);
}.bind(this)
}

Expand Down
88 changes: 48 additions & 40 deletions lib/views/equipmentitem.jade
@@ -1,7 +1,7 @@
extends ./base.jade

append body
if this.props.item
if this.props.item && this.props.type
.container
h2
= this.props.item.name+" "+this.props.item.id
Expand All @@ -17,7 +17,7 @@ append body
div.text-center
img.img-responsive(src="/api/equipment/"+this.props.item.type+"/image")
br
img(src="/api/barcode/EQ-"+this.props.item.type+"-"+this.props.item.id+"/"+(this.props.manufacturer?(this.props.manufacturer+" "):"")+this.props.item.name width="100%")
img(src="/api/barcode/EQ-"+this.props.item.type+"-"+this.props.item.id+"/"+(this.props.type.manufacturer?(this.props.type.manufacturer+" "):"")+this.props.item.name width="100%")
.col-lg-9.col-md-8.col-sm-6.col-xs-12
h3 Daten
.form-horizontal
Expand Down Expand Up @@ -76,36 +76,37 @@ append body
| Objekt erfasst
when "removed"
| Objekt entfernt
.row
.col-xs-12
.pull-left
h3 Inhalt
.btn-toolbar.pull-right(style="margin-top:18px")
ScanButton.pull-left(onScan=this.handleScan supplier="own")
.btn-group.pull-left(style="margin-left:10px")
div(className="btn "+(this.props.remove?"btn-primary":"btn-default") onClick=this.toggleMode)
i.glyphicon.glyphicon-minus
div(className="btn "+(this.props.remove?"btn-default":"btn-primary") onClick=this.toggleMode)
i.glyphicon.glyphicon-plus
table.table.table-striped.table-hover
thead
tr
th ID
th Name
th Menge
th Einzel IDs
tbody
each item, id in this.props.item.contents
if item.newcount > 0
tr
td= id
td= item.name
td= item.newcount
td
each iid, i in item.newids
if i > 0
= ", "
a(href="/equipment/"+id+"/"+iid)= iid
if this.props.type.contents
.row
.col-xs-12
.pull-left
h3 Inhalt
.btn-toolbar.pull-right(style="margin-top:18px")
ScanButton.pull-left(onScan=this.handleScan supplier="own")
.btn-group.pull-left(style="margin-left:10px")
div(className="btn "+(this.props.remove?"btn-primary":"btn-default") onClick=this.toggleMode)
i.glyphicon.glyphicon-minus
div(className="btn "+(this.props.remove?"btn-default":"btn-primary") onClick=this.toggleMode)
i.glyphicon.glyphicon-plus
table.table.table-striped.table-hover
thead
tr
th ID
th Name
th Menge
th Einzel IDs
tbody
each item, id in this.props.item.contents
if item.newcount > 0
tr
td= id
td= item.name
td= item.newcount
td
each iid, i in item.newids
if i > 0
= ", "
a(href="/equipment/"+id+"/"+iid)= iid
script.
var client = require("../client.js");
var TextArea = require("react-textarea-autosize");
Expand All @@ -117,18 +118,18 @@ script.
}

exports.componentDidMount = function(){
if(!this.props.item) this.refresh();
if(!this.props.item) this.loadItem();
if(!this.props.type) this.loadType();
}

exports.refresh = function(){
exports.loadItem = function(){
var self = this;
client.getEquipment(this.props.params.type,this.props.params.id,function(err,data){
if(err) return;
self.props.item = data.item;
self.props.logs = data.logs;
self.props.location = data.location;
self.props.container = data.container;
self.props.manufacturer = data.manufacturer;
for(var type in self.props.item.contents){
self.props.item.contents[type].newcount = self.props.item.contents[type].count;
if(self.props.item.contents[type].ids){
Expand All @@ -139,6 +140,14 @@ script.
});
}

exports.loadType = function(){
client.getEquipmentType(this.props.params.type,function(err,data){
if(err) return;
this.props.type = data;
this.update();
}.bind(this));
}

exports.onSerialNumberChange = function(e){
this.props.item.serialnumber = e.target.value;
this.update();
Expand All @@ -159,7 +168,6 @@ script.
}

exports.handleScan = function(code){
console.log("SCAN",code);
if(!code.count) code.count = 1;
if(this.props.remove){
if(!this.props.item.contents[code.type]){
Expand All @@ -180,13 +188,14 @@ script.
delete this.props.item.contents[code.type].newcount;
delete this.props.item.contents[code.type].newids;
}
console.log(this.props.item.contents);
this.update();
}else{
if(this.props.type.contents instanceof Array){
var allowed = this.props.type.contents.map(function(type){return type._id});
if(allowed.indexOf(parseInt(code.type,10)) < 0) return this.playErrorSound();
}
if(code.item){
console.log("getting container");
client.getEquipmentContainer(code.type,code.item,function(err,container){
console.log("container:",container);
if(err) return this.playErrorSound();
if(this.props.item.contents[code.type] && this.props.item.contents[code.type].newids && this.props.item.contents[code.type].newids.indexOf(code.item) >= 0) return this.playErrorSound();
if(container && container != this.props.params.id) return this.playErrorSound();
Expand Down Expand Up @@ -219,7 +228,6 @@ script.
if(!this.props.item.contents[code.type].newids) this.props.item.contents[code.type].newids = [];
this.props.item.contents[code.type].newids.push(code.item);
}
console.log(this.props.item.contents)
this.update();
};
}
Expand Down

0 comments on commit 5030603

Please sign in to comment.