Created
May 18, 2017 09:05
-
-
Save wizlif/837e625695785931d6a208b498e20b74 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getInput(documents, crop_data) { | |
let crop = crop_data.crop; | |
let inputs = { | |
'title': crop, | |
'src': this.global.imageUrl+crop_data.src, | |
category: [] | |
}; | |
let actual_documents = []; | |
for (let document of documents) { | |
if(document.crops.constructor==Array){ | |
if (this.global.contains(document.crops, crop)) { | |
actual_documents.push(document); | |
} | |
} | |
} | |
for (let doc of actual_documents) { | |
let category_exists: boolean = false; | |
let category_index: string; | |
for (let index in inputs.category) { | |
if (doc.category === inputs.category[index].name) { | |
category_exists = true; | |
category_index = index; | |
} | |
} | |
if (category_exists == false) { | |
inputs.category.push({ | |
name: doc.category, | |
values: [ | |
{ | |
"name": doc.name, | |
"src": this.global.imageUrl+doc.photo_url, | |
"supplier": doc.supplier, | |
"price": doc.price, | |
"unit": doc.unit, | |
"quantity": doc.quantity, | |
"desc":doc.description | |
} | |
] | |
}) | |
} else { | |
inputs.category[category_index].values.push({ | |
"name": doc.name, | |
"src":this.global.imageUrl+doc.photo_url, | |
"supplier": doc.supplier, | |
"price": doc.price, | |
"unit": doc.unit, | |
"quantity": doc.quantity, | |
"desc":doc.description | |
}) | |
} | |
} | |
return inputs; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment